AlexaPi Amazon echo

How to Build Your Own Amazon Echo with a Raspberry Pi

As you’d expect, you’ll need a Raspberry Pi alongside a handful of parts:

A Raspberry Pi 3 (recommended) or Raspberry Pi 2 (you’ll also need a USB Wi-FI adapter with the Model 2) with Raspbian installed. If you haven’t installed Raspbian before, our guide covers everything you need to know.
A MicroUSB power cable
An 8GB MicroSD card
A USB Microphone (I used this cheap $6 mic, but pretty much any USB mic seems to work. The $8 Playstation Eye seems to work especially well if you’re looking for a slight upgrade)
Speakers (any powered speaker does the job, I decided to use a UE Mini Boom because I already owned it and even when it’s plugged into the Pi, it still works as a Bluetooth speaker)
A Keyboard and Mouse for setup (or access to a computer with VNC)

Step One: Register for an Amazon Developer Account

Before you do anything, you’ll need to register for a free Amazon Developer Account, then create a profile for your DIY Echo. This is pretty straightforward:

Log into your Amazon Developer Account.
Click on the Alexa Tab.
Click Register a Product Type > Device.
Name your device type and display name (We chose “Raspberry Pi” for both).
Click Next.
On the Security Profile screen, slick “Create new profile.”
Under the General tab, next to “Security Profile Name” name your profile. Do the same for the description. Click Next.
Make a note of the Product ID, Client ID, and Client Secret that the site generates for you.
Click the Web Settings tab, then click the Edit button next to the profile dropdown.
Next to Allowed Origins, click, “Add Another” and type in: https://localhost:3000.
Next to Allowed Return URLs, click “Add Another” and type in: https://localhost:3000/authresponse Click Next when you’re done.
The Device Details tab is next. It doesn’t matter much what you enter here. Pick a category, write a description, pick an expected timeline, and enter a 0 on the form next to how many devices you plan on using this on. Click Next.
Finally, you can choose to add in Amazon Music here. This does not work on the Pi powered device, so leave it checked as “No.” Click Save.

Now you have an Amazon Developer Account and you’ve created a profile for your Pi-powered Echo. It’s time to head over to the Raspberry Pi and get Alexa working.

Plug everything into your Pi and boot it up. You’ll need to be in the graphic user interface (now dubbed PIXEL) for this because you eventually use a web browser to authenticate your device.

  1. Open the Terminal application on the Raspberry Pi and type: cd Desktop and press Enter.
  2. Type in git clone https://github.com/alexa/alexa-avs-sample-app.git and press Enter.
  3. Once that’s complete, type in: cd ~/Desktop/alexa-avs-sample-app and press Enter.
  4. Type in nano automated_install.sh and press Enter.
  5. This pulls up your text editor. Here, you’ll need to enter your ProductID, ClientID, and ClientSecret that you notes in the step above. Use the arrow keys to navigate to each entry. Enter each detail after the = sign as noted in the image above. When you’re done, tap CTRL+X to save and exit.
  6. You’re now back at the command line. It’s time to run the install script. Type in cd ~/Desktop/alexa-avs-sample-app and press Enter.
  7. Type in . automated_install.sh and press Enter.
  8. When prompted, press Y for the different questions, and answer as you see fit for the rest. This will configure your Pi and install some extra software. This can take up to 30 minutes, so just let it do it’s thing.

Once that finishes, it’s time to start the Alexa service.

The first one you’ll start is the Alexa Web Service:

  1. Type in cd ~/Desktop/alexa-avs-sample-app/samples and press Enter.
  2. Type in cd companionService && npm start and press Enter.

This starts the companion service and opens up a port to communicate with Amazon. Leave this window open.

Open up a second Terminal window (File > New Window). This next step runs a Java app and launches a web browser that registers your Pi-powered Echo with the Alexa web service.

  1. In your new Terminal window type in cd ~/Desktop/alexa-avs-sample-app/samples and press Enter.
  2. Type in cd javaclient && mvn exec:exec and press Enter.
  3. A window will pop up asking you to authenticate your device. Click Yes. This opens up a browser window. A second pop-up will appear in the Java app asking you to click Ok. Do not click this yet.
  4. Log into your Amazon account in the browser.
  5. You’ll see an authentication screen for your device. Click Okay. Your browser will now display “device tokens ready.”
  6. You can now Click the Ok pop-up in the Java app.

Now, your Raspberry Pi has the necessary tokens to communicate with Amazon’s server. Leave this Terminal window open.

Finally, open a third Terminal window (File > New Window). Here, you’ll start the wake word engine. This makes it so you can say “Alexa” to make your Raspberry Pi start listening to you. You have two options for wake word software, Sensory and KITT.AI. Both are free, but Sensory expires after 90 days, so let’s use KITT instead:

  1. Type in cd ~/Desktop/alexa-avs-sample-app/samples and press Enter.
  2. Type in cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai

####Script for alexa voice service.######

[email protected]:~/Desktop $ cat alexa_start.sh
#!/bin/bash
cd ~/Desktop/alexa-avs-sample-app/samples
cd companionService && npm start& > /home/pi/Desktop/alexa.log 2>&1
sleep 8
cd ~/Desktop/alexa-avs-sample-app/samples
cd javaclient && mvn exec:exec & > /home/pi/Desktop/alexa.log 2>&1
sleep 25
cd ~/Desktop/alexa-avs-sample-app/samples
cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai & > /home/pi/Desktop/alexa.log 2>&1

Leave a Reply

Your email address will not be published. Required fields are marked *