snowboyで遊んでみる
やりたいこと
Hey , SiriやOK, GoogleのようなHotWordを変更して、音声認識を行いたい
snowboy
install & demo
ubuntu16.04でも動いた♪
install -> https://s3-us-west-2.amazonaws.com/snowboy/snowboy-releases/ubuntu1404-x86_64-1.1.1.tar.bz2
pip install pyaudio
Snowboy Hotword DetectionのCreate Hotwordでtest.pmdlを作成
python demo.py test.pmdl
demo.py
import snowboydecoder import sys import signal interrupted = False def signal_handler(signal, frame): global interrupted interrupted = True def interrupt_callback(): global interrupted return interrupted if len(sys.argv) == 1: print("Error: need to specify model name") print("Usage: python demo.py your.model") sys.exit(-1) model = sys.argv[1] signal.signal(signal.SIGINT, signal_handler) detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5) print('Listening... Press Ctrl+C to exit') detector.start(detected_callback=snowboydecoder.ding_callback, interrupt_check=interrupt_callback, sleep_time=0.03) detector.terminate()
このdetected_callback=snowboydecoder.ding_callbackに自作関数を入れる。
そうすると、HotWordが入った時に関数が呼ばれる。
注意
Do not append () to your callback function: the correct way is to assign detected_callback=your_func instead of detected_callback=your_func(). However, what if you have parameters to assign in your callback functions? Use a lambda function! So your callback would look like: callback=lambda: callback_function(parameters).