Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -92,23 +92,17 @@ def generate_audio_elevenlabs(text):
|
|
92 |
"use_speaker_boost": False
|
93 |
}
|
94 |
}
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
return audio_path # Ensure the path is to a valid audio file
|
107 |
-
else:
|
108 |
-
logging.error(f"Error generating audio: {response.text}")
|
109 |
-
return None
|
110 |
-
except Exception as e:
|
111 |
-
logging.error(f"Exception in generating audio: {str(e)}")
|
112 |
return None
|
113 |
|
114 |
|
|
|
92 |
"use_speaker_boost": False
|
93 |
}
|
94 |
}
|
95 |
+
response = requests.post(tts_url, headers=headers, json=data, stream=True)
|
96 |
+
if response.ok:
|
97 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as f:
|
98 |
+
for chunk in response.iter_content(chunk_size=1024):
|
99 |
+
if chunk:
|
100 |
+
f.write(chunk)
|
101 |
+
audio_path = f.name
|
102 |
+
logging.debug(f"Audio saved to {audio_path}")
|
103 |
+
return audio_path # Return audio path for automatic playback
|
104 |
+
else:
|
105 |
+
logging.error(f"Error generating audio: {response.text}")
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
return None
|
107 |
|
108 |
|