Tutorials

How to put Alexa on Raspberry Pi

Here's how you can build a home-brew Amazon Echo

There are a variety of ways that ingenious hacker types have got Amazon's Alexa to play nice with the Raspberry Pi, but we're going for the simplest method here, which is to install AlexaPi, a ready-built Python client.

First up, you'll need a Pi (ideally a Pi 3 or Zero W for ease of Wi-Fi connectivity), with a minimum 8GB MicroSD/SD card. You'll need to have Raspbian installed and either a keyboard, monitor and mouse or SSH/remote access enabled, and of course a power supply.

You'll also need a USB microphone and a speaker to plug into the headphone jack. The microphones can be picked up cheaply from the usual internet retailers, and the speaker can be improvised from any powered speaker that accepts a 3.5mm line in, which includes anything from a cheap Bluetooth speaker to a kitchen radio or a full spec Hi-Fi system.

Alternatively, you can buy this kit, designed by Google and sold through resellers like The Pi Hut, which includes a speaker and microphone, as well as all the various cables and connectors needed to hook it all up together.

Advertisement
Advertisement - Article continues below
Advertisement - Article continues below

It also includes a cardboard housing and an activation button, allowing you to basically build your own push-button AI assistant. The kit's designed to allow you to build projects with the Google Assistant, but there's no reason you can't also use it to create something with Alexa.

First you'll need to set up an Amazon Developer account, which is a free (albeit click-intensive) process.

Set up an Amazon Developer account

Once you've set up your Amazon Developer Account, log in. Click on the Alexa Tab, then click 'Register a Product Type', and 'Device'. Name your device type and display name, hit next, then on the Security Profile screen, click "Create new profile."

Under the General tab, next to "Security Profile Name" name your profile and fill in the description. Keep these three short and memorable, or note them down, as you'll need them for the final setup. Click Next.

Now note down the Product ID, Client ID, and Client Secret that is auto-generated - you'll need these to set up the Pi.

Next, hit the Web Settings tab > Edit (next to the profile dropdown), and in Allowed Origins, click, "Add Another" and type in: http://localhost:5050.

Advertisement - Article continues below

Click "Add Another," again, then type in http://your.raspberrypi.ip.address:5050 but replace 'your.raspberrypi.ip.address' with your Raspberry Pi's IP address (bold for emphasis).

Then repeat the steps with Allowed Return URLs, ie: click "Add Another" and type in: http://localhost:5050/code, then "Add Another" and add in http://your.raspberrypi.ip.address:5050/code. Hit Next when you're done.

Finally, the Device Details tab. Pick a category, write a description, pick an expected timeline, and enter 0 on the form next to how many devices you will deploy this on. Leave Amazon Music checked as "No", as it won't run on the Pi.

Whew. With that complete, you're ready to step back into the room and get the Pi up and running with Alexa.

Download and install Git

The next step is to install Git, followed by the actual repositories that will power your homebrew Echo. Kick off with the usual safety-first update with the standard command: sudo apt-get install update

Advertisement
Advertisement - Article continues below

Next, install Git, which is the code management tool that you'll need to unpack and run the AlexaPi software, followed by the software itself. Download Git with the command sudo apt-get install git, then type in cd /opt and press Enter to change the directory.

Advertisement - Article continues below

Finally, type in sudo git clone https://github.com/alexa-pi/AlexaPi.git to download the AlexaPi repos.

Set up AlexaPi

Now that you've downloaded the AlexaPi software, it's time to set it up. Type in sudo ./AlexaPi/src/scripts/setup.sh and press Enter.

Another series of questions is your reward - skip through the operating system and device prompts by hitting enter if you're using the Pi, then consider adding AirPlay support. If you've got an iOS device then being able to stream to your AlexaPi is exceedingly handy, but the software download will take a few minutes if selected.

Once that's downloaded (or dismissed), you'll be asked to enter your Amazon developer information from the earlier setup stages above, including Device Type ID and Security Profile Description, as well as the long Profile ID, Client ID, Client Secret numbers.

Finally, authorise your device. This is a one-time setup, so don't worry, you won't need to do this again. On a standard desktop, laptop or tablet, fire up a browser and type in http://your.raspberrypi.ip.address:5050 replacing your.raspberryi.ip.address with your Raspberry Pi's IP address from earlier. This will prompt you to login to your Amazon Developer account, which will in turn display an authorization token.

Running AlexaPi

With that, you're done - the the Alexa voice service is now installed on your Raspberry Pi. The final step is to simply start the service by rebooting the Pi or using the command:

Advertisement - Article continues below

sudo systemctl start AlexaPi.service

All being well, you'll now be able to speak Alexa commands into the mic, and hear responses back through the speaker. If not, first try typing: sudo systemctl status AlexaPi.service to check the status.

If the status log has dbus and pulseaudio errors (which can happen with the stock version of Raspbian) then you'll need to set up system-wide PulseAudio, or use a workaround.

Advertisement
Advertisement - Article continues below

You're now in a brave new world of voice-enabled Pi interaction - enjoy!

(Thanks to the folk who built and maintain AlexaPi)

Featured Resources

Transform the operator experience with enhanced automation & analytics

Bring networking into the digital era

Download now

Artificially intelligent data centres

How the C-Suite is embracing continuous change to drive value

Download now

Deliver secure automated multicloud for containers with Red Hat and Juniper

Learn how to get started with the multicloud enabler from Red Hat and Juniper

Download now

Get the best out of your workforce

7 steps to unleashing their true potential with robotic process automation

Download now
Advertisement

Recommended

Visit/hardware/32939/raspberry-pi-opens-its-first-high-street-store-in-cambridge
Hardware

Raspberry Pi opens its first high street store in Cambridge

7 Feb 2019
Visit/mobile/32762/a-raspberry-pi-computer-gets-squeezed-inside-a-mouse
Mobile

A Raspberry Pi computer gets squeezed inside a mouse

16 Jan 2019
Visit/mobile/21862/raspberry-pi-top-projects-to-try-yourself
Mobile

Raspberry Pi: Top 37 projects to try yourself

16 Oct 2019
Visit/hardware/33891/raspberry-pi-4-model-b-review-back-and-better-than-ever
Hardware

Raspberry Pi 4 Model B review: Back, and better than ever

13 Aug 2019

Most Popular

Visit/security/vulnerability/354309/patch-issued-for-critical-windows-bug
vulnerability

Patch issued for critical Windows bug

11 Dec 2019
Visit/cloud/microsoft-azure/354230/microsoft-not-amazon-is-going-to-win-the-cloud-wars
Microsoft Azure

Microsoft, not Amazon, is going to win the cloud wars

30 Nov 2019
Visit/operating-systems/microsoft-windows/354297/this-exploit-could-give-users-free-windows-7-updates
Microsoft Windows

This exploit could give users free Windows 7 updates beyond 2020

9 Dec 2019
Visit/hardware/354193/buy-it-to-grow-not-slow-your-business
Sponsored

Buy IT to grow, not slow, your business

25 Nov 2019