Skip to content

Commit

Permalink
fix timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongyihui committed Dec 29, 2017
1 parent 49460e4 commit 96aec30
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions avs/interface/speech_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class SpeechRecognizer(object):
PROFILES = {'CLOSE_TALK', 'NEAR_FIELD', 'FAR_FIELD'}
PRESS_AND_HOLD = {'type': 'PRESS_AND_HOLD', 'payload': {}}
TAP = {'type': 'TAP', 'payload': {}}
WAKEWORD = {'type': 'WAKEWORD', 'payload': {}}

def __init__(self, alexa):
self.alexa = alexa
Expand Down Expand Up @@ -54,7 +55,6 @@ def Recognize(self, dialog=None, initiator=None, timeout=10000):

self.audio_queue.queue.clear()
self.listening = True
self.timeout = timeout / 10 # 10 ms chunk

def on_finished():
self.alexa.state_listener.on_finished()
Expand All @@ -75,7 +75,7 @@ def on_finished():
self.dialog_request_id = dialog if dialog else uuid.uuid4().hex

if initiator is None:
initiator = { "type": "TAP" }
initiator = self.WAKEWORD

event = {
"header": {
Expand All @@ -93,15 +93,15 @@ def on_finished():

def gen():
time_elapsed = 0
while self.listening and time_elapsed <= self.timeout:
while self.listening and time_elapsed <= timeout:
try:
chunk = self.audio_queue.get(timeout=1.0)
except queue.Empty:
break

logger.debug('Sending chunk, time_elapsed = %d' % (time_elapsed))
yield chunk
time_elapsed += 10 # 10 ms chunk
time_elapsed += len(chunk) * 1000 / (2 * 16000) # 16000 fs, 2 bytes width
logger.debug('Sending chunk, time_elapsed = {}'.format(time_elapsed))

self.listening = False
self.alexa.state_listener.on_thinking()
Expand Down

0 comments on commit 96aec30

Please sign in to comment.