reader does finally put and some exception shuffle
parent
fa23e396f1
commit
e26e700a21
|
|
@ -62,36 +62,45 @@ class Reader(threading.Thread):
|
||||||
sr.Microphone.list_microphone_names(),
|
sr.Microphone.list_microphone_names(),
|
||||||
) if v in self.name.split(",")
|
) if v in self.name.split(",")
|
||||||
]
|
]
|
||||||
|
log("mic#", mics[0])
|
||||||
return mics[0]
|
return mics[0]
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
log("Reader.run: start")
|
try:
|
||||||
|
log("Reader.run: start")
|
||||||
|
self._run()
|
||||||
|
except Exception as e:
|
||||||
|
log("Reader:run: exit:", e)
|
||||||
|
finally:
|
||||||
|
self.outq.put(None)
|
||||||
|
log("Reader.run: stop")
|
||||||
|
|
||||||
|
def _run(self):
|
||||||
while not self.should_stop():
|
while not self.should_stop():
|
||||||
mic = None
|
time.sleep(3)
|
||||||
|
mic = sr.Microphone(device_index=self.mic_idx())
|
||||||
try:
|
try:
|
||||||
mic = sr.Microphone(device_index=self.mic_idx())
|
|
||||||
mic.__enter__()
|
mic.__enter__()
|
||||||
while not self.should_stop():
|
while not self.should_stop():
|
||||||
self.outq.put(self._run(mic))
|
try:
|
||||||
|
self.outq.put(self.read(mic))
|
||||||
|
except Exception as e:
|
||||||
|
if not "timed out" in str(e):
|
||||||
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if not "timed out" in str(e):
|
import traceback
|
||||||
import traceback
|
traceback.print_exception(e)
|
||||||
traceback.print_exception(e)
|
log("Reader.run: error:", e)
|
||||||
time.sleep(5)
|
|
||||||
log("Reader.run: error:", e)
|
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
if mic:
|
mic.__exit__(None, None, None)
|
||||||
mic.__exit__(None, None, None)
|
except Exception as e:
|
||||||
except Exception:
|
log("Reader.run.catch: error:", e)
|
||||||
pass
|
|
||||||
self.outq.put(None)
|
|
||||||
log("Reader.run: stop")
|
|
||||||
|
|
||||||
def should_stop(self):
|
def should_stop(self):
|
||||||
return not self.inq.empty()
|
return not self.inq.empty()
|
||||||
|
|
||||||
def _run(self, mic):
|
def read(self, mic):
|
||||||
mic_timeout = int(os.environ.get("MIC_TIMEOUT", 5))
|
mic_timeout = int(os.environ.get("MIC_TIMEOUT", 5))
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
return r.listen(
|
return r.listen(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue