Solshine commited on
Commit
7270f61
1 Parent(s): 04f90d5

Add audio convert button

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -103,29 +103,31 @@ def launch_bot():
103
 
104
  # If assistant has most recently reaponded create audio of response
105
  if st.session_state.messages[-1]["role"] == "assistant":
106
- #text-to-speech
107
- print("Calling in Text-to-speech via suno/bark-small")
108
- synthesiser = pipeline("text-to-speech", "suno/bark-small")
109
-
110
- speech = synthesiser(response, forward_params={"do_sample": True})
111
-
112
- scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"])
113
- # ST interface for audio
114
- print("Now we try to display the audio file in the app")
115
- audio_file = open('bark_out.wav', 'rb')
116
- audio_bytes = audio_file.read()
117
-
118
- st.audio(audio_bytes, format='audio/wav')
119
-
120
- sample_rate = 44100 # 44100 samples per second
121
- seconds = 2 # Note duration of 2 seconds
122
- frequency_la = 440 # Our played note will be 440 Hz
123
- # Generate array with seconds*sample_rate steps, ranging between 0 and seconds
124
- t = np.linspace(0, seconds, seconds * sample_rate, False)
125
- # Generate a 440 Hz sine wave
126
- note_la = np.sin(frequency_la * t * 2 * np.pi)
127
-
128
- st.audio(note_la, sample_rate=sample_rate)
129
 
 
 
130
  if __name__ == "__main__":
131
  launch_bot()
 
103
 
104
  # If assistant has most recently reaponded create audio of response
105
  if st.session_state.messages[-1]["role"] == "assistant":
106
+ audio_result = st.button("Convert to Audio 🔊")
107
+ if audio_result:
108
+ #text-to-speech
109
+ print("Calling in Text-to-speech via suno/bark-small")
110
+ synthesiser = pipeline("text-to-speech", "suno/bark-small")
111
+
112
+ speech = synthesiser(response, forward_params={"do_sample": True})
113
+
114
+ scipy.io.wavfile.write("bark_out.wav", rate=speech["sampling_rate"], data=speech["audio"])
115
+ # ST interface for audio
116
+ print("Now we try to display the audio file in the app")
117
+ audio_file = open('bark_out.wav', 'rb')
118
+ audio_bytes = audio_file.read()
119
+
120
+ st.audio(audio_bytes, format='audio/wav')
121
+
122
+ sample_rate = 44100 # 44100 samples per second
123
+ seconds = 2 # Note duration of 2 seconds
124
+ frequency_la = 440 # Our played note will be 440 Hz
125
+ # Generate array with seconds*sample_rate steps, ranging between 0 and seconds
126
+ t = np.linspace(0, seconds, seconds * sample_rate, False)
127
+ # Generate a 440 Hz sine wave
128
+ note_la = np.sin(frequency_la * t * 2 * np.pi)
129
 
130
+ st.audio(note_la, sample_rate=sample_rate)
131
+
132
  if __name__ == "__main__":
133
  launch_bot()