Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple hot words patch #6

Open
a1higgins-oss opened this issue May 7, 2019 · 0 comments
Open

Multiple hot words patch #6

a1higgins-oss opened this issue May 7, 2019 · 0 comments

Comments

@a1higgins-oss
Copy link

Awesome script and tutorial. Thanks! I added support for multiple hot words and umdl files. Not tested other than for my setup, but FYI in case you want it. Note the double sensitivity setting needed for jarvis.umdl.

diff --git a/customHotword.py b/customHotword.py
index 4ce1445..e66c8ad 100644
--- a/customHotword.py
+++ b/customHotword.py
@@ -17,8 +17,8 @@ interrupted = False
 siteId = 'default'
 mqttServer = '127.0.0.1'
 mqttPort = 1883
-model = ''
-sensitivity = 0.4
+models = []
+sensitivities = []
 hotwordId = 'default'
 
 def loadConfigs():
@@ -59,23 +59,28 @@ def onHotword():
 signal.signal(signal.SIGINT, signal_handler)
 
 if __name__ == '__main__':
-       try:
-               model = sys.argv[1]
-               sensitivity = float(sys.argv[2])
-       except IndexError:
-               print('Please provide model name and sensitivity as argument')
-               sys.exit()
+        num_args = (len(sys.argv)-1)/2
+        for i in range(0, num_args):
+               try:
+                       models.append(sys.argv[1+(i*2)])
+                       sensitivities.extend(sys.argv[2+(i*2)].split(','))
+               except IndexError:
+                       print('Please provide model name and sensitivity pair as argument')
+                       sys.exit()
 
-       if not os.path.isfile('{}.pmdl'.format(model)):
-               print('The specified model doesn\'t exist')
-               sys.exit()
+        for i in range(0, len(models)):
+               if not os.path.isfile(models[i]):
+                       print('The specified model doesn\'t exist')
+                       sys.exit()
 
-       if sensitivity < 0 or sensitivity > 1:
-               print('Sensitivity should by a float between 0 and 1')
-               sys.exit()
+        for i in range(0, len(sensitivities)):
+                sensitivities[i] = float(sensitivities[i])
+               if sensitivities[i] < 0 or sensitivities[i] > 1:
+                       print('Sensitivity should by a float between 0 and 1')
+                       sys.exit()
 
        loadConfigs()
-       detector = snowboydecoder.HotwordDetector('{}.pmdl'.format(model), sensitivity=sensitivity)
+       detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivities)
        print('Listening...')
-       detector.start(detected_callback=onHotword, interrupt_check=interrupt_callback, sleep_time=0.03)
+       detector.start(detected_callback=[onHotword]*len(sensitivities), interrupt_check=interrupt_callback, sleep_time=0.03)
        detector.terminate()

It supports a snipsCustomHotword.service ExecStart setting like:

[Service] ExecStart=/usr/bin/python customHotword.py computer.umdl 0.5 jarvis.umdl 0.5,0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant