Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -158,14 +158,28 @@ def generate_audio_elevenlabs(text):
|
|
| 158 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
| 159 |
VOICE_ID = 'ehbJzYLQFpwbJmGkqbnW'
|
| 160 |
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
| 161 |
-
headers = {
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
| 164 |
if response.ok:
|
| 165 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
| 166 |
for chunk in response.iter_content(chunk_size=1024):
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
| 169 |
else:
|
| 170 |
print(f"Error generating audio: {response.text}")
|
| 171 |
return None
|
|
|
|
| 158 |
XI_API_KEY = os.environ['ELEVENLABS_API']
|
| 159 |
VOICE_ID = 'ehbJzYLQFpwbJmGkqbnW'
|
| 160 |
tts_url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}/stream"
|
| 161 |
+
headers = {
|
| 162 |
+
"Accept": "application/json",
|
| 163 |
+
"xi-api-key": XI_API_KEY
|
| 164 |
+
}
|
| 165 |
+
data = {
|
| 166 |
+
"text": str(text),
|
| 167 |
+
"model_id": "eleven_multilingual_v2",
|
| 168 |
+
"voice_settings": {
|
| 169 |
+
"stability": 1.0,
|
| 170 |
+
"similarity_boost": 0.0,
|
| 171 |
+
"style": 0.60,
|
| 172 |
+
"use_speaker_boost": False
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
| 176 |
if response.ok:
|
| 177 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
| 178 |
for chunk in response.iter_content(chunk_size=1024):
|
| 179 |
+
if chunk:
|
| 180 |
+
f.write(chunk)
|
| 181 |
+
audio_path = f.name
|
| 182 |
+
return audio_path # Return audio path for automatic playback
|
| 183 |
else:
|
| 184 |
print(f"Error generating audio: {response.text}")
|
| 185 |
return None
|