To effectively “Build” our own Alexa speaker, we'll install Amazon Voice Service (AVS) on a Raspberry Pi 4 in this tutorial. We'll call this project AlexaPi. The Amazon Alexa Voice Service (AVS) SDK makes this project feasible. We'll discuss a Raspberry Pi Alexa with a visual interface in a future article if you're set on an Echo Show on Raspberry Pi (Alexa with a screen). The AlexaPi with screen project cannot be started until the stages in the article have been completed.
Why build an Alexa when you could just buy one?
If you don't already have a Raspberry Pi, an Amazon Echo device is less expensive. As of this writing, a brand new Echo Dot sells for $24.99 on Amazon, which is $10 less than the cheapest Raspberry Pi 4, even before you factor in the cost of extra components.
The educational process, not the result, is what makes AlexaPi so enjoyable. You'll get an understanding of how Alexa works behind the scenes and possibly spark an interest in creating your unique device with Alexa included in it. To encourage device makers to incorporate Alexa into their products, Amazon has made this Pi project possible.
What is the difference between AlexaPi and Echo devices?
AlexaPi includes many of the basic features of an Echo device, but it is not intended to be a replacement for purchasing an Echo device. These are some key similarities and differences between Echo and AlexaPi.
- IHeartRadio, TuneIn, and Audible are some of the music services that are activated by default (for US users at the time of the writing of this article). Additional Music Service Providers (MSPs) must be requested with “your Amazon point of contact,” according to Amazon. Once again, the purpose of this project was to encourage hardware makers to include Alexa in their products for sale.
- The same process can be used to operate smart home devices like the TP-Link Kasa, Teckin Avatar, and more with your AlexaPi.
- On AlexaPi, Alexa skills are accessible. For instance, ask Alexa to start the cat food. This is a skill I wrote that plays the sound of opening a can of cat food.
- Calling and messaging: At the time of writing this article in the US, calling using AlexaPi is not supported.
What You’ll Need
- Raspberry Pi 3 or Raspberry Pi 4
- Micro SD Card or an SD card if you’re using an old version of the Pi.
- Power Supply
- USB Keyboard
- USB Mouse
- HDMI Cable
- USB Microphone
- Mini Speaker
Timing: Give yourself a minimum of one hour to do this project. Depending on your Pi model and internet speed, the primary install step takes 30 minutes to over an hour.
The majority of this tutorial is focused on terminal commands. We strongly recommend reading through 25+ Linux Commands Raspberry Pi Users Need to Know first if they are unfamiliar with terminal commands on your Raspberry Pi.
AlexaPi Setup and Install
- Connect your Raspberry Pi to your USB speaker and microphone.
- Boot your Raspberry Pi. See our articles on How to Setup a Raspberry Pi: A Beginner’s Guide or How to do a headless Raspberry Pi install. if you don't already have a microSD card.
- Launch the Chromium browser on your Pi desktop.
- Create or login to your Amazon developer account at https://developer.amazon.com/.
- Click on Developer Console in the top-right corner.
- Mouse over Alexa and click Alexa Voice Service.
- Click Manage Your Products
- Click Add New Products
- Complete the Product Information form.
- Give your product a name and an ID.
- Select Device with Alexa built-in for a product type.
- Select No for the companion app.
- Select Other for Product Category and enter your value in the text field.
- Enter your Brief product description.
- Select Hands-free for “How will end users interact with your product?”
- Uploading an image is optional.
- Select No for commercial distribution, Alexa for Business, AWS IoT Core, and children’s products.
- Click Next.
Next, you’ll be prompted to set up your AVS Security profile.
- Click Create New Profile.
- Enter your profile name and description.
- Click Next.
- Click Other Devices and Platforms in the Platform Information area.
- Enter a Client ID name of your choosing.
- Click Generate ID.
- Click Download, and a config.json file will download to your Pi.
- Check the box for terms and conditions and click Next.
- Click OK. You’ll be taken back to the product page. You should see the product you just created.
- Select AV Jack by right-clicking the speaker icon in the top-right corner of your Raspberry Pi desktop.
- Set the volume to 100%, and left-click on the same speaker icon.
- Open your file manager and navigate to your Downloads folder.
- Move your config.json file from Downloads to pi.
- Open a Terminal on your Raspberry Pi desktop.
- Run updates: udo apt-get update && sudo apt-get upgrade
- Next, enter the following as one command:
wget https://raw.githubusercontent.com/alexa/avs-device-sdk/master/tools/Install/setup.sh \ wget https://raw.githubusercontent.com/alexa/avs-device-sdk/master/tools/Install/genConfig.sh \ wget https://raw.githubusercontent.com/alexa/avs-device-sdk/master/tools/Install/pi.sh
- Next, run the install script.
sudo bash setup.sh config.json [-s 1234]
- Type Agree and press Enter if you agree with AVS's terms and conditions. Depending on your Raspberry Pi model and internet speed, this step might take anywhere from 30 minutes to over an hour.
- You'll be prompted to review the license agreement throughout the installation process. To view the agreement, press Enter. To page through the agreement, press the spacebar.
- When prompted, type yes if you accept the license agreement.
Your build is complete when you see **** Completed Configuration/Build ***.
- During installation, your Raspberry Pi could sometimes freeze or overheat. If this occurs, unplug your Raspberry Pi and let it cool for at least five minutes. Restart your terminal command when your Pi has cooled, and plug it back in. sudo bash setup.sh config.json [-s 1234].
- If you get a fatal error, use curl/curl.h: No such file or directory, which means you must install curl. Enter the following in your terminal:
sudo apt-get install libcurl4-openssl-dev sudo apt-get install libcurl4-gnutls-dev
Launching AVS on Raspberry Pi
Congratulations if you reached **** Completed Configuration/Build *** in the previous step! In the next step, we will start the Alexa app and verify Alexa with our account. Authentication only needs to be done once per AVS app.
- In the terminal, enter
sudo bash startsample.sh
- In your terminal, you'll see a lot of lines scrolling quickly. Scroll up till you see: Visit “https://amazon.com/us/code” to authorize and input the code: [Your unique 6-digit code here]
- In your Chromium browser, navigate to https://amazon.com/us/code.
- Enter the provided code and click “Continue“.
- Click Allow.
- If you see “Success! Your registration is now complete”, you can start testing your AlexaPi.
- Say, “Alexa, good morning.” This should be a “hands-free” experience that does not require you to press any more keys for it to function. Great work if your AlexaPi responds!
- By asking, “Alexa,…” you may now continue to test your AlexaPi. This is a list of “Fun Things to Ask Alexa“.
- In your Chromium browser, navigate to https://alexa.amazon.com.
- location. After you set your device location, you can listen to your current local weather by saying, “Alexa, tell me the weather“.
- To add Smart Home devices, click on Smart Home on the left menu and enable account linking per the instructions from your device manufacturer.
- When you are done with AlexaPi, return to the Terminal and press Ctrl-C.
Fun Things to Ask Your Raspberry Pi-Powered Alexa
What will you ask Alexa now that she is working on your Raspberry Pi? Here are some options.
- Play music.
- Can you rap?
- Can you sing?
- Talk like a pirate.
- Open the cat food.
- Make me a sandwich.
- What’s the first rule of the fight club?
You might add a few LEDs to your project using this Amazon LED tutorial to mimic the lighted ring on the top of the Echo device.
We will add Smart Screen in a future article if you finish the tutorial and are disappointed that there is no Echo Show functionality.