From 11789a5c9846a1b7be5c00540ce7c5cd5d99caf1 Mon Sep 17 00:00:00 2001 From: bel Date: Sat, 1 Apr 2023 10:45:00 -0600 Subject: [PATCH] with boo --- rust-whisper.d/hotwords.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/rust-whisper.d/hotwords.py b/rust-whisper.d/hotwords.py index 55f10ba..b13283b 100644 --- a/rust-whisper.d/hotwords.py +++ b/rust-whisper.d/hotwords.py @@ -67,16 +67,21 @@ class Reader(threading.Thread): def run(self): log("Reader.run: start") while not self.should_stop(): + mic = None try: - with sr.Microphone(device_index=self.mic_idx()) as mic: - while not self.should_stop(): - self.outq.put(self._run(mic)) + mic = sr.Microphone(device_index=self.mic_idx()) + mic.__enter__() + while not self.should_stop(): + self.outq.put(self._run(mic)) except Exception as e: if not "timed out" in str(e): import traceback traceback.print_exception(e) time.sleep(5) log("Reader.run: error:", e) + finally: + if mic: + mic.__exit__(None, None, None) self.outq.put(None) log("Reader.run: stop")