如何关闭使用 AudioPlayer 界面的 Alexa 技能 [英] How to close an Alexa skill that uses AudioPlayer interface

查看:31
本文介绍了如何关闭使用 AudioPlayer 界面的 Alexa 技能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一项 Alexa 技能,我使用 AudioPlayer 界面播放歌曲.

当取消意图被调用时,我会做一个:

'AMAZON.CancelIntent': function() {this.emit(':tell', "再见!");}

问题是alexa说Bye"后,音频没有暂停,技能还在运行.

如何从 Intent 处理程序关闭技能?

解决方案

您必须发送一个 AudioPlayer.Stop 指令来停止任何当前正在播放的音频流.

'AMAZON.CancelIntent': function() {this.response.speak('再见').audioPlayerStop();this.emit(':responseReady');}

在 ask-sdk-v2 中你可以使用:

返回 handlerInput.responseBuilder.addAudioPlayerStopDirective().getResponse();

更新
Alexa 服务将跟踪您的音频播放器技能作为最近流式传输音频的技能,对于任何内置意图,Alexa 将创建一个新会话并触发对您的技能的请求.

<块引用>

当您的技能发送 Play 指令以开始播放时,Alexa 服务会将音频流发送到设备进行播放.一旦会话正常结束(例如,如果您的回复包括设置为 true 的 shouldEndSession 标志),Alexa 记得您的技能开始播放,直到用户执行以下操作之一以下:

  1. 使用不同的技能调用音频播放.
  2. 调用另一个流式传输音频的服务,例如内置音乐服务或 Flash 简报.
  3. 重启设备.

检查此文档 内置的播放意图控制

有关 AudioPlayer 指令的更多信息此处

I am currently developing an Alexa skill where I use the AudioPlayer interface to play a song.

When the Cancel intent is called I do a :

'AMAZON.CancelIntent': function() {
this.emit(':tell', "Bye!");}

The problem is that after alexa said "Bye", the audio is unpaused and the skill is still running.

How can I close the skill from an Intent handler?

解决方案

You have to send an AudioPlayer.Stop directive to stop any currently playing audio stream.

'AMAZON.CancelIntent': function() {
   this.response.speak('Bye').audioPlayerStop();
   this.emit(':responseReady');
}

In ask-sdk-v2 you can use:

return handlerInput.responseBuilder
      .addAudioPlayerStopDirective()
      .getResponse();

Update
Alexa service will track your audio player skill as the skill that most recently streamed audio and for any built in intent, Alexa will create a new session and trigger the request to your skill.

When your skill sends a Play directive to begin playback, the Alexa service sends the audio stream to the device for playback. Once the session ends normally (for instance, if your response included the shouldEndSession flag set to true), Alexa remembers that your skill started the playback until the user does one of the following:

  1. Invokes audio playback with a different skill.
  2. Invokes another service that streams audio, such as the built-in music service or the flash briefing.
  3. Reboots the device.

Check this documentation Built-in Intents for Playback Control

More on AudioPlayer directives here

这篇关于如何关闭使用 AudioPlayer 界面的 Alexa 技能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆