finally close reader

master
bel 2023-03-29 07:45:55 -06:00
parent eda12d9cb6
commit 0e278fffcb
1 changed files with 18 additions and 13 deletions

View File

@ -70,19 +70,24 @@ class Reader(threading.Thread):
def run(self): def run(self):
log("Reader.run: start") log("Reader.run: start")
idx = [ try:
idx for idx,v in enumerate( idx = [
sr.Microphone.list_microphone_names(), idx for idx,v in enumerate(
) if v in self.name.split(",") sr.Microphone.list_microphone_names(),
][0] ) if v in self.name.split(",")
with sr.Microphone(device_index=idx) as mic: ][0]
while not self.should_stop(): with sr.Microphone(device_index=idx) as mic:
try: while not self.should_stop():
self.outq.put(self._run(mic)) try:
except Exception as e: self.outq.put(self._run(mic))
if not "timed out" in str(e): except Exception as e:
log("Reader.run: error:", e) if not "timed out" in str(e):
self.outq.put(None) log("Reader.run: error:", e)
except Exception as e:
log("Reader.run panic:", e)
log("microphones:", sr.Microphone.list_microphone_names())
finally:
self.outq.put(None)
log("Reader.run: stop") log("Reader.run: stop")
def should_stop(self): def should_stop(self):