Running Amazon Echo (Alexa) on Raspberry Pi Zero


Amazon Echo or Alexa is a device and service by Amazon, which allows you to request news, weather information or even automate your home using voice control. People have succeeded in running the Echo software on the Raspberry Pi, making it a low cost and easy to install voice control solution.

Components

The components you’ll need for this build are:

  • Raspberry Pi Zero (works with Pi 2 and 3 as well)
  • USB soundcard with microphone input
  • microphone
  • speaker with amplifier
  • momentary switch
  • USB hub (if using Pi Zero)
  • wifi dongle
  • enclosure or box to store everything in

Software

Amazon Echo

To install Amazon Echo on the Pi, I followed the instructions from Novaspirit Tech:

The instructions in the video are clear and straightforward. Everything was installed in less than 10 minutes.

I did run into issues with Python reaching 100% CPU and some glitches in the audio, so I made modifications to the main script.

 

Default Sound

To have the Pi use the USB sound card by default, some minor changes are required. Edit or create the asound.conf file as follows:

Once the file has been edited or created, restart the process to apply the changes.

Start / Restart

To have the application automatically start at boot and restart whenever it crashes, I created a helper script that check if the process is running, and if it is not, starts it.

Using cron, the script is executed every minute to start/restart the process if needed. You can change the cron expression to check more or less frequently.

Hardware

Connections

The connections are rather straightforward, and can even be configured to be different, in the main.py script of AlexaPi.

In my case, the following connections were made:

  • 5V / GND: power audio amplifier
  • GPIO 25 / GND: arcade button LED
  • GPIO 21Β / GND: arcade button switch

Or as illustrated below:

Screen Shot 2016-04-07 at 21.55.20

Enclosure

For the enclosure, I reused an old box with magnetic lid, which I covered in duct tape to make it silver. I then cut a hole in the top lid for the arcade button to fit in, and a smaller hole at the back for the power cord. A Raspberry Pi sticker is used for decoration.

On the inside of the box are the components, with the speaker and microphone glued to the lid. The result may be messy on the inside, but it is clean on the outside πŸ™‚

IMG_1247 IMG_1248

What can it do ?

Well, pretty much anything! You can ask Alexa about the weather, the news, or even to turn the lights on or off.

Alexa can also be linked to IFTTT, giving access to a bunch of channels using voice control, simply by saying “Alexa, trigger …”.

Try it, you’ll be surprised how easy it is!

27 thoughts on “Running Amazon Echo (Alexa) on Raspberry Pi Zero”

  1. Hi Frederick,
    Great post – as usual!

    I already have a zero and a USB hub, and want to copy exactly what you did, and need some guidance please.

    Could you publish exactly what microphone and button you used (link to Amazon/EBay would really help..) My kids would love to use that button.

    I have a bunch of those cheapest USB dongles with a headphone and a microphone output. I know they work for audio out, but do you happen to know if those devices can provide the audio out and microphone input at the same time? Or do you recommend buying that adafruit card you used and wire a small speaker to it?

    Many thanks, and keep publishing these great posts.

    1. Hi Martin!

      The big button was bought from Pimoroni: https://shop.pimoroni.com/products/massive-arcade-button-with-led-100mm-red
      Of course, it doesn’t need to be that specific button. Any button will do.

      The microphone I used is a Boya microphone from Amazon (https://www.amazon.co.uk/Boya-Lavelier-Condenser-Microphone-Adapter/dp/B00OKBU32A/ref=sr_1_3?ie=UTF8&qid=1462306304&sr=8-3&keywords=boya). I found similar microphones on eBay for 1 EUR though. They have yet to arrive, but will be a much cheaper alternative, as the quality probably doesn’t need to be excellent for Alexa to understand.

      I used a cheap USB dongle as well. They do both input and output simultaneously. Don’t expect too much quality of the output, but for such an application, it is more than enough and super cheap.

      The adafruit amplifier module is needed if you plan to use a speaker, not when using a headset.

      Hope this helps!

  2. great post!!
    I was searching for a start up script to include the main.py. I liked your approach.
    do you need to add python keyword before calling the main.py in your shell script.

    Thanks

  3. I followed the instructions, and all seems to bet working fine, I get the same replays from putty. But I cannot hear anything. I am using a pi 3b with the 3.5mm output for speaker and microphone.

    1. Hi Jason. As I’m using a Pi Zero with USB soundcard, I changed the audio output by editing the asound.conf file. If you wish to keep the onboard sound, you should skip that step, or set the “card” to 0 instead of 1.

      Let me know if that works for you πŸ™‚

  4. Hi I’m a bit of a noob. What is the main script that I have to edit? Where is it located?

    Thanks
    Steven

  5. I got the official Alexa on Pi running but see little help to control my gpio by voice commands.
    I am now in the middle of trying the new Alexa “wake on the word” method.

    I want to use it for IOT on my LAN
    You hint that it can “even to turn the lights on or off.” – could you give a few pointers please?
    Thanks!

      1. I got that running but after leaving it on all night I was frozen out because I had sent over 1000 requests – no idea how.

        All I did was follow the instructions to the letter……

    1. I installed the latest version on a Pi Zero yesterday, but unfortunately, the application causes CPU to max out at 100%. This results in unresponsiveness and the CPU to become very hot πŸ™

  6. I love your projects this one is AMAZING πŸ™‚

    I want to make what you made with the same materials, like with raspberry zero. Does this still work for the new version of jessie on the raspberry pi zero?? If not what version of jessie did you use for this project.

    Thanks in Advance πŸ™‚

    1. Thanks!

      I would assume this still works, even on latest Jessie, though I haven’t tried it.
      What I do know, is that the latest official Alexa guide with voice activation does not work on Pi Zero, as it results in 100% CPU and becomes non-responsive.

  7. You know what’s crazy? I found myself on this page today, researching a future project. Then in the sidebar I see #iltms..
    I clicked the link, and realized that you tweeted at me this morning after receiving your shirt! Crazy..
    Anyway, good work here! I’ll be referring to this in the future! πŸ˜‰

    1. That is crazy! Love your stuff, it’s very inspirational! I recently also created a spiral speaker after remembering your spiral plywood vase from a couple of years back!

      Thank you for taking the time to leave a comment, means a lot! πŸ™‚

  8. Very helpful guide and I appreciate it. After getting everything installed, I run into the 100% CPU issue with Python, too. However, I was not able to get your suggested edit to work. Below is a section of the main.py file showing what I entered (and where). Bash gives me a Syntax Error File “main.py”, line 29 elif val ==1: with a carrot pointing at the “f” in elif

    Do you have any suggestions?
    #Settings
    button = 18 #GPIO Pin with button connected
    lights = [24, 25] # GPIO Pins with LED’s conneted
    device = “plughw:1” # Name of your microphone/soundcard in arecord -L

    #Setup
    recorded = False
    servers = [“127.0.0.1:11211”]
    mc = Client(servers, debug=1)
    path = os.path.realpath(__file__).rstrip(os.path.basename(__file__))

    #avoid CPU at 100 percent with Python – added from frederickvandenbosch’s web site at
    # frederickvandenbosch.be/?p1701
    elif val == 1:
    time.sleep(0.5)

    def internet_on():
    print “Checking Internet Connection”
    try:

Leave a Reply

Your email address will not be published. Required fields are marked *