Update app.py
Browse files
app.py
CHANGED
@@ -54,8 +54,8 @@ def get_image_description(image):
|
|
54 |
# Function to convert text to speech using ElevenLabs
|
55 |
def tts(text):
|
56 |
try:
|
57 |
-
# Generate audio
|
58 |
-
|
59 |
text=text,
|
60 |
voice_id="JBFqnCBsd6RMkjVDRZzb", # Replace with your preferred voice ID
|
61 |
model_id="eleven_multilingual_v2",
|
@@ -63,12 +63,13 @@ def tts(text):
|
|
63 |
)
|
64 |
|
65 |
# Save the audio to a temporary file
|
66 |
-
|
67 |
-
with open(
|
68 |
-
|
|
|
69 |
|
70 |
# Play the audio in Streamlit
|
71 |
-
st.audio(
|
72 |
except Exception as e:
|
73 |
st.error(f"Error generating speech: {e}")
|
74 |
|
|
|
54 |
# Function to convert text to speech using ElevenLabs
|
55 |
def tts(text):
|
56 |
try:
|
57 |
+
# Generate the audio (returns a generator)
|
58 |
+
audio_generator = elevenlabs_client.text_to_speech.convert(
|
59 |
text=text,
|
60 |
voice_id="JBFqnCBsd6RMkjVDRZzb", # Replace with your preferred voice ID
|
61 |
model_id="eleven_multilingual_v2",
|
|
|
63 |
)
|
64 |
|
65 |
# Save the audio to a temporary file
|
66 |
+
audio_file_path = "temp_audio.mp3"
|
67 |
+
with open(audio_file_path, "wb") as f:
|
68 |
+
for chunk in audio_generator:
|
69 |
+
f.write(chunk)
|
70 |
|
71 |
# Play the audio in Streamlit
|
72 |
+
st.audio(audio_file_path, format="audio/mp3")
|
73 |
except Exception as e:
|
74 |
st.error(f"Error generating speech: {e}")
|
75 |
|