Solshine commited on
Commit
6ad68ac
·
verified ·
1 Parent(s): 0345c31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -119,11 +119,14 @@ def launch_bot():
119
  st.write("Convert to Audio 🔊")
120
  with st.popover("Open Audio"):
121
  message2 = {"role": "assistant", "content": "Converting text to speech. This may take a few minutes."}
122
- st.session_state.messages.append(message2)
123
- sound_file = BytesIO()
124
- tts = gTTS('Add text-to-speech to your app', lang='en')
125
- tts.write_to_fp(sound_file)
126
- st.audio(sound_file)
 
 
 
127
 
128
 
129
 
 
119
  st.write("Convert to Audio 🔊")
120
  with st.popover("Open Audio"):
121
  message2 = {"role": "assistant", "content": "Converting text to speech. This may take a few minutes."}
122
+ # Create temporary file for audio
123
+ with tempfile.NamedTemporaryFile(suffix=".mp3") as temp_file:
124
+ tts = gTTS('Add text-to-speech to your app', lang='en')
125
+ tts.write_to_fp(temp_file)
126
+ temp_file.seek(0) # rewind the file pointer
127
+
128
+ # Play the audio file
129
+ st.audio(temp_file)
130
 
131
 
132