Hotel Jetwing Jaffna — Main Restaurant @dassana wijesekara

Tinkering Amazon Alexa Skills with Amazon Echo

Dassana Wijesekara
5 min readMay 22, 2018

--

Amazon Echo is a bluetooth enabled portable “hands free” high definition wireless speaker. It is operated primarily by voice.

Echo has seven microphones arranged symmetrically on a outer ring with beam forming technology which could hear voice commands even while playing music.

Amazon Echo hosts an AVS (Alexa Voice Services) agent which push voice stream to Amazon Alexa Voice Service which could handle complex speech recognition and natural language understanding in the cloud. It provide capability of Automatic Speech Recognition (ASR), Natural Language Understanding (NLU) and Text to Speach (TTS) specifically. Alexa is similar to Siri, Cortana and ok Google.

“Alexa Skill” is a functional container which encapsulate capability built by a third party extending AVS core skills similar to an app in mobile parlance. Skill logic can be built using multiple languages and web stack : Java, C#, Go, Python, PHP, Node.js. Skill need to be hosted network reachable, internet enabled site (AWS, Microsoft Azure, Google Cloud Platform etc.,).

Solution Architecture

A new Alexa skill being used as a AWS lambda function to use Philips Hue API of Philips new LED smart bulbs operated using zigbee.

Voice Interface Design, Intents and Utterances

First step in designing a Amazon Alexa skill is to understand how user would interact with the service via voice. This boils down following fundamental concepts.

Invocation Name

Identify the command that will be used to trigger your skill. For example the Amazon Echo is woken up by the word Alexa or Amazon or Echo. So the typical interaction will go like:

Alexa, ask <invocationname> to <Intent>

The Alexa Voice Service is designed in a way that allows us to be quite flexible in terms of the commands and the words/phrases around it. For example we could interact with the same service in multiple ways as shown below:

1. Alexa, ask <invocationname> to <Intent>

2. Alexa, tell <invocationname> to <Intent>

3. Alexa, ask <invocationName> <Intent>

4. Alexa, ask <invocationName> for <Intent>

For more information on how you can design the Voice Interaction, check out the Voice Design Handbook.

Intents

An Intent is the question that you are asking your Alexa Skill and which will result in the invocation of the actual light dimmer service. Your Skill can support one or more Intents which are usually defined by a JSON file that is titled “IntentSchema.json”. The file contents are shown below:

{
"interactionModel": {
"languageModel": {
"invocationName": "smartlighting",
"intents": [
{
"name": "DimIntent",
"slots": [],
"samples": [
"dim the light please",
"please dim the light",
"dim light"
]
},
{
"name": "ColourIntent",
"slots": [],
"samples": [
"colour my light",
"set the mood"
]
}
],
"types": []
},
"dialog": {
"intents": [
{
"name": "DimIntent",
"confirmationRequired": true,
"prompts": {
"confirmation": "Confirm.Intent.767417209133"
},
"slots": []
},
{
"name": "ColourIntent",
"confirmationRequired": true,
"prompts": {
"confirmation": "Confirm.Intent.505778681118"
},
"slots": []
}
]
},
"prompts": [
{
"id": "Confirm.Intent.505778681118",
"variations": [
{
"type": "PlainText",
"value": "Are you sure to apply colour to light ?"
}
]
},
{
"id": "Confirm.Intent.767417209133",
"variations": [
{
"type": "PlainText",
"value": "Are sure to dim the light ?"
}
]
}
]
}
}

The Intent Schema is very flexible and can also take in parameters which are defined in slots. For more discussion on slots, refer to Intent Schema guide.

Intents

So far we have finalized our Invocation Name and our Intents. We now need to specify the various voice commands that would be spoken as part of the Intent. You can map to more than one utterance to make the voice command flexible.

DimIntent : dim light
DimIntent : please dim the light
DimIntent : dim the light please

ColourIntent : set the mood
ColourIntent : colour my light

User can now speak any of the statements and the Alexa Voice Service will try and map it to the right Intent.

Lambda Function Design

Writing our Custom Skill Code and Deploying it via AWS Lambda

I’m going to use the helloworld sample and customize it to fit our custom Alexa Skill. We will specifically just look at the index.js file where we need to handle the code for our specific Intents. The index.js file is shown below:

/* eslint-disable  func-names */
/* eslint quote-props: ["error", "consistent"]*/
/**
* This sample demonstrates a simple skill built with the Amazon Alexa Skills
* nodejs skill development kit.
* This sample supports multiple lauguages. (en-US, en-GB, de-DE).
* The Intent Schema, Custom Slots and Sample Utterances for this skill, as well
* as testing instructions are located at https://github.com/alexa/skill-sample-nodejs-fact
**/
'use strict';
const Alexa = require('alexa-sdk');
//=========================================================================================================================================
//TODO: The items below this comment need your attention.
//=========================================================================================================================================
//Replace with your app ID (OPTIONAL). You can find this value at the top of your skill's page on http://developer.amazon.com.
//Make sure to enclose your value in quotes, like this: const APP_ID = 'amzn1.ask.skill.bb4045e6-b3e8-4133-b650-72923c5980f1';
const APP_ID = 'amzn1.ask.skill.d0cbc7a8-bfee-4312-9b90-7d6dfdbd2b43';
const SKILL_NAME = 'smartlighting';
const DIM_MESSAGE = "Dimming light !";
//=========================================================================================================================================
//Editing anything below this line might break your skill.
//=========================================================================================================================================
const handlers = {
'LaunchRequest': function () {
this.emit('GetNewFactIntent');
},
'DimIntent': function () {

const speechOutput = DIM_MESSAGE;
this.response.cardRenderer(SKILL_NAME, speechOutput);
this.response.speak(speechOutput);
this.emit(':responseReady');
},
};
exports.handler = function (event, context, callback) {
const alexa = Alexa.handler(event, context, callback);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};

Celebrating with Echo at the end of project.

--

--

Dassana Wijesekara
Dassana Wijesekara

Written by Dassana Wijesekara

Technology evangelist, enterprise software architect many years spent designing world class mission critical software. Pilot, artist, musician and photographer.

No responses yet