adil9858 commited on
Commit
c3f366c
·
verified ·
1 Parent(s): 27e9a0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
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 using ElevenLabs
58
- audio = 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,12 +63,13 @@ def tts(text):
63
  )
64
 
65
  # Save the audio to a temporary file
66
- audio_path = "temp_audio.mp3"
67
- with open(audio_path, "wb") as f:
68
- f.write(audio)
 
69
 
70
  # Play the audio in Streamlit
71
- st.audio(audio_path, format="audio/mp3")
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