Merge pull request #1810 from MycroftAI/feature/auto-try-precise

Check for a Precise model automatically for custom wake words
pull/1816/head
Åke 2018-09-26 19:09:54 +02:00 committed by GitHub
commit 36bfdaba2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -39,6 +39,10 @@ class TriggerReload(Exception):
pass
class NoModelAvailable(Exception):
pass
class HotWordEngine(object):
def __init__(self, key_phrase="hey mycroft", config=None, lang="en-us"):
self.key_phrase = str(key_phrase).lower()
@ -170,11 +174,11 @@ class PreciseHotword(HotWordEngine):
model_url, self.folder,
on_download=lambda: LOG.info('Updated precise model')
)
except HTTPError:
except (HTTPError, ValueError):
if isfile(model_file):
LOG.info("Couldn't find remote model. Using local file")
else:
raise RuntimeError('Failed to download model:', model_url)
raise NoModelAvailable('Failed to download model:', model_url)
return model_file
@staticmethod
@ -267,6 +271,11 @@ class HotWordFactory(object):
complete.set()
sleep(0.5)
loop.reload()
except NoModelAvailable:
LOG.warning('Could not found find model for {} on {}.'.format(
hotword, module
))
instance = None
except Exception:
LOG.exception(
'Could not create hotword. Falling back to default.')
@ -286,7 +295,7 @@ class HotWordFactory(object):
config = Configuration.get()['hotwords']
config = config[hotword]
module = config.get("module", "pocketsphinx")
module = config.get("module", "precise")
return cls.load_module(module, hotword, config, lang, loop) or \
cls.load_module('pocketsphinx', hotword, config, lang, loop) or \
cls.CLASSES['pocketsphinx']()

View File

@ -248,7 +248,7 @@ class RecognizerLoop(EventEmitter):
config = self.config_core.get("hotwords", {word: {}})
if word not in config:
config[word] = {'module': 'pocketsphinx'}
config[word] = {'module': 'precise'}
if phonemes:
config[word]["phonemes"] = phonemes
if thresh: