By Sarvagnya Purohit

The rise of voice interfaces and artificial intelligence are possibly the most interesting thing in the world of modern day computing. This Raspberry Pi tutorial is a simple and fun project you can build without needing any extra components. This will make your Raspberry Pi talk with you! We will use Amazon’s Alexa Voice Service(AVS) to make this work. This will also help you step into the world of AI and introduce basic concepts of Artificial Intelligence.

Required Materials

Hardware

Software

Raspbian Jessie with Pixel Desktop (Burn it into you SD Card and plug it into you RPi)

Resources and Repositories

How Does it Work?

We first have to register an Amazon Developer’s Account so that we can access Amazon’s Developer Services. We use Amazon’s Alexa Voice Services(AVS) to install the Alexa AI for free on the Raspberry Pi. Once the AVS is downloaded and installed on our Raspberry Pi, we can ask it anything like today’s weather, a joke, information on a random person or any other thing that comes to mind that would like to know about. The RPi answers the questions you ask by connecting to Amazon’s Alexa servers through the AVS we installed and finding the appropriate answers.

Creating an Amazon Developer Account

Unless you already have one, go ahead to Developer.amazon.com. Verify your email and you have completed the first step!

Registering Your Product and Creating a Security Profile

After you have completed creating your account, you’ll need to create your Alexa Device and a security profile. Keep a note of your Product ID, Client ID, and Client Secret after performing this step.

Login to the Amazon Developer Portal (developer.amazon.com).

Click on Apps and Services Tab >> Alexa >> Alexa Voice Service >> Getting started.

Click Register a Product Type on the drop-down menu and click on Device.

Fill the values and save them:

Device Type Info

Device Type ID – Provide a simple identifier for your product. Display Name – The display name in the developer portal and what is displayed to users when they register the product with Amazon. Click Next

Security Profile

Click Security Profile on the drop-down menu and select Create a new profile.

Enter a name and description for your security profile, then click Next. For example:

Security Profile Name: Alexa Voice Service Sample App Security Profile

Security Profile Description: Alexa Voice Service Sample App Security Profile Description

A Client ID and Client Secret will be generated for you.

Now click on the Web Settings Tab. Make sure the security profile you just created is selected in the drop-down menu, then click the “Edit” button.

Allowed Origins: Click Add Another and then enter https://localhost:3000 in the text field that appears.

Allowed Return URLs: Click Add Another and then enter https://localhost:3000/authresponse in the text field that appears.

Click Next

Device Details

Image – Use any of your custom images and then upload it.

Category – Other

Description – Alexa Voice Service sample app test

Do you have plans to make your product available to the general public? – No

Click Next

Enabling your Security Profile

Open a web browser, and visit https://developer.amazon.com/lwa/sp/overview.html.

Near the top of the page, select the security profile you created earlier from the drop-down menu and click Confirm.

Enter a privacy policy URL beginning with http:// or https://. For this example, you can enter a fake URL such as http://example.com.

[Optional] You may upload an image as well. The image will be shown on the Login with the Amazon consent page to give your users context.

Click Save.

Next to the Alexa Voice Service Sample App Security Profile, click Show Client ID and Client Secret. This will display your client ID and client secret. Save these values. You’ll need these. Keep a note of them.

Cloning the Sample App

Open terminal, and type the following:

cd Desktop git clone https://github.com/alexa/alexa-avs-sample-app.git

Updating the Install Script with Your Details

Before you run the install script, you need to update the script with the credentials that you got in step 3 – ProductID, ClientID, ClientSecret. Type the following in terminal:

cd ~/Desktop/alexa-avs-sample-app nano automated_install.sh

Paste the values for ProductID, ClientID, and ClientSecret that you got from Step 3 above.

The changes should look like this:

ProductID =”RaspberryPi3″

ClientID =”amzn.xxxxx.xxxxxxxxx”

ClientSecret=”4e8cb14xxxxxxxxxxxxxxxxxxxxxxxxxxxxx6b4f9″

Running the Installation Script

You are now ready to run the install script. This will install all dependencies, including the two wake word engines from Sensory and KITT.AI.

Note: The install script will install all project files in the folder that the script is run from.

To run the script, open terminal and navigate to the folder where the project was cloned. Then run the following command:

cd ~/Desktop/alexa-avs-sample-app . automated_install.sh

You’ll be prompted to answer a few simple questions. These help to ensure that you’ve completed all necessary prerequisites before continuing.

When the wizard starts, it’ll take about 30 minutes to get everything downloaded and installed.

Running the Web Service, Sample App, and Wake Work Engine

Now that installation is complete, you’ll need to run three commands in 3 separate terminal windows:

1) Terminal Window 1: to run the web service for authorization

Terminal Window 2 : to run the sample app to communicate with AVS Terminal Window 3 : to run the wake word engine which allows you to start an interaction using the phrase “Alexa”.

Run all these steps in order else it will not work.

Terminal Window 1

Open a new terminal window and type the following commands to bring up the web service which is used to authorize your sample app with AVS:

cd ~/Desktop/alexa-avs-sample-app/samples cd companionService && npm start

The server is now running on port 3000 and you are ready to start the client.

Terminal Window 2

Open a new terminal window and type the following commands to run the sample app, which communicates with AVS:

cd ~/Desktop/alexa-avs-sample-app/samples cd javaclient && mvn exec:exec





Let’s walk through the next few steps relevant to Window 2.

When you run the client, a window should pop up with a message that says –

Please register your device by visiting the following URL in a web browser and following the instructions: https://localhost:3000/provision/d340f629bd685deeff28a917. Would you like to open the URL automatically in your default browser?

Click on “Yes” to open the URL in your default browser.

If you’re running Raspbian Jessie with Pixel desktop (and with Chromium browser), you may get a warning from the browser. You can get around it by clicking on Advanced -> Proceed to localhost(unsafe).

You’ll be taken to a Login with the Amazon web page. Enter your Amazon credentials.

You’ll be taken to a Dev Authorization page to confirm that you’d like your device to access the Security Profile created earlier.

Click “Okay”.

You will now be redirected to a URL beginning with https://localhost:3000/authresponsefollowed by a query string. The body of the web page will say device tokens ready.

Return to the Java application and click the OK button. The client is now ready to accept Alexa requests

Terminal Window 3

Skip this step to run the same app without a wake word engine.

This project supports two third-party wake word engines: Sensory’s TrulyHandsFree and KITT.AI’s Snowboy. The -e parameter is used to select the agent and supports two values for {{engine}}: kitt_ai and sensory.

Open a new terminal window and use the following commands to bring up a wake word engine from Sensory or KITT.AI. The wake word engine will allow you to initiate interactions using the phrase “Alexa”.

To use the Sensory wake word engine, type –

cd ~/Desktop/alexa-avs-sample-app/samples cd wakeWordAgent/src && ./wakeWordAgent -e sensory

or, type this to use KITT.AI‘s wake word engine –

cd ~/Desktop/alexa-avs-sample-app/samples cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai





You can now talk with your Raspberry Pi!

Make Your Raspberry Pi Run Remotely (Optional)

Now that you’ve got your AVS prototype running, you may want to get rid of the monitor, keyboard, and mouse. You can do that by using SSH and VNC.

Last Step: Talk with Your Raspberry Pi, ENJOY!

You can now talk to Alexa by simply using the wake word “Alexa”. If you prefer, you can also click on the “Listen” button instead of using the wake word. Click the Listen button and wait for the audio cue before beginning to speak. It may take a second or two before you hear the audio cue.