Upload
david-janes
View
576
Download
0
Embed Size (px)
Citation preview
Writing Alexa Voice Skills With NodeJS(with a little IoT)
Introduction
Important Links
• Alexa Skills Console https://developer.amazon.com/edw/home.html#/skills/list
• Sample Code & Skill https://github.com/dpjanes/homestar-alexa
Topics Covered
• Choosing an Architecture
• Creating a Skill
• Interaction Model
• Skills for the IoT
• Testing your Skill
Emphasis
• We'll focus on core concepts
• Intent, Slots, Utterances
• From definition to implementation
About IOTDB
• Open Source IoT Platform
• Based on Semantics
• Natural fit for voice control
• https://github.com/dpjanes/node-iotdb
Architecture
Many Moving Parts
• Home
• Amazon Echo
• IoT Device
• Iot Controller
• Amazon
• Alexa Voice Skill
• Cloud
• Skill Server
• Vendor Server
• Proxy Server
Typical Alexa Voice Skill(hosted)
Typical Alexa Voice Skill(AWS Lambda)
Cloud Based
Home Based
Proxy Based
This Presentation
• Focus on writing Alexa Voice Skill
• Communications between Cloud and your Home will be "open"
e.g. mainly this
CreatingAlexa Voice Skills
e.g. here
Getting Started
• https://developer.amazon.com/edw/home.html#/skills/list
• Create an Account if you don't have one
• will require SMS verification
• Select "Add a New Skill"
Alexa Skill Editor
Alexa Skill Editor
• We'll focus on
• Skill Information
• Interaction Model
• Configuration
• Test
Skill Editor: Skill Information
Alexa Skill Editor
Creating New Skill: Skill Information
Skill Information: Skill Type
• Different types of Skills
• Custom: the most flexible
• Smart Home Skill: don't have to use the "magic word" (the Invocation Name)
• Flash Briefing: news
Skill Information: Skill Type
• What will appear in your Skills List
• What will appear in the App Store
Skill Information: Invocation Name
• The "Magic Word"
• Alexa, ask HomeStar to …
• Alexa, tell HomeStar to …
• Not needed with Smart Home Skills
Skill Editor:Interaction Model
This is the Cool Part
• The Interaction Model determines how Alexa interprets your voice commands
Interaction Terminology
• Utterances
• Slots
• Intents
Utterances
• Step 1 in writing your Alexa Voice Skill
• Write down things you want to say
• Look for Patterns
Utterances"Ask HomeStar…"
• turn on Stove
• turn off Stove
• turn on Light
• turn on Light in the Kitchen
• turn off TV
• turn off Living Room TV
• turn off everything
• to turn off everything
• to turn off everything in the Living Room
• turn down TV
• turn down TV in the Living Room
Utterances"Ask HomeStar…"
• turn on {Thing}
• turn off {Thing}
• turn on {Thing}
• turn on {Thing} in the Kitchen
• turn off {Thing}
• turn off Living Room {Thing}
• turn off {Thing}
• to turn off {Thing}
• to turn off {Thing} in the Living Room
• turn down {Thing}
Utterances"Ask HomeStar…"
• turn on {Thing}
• turn off {Thing}
• turn on {Thing}
• turn on {Thing} in the {Zone}
• turn off {Thing}
• turn off {Zone} {Thing}
• turn off {Thing}
• to turn off {Thing}
• to turn off {Thing} in the {Zone}
• turn down {Thing}
• turn down {Thing} in the {Zone}
Utterances"Ask HomeStar…"
• {Action} {Thing}
• {Action} {Thing}
• {Action} {Thing}
• {Action} {Thing} in the {Zone}
• {Action} {Thing}
• {Action} {Zone} {Thing}
• {Action} {Thing}
• to {Action} {Thing}
• to {Action} {Thing} in the {Zone}
• {Action} {Thing}
• {Action} {Thing} in the {Zone}
Utterances"Ask HomeStar…"
• {Action} {Thing}
• to {Action} {Thing}
• {Action} {Thing} in the {Zone}
• to {Action} {Thing} in the {Zone}
• {Action} {Zone} {Thing}
• to {Action} {Zone} {Thing}
Slots
• These are the {variables} in the Utterances
• e.g. {Thing}, {Zone}, {Action}
• two types of slots:
• Custom (e.g. above)
• Built-In
Slots (Built-In)
• Date
• Duration
• Four Digit Number
• Number
• Time
• Cities…
Slots {Thing}
• lamp
• light
• coffee maker
• kettle
• stove
• tv…
Slots {Action}
• turn off
• turn on
• turn down
• turn up
• open
• close
Slots {Zone}
• Back Door
• Back Garden
• Back Hall
• Back Porch
• Basement
• Basement Bathroom…
Intents
• Basically, Intents are "phases" of your conversation with Alexa
• If "single shot" then this isn't very complicated - just define a "FirstIntent", e.g. HomeStarFirst Intent
Putting it together
Putting it together
Skill Editor:Configuration
Configuration: Endpoint
• Two (major options)
• AWS Lambda
• Hosted - contacts a url
• Note the URL we are using - we'll see it again soon
Configuration: Account Linking
• Used for connecting to systems that have accounts!
• E.g. Smart Homes - what Smart Home does Alexa have to talk to
• Set up when user connects to Skill
Configuration: Account Linking
• Alexa calls your Authorize URL with a number of parameters
• Let the user do something on your website to confirm it
• Your website redirects back to Alexa with a number of magic parameters
Alexa Skill Endpoint /Your Server
e.g. here
Sample Code
• url: https://github.com/dpjanes/homestar-alexa/
• ./hosted/monitor_1.js
N.B.
• Alexa Skill is configured to hit https://alexa.homestar.io/request
• You must use HTTPS
• Amazon provides flexibility in certs
Sample Code (1)
Demo (1)"monitor_1.js"
The Request
The Request
• "session"
• a session of interactions (captured in Intents) between user and Alexa
• user login info (from Account Linking)
• "request"
• the Intent and Slot data
The Request"session"
The Request"session"
• "new": we can be continuing a session
• "sessionId": in case you are, for logging
• "user": all this is set up by Account Linking
• not required if just for yourself
The Request"request"
The Request"request"
• "type"
• "locale"
• "intent"
The Request"request/intent"
• "name"
• "slots"
• Action / Query / Zone / Thing
• We defined these!
The Request"request/intent"
• "request/intent/slots/Action/value": the {{ Action }}
• "request/intent/slots/Thing/value": the {{ Thing }}
The Response
The Response
• "response/outputSpeech/text": this is what Alexa will say to the user
• "response/shouldEndSession": make false if you want to keep going
Sample Code (II)
Demo (II)"monitor_2.js"
Skill Editor: Test
Test
Going Further
IOTDB
• NPM modules
• iotdb
• homestar
• iotdb-commands
• takes Action / Thing / &c and does it
Demo (III)live
Get in touch! David Janes
http://iotdb.org/social/imadeit/