简体   繁体   English

如何在Alexa中循环播放音频

[英]How to loop audio in Alexa

I am building a ambient audio skill for sleep for Alexa! 我正在为Alexa打造一种环境音频技能来睡觉! I am trying to loop the audio so I don't have to download 10 hour versions of the audio. 我正在尝试循环播放音频,因此不必下载10小时版本的音频。 How do I get the audio to work? 如何使音频工作? I have it build to where it will play the audio, but not loop. 我将其构建到可以播放音频的位置,但不能循环播放。

I've solved this problem in my skill Rainmaker: https://www.amazon.com/Arif-Gebhardt-Rainmaker/dp/B079V11ZDM 我已经用我的技能Rainmaker解决了这个问题: https : //www.amazon.com/Arif-Gebhardt-Rainmaker/dp/B079V11ZDM

The trick is to handle the PlaybackNearlyFinished event. 诀窍是处理PlaybackNearlyFinished事件。 https://developer.amazon.com/de/docs/alexa-voice-service/audioplayer.html#playbacknearlyfinished https://developer.amazon.com/de/docs/alexa-voice-service/audioplayer.html#playbacknearlyfinished

This event is fired shortly before the currently playing audio stream is ending. 当前播放的音频流即将结束前不久将触发此事件。 Respond to the event with another audioPlayerPlay directive with behavior ENQUEUE . 使用行为为ENQUEUE另一个audioPlayerPlay指令响应事件。 This will infinitely loop your audio until it gets interrupted by eg the AMAZON.StopIntent . 这将无限循环播放音频,直到被AMAZON.StopIntent中断AMAZON.StopIntent

Advanced: if you want a finite loop, say ten times your audio, use the token of the audioPlayerPlay directive to count down from ten. 高级:如果您想进行有限循环,例如说十倍于音频,请使用audioPlayerPlay指令的标记从十开始递减计数。 Once the counter hits zero, just don't enqueue another audio. 计数器归零后,就不必再排队其他音频了。 But be sure to respond something in this case, even if it's just an empty response. 但是在这种情况下,即使只是空洞的响应,也请务必做出回应。 Otherwise you will get a timeout error or the like. 否则,您将收到超时错误等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM