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 ----------
|
# ---------- audio petlje ----------
|
||||||
async def mic_loop(self) -> None:
|
async def mic_loop(self) -> None:
|
||||||
|
mic_missing = False
|
||||||
while True:
|
while True:
|
||||||
chunk = await self.mic.read()
|
chunk = await self.mic.read()
|
||||||
if not chunk:
|
if not chunk:
|
||||||
log.error("mikrofon je prestao davati podatke")
|
if not mic_missing:
|
||||||
await asyncio.sleep(1)
|
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()
|
await self.mic.start()
|
||||||
continue
|
continue
|
||||||
|
if mic_missing:
|
||||||
|
log.info("mikrofon ponovo radi")
|
||||||
|
mic_missing = False
|
||||||
if self.speaker.is_playing():
|
if self.speaker.is_playing():
|
||||||
continue # half-duplex: ne šalji dok Idriz govori
|
continue # half-duplex: ne šalji dok Idriz govori
|
||||||
await self.conn.send({"type": "input_audio_buffer.append", "audio": base64.b64encode(chunk).decode()})
|
await self.conn.send({"type": "input_audio_buffer.append", "audio": base64.b64encode(chunk).decode()})
|
||||||
|
|||||||
Reference in New Issue
Block a user