Created
April 4, 2017 21:05
-
-
Save maditnerd/a069b73f98195f0cd9e7179efd5ce6fb to your computer and use it in GitHub Desktop.
Snowball demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import snowboydecoder | |
import sys | |
import signal | |
import websocket | |
# Demo code for listening two hotwords at the same time | |
interrupted = False | |
ws = websocket.WebSocket() | |
ws.connect("ws://localhost:42002"); | |
def signal_handler(signal, frame): | |
global interrupted | |
interrupted = True | |
def interrupt_callback(): | |
global interrupted | |
return interrupted | |
if len(sys.argv) != 3: | |
print("Error: need to specify 2 model names") | |
print("Usage: python demo.py 1st.model 2nd.model") | |
sys.exit(-1) | |
def turn_on(): | |
print("ON") | |
ws.send("/radio/new/xx/1/on") | |
def turn_off(): | |
print("OFF") | |
ws.send("/radio/new/xx/1/off") | |
models = sys.argv[1:] | |
# capture SIGINT signal, e.g., Ctrl+C | |
signal.signal(signal.SIGINT, signal_handler) | |
sensitivity = [0.5]*len(models) | |
detector = snowboydecoder.HotwordDetector(models, sensitivity=sensitivity) | |
callbacks = [lambda: turn_on(), | |
lambda: turn_off()] | |
print('Listening... Press Ctrl+C to exit') | |
# main loop | |
# make sure you have the same numbers of callbacks and models | |
detector.start(detected_callback=callbacks, | |
interrupt_check=interrupt_callback, | |
sleep_time=0.03) | |
detector.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment