saadpie commited on
Commit
2433d67
·
verified ·
1 Parent(s): 91a7eef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -58,13 +58,14 @@ async def ws_stream():
58
  while True:
59
  data = await websocket.receive()
60
  if isinstance(data, bytes):
61
- # Handle microphone audio
62
  await session.send(
63
  input={"data": data, "mime_type": "audio/pcm;rate=16000"}
64
  )
65
  elif isinstance(data, str):
66
- # Handle 'echo' text commands from Termux
67
- await session.send(input=data)
 
68
  except Exception as e:
69
  print(f"Client -> Gemini Error: {e}")
70
 
@@ -79,8 +80,8 @@ async def ws_stream():
79
  except Exception as e:
80
  print(f"Gemini -> Client Error: {e}")
81
 
82
- # Run both tasks and wait for them to finish or error out
83
- await asyncio.gather(client_to_gemini(), gemini_to_client())
84
 
85
  except Exception as e:
86
  print(f"Connection failed: {e}")
 
58
  while True:
59
  data = await websocket.receive()
60
  if isinstance(data, bytes):
61
+ # Send real-time audio input
62
  await session.send(
63
  input={"data": data, "mime_type": "audio/pcm;rate=16000"}
64
  )
65
  elif isinstance(data, str):
66
+ # NEW: Explicitly send text as a message turn to trigger response
67
+ # This satisfies the new SDK requirements and avoids the deprecation warning
68
+ await session.send(input=data, end_of_turn=True)
69
  except Exception as e:
70
  print(f"Client -> Gemini Error: {e}")
71
 
 
80
  except Exception as e:
81
  print(f"Gemini -> Client Error: {e}")
82
 
83
+ # Using gather with return_exceptions to keep tasks alive
84
+ await asyncio.gather(client_to_gemini(), gemini_to_client(), return_exceptions=True)
85
 
86
  except Exception as e:
87
  print(f"Connection failed: {e}")