How to Build Your Own Amazon Echo Using Raspberry Pi
Amazon Echo is useful to have at home. It can play podcasts, take reminders and notes, tell you the length of your commute, and even control other appliances in your home. But at $ 50 to $ 150, it’s an expensive proposition if you’re not sure you’ll use it. Good news: you can make it fully functional using the Raspberry Pi.
Update : This method is a little easier and gives you a better end product . We keep this tutorial as it uses the official Amazon repositories, but the system works much better.
What do you get
By the end of this tutorial, you will have a (almost) fully working Amazon Echo that responds to your voice commands. The only 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. This means it can convert units, check athletic performance, read your Kindle books, check the weather, play podcasts and radio, and more. Once you’re done, you can use the Alexa companion app ( iOS and Android) to change your Alexa settings, and you’ll be able to install all the same skills you can use in a real Echo. This includes the likes of Batman, choose your own adventure game or cat database . Perhaps more useful, it includes recently announced integrations with third-party to-do apps like Todoist and Any.do.
It will also work with a variety of connected devices, such as smart bulbs from LIFX or the Nest Thermostat , so you can control them with your voice. Just like the real Echo, your DIY Echo can be linked to If This Then That to add more features like adding tasks to Evernote or getting a notification on your phone when the timer goes off.
As for the price, one thing should be mentioned here: Amazon’s newest Echo Dot (a smaller Echo with a crappy speaker) costs just $ 50, which makes building your own from a $ 35 Raspberry Pi much more difficult. However, there is one key feature of the Raspberry Pi that makes this all worthwhile: it is still a Raspberry Pi, not a single task device . This project simply installs a set of programs that make your Raspberry Pi run like an Echo. Your Raspberry Pi can still work with a number of other projects, such as a retro gaming station (you just need to install a desktop environment ) or a media center . This means you can turn it into a multitasking machine.
What do you need
As you’d expect, you’ll need a Raspberry Pi along with a few details:
- Raspberry Pi 3 (recommended) or Raspberry Pi 2 (you will also need a USB Wi-Fi adapter with model 2) with Raspbian installed. If you haven’t installed Raspbian before, our guide covers everything you need to know .
- MicroUSB power cable
- 8GB microSD card
- USB mic (I used this cheap $ 6 mic , but almost any USB mic seems to work. The $ 8 Playstation Eye seems to work especially well if you’re looking for a small upgrade)
- Speakers (any powered speaker does the job, I decided to use the UE Mini Boom because I already had one and even when connected to the Pi it still works as a bluetooth speaker)
- Keyboard and mouse for configuration (or accessing a computer with VNC )
It is theoretically possible to use the old or the Raspberry Pi Raspberry Pi Zero f O r t h i sp z O J e t r , b y so you will need to manually install the latest version of the Java , to do it. This GitHub thread might help. However, we tested this on Raspberry Pi 2 and 3.
You will build your DIY Echo by installing the Amazon Alexa Skills Kit on your Raspberry Pi. For this tutorial, we will be using the official Amazon code . However, there is one caveat here: you need to manually start the Alexa service every time you boot the Pi . It’s annoying, but assuming you’re not draining too much power or need to reboot the Pi very often, it’s just a little annoying.
Step 1: Register for an Amazon Developer Account
Before you do anything, you need to register for a free Amazon developer account and then create a profile for your DIY Echo. It’s pretty simple:
- Sign in to your Amazon developer account .
- Click the Alexa tab.
- Click Register Product Type> Device.
- Give your device type and display name (we chose “Raspberry Pi” for both).
- Click Next.
- On the Security Profile screen, click Create New Profile.
- On the General tab, next to the Security Profile Name field, 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 Origin, click Add More and enter:
https://localhost:3000
. - Next to Allowed Return URLs, click Add Another and enter:
https://localhost:3000/authresponse
Athttps://localhost:3000/authresponse
click Next. - Next comes the Device Information tab. It doesn’t matter what you enter here. Choose a category, write a description, choose an expected timeline and enter 0 in the form next to how many devices you plan to use this on. Click Next.
- Finally, you can add Amazon Music here. This does not work on a Pi powered device, so leave it checked. Click Save.
You now have an Amazon developer account and have created a profile for your Pi based Echo. It’s time to move on to the Raspberry Pi and get Alexa to work.
Step two: clone and install Alexa
Connect everything to your Pi and boot it up. To do this, you need a graphical user interface ( now called PIXEL ) because you will ultimately be using a web browser to authenticate your device.
- Open the Terminal app on your Raspberry Pi and type:
cd Desktop
and press Enter. - Type
git clone https://github.com/alexa/alexa-avs-sample-app.git
and press Enter. - After that enter:
cd ~/Desktop/alexa-avs-sample-app
and press Enter. - Type
nano automated_install.sh
and press Enter. - Your text editor will open. Here you will need to enter your ProductID, ClientID and ClientSecret that you noted in the step above. Use the ARROW KEYS to navigate to each entry. Enter each part after the
=
sign as shown in the image above. When you’re done press CTRL + X to save and exit. - You are now back at the command line. It’s time to run the installation script. Type
cd ~/Desktop/alexa-avs-sample-app
and press Enter. - Enter
. automated_install.sh
and press Enter. - When prompted, press Y to ask different questions and answer the rest as you see fit. This will configure your Pi and install additional software. This can take up to 30 minutes, so let him do his thing.
Once this is over, it’s time to start the Alexa service.
Step 3. Start the Alexa web service
Then you are going to run three sets of commands at the same time in three different Terminal windows. You will create a new terminal window for each of the following steps. Don’t close the windows! You will need to follow steps three (this), four and five every time you reboot your Raspberry Pi.
The first thing you’ll start is the Alexa web service:
- Type
cd ~/Desktop/alexa-avs-sample-app/samples
and press Enter. - Type
cd companionService && npm start
and press Enter.
This starts the companion service and opens the port for communication with Amazon. Leave this window open.
Step four: run the sample app and verify your account
Open a second terminal window (File> New Window). The next step launches a Java application and a web browser that logs your Pi based echo using the Alexa web service.
- In a new terminal window, type
cd ~/Desktop/alexa-avs-sample-app/samples
and press Enter. - Type
cd javaclient && mvn exec:exec
and press Enter. - A window will appear asking you to confirm the authenticity of your device. Click Yes. A browser window will open. A second pop-up window appears in the Java application asking you to click OK. Don’t click it yet.
- Log into your Amazon account in a browser.
- You will see an authentication screen for your device. Click OK. Your browser will now display “device tokens ready”.
- You can now click the OK popup in your Java application.
Your Raspberry Pi now has the tokens it needs to communicate with the Amazon server. Leave this terminal window open.
Step five: start your awakening mechanism
Finally, open a third terminal window (File> New Window). This is where you start the awakening mechanism. This allows you to say “Alexa” to get your Raspberry Pi to listen to you. You have two options for awakening software: Sensory and KITT.AI. Both are free, but Sensory will expire after 90 days, so let’s use KITT instead:
- Type
cd ~/Desktop/alexa-avs-sample-app/samples
and press Enter. - Enter
cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai
That’s it, your DIY Echo is now working. Try saying “Alexa”. You should hear a beep indicating that he is listening. When you hear this beep, ask a question such as “What is the weather?” or “What’s the score in the Dodgers game?”
Step six: upgrade your microphone and make sure your echo hears you
Finally, depending on the quality of your microphone, you may find it difficult to hear you. Instead of yelling “Alexa” with all our might, let’s get to the command line one last time.
- At the command prompt, type
alsamixer
and press Enter. - Press F6 to select another USB device. Use the ARROW KEYS to select your microphone.
- Use the ARROW KEYS to increase the capture volume.
- When you are satisfied with the volume, press ESC to exit.
- Type
sudo alsactl store
and press Enter to make the settings permanent.
You can now activate your DIY Echo by talking to it like a normal person instead of yelling. You can also change the default volume here if you need to.
Extra credit: adding AirPlay support
One thing your DIY Echo lacks in the commercial version is the ability to act as a Bluetooth speaker. You can add similar functionality using AirPlay . In this way, your Echo also acts as a receiver to which you can send music from your phone or computer. It’s easy to add, you just need to go to the command line one last time via Terminal:
- Type
sudo 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 will install other required software. - When prompted, press Y and wait for everything to download and install.
- Type
git clone https://github.com/njh/perl-net-sdp.git
and press Enter. This is required for the latest AirPlay software. The next few commands build and install this software. - Type
cd perl-net-sdp
and press Enter. - Type
perl Build.PL
and press Enter. - Type
sudo ./Build
and press Enter. - Type
sudo ./Build test
and press Enter. - Type
sudo ./Build install
and press Enter. - Type
CD ..
and press Enter. - You will now get shairport, the DIY Airport program. Type
git clone https://github.com/hendrikw82/shairport.git
and press Enter. - Type
cd shairport
and press Enter. - Type
make
and hit Enter. - Type
./shairport.pl -a AlexaPi
and press Enter.
Thanks to this, you can now stream music or other audio to your DIY Echo using the AirPlay protocol. Now that your Echo is up and running, start experimenting with it.