![手把手教你如何用Lambda + Alexa调用echo设备](https://static001.infoq.cn/resource/image/04/ad/04ccf458cbaadfd7c60304070ec30ead.jpg?x-oss-process=image/crop,x_114,y_227,w_1721,h_966/resize,w_726,h_408)
知识补充:
什么是 AWS Lambda?
AWS Lambda 在可用性高的计算基础设施上运行您的代码,执行计算资源的所有管理工作,其中包括服务器和操作系统维护、容量预置和自动扩展、代码监控和记录,只在需要时执行您的代码并自动缩放,从每天几个请求到每秒数千个请求,其提供了 AWS 基础设施的高可用性,高安全性,高功能性和高可扩展性。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-1.jpg)
具体可参考:
https://docs.aws.amazon.com/zh_cn/lambda/latest/dg/welcome.html
什么是 Alexa Skills Kit?
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-2.jpg)
Alexa 是 Echo 内置的语音助手,通过它能够唤醒 Echo。Alexa 的优点在于,它基于云端,因此我们可以随时对其进行改进。Alexa Skills Kit (ASK)是一个由自服务 API、工具、文件和实例代码的集合,可轻松构建你自定义的 Alexa skills,然后发布。
具体可参考:
https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit
打开链接https://aws.amazon.com/,申请亚马逊AWS账号。登录控制台,选择AWS Lambda服务,创建Lambda Function。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-3.jpg)
选择Alexa Skills Kit
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-4.jpg)
下载需要用到的代码,解压,打开index.js文件,修改文件中的开发者账号ID,如下:
https://s3.cn-north-1.amazonaws.com.cn/bjsdemo/LambdaAlexaSkillsKit/RecipeTemplate.zip
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-5.jpg)
修改完成之后,然后打成 Zip 包上传(注意,这里的打包不需要文件夹,直接把.js 文件打包成 RecipeTemplate.zip)
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-6.jpg)
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-6-5.jpg)
接着点击“Create function”
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-7.jpg)
到这里,Lambda 创建成功。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-8.jpg)
进入https://developer.amazon.com/,创建Alexa Skills Kit。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-9.jpg)
选择 ALEXA
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-10.jpg)
选择“Alexa Skills Kit”
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-11.jpg)
点击“Add a new Skill”
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-12.jpg)
填写Name: Solution Helper,Invocation Name: solution helper
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-13.jpg)
填写Intent Schema,样例代码下载:
https://s3.cn-north-1.amazonaws.com.cn/bjsdemo/LambdaAlexaSkillsKit/IntentSchema.json
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-14.jpg)
填写Sample Utterances,样例代码下载:
https://s3.cn-north-1.amazonaws.com.cn/bjsdemo/LambdaAlexaSkillsKit/SampleUtterances.txt
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-15.jpg)
点击“Save”后会报错,这个时候点击“Add Slot Type”添加。样例代码下载
https://s3.cn-north-1.amazonaws.com.cn/bjsdemo/LambdaAlexaSkillsKit/LIST_OF_ITEMS
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-16.jpg)
然后再点击“保存”,这个时候看到Successfully updated the interaction model
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-17.jpg)
此时,点击“Next”,选择Lambda的ARN地址,例如:
arn:aws:lambda:us-east-1:556776719183:function:LambdaAlexaSkillsKit
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-18.jpg)
复制 Lambda ARN 地址
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-19.jpg)
点击“Next”,即将进入到Test阶段,如下图所示。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-20.jpg)
然后在Enter Utterance中输入“How can I build a map”,点击“Ask Minecraft Helper”,能看到Lambda Response的结果。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-00.jpg)
15.(选做)如果是测试用的话这步可以不进行。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-22.jpg)
接下去会上传两张图片,这两张图片是特定尺寸的,而且是必须要上传的,你可以自定义。或者用两张我已经做好的图片:
https://s3.cn-north-1.amazonaws.com.cn/bjsdemo/LambdaAlexaSkillsKit/AWS+Logo+108.png
https://s3.cn-north-1.amazonaws.com.cn/bjsdemo/LambdaAlexaSkillsKit/AWS+Logo+512.png
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-23.jpg)
16.(选做)如果是测试用的话这步可以不进行。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-24.jpg)
使用Web版Alexa Skill Testing Tool进行测试 https://echosim.io/,注意,这里需要用之前的Amazon账号登录。用鼠标点击进行语音。
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-25.jpg)
当输入语音之后,打开Alexa的测试页面,点击Home,可以看到录音识别的效果。http://alexa.amazon.com/spa/index.html#cards
比如我语音输入:
Alexa, Ask solution helper how can build a map
Echo 回答:
A map can be crafted by placing a compass in the middle square and eight pieces of paper surrounding it.
也可以进行自定义语音设置,比如我语音输入:
Alexa, Ask solution helper how can I get summit ticket
Echo 回答:
Hello, if you want to attend beijing summit, please connect to aws china inside sales team.
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/0902-28.jpg)
搞定,完成!
作者介绍:
毛郸榕
![](https://s3.cn-north-1.amazonaws.com.cn/images-bjs/Mao+Danrong-mini.png)
亚马逊 AWS 中国助理解决方案架构师,负责基于 AWS 的云计算方案架构的咨询和设计,同时致力于 AWS 云服务在国内的应用和推广,毕业于北京航空航天大学云计算专业,硕士,毕业后直接加入亚马逊 AWS 中国。在大规模后台架构、企业混合 IT 和自动化运维等方面有着丰富的实践经验。目前在集中精力学习新一代无服务器架构设计。
本文转载自 AWS 技术博客。
原文链接:
https://amazonaws-china.com/cn/blogs/china/lambda-alexa-echo/
评论