How To Build Your Own Amazon Echo With A Raspberry Pi

How To Build Your Own Amazon Echo With A Raspberry Pi

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 it’s unavailable in Australia, and importing it is 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 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 and play podcasts and radio. 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 $US50 ($65), which might make creating your own from a $US35 ($46) Raspberry Pi a harder sell if you’re visiting the States soon and able to pick one up and hack it. 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

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 adaptor 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 $US6 ($8) mic, but pretty much any USB mic seems to work. The 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

How To Build Your Own Amazon Echo With A Raspberry Pi

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:

  1. Log into your Amazon Developer Account.
  2. Click on the Alexa Tab.
  3. Click Register a Product Type > Device.
  4. Name your device type and display name (We chose “Raspberry Pi” for both).
  5. Click Next.
  6. On the Security Profile screen, click “Create new profile”.
  7. Under the General tab, next to “Security Profile Name” name your profile. Do the same for the description. Click Next.
  8. Make a note of the Product ID, Client ID and Client Secret that the site generates for you.
  9. Click the Web Settings tab, then click the Edit button next to the profile dropdown.
  10. Next to Allowed Origins, click, “Add Another” and type in: https://localhost:3000.
  11. Next to Allowed Return URLs, click “Add Another” and type in: https://localhost:3000/authresponse Click Next when you’re done.
  12. 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.
  13. 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

How To Build Your Own Amazon Echo With A Raspberry Pi

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.

Step Three: Run the Alexa Web Service

How To Build Your Own Amazon Echo With A Raspberry Pi

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:

  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.

Step Four: Run the Sample App and Confirm Your Account

How To Build Your Own Amazon Echo With A Raspberry Pi

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

Step Five: Start Your Wake Word Engine

How To Build Your Own Amazon Echo With A Raspberry Pi

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

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

How To Build Your Own Amazon Echo With A Raspberry Pi

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.

  1. From the command line, type in alsamixer and press Enter.
  2. Tap F6 to select a different USB device. Use the arrow keys to select your microphone.
  3. Use the arrow keys to increase the capture volume.
  4. When you’re happy with the volume, tap ESC to exit.
  5. 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

How To Build Your Own Amazon Echo With A Raspberry Pi

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:

  1. Type in 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 installs different software you’ll need.
  2. Press Y when prompted and wait for everything to download and install.
  3. Type in git clone https://github.com/njh/perl-net-sdp.gitand press Enter. This is required for the newest version of AirPlay’s software. The next few commands build and install this software.
  4. Type in cd perl-net-sdp and press Enter.
  5. Type in perl Build.PL and press Enter.
  6. Type in sudo ./Build and press Enter.
  7. Type in sudo ./Build test and press Enter.
  8. Type in sudo ./Build install and press Enter.
  9. Type in CD .. and press Enter.
  10. Now you’ll grab shairport, the DIY Airport software. Type in git clone https://github.com/hendrikw82/shairport.git and press Enter.
  11. Type in cd shairport and press Enter.
  12. Type in Make and press Enter.
  13. 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.


The Cheapest NBN 50 Plans

Here are the cheapest plans available for Australia’s most popular NBN speed tier.

At Lifehacker, we independently select and write about stuff we love and think you'll like too. We have affiliate and advertising partnerships, which means we may collect a share of sales or other compensation from the links on this page. BTW – prices are accurate and items in stock at the time of posting.

Comments


8 responses to “How To Build Your Own Amazon Echo With A Raspberry Pi”