Explorar el Código

improve hotword detector test method

Martin hace 7 años
padre
commit
ad5f9b4b01
Se han modificado 2 ficheros con 24 adiciones y 23 borrados
  1. 6 23
      voice_control/main.py
  2. 18 0
      voice_control/test.py

+ 6 - 23
voice_control/main.py

@@ -22,19 +22,6 @@ def _init_logging():
         logging.basicConfig(filename=Config.LOGFILE)
         logging.getLogger().setLevel(logging.DEBUG)
 
-def cb():
-    print 'CB!'
-
-def test():
-    import snowboy.snowboydecoder
-    model = 'resources/snowboy/alexa.umdl'
-    detector = snowboy.snowboydecoder.HotwordDetector(model, sensitivity=0.5)
-    print 'a'
-    detector.start(detected_callback=cb, interrupt_check=_interrupt_callback)
-    print 'b'
-    detector.terminate()
-    print 'c'
-
 def _run(cclient):
     _init_logging()
     signal.signal(signal.SIGINT, _signal_handler)
@@ -44,13 +31,9 @@ def _run(cclient):
     services.launch_services(cclient, _interrupt_callback, _signal_handler)
 
 if __name__ == "__main__":
-    if False:
-        test()
-
-    else:
-        cclient = util.curses_util.CursesClient()
-        cclient.title = 'voice_control'
-        cclient.show_cursor = False
-        input_sources.CURSES_CLIENT = cclient
-        output.CURSES_CLIENT = cclient
-        cclient.run(_run, intercept_output_streams=True, cclient=cclient)
+    cclient = util.curses_util.CursesClient()
+    cclient.title = 'voice_control'
+    cclient.show_cursor = False
+    input_sources.CURSES_CLIENT = cclient
+    output.CURSES_CLIENT = cclient
+    cclient.run(_run, intercept_output_streams=True, cclient=cclient)

+ 18 - 0
voice_control/test.py

@@ -1,6 +1,21 @@
 import sys
 import logging
+from config import Config
 
+_HOTWORD_COUNT = False
+def _hotword_interrupt():
+    return _HOTWORD_COUNT > 1
+
+def _hotword_callback():
+    logging.info('Hotword callback called.')
+    global _HOTWORD_COUNT
+    _HOTWORD_COUNT += 1
+
+def _test_hotword_detection():
+    logging.info('Launching hotword detector...')
+    import snowboy.snowboydecoder
+    detector = snowboy.snowboydecoder.HotwordDetector(Config.SNOWBOY_HOTWORD_MODEL, sensitivity=0.5)
+    detector.start(detected_callback=_hotword_callback, interrupt_check=_hotword_interrupt)
 
 def _test_audio_in():
     import speech_recognition as sr
@@ -31,6 +46,7 @@ def run():
         print '\n'.join([
             '1. Audio output',
             '2. Audio input',
+            '3. Hotword detection',
         ])
         return
     
@@ -40,6 +56,8 @@ def run():
         _test_audio_out()
     elif choice == '2':
         _test_audio_in()
+    elif choice == '3':
+        _test_hotword_detection()
 
 if __name__ == "__main__":
     logging.basicConfig(stream=sys.stdout)