1. Why use SnowBoy
The project requires a voice assistant, but there are too few wake-up methods supported by Xiao Ai and Tmall Genie. After some inquiries, I found snowboy. Several voice assistant wake-ups mentioned above seem to be developed based on snowboy.
2. Start environment construction
1. Obtain SnowBoy source code
Just find a directory and clone it
git clone https://github.com/Kitt-AI/snowboy.git
Directory Structure:
2. Compile SnowBoy
My environment is 32-bit Raspberry Pi 4B
Install dependencies first
sudo apt install python3 python3-pyaudio python3-pip libatlas-base-dev portaudio19-dev swig
Enter the SnowBoy compilation directory
cd swig/Python3
compile
make
The compiled file is as follows:
3. Run the samples provided by SnowBoy
Move the compiled library file to the sample file
Go to the sample folder
cd snowboy/examples/Python3
Modify snowboydecoder.py
library references:
Run example:
Appears as follows, that is, it is running normally
3. Create your own wake word
The official website is already broken. Here, according to the snowboy stopped API service, this ISSUE found a third-party
To enter the website, you need to record the wake-up word three times, then name the model, download it, and don’t go into details
After downloading the model, you can test and run your own model
python3 <filename> <model_file>
Here I put the model in another folder and modify it according to my own situation
4. Migrate to the project
1. Move the necessary files to the folder in your project
The necessary documents aresnowboydetect.py
_snowboydetect.so
snowboydecoder.py
demo.py
There is also a folder resources
where the model is stored. If you have your own model, you don’t need to copy this
2. Encapsulate the folder into a library
The Python package library is very simple, just create a new one under the folder __init__.py
(empty file is fine)
Use the library:
from <dic>.<dic> import snowdecoder
At this time, an error that the library cannot be found may be reported, just modify the location of the library reference in the corresponding file
3. Write the project master file
Copy the content in the demo.py file to the main project and run it.
Advanced is naturally to write the demo file by yourself, just learn how to use the API in the demo file
4. Run the program
Since the form of the command line to run is , it is enough python3 <filename> <model_file>
to add parameters to the pycharm's running command and specify it directlymodel_file
.bck
Then click to run ( the and in the directory Makefile
are useless, don’t worry about it, only the four files mentioned above plus a file for building the library plus a folder are useful, it nihaoxiaoyao_model.pmdl
’s my own model file, don’t worry about it)
5. Reference
Raspberry Pi uses snowboy and Baidu voice api to implement voice recognition assistant
A detailed tutorial on compiling and running Snowboy on the Raspberry Pi.