Wait quietly for the microphone to reappear when unplugged
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LzKpYaEsuWDevuNnvSjcFW
This commit is contained in:
@@ -175,13 +175,20 @@ class Assistant:
|
||||
|
||||
# ---------- audio petlje ----------
|
||||
async def mic_loop(self) -> None:
|
||||
mic_missing = False
|
||||
while True:
|
||||
chunk = await self.mic.read()
|
||||
if not chunk:
|
||||
log.error("mikrofon je prestao davati podatke")
|
||||
await asyncio.sleep(1)
|
||||
if not mic_missing:
|
||||
log.error("mikrofon ne daje podatke (isključen?), čekam da se pojavi")
|
||||
mic_missing = True
|
||||
await self.mic.stop()
|
||||
await asyncio.sleep(2)
|
||||
await self.mic.start()
|
||||
continue
|
||||
if mic_missing:
|
||||
log.info("mikrofon ponovo radi")
|
||||
mic_missing = False
|
||||
if self.speaker.is_playing():
|
||||
continue # half-duplex: ne šalji dok Idriz govori
|
||||
await self.conn.send({"type": "input_audio_buffer.append", "audio": base64.b64encode(chunk).decode()})
|
||||
|
||||
Reference in New Issue
Block a user