chibop commited on
Commit
93d9045
·
verified ·
1 Parent(s): dc6cc04

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. chat.py +4 -3
chat.py CHANGED
@@ -61,8 +61,7 @@ def speak(history):
61
  speech = client.audio.speech.create(model="tts-1", voice="alloy", input=text)
62
  audio = base64.b64encode(speech.read()).decode("utf-8")
63
  src = f"data:audio/mpeg;base64,{audio}"
64
- audio_element = f'<audio src="{src}" controls autoplay></audio>'
65
- return audio_element
66
 
67
  def vote(data: gr.LikeData):
68
  if data.liked:
@@ -94,9 +93,11 @@ def main():
94
  mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False)
95
  thread = gr.State(start_thread)
96
  audio_html = gr.HTML(visible=False)
 
 
97
  msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
98
  bot, [chatbot, thread], chatbot).then(
99
- speak, chatbot, audio_html
100
  )
101
  mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
102
  lambda:None, None, mic).then(
 
61
  speech = client.audio.speech.create(model="tts-1", voice="alloy", input=text)
62
  audio = base64.b64encode(speech.read()).decode("utf-8")
63
  src = f"data:audio/mpeg;base64,{audio}"
64
+ return src
 
65
 
66
  def vote(data: gr.LikeData):
67
  if data.liked:
 
93
  mic = gr.Microphone(type="filepath", format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False)
94
  thread = gr.State(start_thread)
95
  audio_html = gr.HTML(visible=False)
96
+ player = gr.Audio(autoplay=True, format="mp3", editable=False, waveform_options={"show_controls": False}, visible=False)
97
+
98
  msg.submit(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
99
  bot, [chatbot, thread], chatbot).then(
100
+ speak, chatbot, player
101
  )
102
  mic.stop_recording(user, [msg, mic, chatbot, thread], [msg, chatbot]).then(
103
  lambda:None, None, mic).then(