KingNish commited on
Commit
2aa799c
1 Parent(s): b905233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -2
app.py CHANGED
@@ -126,7 +126,13 @@ def model(text, web_search):
126
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
127
 
128
  async def respond(audio, web_search):
129
- user = transcribe(audio)
 
 
 
 
 
 
130
  reply = model(user, web_search)
131
  communicate = edge_tts.Communicate(reply)
132
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
@@ -139,7 +145,7 @@ with gr.Blocks() as demo:
139
  web_search = gr.Checkbox(label="Web Search", value=False)
140
  input = gr.Audio(label="Voice Chat", sources="microphone")
141
  output = gr.Audio(label="AI",autoplay=True)
142
- gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True, batch=True, max_batch_size=20, delete_cache=(60,60))
143
 
144
  if __name__ == "__main__":
145
  demo.queue(max_size=200).launch()
 
126
  return "".join([response.token.text for response in stream if response.token.text != "</s>"])
127
 
128
  async def respond(audio, web_search):
129
+ audio_data, sr = audio # Unpack the audio tuple
130
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
131
+ tmp_path = tmp_file.name
132
+ audio_segment = AudioSegment(data=audio_data, sample_width=2, frame_rate=sr, channels=1) # Assuming 16-bit PCM audio
133
+ audio_segment.export(tmp_path, format="wav")
134
+
135
+ user = transcribe(tmp_path)
136
  reply = model(user, web_search)
137
  communicate = edge_tts.Communicate(reply)
138
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
 
145
  web_search = gr.Checkbox(label="Web Search", value=False)
146
  input = gr.Audio(label="Voice Chat", sources="microphone")
147
  output = gr.Audio(label="AI",autoplay=True)
148
+ gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True)
149
 
150
  if __name__ == "__main__":
151
  demo.queue(max_size=200).launch()