diff --git a/mycroft/client/speech/hotword_factory.py b/mycroft/client/speech/hotword_factory.py index dee40b1138..f763a6d9ba 100644 --- a/mycroft/client/speech/hotword_factory.py +++ b/mycroft/client/speech/hotword_factory.py @@ -118,9 +118,16 @@ class PocketsphinxHotWord(HotWordEngine): return file_name def create_config(self, dict_name, config): + """If language config doesn't exist then + we use default language (english) config as a fallback. + """ model_file = join(RECOGNIZER_DIR, 'model', self.lang, 'hmm') if not exists(model_file): - LOG.error('PocketSphinx model not found at ' + str(model_file)) + LOG.error( + 'PocketSphinx model not found at "{}". '.format(model_file) + + 'Falling back to en-us model' + ) + model_file = join(RECOGNIZER_DIR, 'model', 'en-us', 'hmm') config.set_string('-hmm', model_file) config.set_string('-dict', dict_name) config.set_string('-keyphrase', self.key_phrase) diff --git a/test/unittests/client/test_local_recognizer.py b/test/unittests/client/test_local_recognizer.py index 92f21c230e..5dbae7c670 100644 --- a/test/unittests/client/test_local_recognizer.py +++ b/test/unittests/client/test_local_recognizer.py @@ -48,6 +48,27 @@ class PocketSphinxRecognizerTest(unittest.TestCase): with source as audio: assert self.recognizer.found_wake_word(audio.stream.read()) + @patch.object(Configuration, 'get') + def testRecognitionFallback(self, mock_config_get): + """If language config doesn't exist set default (english)""" + conf = base_config() + conf['hotwords']['hey mycroft'] = { + 'lang': 'DOES NOT EXIST', + 'module': 'pocketsphinx', + 'phonemes': 'HH EY . M AY K R AO F T', + 'threshold': 1e-90 + } + conf['lang'] = 'DOES NOT EXIST' + mock_config_get.return_value = conf + + rl = RecognizerLoop() + ps_hotword = RecognizerLoop.create_wake_word_recognizer(rl) + + expected = 'en-us' + res = ps_hotword.decoder.get_config().get_string('-hmm') + self.assertEqual(expected, res.split('/')[-2]) + self.assertEqual('does not exist', ps_hotword.lang) + class LocalRecognizerInitTest(unittest.TestCase): @patch.object(Configuration, 'get')