Alexa Voice Assistant on Raspberry Pi Zero Docking Hub

6,065

57

9

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:

  1. 1x Raspberry Pi Zero W
  2. 1x Raspberry Pi Zero Docking Hub
  3. 1x HDMI monitor
  4. 1x HDMI cable (please note Pi Zero W requires a mini-HDMI connector)
  5. 1x 5v USB 1 A Power Adaptor
  6. 1x micro USB cable
  7. 1x USB keyboard
  8. 1x USB mouse
  9. 1x Mini-Microphone For Mobile Phone/Tablet (the one that supports split speaker port)
  10. 1x External Speaker with 3.5mm Audio Jack.
  11. 1x 3.5mm audio cable (male-to-male)
  12. 1x 8G micro SD card
  13. 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.

  1. Download and install Etcher (https://etcher.io/) for your host PC.
  2. Download the latest Raspbian image from http://downloads.raspberrypi.org/raspbian/images/
  3. Insert the SD into your PC
  4. 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:

  1. You can skip Step 1 as you have already setup your Pi.
  2. Choose "1/ 3.5mm audio" in one of the confirmation questions asked by the automated_install.sh script.
  3. 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.

Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • PCB Contest

      PCB Contest

    9 Discussions

    0
    None
    georgefelix

    4 months ago

    can alexa work without internet connection?

    0
    None
    BruceF11

    11 months ago

    This project calls for parts that aren't even available until May of 2018.

    This "instructable" looks like a pretty blatant promotion of a kickstarter project

    1 reply
    0
    None
    GanieBBruceF11

    Reply 11 months ago

    And as I mentioned, I personally think it is a more expensive option than just using pi3b. It's less bulky, too. Any USB mic will work on it (including a generic webcam).

    0
    None
    Mikkel1955

    11 months ago

    A couple more thoughts. Look at the time stamps on the files. Also, how are you rebooting? If you are using "sudo reboot" try using "sudo shutdown -r now" instead.

    1 reply
    0
    None
    SpotForMakersMikkel1955

    Reply 11 months ago

    I tried both and there is no difference. I suspect the problem is related to the audio output is set to "Auto" in raspi-config - there are a few StackOverflow comments mentioned that. However, I tried to change to "Force to 3.5mm" but it fails. Likely because I have disabled the output audio in config.txt - that is needed to get Alexa (and the wakeword) software working.

    0
    None
    GanieB

    11 months ago

    I don't dig the pi zero and dock combination. Why not use a pi3b instead? It's probably cheaper too.

    0
    None
    Mikkel1955

    11 months ago

    You can try putting the sound configuration in /etc/asound.conf. The other option is editing /etc/modprobe.d/alsa-base.conf.


    2 replies
    0
    None
    SpotForMakersMikkel1955

    Reply 11 months ago

    I tried "/etc/asound.conf" but it didn't work. Every time when it reboots the system will overwrite that file with:

    pcm:!default {

    type plug

    card 1

    }

    ctl:!default {

    type plug

    card 1

    }

    And for some reason, the Alexa software doesn't like that configuration even it is still pointed to the same device.

    I will take a look /etc/modprobe.d/alsa-base.conf. Thx.

    0
    None
    Mikkel1955SpotForMakers

    Reply 11 months ago

    The system should not be overwriting these files. Are you sure you don't have a read-only file system with a RAM overlay for changes? That would account for the files not surviving a reboot. But I am at a loss on how you would create one and not know it.