Introduction: Alexa Voice Assistant on Raspberry Pi Zero Docking Hub
To build an elegant Alexa Voice Assistant on a Pi Zero W with fewer wires and USB dongles, I use a Makerspot's Raspberry Pi Zero Docking Hub. This docking hub has a built-in audio codec which can host a microphone and a speaker through its 3.5mm audio jack.
Let's get started.
Step 1: Get These Parts
These are the parts you need:
- 1x Raspberry Pi Zero W
- 1x Raspberry Pi Zero Docking Hub
- 1x HDMI monitor
- 1x HDMI cable (please note Pi Zero W requires a mini-HDMI connector)
- 1x 5v USB 1 A Power Adaptor
- 1x micro USB cable
- 1x USB keyboard
- 1x USB mouse
- 1x Mini-Microphone For Mobile Phone/Tablet (the one that supports split speaker port)
- 1x External Speaker with 3.5mm Audio Jack.
- 1x 3.5mm audio cable (male-to-male)
- 1x 8G micro SD card
- PC (for flashing the SD card with Raspbian OS image)
Step 2: Prepare SD Card With the Latest Raspbian OS (Stretch/Jessie)
It would be a good idea to start with a fresh Raspbian OS. There are a few ways to prepare a new Raspbian OS on an SD card. But I found that using Etcher with a full Raspbian image is efficient and less error-prone.
- Download and install Etcher (https://etcher.io/) for your host PC.
- Download the latest Raspbian image from http://downloads.raspberrypi.org/raspbian/images/
- Insert the SD into your PC
- Open Etcher, select the Raspbian image, then the SD card drive, and press Flash!
Once the image is prepared, eject the card safely and get ready for next step.
Step 3: Setup Your Pi and Docking Hub
You need to install your Pi Zero W on the Raspberry Pi Zero Docking Hub. There are 4 sets of screws and standoffs and it will take less than a minute to assemble.
Insert the prepared SD card into the Pi Zero W. Connect your monitor to the Pi Zero W's HDMI port (must be done before powering up the Pi), connect the USB keyboard and mouse and finally connect the microphone and speaker. To power up, connect the 5v USB power cable to the power port on the docking hub (NOT THE PWR PORT ON THE PI).
You should see the normal Raspbian OS coming up on the monitor.
Step 4: Configure Your Pi
Setup WiFi.
Left mouse click over the WiFi icon on the top bar. Choose your network to connect. You only need to do once unless the network setting has changed or need to be changed.
Setup Default Audio
This step is important to get the Raspberry Pi Zero Docking Hub audio to work with the default Alexa software.
Start a terminal and edit /boot/config.txt
sudo nano /boot/config.txt
Disable the analog and hdmi audio by inserting '#' in front of the following line in the file:
#dtparam=audio=on
Press ctrl-x, y, and enter to save.
In the same terminal, edit ~/.asoundrc
nano ~/.asoundrc
Replace the content of that file with the following:
pcm.!default { type plug slave { pcm "hw:1,0" } } ctl.!default { type plug card 1 }
Press ctrl-x, y, and enter to save.
Unfortunately, I have yet to find a permanent way to set the default. In the meantime, you need to do it at every startup.
Enable SSH/VNC (Optional)
If you don't want to use the monitor, keyboard, and mouse at next startup, enabling these options would allow you to remote access the Pi. These options are under Preference/Raspberry Pi Configuration, then go to Interfaces and checkmark the SSH and VNC options.
Step 5: Install Alexa Software
I am not going to repeat the excellent instructions provided by the Alexa AVS sample project. Just go to their Github project (link) and follow the instructions there to setup the Alexa software.
Though there are a few points to note:
- You can skip Step 1 as you have already setup your Pi.
- Choose "1/ 3.5mm audio" in one of the confirmation questions asked by the automated_install.sh script.
- I am not able to start the Sensory wake word engine (illegal instruction encountered), so I use Snowboy (kitt_ai).
Step 6: Alexa, High Five!
Congratulation! Say "High Five" to Alexa.
If you have enabled SSH (or VNC server), you can restart the Pi and run Alexa software headless (without the monitor/keyboard/mouse). In your PC run three SSH terminals and connect to the Pi. Use those terminals to start the Alexa executables (i.e. "npm start", "mvn exec:exec", and "wakeWordAgent -e kitt_ai"). Another advantage to run headless is that the Alexa java program (mvn exec:exec) runs a bit smoother.
Overall, I am impressed with the performance of the Alexa sample running on Pi - the voice capturing is quite responsive, accurate and reliable. There is certainly a performance gap between the native Echo (Dot) and this setup but the gap is not that big. One thing I am not happy though is I can't get Amazon Prime Music playing on this setup although somebody said Prime Music is supported. Maybe there is a difference what Amazon allows between Canada and US or something that I have not set up right. If you know how to get Prime Music with the Alexa sample, please let me know.