Nessun risultato trovato
We recently launched the Alexa Skills Kit (ASK), a collection of self-service APIs and tools that make it fast and easy for you to create new voice-driven capabilities for Alexa. Alexa is the same cloud-based voice service that powers Amazon Echo, a new category of device designed around your voice. With a few lines of code, you can easily integrate existing web services with Alexa or, in just a few hours, you can build entirely new experiences designed around voice. No experience with speech recognition or natural language understanding is required—Amazon does all the work to hear, understand, and process the customer’s spoken request so you don’t have to.
To get started with the Alexa Skills Kit, we recommend you review the following materials in order:
You should also check out this free 38 minute video that will introduce you to the capabilities of the Alexa Skills Kit (ASK) using an Amazon Echo device and walk you through building your own skills for Alexa. We use AWS Lambda as an example hosted cloud service – you can follow along at no cost using the AWS free tier. After watching the video you will have an understanding of the Alexa Skills Kit and be able to publish an Alexa skill that can be enabled on an Amazon Echo device.
You can watch the video here and download the slides here.
Customers interact with the Alexa skills you develop by asking a question or stating a command in natural language. The user says a supported phrase such as “ask,” an invocation name that identifies the capability that the user wants to use, and then a specific request or question:
User: “Alexa, ask Greeter to say hello world.”
The above example breaks down like this:
· “Say hello” is the specific request, question, or command mapped to a particular intent for the service.
In this context, an intent represents a high-level action that fulfills a user’s spoken request. Intents can optionally have arguments called slots that collect additional information needed to fulfill the user’s request. Intents are specific to Alexa and do not share the same structure as Android intents.
Defining the phrases users speak to make requests and the corresponding intents mapped to those phrases is part of defining the voice interface for an Alexa skill. For details, see Defining the Voice Interface.
The service that implements the particular skill constructs an appropriate response to the intent and sends it back. This reply can include both text that Alexa converts to speech and information to display in a graphical card in the Amazon Echo App, which is available for Fire OS, Android, iOS, and through web browsers. Alexa converts the provided text to speech and reads it back to the user. If you include information for a card, Alexa also sends the card to the user’s Echo App.
The following diagram illustrates the flow of a user's command:
To give Alexa new capabilities, you need the following:
Registering a new skill or ability on the Amazon Developer Portal creates a configuration containing the information that the Alexa service needs to do the following:
Note - You must register a skill before you can test it with an Echo device.
Customers will never interact with your Cloud-based service directly, instead all of their requests will go to the Amazon Alexa Service which in turn will create http post requests your service handles using a predefined contract you have set up.
This contract is set up in the developer portal and you will need to define interactions for your Alexa skill through Intent Schemas
• Each intent consists of two fields. The intent field gives the name of the intent. The slots field lists the slots associated with that intent.
• Slots can also include types such as LITERAL, NUMBER, DATE, etc.
Here is an example of what an Intent Schema can look like:
The mappings between the intents you define and the spoken utterances that invoke those intents are provided in a tab-separated text document of sample utterances.
• Each possible phrase is assigned to one of the defined intents.
• GetHoroscope what is the horoscope for {pisces|Sign}
• GetHoroscope what will the horoscope for {leo|Sign} be {next tuesday|Date}
Here is an example of a sample utterance:
The Alexa Service will use these configurations to know how to call your cloud-based service endpoint and to understand how your customer will be talking to an Alexa-enabled device like Echo.
Note – The more sample utterances you include the better Alexa will be able to understand your customers. Make sure you include as many utterances as you can with different samples of data.
Now that you have configured the Alexa skill in the developer portal you will next need to ensure your cloud based service is capable of the following:
· Uses HTTP over SSL/TLS on port 443
· Must be Internet-accessible
· Presents a trusted certificate matching domain name
Once you have set up the configuration for your Alexa skill in the Developer portal your cloud-based service endpoint will be called by the Amazon Alexa Service. This will happen in the following manner:
· You will need to handle POST requests to your service over port 443 and parse the JSON
· You will need to check the session variable to see if the user started a new session or if request is from existing one
· Requests always Include a type, requestId and timestamp
· requestId maps directly to LaunchRequest, IntentRequest and SessionEndedRequest
Here is an example of what a request HTTP header will look like:
Here an example of the request body sent to your service in JSON format:
*Note – AWS Lambda now includes a code template that will automatically handle all of these requests for you and does not require the creation of an SSL certificate. For more information on creating an Alexa AWS Lambda compute function click here.
We have included both Java-based Web Service examples and Node JS Javascript examples as part of the Alexa Skills Kit. In addition to these samples, we provide a complete walk through on how to create your own service to handle Alexa requests as a Web Service using Java and how to create a compute function in AWS Lambda to service Alexa requests.
The Java Web Based Service example provides a Hello World example.
The Node JS Lambda samples provide an array of scenarios including database access and storing session attributes. Here is a complete list of the samples available to download.
Concept |
Description |
Samples |
---|---|---|
Session state |
When a user asks Alexa to perform an action that is mapped to a particular skill, this opens a new session. All requests from this user are directed to your service until the session closes. Each request sent to your service includes a flag you can use to determine whether a session is new or existing, and you can use session attributes to save data with your response during the session. These samples illustrate managing this session. |
|
Multi-stage conversation |
A service can manage a conversation with different stages in which you keep track of the stage the user is in. |
|
Web lookup |
Getting information from various web sites such as Wikipedia and formatting it a voice-friendly way is a useful capability for Alexa, as illustrated with History Buff. |
|
Using a database to persist data between sessions |
The new ability you add to Alexa may need to persist data between sessions so that users can resume where they left off later. Score Keeper illustrates reading and writing to a database using AWS DynamoDB, which is very easy to access from a Lambda function. |
|
Pagination |
If your service returns a large list of data, reading all that back to the user may not be very user friendly. When writing for the ear (not the eye), it is better to give users smaller chunks of information and let them control how much data they want. You can do this by implementing pagination – read back X items in a list, keep track of where you are in the list, and prompt the user if they want more. |
|
NUMBER Slots |
The NUMBER slot type converts numeric words into digits that you can then manipulate as numbers. |
|
DATE Slots |
The DATE slot type converts phrases representing absolute and relative dates into date formats. |
|
LITERAL slots |
The LITERAL slot type passes the slot data to the intent with no conversion. These slots are useful for some free-form data, but work best with short phrases, such as names. |
|
If you configure your app as a Lambda function, the Alexa service executes your function when a user makes a request. Your function then returns the response. Using a Lambda function for your app eliminates some of the complexity around setting up and managing your own endpoint:
You can download the AWS Lambda Node JS samples here and the Java AWS Beanstalk samples here.
With the launch of the Alexa Skills Kit (ASK) you have a unique opportunity to create new Alexa skills that customers can teach their Alexa-enabled devices, like the Amazon Echo. By submitting your Alexa skill today you will be ready when we launch the first new capabilities built using ASK later this year. We can’t wait to see what you create!
You may also want to check out these additional Alexa developer resources:
Alexa Skills Kit (ASK)
Alexa Developer Forums
Getting Started with the Alexa Skills Kit
Alexa Skills Kit Voice Design Handbook
Create a developer account on the Amazon Appstore
Free Video Training - An Introduction to Amazon Echo and the Alexa Skills Kit
-Dave (@TheDaveDev)
Want the latest app and game news delivered to your inbox? Stay in the loop on the latest industry best practices, Amazon promotions, and new launches by subscribing to our weekly blog summary here.