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 https://github.com/alexa/alexa-avs-sample-app.git

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

Once these are added, run ". automated_install.sh" 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 automated_install.sh
$> . automated_install.sh

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...

No comments:

Post a Comment