This simple project allows you to add AI to a Raspberry Pi so it can talk to you.

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.

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!

Amazon-developer-login-1024x427.jpg

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.
Amazon-developer-console.jpg

  • Click Register a Product Type on the drop-down menu and click on Device.
Alexa-product-registry.jpg

  • Fill the values and save them:

Device Type Info

  1. Device Type ID – Provide a simple identifier for your product.
  2. Display Name – The display name in the developer portal and what is displayed to users when they register the product with Amazon.
  3. Click Next
Create-a-new-device-type-1024x337.jpg

Security Profile

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

Alexa-security-profile-1024x498.jpg

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
Alexa-Service-Sample-App-1024x351.jpg

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.
Alexa-Pi-Web-Settings-1024x381.jpg

Alexa-Pi-Allowed-Origins-1024x370.jpg

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
Alexa-Pi-Device-Details-1024x420.jpg

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

Alexa-Pi-Select-a-Security-Profile-1024x164.jpg

  • 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.
Alexa-Pi-Consent-Screen-Info.jpg

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.

Alexa-Pi-Voice-Service-App-Security-1024x344.jpg

Alexa-Pi-OAuth2-Credentials-1024x359.jpg

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
Alexa-Pi-AVS-Desktop1.jpg

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.

instalscript-1.png

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:

  • 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
terminalwindow-1.png

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
aveterminal.png

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.

click-yes-window.png

  • 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).
coonection-private-1.png

connectionprivate-2.png

  • You’ll be taken to a Login with the Amazon web page. Enter your Amazon credentials.
alexa-login.png

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

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.

device-token-ready.png

  • Return to the Java application and click the OK button. The client is now ready to accept Alexa requests.
token-ready-okay.png

alexareadytoplay.png

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
alexareadytoplay2-1.png

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.


Maker Pro Logo
Continue to site
Quote of the day

-