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:
idriz
2026-09-02 19:05:22 +02:00
parent c37041ae76
commit 7e69c3af24

View File

@@ -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()})