develops20 commited on
Commit
a915c74
·
verified ·
1 Parent(s): cc06717

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -179,25 +179,25 @@ class VoiceAgent:
179
  # Initialize the agent
180
  agent = VoiceAgent()
181
 
182
- async def process_voice_input(audio_file):
183
  """Process voice input and return voice response"""
184
  if audio_file is None:
185
  return None, "Please record some audio first."
186
 
187
  try:
188
- # Convert speech to text
189
- text = await agent.speech_to_text(audio_file)
190
- if text.startswith("Error"):
191
  return None, text
192
 
193
  # Process with MCP
194
- result = await agent.process_with_mcp(text)
195
  response_text = result["response"]
196
 
197
  # Convert response to speech
198
  if ELEVENLABS_API_KEY:
199
  try:
200
- audio_bytes = await agent.text_to_speech(response_text)
201
  # Save to temporary file
202
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
203
  tmp_file.write(audio_bytes)
 
179
  # Initialize the agent
180
  agent = VoiceAgent()
181
 
182
+ def process_voice_input(audio_file):
183
  """Process voice input and return voice response"""
184
  if audio_file is None:
185
  return None, "Please record some audio first."
186
 
187
  try:
188
+ # Convert speech to text (now synchronous)
189
+ text = asyncio.run(agent.speech_to_text(audio_file))
190
+ if "error" in text.lower() or "unavailable" in text.lower():
191
  return None, text
192
 
193
  # Process with MCP
194
+ result = asyncio.run(agent.process_with_mcp(text))
195
  response_text = result["response"]
196
 
197
  # Convert response to speech
198
  if ELEVENLABS_API_KEY:
199
  try:
200
+ audio_bytes = asyncio.run(agent.text_to_speech(response_text))
201
  # Save to temporary file
202
  with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
203
  tmp_file.write(audio_bytes)