November 30, 2016

DIY Alexa Raspberry Pi Voice Assistant

Amazon did something really cool. They made their Alexa voice assistant code open source and cross platform. That means instead of buying their Amazon Echo to get a home assistant, you can simply install it on any system you want.

It's actually a fairly straightforward project, especially if you've setup a Raspberry Pi before (or eight #fromthevault)! Basically you're just installing an application, and setting up a microphone and speaker. Nothing fancy.

There are already some great guides for getting started too for both Raspberry Pi and Alexa. I'm just going to direct you to these, give a rough overview, and add some additional tips.

Here it is in action:

Shopping List

For equipment, you'll need:

1. A Raspberry Pi 3 with SD card and USB micro power source:

2. A monitor with HDMI, and a keyboard and mouse for the install. These can be borrowed from another machine, as you don't need them once it's running.

3. A speaker and microphone combo. Any speaker with a 3.5mm Aux input will work. Microphone must be USB connected. I am using:

Raspberry Pi Raspbian Installation

The Raspberry Pi is the brain of Alexa, and needs an operating system and internet connection to function. I strongly recommend Raspbian Jessie with Pixel (download and install guide can be found here). This is what most Raspberry Pi projects have been tested on, so things tend to go more smoothly.

Once the Pi starts up, run the following in terminal to get the software up to date:

$> sudo apt-get update
$> sudo apt-get upgrade

Install Alexa

To install Alexa, head over to the excellent guide by Amazon.

Essentially it boils down to getting a developer account here, and following the steps here to setup the credentials you need for a home application. Note your Device ID, Client ID, and Client Secret from your developer account.

Then head to your Pi and run the following in a terminal:

$> git clone

Now the repository is downloaded. Navigate to the new alexa-avs-sample-app directory and edit to include your personal Device ID, Client Secret, and Client ID.

Once these are added, run "." to begin installation. The install script configures the audio devices on your Pi too, so make sure your speaker and mic are plugged in at this stage.

These commands look like:

cd alexa-avs-sample-app
$> nano
$> .

This process takes about 30 minutes, and will have a few prompts along the way.

Running Alexa

When you finish the installation, you'll see instructions of how to proceed. The Amazon install guide also covers running these three steps.

Command 1:

The first command starts the companion service which opens port 3000 for communication with Amazon.

$> cd ~/Desktop/alexa-avs-sample-app/samples
$> cd companionService && npm start

Command 2:

The second starts the Alexa app, which prompts you to open a browser and get authenticated.

If this fails in Chromium try going to settings -> advanced -> Privacy -> content settings -> allow key generation.

$> cd ~/Desktop/alexa-avs-sample-app/samples
$> cd javaclient && mvn exec:exec

Command 3:

The last command enables the use of Wake Words. If this fails, there is probably something wrong with your audio setup. I had to re-run the install after using a new mic. You can use kitt_ai or sensory, I use kitt_ai as it doesn't require a license renewal and works great.

$> cd ~/Desktop/alexa-avs-sample-app/samples
$> cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai

Once all three are running, you should be able to say "Alexa" (wait for the acknowledging beep), and speak with your personal assistant to your hearts content.

If you are running "Headless" (with no monitor), checkout this page on how to setup a VNC server  and run a graphical session remotely.

Using  Alexa

Now that you've got a personal assistant, what should you do?

My favourite voice commands so far are:
  • Tell me a joke.
  • Do you believe in ghosts?
  • Do you like Jeff Bezos?
  • Sing me a song.
  • I am your father. 
To customize the experience, go to the Amazon Alexa page. The app also doesn't allow non USA addresses. This means I have to say "what's the weather in Toronto" instead of "What's the weather". It does have my address on record under traffic though, and seems to know about local businesses.

There's also the Mr. Robot treatment where you use Alexa as your therapist. Suit yourself...


emna barred said...

is it possible to configure alexa to speak french?

Unknown said...

I don't think so. Currently Alexa only speaks English (US & UK) and German.

Ben said...

Dude, I love your website and this tutorial. I've installed this Alexa Service on my RPi and it works. But I'm wondering how you make it "Always On", or "Automatic" I mean, this sample asks you to click on "Listen" each time you use alexa but on your video you do not seem to require this, how do you do that? Thanks in advance for your help -Ben

Anonymous said...

is it possible to installed on laptop which running linux

Abdelrahman said...

do I have to have a microphone usb since my speaker has a mic?

Ben Eagan said...

Yes it's possible on a laptop.

You may not need microphone usb if your speaker has it built it... Just something you'll have to test!

Unknown said...

Hi Ben, thank you for the guides, they've been extremely helpful. I'm having a small problem that I was hoping you could help me with. When I have the three terminal windows open to run Alexa and I open a fourth terminal window to run MagicMirror, I experience so much lag that MagicMirror will not fully load. Any suggestions to get them both to run at the same time?

Post a Comment