我目前正在开发一项 Alexa 技能,其中我使用 AudioPlayer
界面来播放歌曲。
当调用取消意图时,我执行以下操作:
'AMAZON.CancelIntent': function() {
this.emit(':tell', "Bye!");}
问题是,Alexa 说“再见”后,音频未暂停,技能仍在运行。
如何从意图处理程序中关闭技能?
最佳答案
您必须发送 AudioPlayer.Stop
指令来停止任何当前正在播放的音频流。
'AMAZON.CancelIntent': function() {
this.response.speak('Bye').audioPlayerStop();
this.emit(':responseReady');
}
在ask-sdk-v2中您可以使用:
return handlerInput.responseBuilder
.addAudioPlayerStopDirective()
.getResponse();
更新
Alexa 服务将跟踪您的音频播放器技能作为最近传输音频的技能,对于任何内置意图,Alexa 将创建一个新 session 并触发对您的技能的请求。
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:
- Invokes audio playback with a different skill.
- Invokes another service that streams audio, such as the built-in music service or the flash briefing.
- Reboots the device.
查看此文档 Built-in Intents for Playback Control
有关 AudioPlayer 指令的更多信息 here
关于aws-lambda - 如何关闭使用 AudioPlayer 界面的 Alexa 技能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52532272/