richardorama commited on
Commit
de29661
·
verified ·
1 Parent(s): 1801762

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -147,24 +147,19 @@ if STATEMENT:
147
  if st.sidebar.button('Convert Text to Speech'):
148
  text = STATEMENT
149
 
150
- # Generate speech
151
- speech = tts(text)
152
-
153
- # Access the audio waveform from the dictionary (assuming key name is 'audio')
154
- audio_data = speech['audio']
155
-
156
- # Convert audio data to a bytes object
157
- wav_bytes = sf.write(None, audio_data, samplerate=speech['sampling_rate'], format='wav')
158
-
159
- # Create a download button for the audio file
160
- st.sidebar.download_button(
161
- label="Download Audio",
162
- data=wav_bytes,
163
- file_name="generated_audio.wav",
164
- mime="audio/wav"
165
- )
166
-
167
- st.sidebar.write('Text converted to speech (download available)')
168
  else:
169
  st.sidebar.button('Convert Text to Speech', disabled=True)
170
  # st.warning(' Please enter Statement!')
 
147
  if st.sidebar.button('Convert Text to Speech'):
148
  text = STATEMENT
149
 
150
+ try:
151
+ speech = tts(text)
152
+ audio_data = speech['audio']
153
+ wav_bytes = sf.write(None, audio_data, samplerate=speech['sampling_rate'], format='wav')
154
+ st.sidebar.download_button(
155
+ label="Download Audio",
156
+ data=wav_bytes,
157
+ file_name="generated_audio.wav",
158
+ mime="audio/wav"
159
+ )
160
+ st.sidebar.write('Text converted to speech (download available)')
161
+ except Exception as e:
162
+ st.sidebar.write(f"Error: {str(e)}")
 
 
 
 
 
163
  else:
164
  st.sidebar.button('Convert Text to Speech', disabled=True)
165
  # st.warning(' Please enter Statement!')