More gracefully handle unexpected errors in listener, unit test mock class shouldn't generate unexpected errors.
parent
2452c74abd
commit
745d4920e1
|
@ -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() != '':
|
||||||
|
|
|
@ -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):
|
||||||
|
if len(self.transcriptions) > 0:
|
||||||
return self.transcriptions.pop(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
|
||||||
|
|
Loading…
Reference in New Issue