question

tuqire avatar image
tuqire asked ·

Can `directives` object take an array of audio files to stream one after the other?

Hi,

I have recently started building an Alexa Skill and have found it really easy to work with.

Currently, when the user makes a request to the skill I am developing, the app gathers a list of 5 or so audio clips it wants to play back to the user. The app returns the first one, and persists the other 4. When the 'AudioPlayer.PlaybackNearlyFinished' request is executed, the app the pops one of the persisted list and returns it. It does this until the list is empty.

My question is, is there a way I can return the entire list of audio files on the first request, and Alexa can them stream them in the correct order? I have noticed the `directives` prop is an array, so I am assuming this is possible?

alexa skills kitaudioaudioplayer
10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

roy-1 avatar image
roy-1 answered ·

Hi tuqire,

Yes, the best way to handle your use-case would be as you described. By listening for AudioPlayer.PlaybackNearlyFinished and then sending along the next stream in your queue. I like to think of AudioPlayer.PlaybackNearlyFinished as more of a back-end functionality to help for queue management.


Regarding having Alexa speak before playing the next stream in your queue, responses to `AudioPlayer.PlaybackNearlyFinished` cannot include outputSpeech, card, or reprompt.

However, if your users say "next" to switch between tracks, then you can send outputSpeech in the resulting Play directive. The Ted Talks skill is a great example of this, if you want to check it out.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

roy-1 avatar image
roy-1 answered ·

Hello,

You can only send one Play directive in a request, and each directive is limited to one audio stream. Alexa tracks up to two audio streams, the currently playing one, and an optionally enqueued stream. Any list functionality on top of this will need to be managed by the skill and it's back-end.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tuqire avatar image
tuqire answered ·

@Roy apologies for the delayed response, I have just seen this.

Does this mean if I wish to stream multiple audio files through one command, storing the queue in my back-end, and listening for the `AudioPlayer.PlaybackNearlyFinished` request before returning the next one on the list is the correct way of doing things?

Also another query, is it possible to get Alexa to speak before streaming any audio file returned for the `AudioPlayer.PlaybackNearlyFinished`? Like we can with intents.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

meep avatar image
meep answered ·

You could also look at .M3U playlists. This allows you queue up multiple audio URLs in a single play directive.

As an added bonus, provided that the ,m3u file itself is served from https, you can even use http hosted audio links inside the file, negating the requirement for the audio files themselves to be https hosted.

10 |2000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.