当前位置:   article > 正文

使用 snowboy 配置多个热词唤醒_snowboy 几个汉字的唤醒 识别率高 能耗低

snowboy 几个汉字的唤醒 识别率高 能耗低

实验环境:荔枝派zero 代码:使用python3代码

snowboy 是一个开源的、轻量级语音唤醒引擎,可以通过它很轻松地创建属于自己的类似“hey, Siri” 的唤醒词。它的主要特性如下:

高度可定制性。可自由创建和训练属于自己的唤醒词 始终倾听。可离线使用,无需联网,保护隐私。精确度高,低延迟 轻量可嵌入。耗费资源非常低(单核
700MHz 树莓派只占用 10% CPU) 开源跨平台。开放源代码,支持多种操作系统和硬件平台,可绑定多种编程语言
详细看了官网提供的安装配置教程(已经很久没更新,有点过于繁琐了),几番尝试之后,感觉下面的介绍算是最新也相对最简单的方法了吧。

PS:只针对 Linux 系统(包含树莓派),其他平台可参考 Github

1、从Git获取snowboy源码

获取源代码:$ git clone https://github.com/Kitt-AI/snowboy.git
  • 1

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
  • 1
  • 2
  • 3
  • 4

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
  • 1
  • 2

运行如下:

 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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

成功识别会输出如下信息:
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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/88342
推荐阅读
相关标签
  

闽ICP备14008679号