Respeaker 2-Mics Pi HAT + Raspberry Pi Zero W
It is constantly reported that Respeaker Pi HAT does not work well with the new Raspbian OS. For example, when I tried to install the driver even with the --compat-kernel
option, the system either cannot detect the sound card or has no sound from the Respeaker device. After trial and error, I found the following workaround.
First we install a specified version of Raspbian, namely raspbian-2019-07-12 (some other old versions might also work; however, they are not tested yet). This is done by the way described in the previous post Install Debian on Raspberry Pi 4B, except that the operating system is replaced with the aforementioned version of Raspbian. In addition, after the image is written to the SD card, in the root of the SD card, create an empty file exactly named ssh (note: ssh, not ssh.txt or something else), and one file exactly named wpa_supplicant.conf with the following content:
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
ssid="WIFI-NAME"
psk="WIFI-PASSWORD"
key_mgmt=WPA-PSK
}
where US is replaced with your country code, WIFI-NAME with your home WiFi SSID, and WIFI-PASSWORD with the corresponding WiFi password. These two files will enable the Raspberry device (installed with a Raspbian OS) to automatically connect to the specified WiFi and also to be accessible via SSH. This is useful especially for Raspberry Pi Zero as it does not come with handy input ports such as USB ports for mouse or keyboard.
Next, we insert the SD card (with the Raspbian OS) to the Raspberry device, and connect the Respeaker Pi HAT to the Raspberry device. Power the device on, wait for a few minutes, and then login the home router to find the IP address of the device. After that, we can connect to the device via SSH, and use the following commands to install the driver for Respeaker.
git clone https://github.com/respeaker/seeed-voicecard
cd seeed-voicecard
sudo ./install.sh --compat-kernel
sudo reboot
After rebooting the Raspberry device, if the driver is installed successfully, then by the command arecord -l
, we can see the following output:
pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
To test the driver works properly, we can use the command arecord -f cd -Dhw:1 -d 10 > test.wav
to record the audio for 10 seconds. The recording is saved to test.wav and can be downloaded via a sftp client (such as FileZilla) and played in a laptop.
GStreamer
When we deploy the smart home system, we might have a hub and we want to direct all audio input to the hub for processing. In this case, we can use GStreamer.
sudo apt-get install gstreamer1.0-tools
gst-launch-1.0 autoaudiosrc ! audioconvert ! audioresample ! audio/x-raw, rate=16000, channels=1, format=S16LE ! udpsink host=192.168.1.126 port=12333
where the IP address 192.168.1.126 is to be replaced with the IP address of your speech recognition hub, for example, a Rhasspy instance.
A Simplified Rhasspy Satellite
I found that the Rhasspy 2.5.10 is slow on Raspberry Pi + Respeaker Pi HAT 2-mic, even when it runs as a satellite responsible only for wake detection, audio input and output. Therefore, I pull out some codes from Rhasspy and make them into a much simplified Rhasspy satellite specifice to Raspberry Pi + Respeaker Pi HAT 2-mic. It runs rather smoothly now. Here I use
- a Rhaspberry Pi Zero with WiFi running Respberry Pi OS Lite (released on May 7, 2021); see here for installing Raspberry Pi OS.
The first thing is to install driver for Respeaker Pi HAT 2-mic.
sudo apt update
sudo apt install -y git
# install driver for Respeaker Pi HAT 2-mic
# use this repo for supporting current Raspbian
git clone https://github.com/HinTak/seeed-voicecard
cd seeed-voicecard
sudo ./install.sh
sudo reboot now
# install mplayer if you want to play mp3 audio
sudo apt install -y mplayer
The Raspberry Pi OS Lite ships with Python 3, but we need to install some required modules. After that, simply check out my code from GitHub, change some settings, and run it.
sudo apt install -y python3-pip python3-pyaudio
pip3 install pvporcupine webrtcvad
git clone https://github.com/SmartopiaHub/rhasspy-rpizero
cd rhasspy-rpizero
# run the simplified rhasspy satellite
# before this, open rhasspy_rpizero.py and change some settings accordingly
# the default wake word is bumblebee
python3 rhasspy_rpizero.py
Speaker
The speaker I confirmed to work with Raspberry Pi and Respeaker Pi HAT is the Logitech Z121 compact stereo USB powered speaker. However, I believe that any speakers with 3.5mm input should work well.