Skip to content

Commit c124b14

Browse files
committed
reinit portaudio on retry
1 parent 65e8cfb commit c124b14

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎robot_orchestrator/hal/real/microphone.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,24 @@ def probe(self) -> ProbeResult:
1717
for _ in range(RETRY_ATTEMPTS - 1):
1818
if result.ok:
1919
return result
20+
if result.detail == "no matching input device":
21+
self._reinit_portaudio()
2022
time.sleep(RETRY_DELAY_S)
2123
result = self._probe_once()
2224
return result
2325

26+
def _reinit_portaudio(self) -> None:
27+
# PortAudio snapshots the device list once at init; a USB sound card that
28+
# enumerates after that snapshot (e.g. right after a cold boot) never shows
29+
# up in this process until PortAudio is torn down and re-initialized.
30+
try:
31+
import sounddevice as sd
32+
33+
sd._terminate()
34+
sd._initialize()
35+
except Exception:
36+
pass
37+
2438
def _probe_once(self) -> ProbeResult:
2539
try:
2640
import numpy as np

0 commit comments

Comments
 (0)