Posts

Building an Interactive Alexa Quiz Skill, Part 2

Disclaimer: this was typed late at night on a tired mind. Please excuse typos, convention errors, and generally poor writing. 🙂

Howdy, Alexa nerds! Welcome back to our journey in learning Amazon Alexa Skill Development. Quick funny aside, would you care to guess my most common use of the Echo? It’s to play looong Spotify playlists that are basically background noise to help our new dog when Hannah & go to the gym or meet friends. Anyway!

Let’s jump back in. The previous article covered setting up an AWS Lambda function for the Alexa Skill Service. Now, we’ll be working more with the Skill interface. See below for the conceptual overview, or an early article on building Alexa skill interfaces for a basic fact skill.

2017-03-07-001-Alexa-Skill-Interface-Develpoment-Framework

 

Working in the Amazon Developer Console: Alexa Skills Kit

You probably know the drill now, log in to the Amazon Developer console. Once you’ve logged in, select the “Alexa” menu item from the home screen, then choose the “Alexa Skills Kit” Option.

2017-03-27-B-001-Alexa-Quiz-Skill-Create-Alexa-Skill-Interface-Start

If you’ve previously published or started development of skills, you should see them listed on this screen. Now, click, “Add a New Skill”. We should be looking at a very familiar screen here. 🙂

Add/edit the following:

  • Language (assuming you’ll leave the English US default here)
  • Name of the Skill displayed in the Alexa app and store
  • Invocation name users will speak to start your skill

Click Save and Next to proceed.

2017-03-27-B-002-Alexa-Quiz-Skill-Create-Alexa-Skill-Information

 

Working with the Interaction Model

Here comes the tough part, more copy and paste! Okay, sarcasm and humor doesn’t always translate well via text. We’re going to continue to lean fairly heavily on Amazon’s examples here to get ourselves familiarized with the more advanced concepts of intent schema and slot types.

That caveat aside, head back to the files we originally downloaded, but this time, we’re interested in the speechAssets folder and its contents:

  • json
  • Sample utterances (text document)

First, let’s open up the Intent Schema JSON file in our text editor of choice. Below, a look at what you should approximately be seeing. Copy and paste the entirety of the JSON file into the Intent Schema field of the Interaction Model tab.

2017-03-27-B-003-Alexa-Quiz-Skill-Create-Alexa-Skill-Intent-Schema-JSON

Audible: Our First Encounter with Custom Slot Types

Alright, no smooth segue here. We’re having the first encounter with what’s known as custom slot types.

If you were to try and save the skill progress so far, you’ll receive an error message from the developer console that says something like, “Error: There was a problem with your request: Unknown slot type ‘LIST_OF_ANSWERS’ for slot ‘Answer’. Why is that?

2017-03-27-B-004-Alexa-Quiz-Skill-Create-Alexa-Skill-Custom-Slot

If you take a closer look at the Intent Schema JSON file, you’ll notice that  most of the intents are built-in Amazon intents. E.g., “intent”: “AMAZON.RepeatIntent”. The “AnswerIntent” looks nothing like the built-in Amazon intents. Instead, we see a name, “Answer” and type, “LIST_OF_ANSWERS” that was so delicately referenced in the error message.

So how do we remedy this situation? We use the information presented to us in the error message and the JSON file to work our way over this issue. You’ll likely note under the custom slot types mentions “Enter Type”.

2017-03-27-B-005-Alexa-Quiz-Skill-Create-Alexa-Skill-Custom-Slot-Values

Match that information up with our error message and the JSON code, and we’ll enter, “LIST_OF_ANSWERS”. In the values section, we’ll enter on separate lines: 1, 2, 3, and 4. I’ll note here for clarity, that this essentially corresponds to the A/B/C/D multiple choice functionality of the quiz. We’ll see this in greater detail in a bit.

Okay, click “Add” as highlighted above, then click “Save”. Next, return to your files and open up the Sample Utterances text file. You should see something like the below.

2017-03-27-B-006-Alexa-Quiz-Skill-Create-Alexa-Skill-Sample-Utterances

You’ll note it’s quite a bit different than the previous, simple, fact-dispensing Skill we previously built. Take note of the {Answer} sample utterance. These are the pieces of dynamic input and interaction coming together into an Alexa Skill. We’ve defined a custom interaction outside of Amazon’s standard functions, and specified a range of acceptable answers the user can give us. That whole structure meets the user experience here, called in by the {Answer} slot name and custom slot type.

Enough conceptual babble. Copy and paste the sample utterances text into the developer console! Click Save beneath the sample utterances, and click Next.

2017-03-27-B-007-Alexa-Quiz-Skill-Create-Alexa-Skill-Sample-Utterances-List

 

Continuing the Skill Interface Build-out

Alright, so far, we’ve accomplished the following:

  • Provided basic skill information about our new skill
  • Specified details about the interaction model, including;
    • Intent Schema
    • Custom Slot Type
    • Acceptable/specified values for the custom slot type
    • Sample utterances

Next, we need to fill in some simple but crucial configuration details. Remember the ARN we generated by setting up the AWS Lambda function in the previous article? You need it here. Below you can see:

  1. I’ve selected the recommended endpoint type of AWS Lambda ARN
  2. Selected my geographic region of North America and,
  3. Pasted in the full ARN

I’m not going to work with account linking yet, because honestly, it looks really darn complicated and its well past midnight as I type this. Soon. 🙂 Click next and proceed to the testing tab!

In the testing tab, you should first see that the skill is enabled for testing on your account. You can:

  • play back responses from Alexa in the voice simulator to test pronunciation, etc
  • More importantly, use the service simulator to run a sample utterance, and see if your skill actually works.

2017-03-27-B-008-Alexa-Quiz-Skill-Testing-Alexa-Skill

Above, we can see the response to our sample utterance asking SEO Quiz returns as expected. Woohoo! Also, did you know the Alexa voice simulator automatically bleeps out most curse words? Did you know you can kind of work around that by putting extra vowels in the word? I digress. (It’s almost 1 am writing this now, productivity on the rise!) When you’re satisfied, click Next.

We’re getting close! Time to enter some publishing information. I’ll leave the first few sections to you: Category, Sub-Category, Testing Instructions, Country/Region availability, Short and Full skill descriptions.

Now, in the example phrases, I provided some updates to the sample utterances, namely to the starting Intent. Below, see the example phrases of “Alexa open SEO Quiz” and so forth. The “gotcha” here that set me back on my first skill is that the example phrases must be derived from your sample utterances.

2017-03-27-B-009-Alexa-Quiz-Skill-Testing-Alexa-Skill

Upload your 108×108 and 512×512 pixel icon images, click Next and submit the requisite privacy & compliance information. Done!

 

Wrap-Up

So, we’re mostly done, not completely done. The part for usto do now is customizing the template code in your AWS index.js file. Ideally, I would prefer a more eloquent closing, but it’s late, will have to wait for another time. Look after each other.

 

DSC_0002 Zach Doty Cover Photo for Interactive Alexa Quiz Skill Development

Building an Interactive Quiz Alexa Skill, Part 1

Hello Alexa geeks! Welcome back to our journey of learning how to develop Amazon Alexa Skills for the Echo and more. Last time, we completed the build process for our first simple “fact-dispensing” Alexa Skill.

In this article, we’ll start the process for a skill that accepts user input in the form of a quiz, fun! If you recall from our first skill, there are two parts to skill development:

  1. The Skill service development, in AWS (Lambda)
  2. The Alexa Skill interface details through the Amazon / Alexa Developer Console

 

2017-03-01-001-Alexa-Skill-Develpoment-Framework

 

Getting Started in AWS Lambda

You’ll notice as we progress from our early articles, there will be less detail paid to more basic instructions, such as our first! First, log in to the Amazon AWS portal.

Navigate to the Lambda service. If you’re the casual developer just working in this course, odds are the Lambda link will be near the top of screen under “Recently Visited Services”. Once you’ve clicked through, click, “Create a Lambda Function”.

2017-03-27-001-Alexa-Quiz-Skill-Create-AWS-Lambda-Function

On the next screen, you should see something like “Select blueprint” (Note: at the rate of change Amazon has been pursuing, this screen could change, even in a matter of weeks!) Click the “Blank Function” option, we’re starting this one from scratch!

2017-03-27-002-Alexa-Quiz-Skill-Create-Blank-AWS-Lambda-Function

The next screen should be, “Configure triggers”. Click inside the gray dash-outlined box, and select, “Alexa Skills Kit” from the dropdown menu. Click next!

2017-03-27-003-Alexa-Quiz-Skill-Configure-Alexa-Skills-Kit-Trigger

 

AWS Lambda Function Configuration for Alexa

Now we should be able to configure the basics of our function. Enter the following:

  • Function name
  • Description

The default runtime environment should be Node.js 4.3. If not, change it to Node.js 4.3.

(Note: Amazon just introduced support for Node.js 6.10, so that may be the preferred format going forward!) Will try to provide an article update, should that be the case.

2017-03-27-004-Alexa-Quiz-Skill-Configure-Alexa-Function

Onward! Now, we need to upload some code to this burgeoning success. Throwback time, do you remember the files we downloaded in one of the first articles? Time to go back to them again. In your folder of numbered skill templates, go to “2-reindeerGames”, “src” folder and safely open the index.js file in your text editor of choice.

2017-03-27-005-Alexa-Quiz-Skill-Lambda-Function-Code

Copy and paste (replacing all previous code) into the code window that should appear.  This assumes you’ve selected the Code entry type of “Edit code inline” for the Lambda function code. As we work on more increasingly more advanced skills, we will likely use the zip upload feature to accommodate additional code resources. The astute will note we’ve merely copied and pasted code here. Yes, we’ll go back and customize soon. 🙂

Beneath the code window, leave the index.handler intact, select an existing role option in the Role dropdown menu, and use the role we previously created. Leave the other settings as-is, click the “Next” button to review details, and click, “Create Function”!

2017-03-27-006-Alexa-Quiz-Skill-Lambda-Function-Creation

Be sure you take note / record the ARN in the upper right-hand corner, as we’ll need that in our forthcoming Skill Interface development section.

Wrap-Up

That’s the first part! I don’t know about you, but this is getting easier as I go. We’ll next cover the skill interface and customization to make it your own skill. If this is your first article, be sure to check out the running stable of articles on how to learn Amazon Alexa skill development. Also, there’s a growing body of work on how to learn PostgreSQL, and some fledgling articles on learning algorithmic trading, for good measure.

Share your experience, thoughts and feedback in the comments below. Don’t be a stranger, help your friends along in Alexa Skill development and share with them. Cheers!

 

 

 

 

 

 

DSC_0005 Cover Photo by Zach Doty for Build Your Own Amazon Alexa x Echo from Raspberry Pi

How to Build Your Own Amazon Alexa with a Raspberry Pi

Howdy, it’s been a minute since my last post on Alexa Skill Development. I left us hanging, as I mentioned in one of my previous SQL posts, work craziness, sickness, and general life stuff happening imposed a brief, involuntary hiatus on writing.

Enough self talk to make future self feel better. Let’s build our own Amazon Alexa with a Raspberry Pi! What a step up from our previous articles. 🙂

But first! A couple of notes: This is NOT necessary for you to do in learning Alexa Skill Development. You can use a regular Echo instead of this expedition into Computer Homebrew 102. Also, I developed my first Alexa skill without an Echo or comparable device at all. One more thing, this is a long post that is both deep and wide ranging. Don’t say I didn’t warn you.

1. The Materials List

To get started, you’ll need a few things:

  1. Raspberry Pi, version 2 or later
  2. Power source
  3. Micro SD card (Recommended at least 8 gb in storage size)
  4. Speaker with a line-in 3.5mm cable (or headphones of similar line-in spec)
  5. USB microphone
  6. Keyboard and Mouse
  7. HDMI cable to connect to a monitor or TV
    1. Obviously, you need a monitor or TV. 🙂

 

A few notes on the Raspberry Pi: I recommend you get a pre-assembled kit, for time and convenience, if nothing else. I previously purchased from CanaKit on Amazon, and have been pleased with it. If, for some reason, you are building your own or need to reformat, the two articles below from RaspberryPi.org are simple, fast instructions to get you up to speed.

 

Formatting a MicroSD card 32 GB or less:

https://www.raspberrypi.org/documentation/installation/noobs.md

Downloading New Out of Box Software (NOOBS) for Raspberry Pi, in preparation of your first boot.

https://www.raspberrypi.org/downloads/noobs/

 

Okay, we’re going to proceed assuming that you’ve taken care of the above, and have successfully booted your Pi, connected all requisite hardware, connected to the internet, and so on. Below is where I’m at.

2017-02-20-001-Alexa-Raspberry-Pi-Successful-Boot

2. Installing Other Utilities

Another note here, it is possible to SSH (read: a bit like Microsoft’s RDP remote desktop application, but command line style) your way into the Raspberry Pi. I will not be doing that. This may sound a bit silly, but I don’t have a multi-screen dock for my laptop (capped at 2), and I’m happy for the Pi and other monitor to be a standalone computer. (Perks of a wide desk.) Also, the Wi-Fi USB card I’m using is very slow at the moment. Also, an edit after I’ve written this post offline: Linux-esque command line work is a royal pain in the you-know-what. Remarkable computing has advanced to where it is today. More on Raspberry Pi intricacies later.

Enough of my discourse, let’s continue setting up our Raspberry Pi / DIY Alexa to-be. Task time.

Navigate to your Pi’s command line module.

  1. We’re going to update the GET. Type:
    1. sudo apt-get update (Pro tip: don’t misspell sudo as I’ve laughingly done on the first try.)
    2. In the new line created by default, type: clear and hit enter. This will clear your command line.

2017-02-20-003-Alexa-Raspberry-Pi-Get-Update

3. Registering Your Raspberry Pi as an Alexa Voice Service Device Type

Alright, head to the Amazon Developer Portal and log in with your credentials.. (If you’ve followed along with previous posts, you have a login! If not, see this article on setting up an AWS account.)

C-2017-02-23-001-Alexa-Raspberry-Pi-Registration

Once you’ve logged in, click on the Alexa navigation item, then click “Get Started”. You should land on a page that has a “Register Product Type” drop-down. Select Device and continue.

C-2017-02-23-002-Alexa-Raspberry-Pi-Registration

You’ll be taken to a new screen / process to create a new device type. Choose and type your  device type ID and display name. For ease of process here, I’ve used the same value for device type ID and display name.

C-2017-02-23-003-Alexa-Raspberry-Pi-Registration

Once you’ve selected your ID and name of choice, click next. Now we need to create a new security profile. Click the dropdown menu that reads, “Select Security Profile” and click, “Create New Profile”. If you’ve filled out all the fields properly, you should have the option to submit this device / product. Hooray! Below is what I see after I submit the new device.

C-2017-02-23-004-Alexa-Raspberry-Pi-Registration

Create a Security Profile Name and Description of your choosing and click “Next”.

C-2017-02-23-005-Alexa-Raspberry-Pi-Registration

You’ll now see a new screen with your created security profile. Below, you should see some tabs such as, “General”, “Web Settings”, “Android/Kindle Settings”, and so forth. Click on “Web Settings” and then click “Edit”.

C-2017-02-23-006-Alexa-Raspberry-Pi-Registration

You should now be able to edit the “Allowed Origins” and “Allowed Return URLs” fields. Enter the following values into each of the fields, respectively:

1) https://localhost:3000

2) https://localhost:3000authresponse

Once you’ve entered the above values, click “Next”.

C-2017-02-23-007-Alexa-Raspberry-Pi-Registration

Now we need to add some additional detail about our device type.

  • Upload an image (I used this one, they’re picky about sizing)
  • Choose a category (I selected “Other”)
  • Provide a short description to your pleasing
  • Select “No” for plans on making product available to general public
  • Select “No” for product directed to children

C-2017-02-23-008-Alexa-Raspberry-Pi-Registration

Click “Next” to proceed. The next screen asks about applying for access to Amazon Music. I’m selecting “No” for the purposes of this exercise.

4. Enable Login With Amazon for your new Device / Product

Sweet! After you click, “Submit”, you should see the below. Now head over to the “Apps & Services” section, and select the “Login with Amazon” item, once the Apps & Services screen has loaded.

C-2017-02-23-009-Alexa-Raspberry-Pi-Registration

From the drop-down menu of existing security profiles, select the profile we just created. You’ll need to enter a consent privacy notice URL and a consent logo image. Because we’re doing anything public facing, you can enter any URL you’d like here. For the image, I used the same image from the device creation process. Click “Save” and let’s keep moving.

C-2017-02-23-011-Alexa-Raspberry-Pi-Registration

Upon a successful save, you should see a table with a column labeled “Oauth2 Credentials”. Click, “Show Client ID and Client Secret”, copy and save the information somewhere safe. Next stop, Raspberry Pi.

5. Install the Application on Your Raspberry Pi

Flip back over to your Raspberry Pi and type the following two bullet point texts as unique lines into command line.

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

It should take a minute or two to process, and you should see the below.

C-2017-02-23-012-Alexa-Raspberry-Pi-Sample-App-Setup

Next, type the below point texts as unique lines into command line:

  • cd alexa-avs-sample-app/
  • nano automated_install.sh

After returning the two above lines, you should see something like the below. Remember what we entered in the Developer Console a few steps ago? You’ll need this information here. (Highlighted boxes.) Update from 2/25/2017: I actually had quite a bit of trouble with this step. Linux command line / text emulator is not my friend yet. The trouble I had here was making and saving my changes to the below. However, the program is surprisingly helpful! It will prompt you to verify credentials before install proceeds.

C-2017-02-23-014-Alexa-Raspberry-Pi-Sample-App-Setup

After you’ve made the appropriate changes, command line language of CTRL + X should help you save the changes. Close out the command line window and re-open. Type the following bullet texts:

  • cd Desktop
  • cd alexa-avs-sample-app
  • . automated_install.sh

When prompted for the AVS + Raspberry Pi License and Agreement, obviously answer and/or “y” to proceed, and answer yes and appropriate and desired throughout the setup process. E.g., you’ll be asked about language preference, audio input settings, enabling wake word detection, and so forth. (It takes anywhere from 30 min to 1 hour.)

Once the install runs, it’s time to start the Alexa service!

6. Running the Alexa Service / Finishing Touches

To test and run the Alexa service, we need 3 command line terminals open. The command paths for these are at the end of the install. (As I type this, the latest install on my Pi is approaching 45 minutes, so I’ll have to give you the bare bones for now based on past tests and some generous documentation.

The first terminal will set Alexa up to be listening on port 3000 (remember the local host URLs from earlier?) The second window deals with setting up a Java client and logging into Amazon with the Security profile we set up. Logging in and confirming will enable you to initiate the connection to Alexa, paving the way for the third terminal, which enables the wake word detection and actual running of the Alexa service. Woohoo! I’ll update with examples later.

Update — 2/25/2017:

So, the whole process took a looooong time. At about 3 am of the night I wrote / finished this post, the Pi finally finished unpacking and installing everything. Below is our success confirmation! I’ll be testing this evening…

Wrap-Up

Goodness, what a ride, if you stuck it through the whole article. You could do this, or just get a darn Echo. After all this, I recommend you buy an Echo. 🙂

Other miscellaneous updates from 2/25/2107: By the time I got to the wrap up, it was 3:30 in the morning, yikes! I wasn’t feeling very descriptive, nor was I yesterday either. This was an incredibly long process that took several days from start to finish. Was it worth it? Yes. I’m still going to test the capabilities tonight and hopefully have some follow up’s in the coming days. Will I be primarily using an Echo moving forward? Yes.

Getting Started with Alexa Development 02: Signing Up to Alexa Development Portal

Welcome back to our journey in learning how to program Amazon Alexa Skills via Echo voice search. In the previous article, we walked through the process of setting up an Amazon Web Services (AWS) account. Today, we’ll set up an account at the Alexa Development portal, a distinct entity from the AWS portal.

 

Without further ado, let’s jump in. Go to https://developer.amazon.com/public/solutions/alexa.

2017-02-03-001-Alexa-Developer-Home-Screen

You should land on something like the above screen. Click on the “Sign In” button, you can create a new account from this screen if you need.

Important Note: If you already have an Amazon.com account (regular old Amazon shopping account), use those credentials to log in.

Obviously, if you’re a returning Alexa Development Portal user, you can skip the account creation process shown below. If you’re creating a new account, you’ll need to fill out a screen that will likely resemble the below, and click “Save and Continue” when you’ve finished.

2017-02-03-002-Alexa-Developer-Account-Creation

Next, you should be presented with an App Distribution and Services Agreement screen. Be sure to give it a quick read. If you want to use the services, then you’ll need to agree by clicking save and continue. 🙂

The final registration step addresses payments and whether you plan to monetize the apps you develop. For the purposes of my usage, and this learning, I checked “No” to both options before proceeding.

2017-02-03-003-Alexa-Developer-Account-Creation-Monetization

Once you finish that step, you should find yourself in the Amazon Developer Console! Good thing we got the hard material out of the way first, huh?

This should wrap up a pretty quick introductory section for setups. Feel free to visit my previous article on getting set up with AWS, or go to my learning home page on how to start developing Alexa Skills. Thanks and see you at the next article!

The Absolute Beginning for Amazon Alexa Voice Skill Development

An Introduction to this Alexa Learning Journey

So if you’ve visited my site at all in the past, you’ll notice this is the most blogging I’ve done in…ever? Put another way, a significant confluence of factors has dialed up my motivation to doggedly pursue learning and growth. So, here we are at learning Alexa skills!

A few weeks ago, I was suckered by the cheap promise of a free hoodie from Amazon, in exchange for building and publishing my first Amazon skill. You can experience the equally cheap output of that effort by saying, “Alexa, start silly marketing strategies” (again and again.)

Is it a good skill? No! Nor am I going to pull a Dollar Shave Club here either. It’s a bad skill! It’s not interactive. You just have to keep asking it over and over for some dumb buzzword-laden sentences. I promise I only account for 75% of the utterances. 🙂

2017-01-25-001-Silly-Marketing-Strategies

Honestly, I’m thrilled to have published an Alexa skill. But there’s so much more out there! Thus, I’m embarking on yet another educational journey, this one into Amazon Alexa Voice Skill Development.

Getting Set Up with Resources You Need for Alexa Skill Development

The instructions below are for PC only. Apologies, Mac users!

  1. You need to create a folder directory in which we’ll be housing our various materials and code.
  2. Visit the Alexa Skills Kit JS Git Hub page and download all materials as a ZIP.
    1. 2017-01-25-002-Alexa-Skills-Kit-JS-Git-Hub
  3. Once you’ve downloaded the ZIP file, move it from your default Downloads directory, and into the folder you created in Step 1.
  4. Extract the ZIP file. The unzipped folder should be named, by default, “alexa-skills-kit-js-master”. Within the unzipped folder is yet another folder of the same name.
  5. Take the all the contents within the two folders described above, and move them into the “Alexa” directory, higher up.
    1. Move the contents from the “samples” folder into the main “Alexa” directory, so the skill folders (spaceGeek, reindeerGames, etc.) are in the umbrella directory.
  6. When you’ve completed Step 5, you should be left with A) Three text files, and a bunch of skill folders, B) an empty “samples” folder [A&B you moved up two directories into the “Alexa” umbrella folder], C) an empty “alexa-skills-kit-js-master” folder and D) the original zip file.
  7. Delete items B, C, and D from step 6.
  8. Download and install a code/text editor. I personally prefer Sublime Text 2, but a lot of folks prefer Notepad++ as well.
    1. A dedicated code/text editor is highly preferable here, as much of the code for the Alexa skills in JS – Node.JS in particular, I believe.
  9. After you’ve muddled your way through this folder architecture, go into the README file and not the order of Skills. Number the skill folders accordingly in the umbrella directory, excluding helloWorld. (You should have skills 1-9, starting with spaceGeek and ending with ChemistryFlashCards.)

2017-01-25-003-Alexa-Folder-Structure

Alright, that’s it for now! Next, we’ll look at setting up access to Amazon Developer and Amazon Web Services.