demo2.py
Go to the documentation of this file.
1 import snowboydecoder
2 import sys
3 import signal
4 
5 # Demo code for listening two hotwords at the same time
6 
7 interrupted = False
8 
9 
10 def signal_handler(signal, frame):
11  global interrupted
12  interrupted = True
13 
14 
16  global interrupted
17  return interrupted
18 
19 if len(sys.argv) != 3:
20  print("Error: need to specify 2 model names")
21  print("Usage: python demo.py 1st.model 2nd.model")
22  sys.exit(-1)
23 
24 models = sys.argv[1:]
25 
26 # capture SIGINT signal, e.g., Ctrl+C
27 signal.signal(signal.SIGINT, signal_handler)
28 
29 sensitivity = [0.5]*len(models)
30 detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity)
31 callbacks = [lambda: snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING),
32  lambda: snowboydecoder.play_audio_file(snowboydecoder.DETECT_DONG)]
33 print('Listening... Press Ctrl+C to exit')
34 
35 # main loop
36 # make sure you have the same numbers of callbacks and models
37 detector.start(detected_callback=callbacks,
38  interrupt_check=interrupt_callback,
39  sleep_time=0.03)
40 
41 detector.terminate()
def signal_handler(signal, frame)
Definition: demo2.py:10
def interrupt_callback()
Definition: demo2.py:15


dialogflow_ros
Author(s): Anas Abou Allaban
autogenerated on Mon Jun 10 2019 13:02:59