music_player_skill
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
music_player_skill [2016/12/30 23:53] – Continuing tutorial text santiagoricoy | music_player_skill [2017/01/02 00:38] (current) – santiagoricoy | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Creating an Alexa Skill to Play a Music File ====== | ====== Creating an Alexa Skill to Play a Music File ====== | ||
+ | |||
+ | |||
+ | {{ youtube> | ||
+ | |||
+ | |||
+ | |||
+ | |||
<!-- Replace the above line with the name of your "How To" Tutorial e.g. How to Laser cut Your Name in Wood --> | <!-- Replace the above line with the name of your "How To" Tutorial e.g. How to Laser cut Your Name in Wood --> | ||
Line 10: | Line 17: | ||
**Keywords: | **Keywords: | ||
\\ | \\ | ||
+ | |||
+ | ---- | ||
<!-- Add a representative photo of your tutorial below. | <!-- Add a representative photo of your tutorial below. | ||
Line 15: | Line 24: | ||
{{ sricoy: | {{ sricoy: | ||
\\ | \\ | ||
- | By the end of this tutorial, you'll have a working Alexa Skill that can be run by | + | By the end of this tutorial, you'll have a working Alexa Skill that plays music, which can be run by speaking a predefined phrase. |
+ | |||
+ | This picture shows part of the Amazon Developer console, which allows you to use many items offered by Amazon to developers; in this case, testing the voice-controlled side of an Alexa skill. We need to understand how to stream files through our Alexa-enabled device. Solving this some degree is important because it demonstrates the ability to fetch files from the web with the Alexa Voice Service (AVS), which implies it can be used to manipulate and control other items in the cloud, and connected devices. This tutorial shows you how to set up a lambda function that talks to the voice-operated end of an Alexa skill. | ||
+ | |||
- | This picture shows part of the Amazon Developer console, which allows you to use many items offered by Amazon to developers; in this case, testing the voice-controlled side of an Alexa skill. We need to understand how to stream files through our Alexa-enabled device. Solving this is to some degree is important because it demonstrates the ability to fetch files from the web with the Alexa Voice Service (AVS), which implies it can be used to manipulate and control other items in the cloud, and connected devices. This tutorial shows you how to set up a lambda function that talks to the voice-operated end of an Alexa skill. | + | ---- |
\\ | \\ | ||
Line 42: | Line 55: | ||
* [[music_player_skill# | * [[music_player_skill# | ||
* [[music_player_skill# | * [[music_player_skill# | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
==== Required Items ==== | ==== Required Items ==== | ||
Line 47: | Line 64: | ||
To complete this tutorial, you'll need the following items: | To complete this tutorial, you'll need the following items: | ||
- | * The files within | + | * The contents of this git repository: [[https:// |
* Computer with Internet access | * Computer with Internet access | ||
* Wireless internet access (if using an Amazon device) | * Wireless internet access (if using an Amazon device) | ||
Line 60: | Line 77: | ||
^PART NAME/ | ^PART NAME/ | ||
| Amazon Echo Dot | Amazon.com | | Amazon Echo Dot | Amazon.com | ||
+ | |||
+ | |||
+ | |||
+ | ---- | ||
Line 71: | Line 92: | ||
Most Alexa skills are made up of a skill created with the Alexa Skills Kit in the AWS Developer Console and an AWS Lambda function that the skill sends its requests to. | Most Alexa skills are made up of a skill created with the Alexa Skills Kit in the AWS Developer Console and an AWS Lambda function that the skill sends its requests to. | ||
- | Here we'll initiate the two parts and then set up our skill: | + | Here we'll initiate the two parts and then connect |
Line 79: | Line 100: | ||
If you do not already have one, create an [[https:// | If you do not already have one, create an [[https:// | ||
- | \\ | ||
- | \\ | ||
- | \\ | ||
- | \\ | ||
**Step 2**: | **Step 2**: | ||
Line 93: | Line 110: | ||
Creating an IAM role: | Creating an IAM role: | ||
+ | |||
+ | {{: | ||
From the AWS Management Console, under the " | From the AWS Management Console, under the " | ||
+ | |||
+ | {{: | ||
This role will be given to a Lambda function, so we will select that option. Click through to the next page. | This role will be given to a Lambda function, so we will select that option. Click through to the next page. | ||
+ | |||
+ | {{: | ||
Select " | Select " | ||
Line 105: | Line 128: | ||
Creating a Lambda function: | Creating a Lambda function: | ||
+ | |||
+ | In the upper right-hand corner, confirm that your region is set to "N. Virginia" | ||
In the upper left of the window, click " | In the upper left of the window, click " | ||
+ | |||
+ | {{: | ||
Now we are prompted to select a blueprint. Click " | Now we are prompted to select a blueprint. Click " | ||
+ | |||
+ | {{: | ||
Select the Alexa Skills Kit as your trigger. Move onto the next page. | Select the Alexa Skills Kit as your trigger. Move onto the next page. | ||
- | Here you'll be prompted to give a name, description, | + | {{: |
- | Scroll down to " | + | Here you'll be prompted |
- | We will review our program now | + | {{: |
+ | Scroll down to " | ||
+ | We will complete the Lambda function right after creating the Alexa Skill. | ||
+ | **Step 5**: | ||
+ | Configuring the Alexa Skill: | ||
+ | |||
+ | {{: | ||
< | < | ||
From the Amazon Developer Console dashboard, click on the " | From the Amazon Developer Console dashboard, click on the " | ||
+ | {{: | ||
Click "Add a new skill" | Click "Add a new skill" | ||
- | The first section of the Alexa Skill, "Skill Information", | + | {{: |
+ | |||
+ | The first section of the Alexa Skill, "Skill Information", | ||
The skill' | The skill' | ||
Line 136: | Line 173: | ||
Please select the " | Please select the " | ||
- | **Step 4**: | ||
This page allows us to create our interaction model. The top text box allows us to define what intents we would like to use in an intent schema. Intents are requests that can be triggered by verbal commands. A few of our intents are required by the Alexa skills kit because we will be streaming music. Intents are specified in JSON format. | This page allows us to create our interaction model. The top text box allows us to define what intents we would like to use in an intent schema. Intents are requests that can be triggered by verbal commands. A few of our intents are required by the Alexa skills kit because we will be streaming music. Intents are specified in JSON format. | ||
- | Please extract the zip archive that can be downloaded in the " | + | {{: |
+ | |||
+ | In the extracted folder, inside the " | ||
+ | |||
+ | {{: | ||
Also in the " | Also in the " | ||
Line 146: | Line 186: | ||
Click " | Click " | ||
- | **Step | + | **Step |
- | The Global Fields page is where we set up where our requests will be sent. | + | The Global Fields page is where we define |
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | We need to complete our lambda function in order to complete this portion. Go into the "Skill Information" | ||
+ | |||
+ | |||
+ | Scroll back up to " | ||
+ | |||
+ | With node.js installed, using a command line (the Git shell is what I used on Windows), navigate to the " | ||
+ | |||
+ | Use this command: | ||
+ | |||
+ | |||
+ | <fc green> | ||
+ | npm install | ||
+ | </fc> | ||
+ | |||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | It will probably stall for a second, don't worry. Once complete, you will see a " | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Select everything within the " | ||
+ | |||
+ | {{: | ||
+ | |||
+ | We will now upload the created zip file into the section of our Lambda function called " | ||
+ | |||
+ | {{: | ||
+ | |||
+ | In your Alexa Skill configuration page, select ARN as your service endpoint type, and paste your ARN into the text box, being sure to check the North America box. Move on to the next page and now everything is done! | ||
+ | |||
+ | It's time to begin testing...maybe troubleshooting? | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ==== Programming ==== | ||
+ | |||
+ | We got it working, so, how exactly does this thing work? | ||
+ | |||
+ | Well, we'll go through a quick overview here, and I'll link relevant content as I go. | ||
+ | |||
+ | 1. **The Alexa Skill** | ||
+ | |||
+ | The skill built through the developer console has no actual programming involved. | ||
+ | |||
+ | What we do define is what the end user will say to invoke our skill, or navigate options within the skill. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | The intent schema and sample utterances combined represent things the user might say, and what to do in response. | ||
+ | |||
+ | The intent schema is where we set up which intents we will use. Intents are a way of specifying the request sent by the skill to our function in Lambda. | ||
+ | |||
+ | In our example, we use a custom intent called " | ||
+ | |||
+ | For more on defining an Alexa skill' | ||
+ | |||
+ | {{: | ||
+ | |||
+ | |||
+ | We must send our request somewhere, and the global fields section of our skill allows us to specify whether we are sending requests to our own URL or to an AWS Lambda function. It is easier to use the Amazon Resource Number (ARN) of a Lambda function, because we do not have to deal with any specifics concerning how our requests are sent to the Lambda function, we only need to write the code that our function will use to handle requests. | ||
+ | |||
+ | |||
+ | 2. **The Lambda Function** | ||
+ | |||
+ | The Lambda function is where our code is hosted and responds when triggered by the Alexa skill. Otherwise, the function will sit idle and do nothing, making it very efficient for our purposes. With that said, let's take a brief look at our code below. | ||
+ | |||
+ | <code javascript> | ||
+ | |||
+ | 'use strict'; | ||
+ | |||
+ | var Alexa = require(' | ||
+ | var constants = require(' | ||
+ | var stateHandlers = require(' | ||
+ | var audioEventHandlers = require(' | ||
+ | |||
+ | exports.handler = function(event, | ||
+ | var alexa = Alexa.handler(event, | ||
+ | alexa.appId = constants.appId; | ||
+ | alexa.dynamoDBTableName = constants.dynamoDBTableName; | ||
+ | alexa.registerHandlers( //this function allows us to register our handlers | ||
+ | stateHandlers.startModeIntentHandlers,// | ||
+ | stateHandlers.playModeIntentHandlers, | ||
+ | stateHandlers.remoteControllerHandlers, | ||
+ | stateHandlers.resumeDecisionModeIntentHandlers, | ||
+ | audioEventHandlers //there are multiple in this file | ||
+ | ); | ||
+ | |||
+ | alexa.execute(); | ||
+ | |||
+ | }; | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | If you recall in the Lambda function, we use " | ||
+ | |||
+ | For more on handling requests, please visit this link: [[https:// | ||
+ | |||
+ | 3. **IAM and the DynamoDB Table** | ||
+ | |||
+ | {{: | ||
+ | |||
+ | In our example, we don't explicitly setup an Amazon DynamoDB table, but rather it is set up by our Lambda function. However, when we created a role with the Identity and Access Management service (IAM) and set it as our Lambda function' | ||
+ | |||
+ | Amazon CloudWatch is a service that allows us to track metrics of our Amazon Web Services (AWS) account. This ability isn't explicitly used by the skill, but there may be overlap in permissions from CloudWatch that let the function create a table in DynamoDB. | ||
+ | |||
+ | **NOTE:** If you intend to repurpose this sample and change what is actually played by the skill, you will need to go into DynamoDB and delete the table created by the function, as it holds details about what the user has played, but may not replace them correctly with new audio sources. | ||
+ | |||
+ | ---- | ||
==== Final Words ==== | ==== Final Words ==== | ||
- | <!-- | ||
- | This tutorial' | ||
- | Speculating future work derived from this tutorial, includes < | + | This walkthrough has gotten us off the ground with a music-playing Alexa skill, using built-in intents, Amazon DynamoDB, and Amazon IAM. For more on how skills work, please review other links [[echo_tutorial|here]] for an introduction to developing for Alexa. |
+ | |||
+ | For more information on this particular sample, please go through the README.md file. | ||
+ | |||
- | --> | ||
For questions, clarifications, | For questions, clarifications, | ||
music_player_skill.1483170831.txt.gz · Last modified: by santiagoricoy