How to loop audio in Alexa

柔情痞子 提交于 2019-12-21 06:23:15

问题


I am building a ambient audio skill for sleep for Alexa! I am trying to loop the audio so I don't have to download 10 hour versions of the audio. How do I get the audio to work? I have it build to where it will play the audio, but not loop.


回答1:


I've solved this problem in my skill Rainmaker: https://www.amazon.com/Arif-Gebhardt-Rainmaker/dp/B079V11ZDM

The trick is to handle the PlaybackNearlyFinished event. 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. This will infinitely loop your audio until it gets interrupted by e.g. the 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. 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.



来源:https://stackoverflow.com/questions/50421491/how-to-loop-audio-in-alexa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!