Alexa Baked in a Pi

You can put Alexa in a Raspberry Pi, and that is pretty cool.

Alexa is Amazon's intelligent agent, like Siri for your living room. Standing nearby, you speak to it with a question or a command, and it responds verbally.

Normally Alexa lives inside a $180 device called an Amazon Echo, or the new $50 Echo Dot. But Emily Withrow at Northwestern University's KnightLab told me it was possible to put the Alexa code inside a cheap Raspberry Pi hobby computer. And I happened to have an old Pi lying around.

So I gave it a whirl!

Ingredients

The main components:

  • Raspberry Pi. It seems any version of the Pi will work. If you have a Pi, here's a good guide to what version it may be. Version 1 requires an extra step (more below).
  • A USB Microphone This is the one I used and it worked right off the bat.
  • A battery-powered speaker like this.
  • An SD memory card like this one.
  • A connection to the internet. I used an Ethernet cable to my router. Another option is a wifi dongle like this one. Version 3 of the Raspberry Pi comes with wifi capabilities installed.

My setup also uses:

During the setup only, I also used:

  • A USB keyboard.
  • A monitor with an HDMI inputs
  • An HDMI cable to connect the Pi to the monitor.

Prepping the Pi's Software

The Alexa Pi code isn't some under-the-table hack; the Amazon Alexa team itself has posted a complete guide for setting up Alexa on a Raspberry Pi on Github! Which is pretty amazing. I started by installing a new Raspbian operating system on the Raspberry Pi as described in Amazon's instructions.

Here I got stuck for a moment, because even though some documentation says using a 4GB memory card will work to hold the Pi's operating system I found that I needed to use (and go get) something bigger. I used a 32GB card.

Also, I'm using Version 1 of the Pi, and almost all of the documentation refers to Pi versions 2 and 3. But there's a discussion thread about using Version 1 that includes this comment about an extra shell command you need to use for Version 1:

wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb

With the Pi software set, I was ready to install Alexa.

Wake Me Up with Your Voice

When you use an Amazon Echo, you engage Alexa by saying "Alexa ..." followed by your command or question. Like "Alexa ... what's the weather today?"

About 15 days ago, the Amazon team added this "wake word" ability to the Pi code. They do this by including, and supprting, third-party speech sensing software. That software has some licensing restrictions you may want to check out.

I'm fully intend to try this, following all of the Amazon team's instructions. But when I built mine just a month ago, I did something slightly different.

Wake Me Up with a Button

My setup uses a physical button to "wake" Alexa -- partly because the "wake word" support didn't exist a mere four weeks ago(!), but also because I liked that something physical would be needed to open a microphone in the middle of my house. So I followed the instructions described in a video by Novasprit Tech, with some minor changes:

  • I used the original repo described in the video, not the copy he mentions. The original seems to have been fixed nicely. I installed it with:
git clone https://github.com/sammachin/AlexaPi.git
  • I didn't need to install Git with apt-get install git ... as it was already loaded.
  • I initially tried to operate my Pi remotely, over SSH (which is how I usually play with the Pi), but it turns out you actually have to wire up a keyboard and monitor because some of the steps involve hitting Amazon's developer website with the Pi's own browser. (You could also VPN into the Pi, but that's a hassle I didn't want to pursue.)
  • You must be logged into your Amazon developer account on the Pi's browser before running the setup described in the video. Otherwise you never make it to the page you need.
  • I didn't get the error described in the video; my creds.py file seemed to be set up correctly.

Here's the wiring diagram for the button and LED:

The Male-Female jumper wires make it easy to connect the Pi to the breadboard. Note that the GPIO pins for various versions of the Pi may be different. The key things to know are:

  • The Button connects to GND and GPIO 18
  • The Red LED leg connects to GPIO 24
  • The Green LED leg connects to GPIO 25
  • The Ground LED leg connects to GND

Here's more info on how the pins are numbered on a Pi.

Once I got it all wired up, it worked!

Troubleshooting

  • I had to force the Pi's audio through the 3.5mm jack instead of going to the HDMI cable as described here using: sudo raspi-config
  • I couldn't figure out how to get the software to recognize I was in New York, not Seattle, until I found the Alexa device home page.

Next Steps

One big improvement would be to power the speaker from the Pi's power supply, if that's possible. Right now, I'm using a battery-powered speaker, which I have to turn on to use Alexa (and remember to turn it off when I'm done).

The whole point of having a working version of Alexa was to try my hand at making "skills" -- which are like apps -- to extend the bot's capabilities. So that's next!