问题
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