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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -153,15 +153,16 @@ if STATEMENT:
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 byte array
157
- wav_data = sf.write_buffer(audio_data, samplerate=speech['sampling_rate'])
158
-
159
- # Encode the byte array to base64
160
- base64_audio = base64.b64encode(wav_data).decode("utf-8")
161
-
162
- # Generate a download link
163
- download_link = f"<a href='data:audio/wav;base64,{base64_audio}'>Download Speech</a>"
164
- st.sidebar.write(download_link, unsafe_allow_html=True)
 
165
 
166
  st.sidebar.write('Text converted to speech (download available)')
167
  else:
 
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: