More gracefully handle unexpected errors in listener, unit test mock class shouldn't generate unexpected errors.

pull/70/head
Sean Fitzgerald 2016-05-28 14:28:12 -07:00
parent 2452c74abd
commit 745d4920e1
2 changed files with 7 additions and 1 deletions

View File

@ -207,6 +207,8 @@ class AudioConsumer(threading.Thread):
"Your device is not registered yet. To start pairing, " "Your device is not registered yet. To start pairing, "
"login at cerberus.mycroft.ai") "login at cerberus.mycroft.ai")
utterances.append("pair my device") utterances.append("pair my device")
except Exception as e:
logger.error("Unexpected exception: {0}".format(e))
else: else:
logger.debug("STT: " + text) logger.debug("STT: " + text)
if text.strip() != '': if text.strip() != '':

View File

@ -19,6 +19,7 @@
import unittest import unittest
from Queue import Queue from Queue import Queue
import speech_recognition
from os.path import dirname, join from os.path import dirname, join
from speech_recognition import WavFile, AudioData from speech_recognition import WavFile, AudioData
@ -35,7 +36,10 @@ class MockRecognizer(object):
self.transcriptions = [] self.transcriptions = []
def recognize_google(self, audio, key=None, language=None, show_all=False): def recognize_google(self, audio, key=None, language=None, show_all=False):
return self.transcriptions.pop(0) if len(self.transcriptions) > 0:
return self.transcriptions.pop(0)
else:
raise speech_recognition.UnknownValueError()
def set_transcriptions(self, transcriptions): def set_transcriptions(self, transcriptions):
self.transcriptions = transcriptions self.transcriptions = transcriptions