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:

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:

  1. Sign in to your Amazon developer account .
  2. Click the Alexa tab.
  3. Click Register Product Type> Device.
  4. Give 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. On the General tab, next to the Security Profile Name field, 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 Origin, click Add More and enter: https://localhost:3000 .
  11. Next to Allowed Return URLs, click Add Another and enter: https://localhost:3000/authresponse At https://localhost:3000/authresponse click Next.
  12. 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.
  13. 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.

  1. Open the Terminal app on your Raspberry Pi and type: cd Desktop and press Enter.
  2. Type git clone https://github.com/alexa/alexa-avs-sample-app.git and press Enter.
  3. After that enter: cd ~/Desktop/alexa-avs-sample-app and press Enter.
  4. Type nano automated_install.sh and press Enter.
  5. 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.
  6. 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.
  7. Enter . automated_install.sh and press Enter.
  8. 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:

  1. Type cd ~/Desktop/alexa-avs-sample-app/samples and press Enter.
  2. 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.

  1. In a new terminal window, type cd ~/Desktop/alexa-avs-sample-app/samples and press Enter.
  2. Type cd javaclient && mvn exec:exec and press Enter.
  3. 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.
  4. Log into your Amazon account in a browser.
  5. You will see an authentication screen for your device. Click OK. Your browser will now display “device tokens ready”.
  6. 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:

  1. Type cd ~/Desktop/alexa-avs-sample-app/samples and press Enter.
  2. 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.

  1. At the command prompt, type alsamixer and press Enter.
  2. Press F6 to select another USB device. Use the ARROW KEYS to select your microphone.
  3. Use the ARROW KEYS to increase the capture volume.
  4. When you are satisfied with the volume, press ESC to exit.
  5. 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:

  1. 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.
  2. When prompted, press Y and wait for everything to download and install.
  3. 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.
  4. Type cd perl-net-sdp and press Enter.
  5. Type perl Build.PL and press Enter.
  6. Type sudo ./Build and press Enter.
  7. Type sudo ./Build test and press Enter.
  8. Type sudo ./Build install and press Enter.
  9. Type CD .. and press Enter.
  10. You will now get shairport, the DIY Airport program. Type git clone https://github.com/hendrikw82/shairport.git and press Enter.
  11. Type cd shairport and press Enter.
  12. Type make and hit Enter.
  13. 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.

More…

Leave a Reply