From 7e69c3af245cb3e90372dd92c018efc3345c6098 Mon Sep 17 00:00:00 2001 From: idriz Date: Wed, 2 Sep 2026 19:05:22 +0200 Subject: [PATCH] Wait quietly for the microphone to reappear when unplugged Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01LzKpYaEsuWDevuNnvSjcFW --- idriz/assistant.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/idriz/assistant.py b/idriz/assistant.py index c2c6b83..2d68ed5 100644 --- a/idriz/assistant.py +++ b/idriz/assistant.py @@ -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()})