DIY Amazon Alexa using Raspberry Pi | Standalone | May 2018

Alexa-Pi

DIY Amazon Alexa using Raspberry Pi | Standalone | May 2018

Alexa, what’s the weather now?

Currently, in Bengaluru, It’s 23oC with intermittent Clouds.

Did you impressed with Alexa replies ever? Let’s build our Own Amazon Echo with Raspberry Pi that can respond to your Voice commands just like an Amazon Echo device. It will provide almost all services that an Echo does like Weather forecast, Calculations, Home automation, IFTTT and Many more. To build it, all you need is

I will be using VNC Viewer to access the Pi Desktop GUI. If you want to know how to connect your Raspberry Pi with the laptop in headless mode, check this tutorial here.

Buy Raspberry Pi Model B+

Step 1: Register for an Amazon developer account by visiting Amazon Developer Website. Follow the on-screen instructions and complete your Registration. Once registration is completed login to your account. Then click on the ‘Alexa Voice Service’ tab.

1.Amazon Developer Account

Step 2: On the next screen click on ‘get started’.

2.Get Started

Step 3: Click on ‘New Product’ then give any name to your product. Here I gave ‘

Product Name: Alexa Pi’.

Product ID: ‘Alexa_Pi’ (Any name you prefer, Make sure there will be no spaces).

Product Type: Alexa-Enabled Device

Will your device use a companion app? : Yes

3.Product details

Fill the rest accordingly.

4.Product details cont

Click Next.

Step 4: Creating a Security profile. Click on create new security profile and give a name and description.

Create Security Profile

Step 5: Now Copy all Client ID, Client Secret into a Notepad file. We will need it later.

In the Allowed origins and Allowed return URL text boxes paste the following

In the text box of Allowed Origins enter: https://localhost:3000

In the text box of Allowed Return URLs enter: https://localhost:3000/authresponse

Click add to add these

Origin details

Then agree to the terms and conditions and click ‘Finish’. Now you will see these on the dashboard.

AVS Dashboard

Keep the Security Profile ID, Client ID and Client Secret keys that we copied in notepad earlier as we will need them shortly. You can access these in the dashboard too.

Setting up Alexa on Raspberry Pi

Once we have set up the developer account with all necessary details, we need to clone the Alexa AVS Samples to the Raspberry Pi.

Step 1: I’m using VNC Viewer and Putty for SSH into the Raspberry Pi. The GIT might have pre-installed in the Stretch OS. So you can go further. If not, then you need to install it.

By using the following command, you can clone the Alexa AVS Samples

Step 2: Once cloning is done. Navigate to the AVS Sample directory using CD command (Change Directory).

Step 3: Now we need to modify the automated_install.sh file with Device Type ID, Client ID and Client Secret, that we copied already in a Notepad.

Run the following command to edit the file.

Step 4: We need to change 3 values here.

Replace YOUR_PRODUCT_ID_HERE with the Device Type ID.
Replace YOUR_CLIENT_ID_HERE with your Client ID.
Replace YOUR_CLIENT_SECRET_HERE with your Client Secret.

Automated install

After placing the values in the correct places, Save it by pressing Ctrl + X and then Y and then Enter.

Step 5: Now we need to install the Alexa Samples. Run the following command.

It will ask few prompts before installation begins. Type Y for all those questions and Enter.

The prompts will be

  • General license agreement Terms and Conditions – Y.
  • Do you have an Amazon developer account? – Y
  • Is the information correct (Product ID, Client ID and Client Secret) – Y.
  • Which locale do you need to use. Choose the en-US for English US [Enter specific numbers only].
  • Are you using 3.5mm Jack or HDMI Cable for Audio Output? – Select 3.5mm Jack [Enter specific number only]
  • Do you want to enable ‘’Alexa’’ Wake Word Detection? – Y

Now the installation will start automatically. It will take more than 30 minutes to install all the necessary files. Just relax and it’s time for a coffee break.

Authenticate your Raspberry Pi Alexa with Amazon Echo Alexa Account

Step 1: Start the Alexa Web Service, Open Terminal window and type the following command

Once the service is started successfully, it will show ‘Listening to port 3000’.

Listening Port

Step 2: Open a new tab in the terminal by pressing Ctrl + T. Let’s initialize the JAVA App that register and authenticate our device.

Use the following command to initialize it.

Step 3: Now a window will open up and asking for Authenticate our device. There will be two pop up will show one by one. In the first pop up, Click ‘Yes’ to allow automatically open the URL in the default browser.

Open browser popup

Note: Click ‘ok’ on the second popup after authentication completes.

Step 4: Now in the browser it shows the connection is not private (because we are running self-generated SSL). So, just click ‘Show Advanced’ and then click ‘Proceed to localhost (unsafe)’.

11.Connection Private

12.Proceed to local host

Step 5: Now the browser will open Amazon login page. Log in using your Developer account. Then click ‘Allow’. It will show device token ready.

Device Token Ready

Step 6: Now press ‘ok’ button on the second popup.

Step 7: Now we need to start up the wake word engine. So open a new tab in the terminal by pressing Ctrl + T. Enter the following command

This will start up the wake word engine. There are few other wake word engines like sensory are available. But it will get expired after few days. KITT.AI wake word software is completely free.

That’s all done! Now try saying ‘Alexa’ followed by the command phrases.

Example: Alexa, What is the weather today?

Automatically Start Alexa Service during Startup

Step 1: Create a startup script by running the following command.

Step 2: Copy the scripts exactly how they are given. This script will load a new terminal and run the services one by one (The one we did manually).

Now press Ctrl + X then Y. Press enter to save.

Step 3: Set permissions for the startup script that we created. To do this run the following command

Step 4: Now we need to modify the configuration file to run Alexa during Startup. Open the autostart config file by running the following command.

In that file find the line

Replace this line with the following

Save the file by pressing Ctrl + X then Y and Enter.

Everything is set up right now to run Alexa as standalone. Now reboot the Raspberry Pi. The Alexa Services will startup and you can able to hear that Alexa responds with ‘Hello’.

Try saying ‘Alexa’ followed by ‘your Questions’ after the beep sound. Alexa, How old are you?.

Check this trial video with Alexa Skill – https://youtu.be/rPv8DfSYIj0

Share this post

Leave a Reply

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