KC Kern
KC Kern

Reputation: 400

Pre-loading MP3 Audio URLs in Lambda (Alexa Skill)

Using this Amazon-provided library, I am working on an alexa skill that plays a queue of short mp3 files. The code that triggers the audio looks like this:

this.response.audioPlayerPlay('REPLACE_ALL', mp3HttpsUrl, mp3HttpsUrl, null, 0);

(function documentation here)

This is further invoked during the PlaybackNearlyFinished audio event handler to queue up the next audio file URL.

It works fine, but there is about a 3~4 second gap between the audio playback. I would like to reduce the gap, and have as-close-to-uninterrupted playback as possible.

In a browser setting, this would be achieved by pre-loading to cache before the time to play has arrive; when the URL finally does gets called to play, the browser just plays it from local storage, delivering a experience with virtually no lag.

How can this be achieved in an alexa lambda function? How do I pre-load the "on-deck" URL so it eventually plays without a gap?

Upvotes: 0

Views: 615

Answers (1)

Todd
Todd

Reputation: 41

In your audioatream play command: pass it the URL to a m3u playlist that contains your glob of mp3 links.

This way it's one json package going to Alexa. Also note that the hyperlink to m3u must be https.

I saw somewhere in Alexa docs that it supports playlists.

The catch is that I believe you will receive a nearly finished event for each item in your playlist.

If your stuff is database driven, just create a CGI that returns a standard text html header and you can dynamically create your m3u on the fly, based on a token or unique Iyou'd you send down as part of your URL:

https://wackydimain.com/myscripts/dynamic_m3u.cgi?token=1234

Upvotes: 1

Related Questions