retry slower on bad mic things but ultimately segfault still

master
bel 2023-04-01 10:35:04 -06:00
parent 465193b60d
commit bb578e98f6
1 changed files with 20 additions and 16 deletions

View File

@ -52,25 +52,29 @@ class Reader(threading.Thread):
self.inq = inq self.inq = inq
self.outq = outq self.outq = outq
def run(self): def mic_idx(self):
log("Reader.run: start") mics = []
try: while not mics:
idx = [ log(f'searching for one of {self.name.split(",")} in {sr.Microphone.list_microphone_names()}...')
time.sleep(1)
mics = [
idx for idx,v in enumerate( idx for idx,v in enumerate(
sr.Microphone.list_microphone_names(), sr.Microphone.list_microphone_names(),
) if v in self.name.split(",") ) if v in self.name.split(",")
][0] ]
with sr.Microphone(device_index=idx) as mic: return mics[0]
def run(self):
log("Reader.run: start")
while not self.should_stop(): while not self.should_stop():
try: try:
with sr.Microphone(device_index=self.mic_idx()) as mic:
while not self.should_stop():
self.outq.put(self._run(mic)) self.outq.put(self._run(mic))
except Exception as e: except Exception as e:
if not "timed out" in str(e): if not "timed out" in str(e):
time.sleep(5)
log("Reader.run: error:", e) 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) self.outq.put(None)
log("Reader.run: stop") log("Reader.run: stop")