Spaces:
Sleeping
Sleeping
Delete audio_generator.py
Browse files- audio_generator.py +0 -41
audio_generator.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import httpx
|
| 3 |
-
|
| 4 |
-
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY") # Make sure to set this in your environment
|
| 5 |
-
VOICE_ID = "EXAVITQu4vr4xnSDxMaL" # Default voice ID; you can replace with your preferred voice
|
| 6 |
-
|
| 7 |
-
def generate_audio_from_text(text, output_path="output/audio.mp3"):
|
| 8 |
-
try:
|
| 9 |
-
url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}"
|
| 10 |
-
|
| 11 |
-
headers = {
|
| 12 |
-
"Accept": "audio/mpeg",
|
| 13 |
-
"Content-Type": "application/json",
|
| 14 |
-
"xi-api-key": ELEVENLABS_API_KEY
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
payload = {
|
| 18 |
-
"text": text,
|
| 19 |
-
"model_id": "eleven_monolingual_v1",
|
| 20 |
-
"voice_settings": {
|
| 21 |
-
"stability": 0.4,
|
| 22 |
-
"similarity_boost": 0.8
|
| 23 |
-
}
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
with httpx.Client() as client:
|
| 27 |
-
response = client.post(url, headers=headers, json=payload)
|
| 28 |
-
|
| 29 |
-
response.raise_for_status()
|
| 30 |
-
|
| 31 |
-
os.makedirs(os.path.dirname(output_path), exist_ok=True)
|
| 32 |
-
|
| 33 |
-
with open(output_path, "wb") as f:
|
| 34 |
-
f.write(response.content)
|
| 35 |
-
|
| 36 |
-
print(f"[Done] Audio saved to: {output_path}")
|
| 37 |
-
return output_path
|
| 38 |
-
|
| 39 |
-
except Exception as e:
|
| 40 |
-
print(f"[Error] Audio generation failed: {str(e)}")
|
| 41 |
-
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|