Bugfix/issue 2563 (#2692)

* Issue-2563 Added fallback to english model
* Added test case for checking config set up
* Added more descriptive log message
pull/2704/head
katridi 2020-09-22 08:31:01 +03:00 committed by GitHub
parent 2e1247dd5c
commit 6e197d0138
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -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)

View File

@ -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')