The Simplest Way to Build A Raspberry Pi-Powered Amazon Echo
The Amazon Echo can be a great device to have in your home. Upon voice command, it is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic and other real-time information. It can also control several smart devices acting as a home automation hub; controlling the temperature of your home, for instance.
However, much like all of our other fun and convenient little gadgets, it comes at a price. Ranging from $50 to $150, it can be something of an expensive convenience, particularly if you’re not quite sold on its value.
If you’ve any Maker proclivities, though, and you’d like to see if there’s a DIY alternative, here’s your answer: through the wonders of the Raspberry Pi, here’s how you can create your own, fully-functional Amazon Echo.
A brand of smart speaker developed by the innovative folks at Amazon, the Amazon Echo (or simply Echo) connects to the voice-controlled intelligent personal assistant service Alexa.
Remarkably, this DIY Echo works just like the real device, activated simply by saying the wake word “Alexa”.
While other DIY versions make use of Amazon’s official resources, this project utilizes a GitHub project called Alexa Pi. This installs the identical Alexa voice service that Amazon uses onto your Raspberry Pi.
What you’ll need for your DIY Alexa:
A Raspberry Pi is at the top of the list and here are the rest of the components required:
- A Raspberry Pi 3 (recommended), Raspberry Pi Zero W, or Raspberry Pi 2 (you’ll also need a USB Wi-FI adapter with the Model 2) with Raspbian installed and Wi-Fi set up. If you haven’t installed Raspbian before, our guide covers everything you need to know. While I’m going to concentrate on installing this on the Raspberry Pi, a number of other devices are supported. You can find a whole list here. I ran the installation on a C.H.I.P. as well just out of curiosity and it worked fine.
- 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) If you’re using the Raspberry Pi Zero W you’ll also need a MicroUSB-USB adapter.
- 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 use SSH, Adafruit’s Pi Finder makes this project much easier to do from your main computer because you can copy/paste the longer commands).
Step One: Register for a Free Amazon Developer Account
First up, before you start assembling anything, you’ll need to register for a free Amazon Developer Account, and create a profile for your DIY Echo.
- Log into your Amazon Developer Account.
- Click on the Alexa Tab.
- Click Register a Product Type > Device.
- Name your device type and display name (I arbitrarily chose “Pi2” for both, though you can enter pretty much whatever you want here), then click Next.
- On the Security Profile screen, click “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:
- Click “Add Another,” then type in
http://your.raspberrypi.ip.address:5050but replace with
your.raspberrypi.ip.addresswith your Raspberry Pi’s IP address. You can find your Pi’s IP address using the Pi Finder tool detailed here.
- Next to Allowed Return URLs, click “Add Another” and type in:
- Click “Add Another” and add in
http://your.raspberrypi.ip.address:5050/codeonce again replacing
your.raspberrypi.ip.addresswith your own info. 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: Install Git and AlexaPi
Next you’ll need to fire up Terminal on your Raspberry Pi because everything happens in the command line. Before you start the installation you need to update and install a couple things:
- Type in
sudo apt-get install updateand press Enter to make sure your version of Raspbian is up to date. Let it do its thing here.
- Type in
sudo apt-get install gitand press Enter to install Git. Again, let it do its thing.
- Type in
cd /optand press Enter to change the directory.
- Finally, type in
sudo git clone https://github.com/alexa-pi/AlexaPi.gitand press Enter to clone the AlexaPi GitHub repository. Again, give it a second to download and do its thing.
That’s it for the downloading portion, onward to actually installing it.
Step Three: Run the AlexaPi Installation Script
Next, you’ll run an installation script. This automates the installation of everything else you need to get your Echo up and running.
- Type in
sudo ./AlexaPi/src/scripts/setup.shand press Enter.
- You’ll be asked a series of questions. If you’re using the Raspberry Pi, just press Enter for both the operating system and device prompts. The last question asks if you want to add AirPlay support. If you have an iOS device, this makes it so you can easily stream music from your iPhone to your DIY Echo over Airplay. The script will then download a bunch of software for the next 5-10 minutes, so go ahead and relax for a bit.
- Eventually, you’ll be asked to enter in your Amazon developer information. Type in the Device Type ID and Security Profile Description you made way back in step one (we used AlexaPi). Next, you’ll need to enter in all those long, complicated numbers for your Profile ID, Client ID, Client Secret.
- Finally, the last thing you need to do is authorize your device. You only need to do this once. Head back to your main computer and open up a web browser. Than type in
your.raspberryi.ip.addresswith your Raspberry Pi’s IP address from earlier. You’ll then need to log into your Amazon account. After that, you’ll see an authorization token.
That’s it, the Alexa voice service is now installed on your Raspberry Pi. You just need to start the service. You can either just reboot your device completely, or type in
sudo systemctl start AlexaPi.service and press Enter to start it.
Go ahead and try it, say “Alexa” into the mic, and it should reply back with a “Yes?”
If it’s not working, you can type in
sudo systemctl status AlexaPi.service and press Enter to check the status.
Alexa will start up automatically when you reboot your device or if the power goes out for some reason, so you shouldn’t ever have to think about it again.
Thanks to LifeHacker for the resources for this project!
Here’s a fun little video fo the Alexa Pi or PiLexa in action: