Skip to content

Instantly share code, notes, and snippets.

@mdang
Last active December 20, 2019 15:36
Show Gist options
  • Save mdang/5e694888a4783c8f328daa578fe9f36f to your computer and use it in GitHub Desktop.
Save mdang/5e694888a4783c8f328daa578fe9f36f to your computer and use it in GitHub Desktop.
Lesson: Alexa

Alexa

Prerequisites

Why Develop for Alexa?

  • Millions of devices sold to date (Estimated 11 million)
  • Top sellers on Amazon during Christmas 2016
  • Companies need developers to build out skills (e.g. Starbucks)

How Alexa Works

When a user speaks to an Alexa-enabled device, the speech is streamed to the Alexa service in the cloud. Alexa recognizes the speech, determines what the user wants, and then sends a structured request to the particular skill that can fulfill the user’s request. All speech recognition and conversion is handled by Alexa in the cloud. Every Alexa skill has an interaction model defining the words and phrases users can say to make the skill do what they want. The type of skill you build dictates the interaction model that Alexa uses to communicate with your users.

Alexa Skills

Skill Types

  • Custom Skills
  • Smart Home Skill API - The Smart Home Skill API enables you to create skills to control cloud-connected devices
  • Flash Briefing Skill API - A Flash Briefing Skill provides content for a customer’s Flash Briefing, and so when you create a Flash Briefing skill, you have a chance for your original content to reach customers on a daily basis.

Understanding the Different Types of Skills

Custom Skills

  1. Define intents (Requests the skills can handle)
  • Look up tide information
  • Order a pizza
  • Request a taxi
  1. The words users say to make (or invoke) those requests. This is the interaction model, and it provides the voice user interface by which users communicate with the skill.
  • Get high tide for Seattle (this phrase would be mapped to a TideRequest intent)
  • Order a large pepperoni pizza (this phrase would be mapped to an OrderPizza intent)
  • Order a car (this phrase would be mapped to an OrderCar intent)
  1. The name Alexa uses to identify your skill, called the invocation name. Users include this when making a request. For example, the skill for looking up tides could be called “tide pooler”.

User: get high tide for Seattle from Tide Pooler

Hosting Custom Skills

Create a Custom Skill

Steps to Build a Custom Skill

1. Design a Voice User Interface

Create your intent schema. This is a JSON structure which declares the set of requests (“intents”) your service can accept and handle.

// IntentSchema.json
{
  "intents": [
    {
      "intent": "HelloWorldIntent"
    },
    {
      "intent": "AMAZON.HelpIntent"
    }
  ]
}

Intents can optionally support named parameters with slots. Alexa will pass these values to the Lambda function when invoked.

{
  "intents": [
    {
      "intent": "GetHoroscope",
      "slots": [
        {
          "name": "Sign",
          "type": "LIST_OF_SIGNS"
        },
        {
          "name": "Date",
          "type": "AMAZON.DATE"
        }
      ]
    },
    {
      "intent": "GetLuckyNumbers"
    }
  ]
}

You can then access slot variables like so within Node:

intent.slots.Sign.value

Slot Type Reference

Create a set of sample utterances that map to your intents. These are the phrases users say when interacting with your skill.

HelloWorldIntent say hello
HelloWorldIntent say hello world
HelloWorldIntent hello
HelloWorldIntent say hi
HelloWorldIntent say hi world
HelloWorldIntent hi
HelloWorldIntent how are you

If you have slots defined, you can create a sample utterance like so:

GetHoroscopeIntent what will the horoscope for {Sign} be on {Date}

2. Set up the Skill

3. Write and Test the Code for Your Skill

4. Submit the Skill

Code Samples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment