Those of you who haven’t have an access to buy Amazon’s Echo, you can build one for yourself! By using Raspberry Pi 3 worth USD $45, a free Alexa voice service from Amazon and following few simple steps you can build one easily!
There are many instructibles available on the internet on how to use Alexa on Raspberry Pi 3 to make a voice activated personal assistant, however many of them might leave you with dismay as they seems to be broken in explaining complete steps. In this small blog post we intend to make it simple for you! so without wasting too much of a time, let’s start making one…
What we need?
In order to start building an equivalent of Echo, you need some hardware and follow simple steps to flash the required software and scripts. So what you essentially need is
Raspberry Pi 3 1 Nos
Push button switch 1 Nos
USB speaker and mic 1 Nos
cables/wires 1 Nos
Lets build the hardware
Building hardware is a piece of cake just get Raspberry Pi 3 and place a push button switch between GPIO18 (Pin 12) and GND (Pin 6). We need a button because Alexa can not be activated by voice so we need to push a button in order to make Alexa listen to questions and commands. The connection is as shown in the picture below.
There are few important points that need to be remembered. You need to use external USB mic and speaker as the default audio port doesn’t work with it. So get one cheaper external USB speaker and mic set.
Now once you have all the hardware connected, connect the Micro USB cable to provide power to the device. Make sure that you have an adapter which provides 5V stable DC with 2A current. Insert MicroSD card with a minimum of 8GB memory space and make sure that you have Raspbian running on it.
We are not going to tell you on how to get Raspbian running on RPI3 as it’s the basic of this tutorial. You can still get the step by step process on flashing Raspbian on RPI3 in this link
Creating Amazon developer account and getting keys
In order to use Alexa on your IoT device, you need to create a developer account and get the necessary keys from the developer portal. Simply go to https://developer.amazon.com/ and sign in with your amazon id. you can use your existing amazon account or create a new one.
Once you are logged in with your amazon account, click on “Alexa” on the top menu and then select “Alexa Voice service” as shown in the picture below
Click on “Get Started” which will open up a page to request you to register a new product. Select “Device” from the “Product Type”.
In the next screen be careful to enter the following details.
For the Device Type ID enter as “my_device” (yes, do not use any other name as it will not work)
and chose your display name as you wish, we selected it as “SantronixEcho”
After entering these details, click next. In the next screen, you would see few Ids and keys already generated. Enter the profile Id and profile description. The profile description and keys would be required to enter during installation of Alexa on RPi3.
Then go to “Web Settings” tab and following details carefully
In allowed origins enter the localhost and a url containing the IP address of your Raspberry Pi. In my case, my RPi3 was on an IP 192.168.0.103 so we used the origin urls and return urls as shown in the picture below.
after completing these information, click Next and fill up the following details. You can enter these details as per your need but for the convenience we are showing the ones which we used.
Click next and in the next screen which will ask you about Amazon Music, you can chose and proceed to save.
That’s it! Your developer account is now set and the device IDs and keys are ready.
Next is to download the alexa software on your Pi and configure it.
Downloading Software and configuration
Connect your pi to your home network and note down the IP address. You can open the Pi Console using SSH, using a software like Putty.
This will open up an SSH shell. You can enter your Pi’s username and password. The default username and password for the Pi is “pi” and “raspberry” respectively (without quote marks).
First thing is to install git. to do that type, sudo apt-get install git and hit enter.
Once git is install you can download the software from github, the link for the software on github is
First create a Downloads directory and then download the software as shown in the picture below.
After the software is successfully downloaded a new folder will with a name “AlexaPi” will be created. just execute the following commands one by one
Now it’s time to enter the details from your developer account. Just open the product page on amazon developer account you created earlier and copy and paste the following details one by one as shown in the picture below
Once you reach upto this
Now open a web browser on your computer and type the http://192.168.0.103:5000 and hit enter. If it asks you to login the Amazon account, please enter your credentials and login, after the successful login it will generate the key as shown below
You would need a slight modification in the cred file to do so on your putty screen and enter the command
sudo nano creds.py
Edit the file to include the key refresh_token for the token key as follows
Now press Ctrl + X and press Y to save the file! That’s it! You are now ready with your Alexa!!
Test your Alexa
To test it, just type python main.py and hit enter. It will take some time to connect and if you have a good internet connection and connected your speaker and mic correctly your will hear a voice – Hello!
All done! Hope this tutorial has made it simple for you to download, configure and test Alexa on your Raspberry Pi! Post your comments and likes for this blog post if you liked it!
– Santosh Ambekar