How to install Alexa on Raspberry Pi 3B+ in 30 Minutes. Installing Alexa on Raspberry Pi 3B+ is very easy and simple. After making this you will not need to buy any smart speakers like Amazon echo because here we will use our old speakers for Alexa on Raspberry Pi 3B+. So lets install Amazon Alexa on Raspberry Pi 3B+.
Raspberry Pi is a single-board computer that is also an IoT device. Using this you can use a Linux desktop and also do awesome IoT projects. We all know Alexa is a powerful virtual assistant made by Amazon.
Amazon Alexa on Raspberry Pi 3B+ is very handy for performing day to day tasks like alarm, reminders, news, sports update etc.
If you want to make Google Assistant powered Virtual Assistant with your Raspberry Pi 3B then follow this post.
Install Raspbian OS os Raspberry Pi
To use Amazon Alexa on Raspberry Pi 3B+ we have to install the latest Raspbian OS in our Raspberry Pi 3B+. I already a dedicated post for this. Please visit the following post for the guide of Raspbian OS Installation.
Products Need to use Alexa on Raspberry Pi 3B+
Register on Amazon Developer
First of all we have to make a developer account on Amazon developer.
If you have already an account just login. Otherwise, use your email id to create a fresh account & verify email id.
On registration page give some email id, phone no & address. Do not worry nothing will be verified. Make sure you chose the country right to get local assistant from Alexa.
First select Alexa Voice Services (AVS).
Now Click on Product & give some product name, ID.
Here select “Device with Alexa built-in“
The product Category will be Wireless speaker & select other options as shown in the pictures.
Now we have to set Security profile. Select Create new profile & give some profile name & description.
Now click Others devices and give a client name and click generate ID.
Now Click on Download button to download the JSON File. This file is very important!
Setting up Speaker & Mic for Alexa on Raspberry Pi 3B+
To setup speaker and mic, first insert your usb mic or sound card. Then run following 2 commands to see the recording & playback device id.
Now note down card no and device no. As I am going to use default 3.5 mm jack so I have to use Card 0 & device 1 which in bcm2835 ALSA.
Now run the following command to set default audio devices.
After editor opens, copy the following text and paste there. Do not forget to replace the card no and device no with your card and device.
pcm "hw:<card number>,<device number>"
pcm "hw:<card number>,<device number>"
In my case mic id is 1,0 and speaker is 0,0. After it, Save it by pressing Ctrl+O & exit it by Ctrl+X.
Now just run the following command to set the volume, gain of your audio devices.
Alexa SDK Installation
To install Amazon Alexa on Raspberry Pi 3B+, first go to File Manager and create a Folder named “alexa” inside your home directory which typically “/home/pi/”.
Now copy the previous downloaded JSON file inside alexa folder.
Now open that folder and press “F4” to open terminal on present directory.
To install AVS SDK run the following commands one by one. Run commands 1 line at a time & in the same order given below.
This tutorial will install google assistant in the “alexa” folder inside the home directory of “pi” user.
sudo apt-get update
sudo apt-get upgrade
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 \
sudo bash setup.sh config.json [-s 1234]
Now you will be asked to agree the terms and condition inside terminal. Just Type “AGREE” there.
After installation completes, you will see this screen.
Get Refresh Token
Now we have to grant alexa to control device. For this we have to get a token. To do this type the following command.
sudo bash startsample.sh
Then will see a code and a link. Just open the link in the browser where amazon account is logged in & enter the code. This is like 2 step verification.
After entering the code click on Allow.
At last registration successful will show.
If you get the following error during device authorization then you are unlucky like me.
Simple solution is to clear browser data and create a fresh new amazon developer account with new email ID. I am also became successful on second attempt.
So, after successful authorization you will see device “AUTHORIZED”.
If you see “Alexa is Idle” then you have successfully installed Alexa on Raspberry Pi 3B+
Create Desktop Shortcut
To directly run Alexa on Raspberry Pi 3B+, you have to create a desktop shortcut, just create a new file & name it “alexa.sh“. Now just copy and paste the following and save that file.
./SampleApp "/home/pi/alexa/build/Integration/AlexaClientSDKConfig.json" "/home/pi/alexa/third-party/alexa-rpi/models" DEBUG9
After this make the file executable. To do this go to the properties of the “alexa.sh” and make the read, write & executable to “Anyone“
Now when you double click on the file from desktop and execute it, Alexa Assistant will start. Just say “Alexa” to ask your question.
Start on Boot
To run Alexa on Raspberry Pi 3B+ on startup, we have to add this file into crontab. To do this first run the following command.
After this add the following line in last line.
@reboot bash /home/pi/Desktop/alexa.sh
Now Save it by pressing Ctrl+O & exit it by Ctrl+X.
From now, after every startup of Raspbian OS, Alexa Assistant will start automatically.
To disable automatic startup, just remove the line you added in crontab & you will be done.
Simultaneously Run Alexa And Google Assistant On Raspberry Pi 3B+