master
parent
02ce0aeef4
commit
3adc1d0efa
|
|
@ -20,6 +20,8 @@ class Recognizer(threading.Thread):
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
got = self.q.get()
|
got = self.q.get()
|
||||||
|
if not got:
|
||||||
|
break
|
||||||
self.one(got)
|
self.one(got)
|
||||||
|
|
||||||
def one(self, audio):
|
def one(self, audio):
|
||||||
|
|
@ -66,18 +68,29 @@ class Listener():
|
||||||
return mic
|
return mic
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
try:
|
||||||
|
return self._run()
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _run(self):
|
||||||
mic_timeout=int(environ.get("MIC_TIMEOUT", 5))
|
mic_timeout=int(environ.get("MIC_TIMEOUT", 5))
|
||||||
# obtain audio from the microphone
|
# obtain audio from the microphone
|
||||||
r = sr.Recognizer()
|
r = sr.Recognizer()
|
||||||
return r.listen(self.mic(), timeout=mic_timeout, phrase_time_limit=mic_timeout)
|
#return r.listen(self.mic(), timeout=mic_timeout, phrase_time_limit=mic_timeout)
|
||||||
|
return r.record(self.mic(), duration=mic_timeout)
|
||||||
|
|
||||||
q = queue.Queue(maxsize=1)
|
q = queue.Queue(maxsize=1)
|
||||||
l = Listener()
|
l = Listener()
|
||||||
t = Recognizer(q)
|
t = Recognizer(q)
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
|
while True:
|
||||||
got = l.run()
|
got = l.run()
|
||||||
q.put(got)
|
q.put(got)
|
||||||
|
except Exception:
|
||||||
t.join()
|
pass
|
||||||
|
finally:
|
||||||
|
l._mic.__exit__(None, None, None)
|
||||||
|
t.join()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue