亚马逊echo中国使用_如何为亚马逊的Echo Show设计和编码Alexa技能

本文介绍了如何为带有屏幕的亚马逊Echo Show设计和编码Alexa技能,利用新硬件功能。文章详细阐述了新版本Alexa Skills Kit带来的升级,包括六种视觉模板、支持基本HTML标记以及处理触摸事件的新意图。此外,还说明了如何将现有技能适应新设备,同时保持所有设备的向后兼容性。
摘要由CSDN通过智能技术生成

亚马逊echo中国使用

by Terren Peterson

由Terren Peterson

如何为亚马逊的Echo Show设计和编码Alexa技能 (How to design and code Alexa skills for Amazon’s Echo Show)

I’m an Amazon Alexa Developer Champion, and have published more than a dozen skills on the Alexa platform. This includes award winning skills like Hurricane Center, Scavenger Hunt, and Robot Roxie.

我是Amazon Alexa开发人员冠军 ,并且已经在Alexa平台上发布了十多种技能。 其中包括屡获殊荣的技能,例如飓风中心寻宝游戏机器人机器人

The latest device added to the Amazon Echo family features a screen that complements its audio experience. It’s called the Echo Show, and here are the hardware specifications. It features a 7" touchscreen display, a 5 Mega-pixel camera, and dual 2 inch stereo speakers.

添加到Amazon Echo系列的最新设备的屏幕可以补充其音频体验。 这就是所谓的Echo Show, 这是硬件规格 。 它具有7英寸触摸屏显示屏,5百万像素摄像头和双2英寸立体声扬声器。

In this article, I’ll show you how to design and code a new Alexa skill that takes advantage of this new hardware.

在本文中,我将向您展示如何设计和编码利用此新硬件的Alexa新技能。

软件平台的重大升级 (Major Upgrades to the Software Platform)

These hardware improvements required an upgrade to the underlying software running the platform. The Alexa Skills Kit (ASK) introduced a major release to power the added screen features. This is the largest set of enhancements to the ASK since the platform launched.

这些硬件改进要求升级运行该平台的基础软件。 Alexa技能套件(ASK)推出了一个主要版本,以增强所添加的屏幕功能。 这是自平台推出以来对ASK的最大增强。

技能建设背景 (Background on Skill Building)

If you’re not familiar with developing Alexa applications — called “Skills” — here’s a brief overview.

如果您不熟悉开发Alexa应用程序(称为“技能”),这里是简要概述。

  • A custom voice application interfaces with the natural language processing engine. This interprets audio commands provided by the user. Each application includes a customized intent model to direct the skills messages. A set of sample utterances train the voice recognition models which intent in the model to use.

    定制语音应用程序与自然语言处理引擎对接。 这解释了用户提供的音频命令。 每个应用程序都包含一个定制的意图模型来指导技能消息。 一组样本话语训练了要在模型中使用的语音识别模型。
  • A unique API receives all messages for the custom skill. Alexa requires a RESTful interface to be specified in the custom voice application. The skill author writes the API, and chooses the hosting platform. The preferred hosting platform is the AWS service Lambda. This is due to the slick compatibility of the security model across Amazon and low hosting costs. The API call contains a standard set of attributes relating the call made by the device. This contains data around the current invocation of the skill.

    唯一的API会接收有关自定义技能的所有消息。 Alexa要求在自定义语音应用程序中指定RESTful接口。 技术作者编写API,然后选择托管平台。 首选的托管平台是AWS服务Lambda。 这是由于整个Amazon的安全模型具有出色的兼容性以及较低的托管成本。 API调用包含与设备调用相关的一组标准属性。 这包含有关当前技能调用的数据。

Here is an example of a request to the Hurricane Center skill API:

以下是对飓风中心技能API的请求示例:

{  "session": {    "sessionId": "SessionId.5725be2d-99f8-4afd-909f-1f1d3882067a",    "application": {      "applicationId": "amzn1.echo-sdk-ams.app.709xxx"    },    "attributes": {},    "user": {      "userId": "amzn1.ask.account.AFP3xxx"    },    "new": true  },  "request": {    "type": "LaunchRequest",    "requestId": "EdwRequestId.260fd856-668f-4dd2-af9d-60d80e4cc8e0",    "locale": "en-US",    "timestamp": "2017-07-02T00:54:57Z"  },  "version": "1.0"}

The API for the custom skill processes the request, and responds with values for the Alexa device. The message model returned is a standard set of attributes, and written in JSON. The Alexa voice on the device reads the outputSpeech attribute.

定制技能的API处理请求,并使用Alexa设备的值进行响应。 返回的消息模型是一组标准属性,并以JSON编写。 设备上的Alexa语音读取outputSpeech属性。

Here is an example the corresponds to the call made to Hurricane Center skill above:

这是与上面对飓风中心技能的呼叫相对应的示例:

{ “version”: “1.0”, “sessionAttributes”: {} “response”: {     “outputSpeech”: {         “type”: “PlainText”,         “text”: “Welcome to the Hurricane Center, the best source for information related to tropical storms, past or present. There are no active tropical storms right now, but if you would like to learn more about storms, please say something like tell me a storm fact.”     },     “card”: {         “content”: “No Current Storms in either the Atlantic or Pacific Ocean.”,         “title”: “Welcome to Hurricane Center”,         “type”: “Simple”     },     “reprompt”: {         “outputSpeech”: {             “type”: “PlainText”,             “text”: “Please tell me how I can help you by saying phrases like, list storm names or storm history for 2013.”         }     }, }, “shouldEndSession”: false }}

回声秀有什么变化? (What Changed for the Echo Show?)

To leverage the new visual features of the Show, the model for the response expanded. The model now includes new attributes to use the new hardware features. The custom written API for the skill includes these attributes in its response.

为了利用表演的新视觉功能,扩展了响应模型。 该模型现在包括使用新硬件功能的新属性。 该技能的定制书面API在其响应中包括这些属性。

New templates supporting different use cases for the screen are central to it. These templates enable the Show to augment the voice experience. Full detail on these changes is available on the Amazon Developer website.

支持屏幕不同用例的新模板是其中的核心。 这些模板使Show可以增强语音体验。 有关这些更改的完整详细信息,请访问Amazon Developer网站

六种视觉模板可供选择 (Six visual templates to choose from)

There are six templates available with the initial launch of the new ASK. Each template provides the ability to leverage the touch screen on the Echo Show. There are two types of templates. Four of them provide basic usage of the screen, the other two templates add the ability to manage lists of data. The skill developer selects which template is most applicable for each use case.

新ASK的首次启动有六个模板可用。 每个模板都可以利用Echo Show上的触摸屏。 有两种类型的模板。 其中四个提供了屏幕的基本用法,其他两个模板增加了管理数据列表的功能。 技术开发人员选择哪种模板最适合每个用例。

Echo Show支持基本HTML标记 (Echo Show supports basic HTML tagging)

The Alexa platform already has a visual option before these changes. This is within the mobile application on your device pairs with — named the companion app. This performed initial setup and configuration by pairing with the device. Some skills use it to complement the voice first user experience. Here is what it looks like for Hurricane Center.

在进行这些更改之前,Alexa平台已经具有可视选项。 这是在与您的设备配对的移动应用程序中,该应用程序名为“伴侣应用程序”。 通过与设备配对执行了初始设置和配置。 一些技能使用它来补充语音优先用户体验。 这是飓风中心的外观。

The companion application has limits in how it can render information. All words on the screen are plain text. It does not support HTML, including changing the font type, font size, underlining, etc.

配套应用程序在呈现信息方面有一些限制。 屏幕上的所有单词均为纯文本。 它不支持HTML,包括更改字体类型,字体大小,下划线等。

An optional small image displays on the screen that changes with each voice response. Usability on the app is poor when rendering a large amount of data given the clear text constraint. Usability is also poor when rendering lists of data which may be important to the narrative of the skill.

屏幕上显示一个可选的小图像,该图像随每个语音响应而变化。 在明文限制的情况下,渲染大量数据时,应用程序的可用性很差。 在呈现可能对技能叙述很重要的数据列表时,可用性也很差。

Within the templates of the new ASK, both simple text and basic HTML syntax are now supported. Pairing this with the list template provides a whole new level of user experience.

在新ASK的模板中,现在支持简单文本和基本HTML语法。 将其与列表模板配对可提供全新的用户体验。

处理触摸事件的新意图 (New intents to handle touch events)

The screen on the Echo Show does more than act as a display, it also has touch sensors. Interacting with the screen creates events along with audible utterances. These include, back-button, right, left, etc. as the user can gesture with text and lists on the screen.

Echo Show上的屏幕不仅可以充当显示器,还具有触摸传感器。 与屏幕互动会创建事件以及可听见的话语。 这些包括后退按钮,向右,向左等,因为用户可以在屏幕上用文本和列表进行手势操作。

The device handles most of the new standard intents. They can be incorporated into your skill when rendering lists.

该设备可处理大多数新标准意图。 呈现列表时,可以将它们合并到您的技能中。

现有技能可在新设备上使用 (Existing Skills work on the new Device)

All 15,000 existing skills on the platform work with the Echo Show. They will use information that is currently rendered on the companion application. Here is an example with the Hurricane Center skill.

该平台上的所有15,000现有技能都可以与Echo Show配合使用。 他们将使用当前在配套应用程序上呈现的信息。 这是飓风中心技能的示例。

The skill works, but the usability of the screen is poor as the font is too large. The screen shows the same information that shared with the companion application. Without changes, it isn’t using a template, so there is no scrolling enabled in case the user wants to read the full text.

该技能有效,但是由于字体太大,屏幕的可用性很差。 屏幕显示与配套应用程序共享的相同信息。 如果不进行更改,则不会使用模板,因此,如果用户要阅读全文,则不会启用滚动。

For reference, here is the GitHub repo that contains the entire source code for this skill.

作为参考,这是GitHub存储库,其中包含此技能的完整源代码。

terrenjpeterson/hurricaneAlexa Skill for providing hurricane updatesgithub.com

terrenjpeterson /飓风 Alexa提供飓风更新的技能 github.com

极端改头换面-回声秀版 (Extreme Makeover — Echo Show Edition)

Here are the steps required to take advantage of the new features in the ASK. These changes will leverage the hardware capabilities for users with an Echo Show.

以下是利用ASK中的新功能所需的步骤。 这些更改将利用Echo Show为用户利用硬件功能。

步骤1 —激活技能的模板功能 (Step 1 — Activate template feature for the skill)

Activating it for a skill requires selecting a radio button on a new or existing skill. There is a new indicator to “Render Template”. Once it is set, the skill can now leverage the extra abilities of the Echo Show.

激活一项技能需要选择新技能或现有技能上的单选按钮。 “渲染模板”有了新的指示符。 设置好之后,该技能现在可以利用Echo Show的额外功能。

步骤2 —选择一个模板,然后将属性添加到API响应 (Step 2 — Select a template, then add attributes to the API response)

The ASK now contains templates outlining the visual patterns supported by the Echo Show. These map to different UI patterns, including displaying images and lists. There is good reference documentation on the Amazon developer website.

现在,ASK包含模板,概述了Echo Show支持的视觉模式。 这些映射到不同的UI模式,包括显示图像和列表。 Amazon开发人员网站上有很好的参考文档

For my Hurricane Center skill, I’ve chosen to use the “BodyTemplate1” for the main display. This takes advantage of the ability to display a background image on the Show. It also renders an improved user experience for the textual response. Here are the new attributes to include to the existing JSON response.

对于我的飓风中心技能,我选择将“ BodyTemplate1”用作主显示。 这利用了在演出中显示背景图像的能力。 它还为文本响应提供了改进的用户体验。 这是要包括在现有JSON响应中的新属性。

directives: [ {   type: “Display.RenderTemplate”,   template: {       type: “BodyTemplate1”,       token: “T123”,       backButton: “HIDDEN”,       backgroundImage: {           contentDescription: “StormPhoto”,           sources: [               {                  url: “https://s3.amazonaws.com/hurricane-data/hurricaneBackground.png”               }           ]      },      title: “Hurricane Center”,      textContent: {          primaryText: {              text: cardInfo,              type: “PlainText”          }      }  }}],

The background image used matches the dimensions of the Echo Show — 1024 x 600 pixels. Hosting images follows the same pattern as with the companion application. The image object needs to be accessible from the internet without any authentication.

所使用的背景图像与Echo Show的尺寸匹配-1024 x 600像素。 托管图像遵循与配套应用程序相同的模式。 该图像对象需要无需任何身份验证即可从Internet访问。

第3步-发布技能的新版本 (Step 3 — Publish a new version of the skill)

Rendering templates changes the skill, requiring to go through the certification process again. It doesn’t need publishing a separate skill for the new device. This means all the prior ratings and users that have enabled it on their accounts will carry forward. Test the skill on other devices to make sure that nothing broke.

渲染模板改变了技能,需要再次进行认证过程。 不需要为新设备发布单独的技能。 这意味着所有先前的分级以及在其帐户上启用了该分级的用户都将继续使用。 在其他设备上测试该技能,以确保没有任何损坏。

新版本的技能 (New Version of the Skill)

Here is what the hurricane skill looks like after the work described above.

这是经过上述工作后的飓风技能。

The photo now appears as a background image rather than the default canvas. The text intended for the companion application renders on the Echo Show screen. The font size is appropriate, in a readable format. This is a major improvement in usability, with not a significant effort in coding.

现在,照片将显示为背景图像,而不是默认的画布。 用于配套应用程序的文本将在“回声显示”屏幕上呈现。 字体大小合适,格式可读。 这是可用性方面的重大改进,无需花费大量精力进行编码。

所有设备的向后兼容性 (Backwards Compatibility for all Devices)

We want the skill to continue to work for existing devices given that the Echo Show is new. That requires a little extra logic when formatting the response in the API. The interface contract requires the API provide only attributes readable by the device. This means extra attributes intended for the Echo Show creates errors when sent to an earlier Echo.

鉴于Echo Show是新产品,我们希望该技术继续适用于现有设备。 在API中格式化响应时,这需要一些额外的逻辑。 接口协定要求API仅提供设备可读的属性。 这意味着用于回声显示的额外属性在发送到较早的回声时会产生错误。

Stopping this error requires interpreting the context section of the native request object. This section provides information about the device, including if it contains a display. This attribute is only present with an Echo Show. If this attribute is not present, the API excludes the directives attribute. Here is a sample of a request from the Hurricane Center skill generated by an Echo Show.

要停止此错误,需要解释本机请求对象的上下文部分。 本节提供有关设备的信息,包括设备是否包含显示器。 此属性仅在回声显示中存在。 如果此属性不存在,则API会排除指令属性。 这是回声秀产生的飓风中心技能请求的示例。

“context”: {     “AudioPlayer”: {         “playerActivity”: “STOPPED”     },     “Display”: {         “token”: “T123”     },     “System”: {         “application”: {             “applicationId”: “amzn1.echo-sdk-ams.app.709xxx”         },         “user”: { “userId”: “amzn1.ask.account.AFP3xxx” },         “device”: {             “deviceId”: “amzn1.ask.device.AFAQxxx”,            “supportedInterfaces”: {                 “AudioPlayer”: {},                 “Display”: {                     “templateVersion”: “1.0”,                     “markupVersion”: “1.0”                 },             “VideoApp”: {}         }     },}

In the example above, the System.device.supportedInterfaces.Display attribute exists, indicating that the request is originated by an Echo Show. Here is the request from the same skill generated by an Echo Dot.

在上面的示例中,存在System.device.supportedInterfaces.Display属性,指示该请求是由回声显示发起的。 这是回声点产生的相同技能的请求。

“context”: {     “AudioPlayer”: {        “playerActivity”: “IDLE”     },     “System”: {         “application”: {            “applicationId”: “amzn1.echo-sdk-ams.app.709xxx”         },         “user”: { “userId”: “amzn1.ask.account.AFP3xxx” },         “device”: {             “deviceId”: “amzn1.ask.device.AFAQxxx”,             “supportedInterfaces”: {                 “AudioPlayer”: {}             }         },         “apiEndpoint”: “https://api.amazonalexa.com”     } }

In the second example, there are no display attributes. That’s easy to recognize, and now reflected in my skill.

在第二个示例中,没有显示属性。 这很容易识别,现在体现在我的技能上。

下一步是什么? (What’s Next?)

It’s amazing the speed at which the platform is growing. There are now 15,000 custom skills available for users to try out. The hardware options are enabling even deeper user experiences. I will be spending the next few months porting over my skills to the new platform. Hope this helps updating yours!

该平台的增长速度令人惊讶。 现在有15,000种自定义技能可供用户试用。 硬件选项可提供更深的用户体验。 在接下来的几个月中,我将把我的技能移植到新平台上。 希望这有助于更新您的!

翻译自: https://www.freecodecamp.org/news/how-to-design-and-code-alexa-skills-for-amazons-echo-show-c5716da8fee5/

亚马逊echo中国使用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值