The Amazon Echo is useful to have around the home. It can play podcasts, take reminders and notes, tell you the length of your commute, even control other appliances in your house. But at prices ranging from $50 to $150, it’s an expensive proposition if you’re not sure you’ll use it. Good news though, you can make a fully-functional one using a Raspberry Pi.
What You’ll Get
By the end of this guide, you’ll have a (nearly) fully functioning Amazon Echo that responds to your voice commands. The one thing it can’t do is access music services like Amazon Prime, Spotify, or Pandora. Otherwise, it’s an Echo with all the bells and whistles of Alexa, Amazon’s virtual assistant. Which means it can do unit conversions, check sports scores, read your Kindle books to you, check the weather, play podcasts and radio, and tons more. Once you’re finished, you’ll be able to use the Alexa companion app (iOS and Android) to alter your Alexa’s settings, and you’ll be able to install all of the same skills that you can on a real Echo. This includes the likes of the Batman choose your own adventure game or a database of cat facts. Perhaps on the more useful end, it includes the recently announced integrations with third-party to-do apps like Todoist and Any.do.
It will also work with a variety of connected devices like smart light bulbs from the likes of LIFX or the Nest Thermostat, so you can control them with your voice. Like the real Echo, your DIY Echo can be linked up to If This Then That to add more features, like adding to-dos to Evernote or to get a notification on your phone when the timer goes off.
As far as price is concerned, there’s one thing we should mention here: Amazon’s newest Echo Dot (the smaller Echo with a junky speaker) is just $50, which makes creating your own from a $35 Raspberry Pi a much harder sell. However, there’s one key feature of the Raspberry Pi that makes it all worthwhile: it’s still a Raspberry Pi, and not a unitasking device. This project merely installs a set of programs that enable your Raspberry Pi to function like an Echo. Your Raspberry Pi can still work with a number of other projects, like a retro game station (you’ll just need to install the desktop environment) or a media center. This means you can turn it into a multitasking machine.
What You’ll Need
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)
It is theoretically possible to use an older Raspberry Pi or a Raspberry Pi Zero for this project, but you’ll need to manually install the latest version of Java to do so. This thread over on GitHub can help. We, however, tested this on the Raspberry Pi 2 and 3.
You’ll build your DIY Echo by installing the Amazon Alexa Skills Kit onto the Raspberry Pi. For this guide, we’ll be using Amazon’s official code. This comes with one caveat though: it requires you to manually start the Alexa service each time you boot the Pi. It’s annoying, but assuming you don’t lose power a lot or need to restart your Pi very often, it’s only a little annoying.
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.
Step Two: Clone and Install Alexa
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.
- Open the Terminal application on the Raspberry Pi and type:
cd Desktop
and press Enter. - Type in
git clone https://github.com/alexa/alexa-avs-sample-app.git
and press Enter. - Once that’s complete, type in:
cd ~/Desktop/alexa-avs-sample-app
and press Enter. - Type in
nano automated_install.sh
and press Enter. - 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. - 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. - Type in
. automated_install.sh
and press Enter. - 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.
Step Three: Run the Alexa Web Service
Next, you’re going to run three sets of commands at once in three different Terminal windows. You’ll create a new Terminal window for each of the following steps. Don’t close any windows! You’ll need to do steps three (this one,) four, and five every time you reboot your Raspberry Pi.
The first one you’ll start is the Alexa Web Service:
- Type in
cd ~/Desktop/alexa-avs-sample-app/samples
and press Enter. - 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.
Step Four: Run the Sample App and Confirm Your Account
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.
- In your new Terminal window type in
cd ~/Desktop/alexa-avs-sample-app/samples
and press Enter. - Type in
cd javaclient && mvn exec:exec
and press Enter. - 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.
- Log into your Amazon account in the browser.
- You’ll see an authentication screen for your device. Click Okay. Your browser will now display “device tokens ready.”
- 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.
Step Five: Start Your Wake Word Engine
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:
- Type in
cd ~/Desktop/alexa-avs-sample-app/samples
and press Enter. - Type in
cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai
That’s it, your DIY Echo is now running. Go ahead and try it out by saying “Alexa.” You should hear a beep indicating that it’s listening. When you hear that beep, ask a question like, “What’s the weather?” or “What’s the score in the Dodgers game?”
Step Six: Improve the Microphone and Make Sure Your Echo Can Hear You
Finally, depending on the quality of your microphone, you may notice that it has trouble hearing you. Instead of screaming “Alexa” at the top of your lungs, let’s go to the command line one last time.
- From the command line, type in
alsamixer
and press Enter. - Tap F6 to select a different USB device. Use the arrow keys to select your microphone.
- Use the arrow keys to increase the capture volume.
- When you’re happy with the volume, tap ESC to exit.
- Type in
sudo alsactl store
and press Enter to make the settings permanent.
Now, you should be able to trigger your DIY Echo by talking to it like a normal human instead of yelling. You can also change the default volume here if you need to.
Extra Credit: Add AirPlay Support
One thing your DIY Echo is missing from the commercial version is the ability to function as a Bluetooth speaker. You can add similar functionality with AirPlay. This way, your Echo also acts as a receiver that you can send music from your phone or computer to. It’s easy to add, you’ll just need one last trip to the command line through Terminal:
- Type in s
udo apt-get install git libao-dev libssl-dev libcrypt-openssl-rsa-perl libio-socket-inet6-perl libwww-perl avahi-utils libmodule-build-perl
and press Enter. This installs different software you’ll need. - Press Y when prompted and wait for everything to download and install.
- Type in
git clone https://github.com/njh/perl-net-sdp.git
and press Enter. This is required for the newest version of AirPlay’s software. The next few commands build and install this software. - Type in
cd perl-net-sdp
and press Enter. - Type in
perl Build.PL
and press Enter. - Type in
sudo ./Build
and press Enter. - Type in
sudo ./Build
test and press Enter. - Type in
sudo ./Build
install and press Enter. - Type in
CD ..
and press Enter. - Now you’ll grab shairport, the DIY Airport software. Type in
git clone https://github.com/hendrikw82/shairport.git
and press Enter. - Type in
cd shairport
and press Enter. - Type in
Make
and press Enter. - Type in
./shairport.pl -a AlexaPi
and press Enter.
With that, you can now stream music or other audio to your DIY Echo using the AirPlay protocol. Now that your Echo is up and running, go ahead and start playing around with it.