赞
踩
实验环境:荔枝派zero 代码:使用python3代码
snowboy 是一个开源的、轻量级语音唤醒引擎,可以通过它很轻松地创建属于自己的类似“hey, Siri” 的唤醒词。它的主要特性如下:
高度可定制性。可自由创建和训练属于自己的唤醒词 始终倾听。可离线使用,无需联网,保护隐私。精确度高,低延迟 轻量可嵌入。耗费资源非常低(单核
700MHz 树莓派只占用 10% CPU) 开源跨平台。开放源代码,支持多种操作系统和硬件平台,可绑定多种编程语言
详细看了官网提供的安装配置教程(已经很久没更新,有点过于繁琐了),几番尝试之后,感觉下面的介绍算是最新也相对最简单的方法了吧。PS:只针对 Linux 系统(包含树莓派),其他平台可参考 Github
1、从Git获取snowboy源码
获取源代码:$ git clone https://github.com/Kitt-AI/snowboy.git
2、安装相关依赖
安装 PyAudio:$ sudo apt-get install python3-pyaudio
安装 PyAudio:$ sudo apt-get install sox
安装 SWIG(>3.0.10):$ sudo apt-get install swig
安装 ATLAS:$ sudo apt-get install libatlas-base-dev
3、编译源代码
安装: cd snowboy ;python3 setup.py install
编译 Python3 绑定:$ cd snowboy/swig/Python3 && make
4、测试
官方源代码使用 Python3 测试有报错,经测试需修改 snowboy/examples/Python3 目录下的 snowboydecoder.py 文件。
将第 5 行代码 from * import snowboydetect 改为 import snowboydetect 即可直接运行。
#使用自己训练的‘’小白‘’模型
python3 demo.py resources/models/xiaobai.pmdl
运行如下:
root@ubuntu:/yangfeiwu/sonwboy/examples/Python3# python3 demo.py resources/models/xiaobai.pmdl Listening... Press Ctrl+C to exit ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958 ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to create IPC semaphore Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jack server is not running or cannot be started JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:40:54 INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:40:57 INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:40:58 INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:41:07 INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:41:11 INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:51:18
成功识别会输出如下信息:
INFO:snowboy:Keyword 1 detected at time: 2020-03-09 05:40:54
5、多个模型和回调
demo2.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) != 3: print("Error: need to specify 2 model names") print("Usage: python demo.py 1st.model 2nd.model") sys.exit(-1) 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: snowboydecoder.play_audio_file(snowboydecoder.DETECT_DING), lambda: snowboydecoder.play_audio_file(snowboydecoder.DETECT_DONG)] 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()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。