ubuntu 16.04 环境下:Wukonchatbot——语音唤醒:hot

版权声明: https://blog.csdn.net/weixin_32393347/article/details/82863669

语音唤醒 and hotword

参考snowboy

支持:linux、树莓派、moc 和windows
制作过程:

- 1.snowboy 唤醒模型制作:
- 2.环境安装:(ubuntu)
- 3.测试你的唤醒词
  1. snowboy 官网

1.snowboy 唤醒模型制作:

1.官网申请账号,可github登陆
2. 选取一个唤醒词:比如老张
3. 按流程制作和录音:3次
4. 测试模型
5.下载模型:备用

2.环境安装:(ubuntu)

  • SoX (audio conversion)
  • PortAudio or PyAudio (audio capturing)
  • SWIG 3.0.10 or above (compiling Snowboy for different languages/platforms)
  • ATLAS or OpenBLAS (matrix computation)
#1.在ubuntu 16.04 下安装
#Access Microphone:
sudo apt-get install python-pyaudio python3-pyaudio sox
pip install pyaudio
#tip:测试硬件是否能够录音
rec temp.wav

3.swig环境安装

#1.安装g++依赖包()
sudo apt-get install g++
#2.ubuntu 环境下默认安装,终端输入一下命令,可以查看版本
g++ -version
#3.安装 pcre
sudo apt-get install libpcre3 libpcre3-dev
#4. 解压 swig 源码 
chmod 777 swig-3.0.12.tar.gz # 改变权限
tar -xzvf swig-3.0.12.tar.gz # 解压
#5. 配置、编译和安装 swig
#指定安装目录
./configure --prefix=/home/errolyan/swig/   
#编译
make
#安装
make install
# 6.配置安装路径
sudo vim /etc/profile
#将刚才的路径 /home/errolyan/swig/bin添加到profile文件的path下面:(文件最后几行)
export SWIG_PATH=/home/errolyan/swig/bin
export PATH=$SWIG_PATH:$PATH
#7.刷新环境
source /etc/profile
#8.测试swig
swig -version
#可以看到版本信息

4.Ubuntu 16.04 安装OpenBLAS步骤

git clone git://github.com/xianyi/OpenBLAS
 cd OpenBLAS
 sudo apt-get install gfortran
 sudo make FC=gfortran   #tips:gfortran --version 未有版本 需要安装 sudo apt-get install gfortran
 sudo make install

然后执行以下命令:

sudo ln -s /opt/OpenBLAS/lib/libopenblas.so.0   /usr/lib/libopenblas.so.0

查看版本信息

g++ --version
gcc --version
gfortran --version

结果gfortran也有,在目录/usr/lib/x86_64-linux-gnu/里面:

sudo ln -s /usr/lib/x86_64-linux-gnu/libgfortran.so.3 /usr/lib/libgfortran.so

编译例子:
gcc testOpenBlas.c  -I /opt/OpenBLAS/include/ -L/opt/OpenBLAS/lib -lopenblas

4.安装atlas和openblas(安装一个就可以)

#Then install the atlas matrix computing library:

sudo apt-get install libatlas-base-dev

测试你的唤醒词

添加你自己的模型文件到固定的路径:更改dome里面的自己的模型路径

#需要的文件结构为
├── README.md
├── _snowboydetect.so
├── demo.py
├── demo2.py
├── light.py
├── requirements.txt
├── resources
│   ├── ding.wav
│   ├── dong.wav
│   ├── common.res
│   └── snowboy.umdl
├── snowboydecoder.py
├── snowboydetect.py
└── version

我的源代码:

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]

# capture SIGINT signal, e.g., Ctrl+C
signal.signal(signal.SIGINT, signal_handler)

detector = snowboydecoder.HotwordDetector("悟空.pmdl", sensitivity=0.5, audio_gain=1)
print('Listening... Press Ctrl+C to exit')

# main loop
detector.start(detected_callback=snowboydecoder.play_audio_file,interrupt_check=interrupt_callback,sleep_time=500)

detector.terminate()

猜你喜欢

转载自blog.csdn.net/weixin_32393347/article/details/82863669