I'm trying to get the new streaming audio API going. Is the following response valid? I'm getting a "there was a problem with the skill" error when I test it on my device.
Here is the code for my AWS-lambda function:
def lambda_handler(event, context):
return {
"response": {
"directives": [
{
"type": "AudioPlayer.Play",
"playBehavior": "REPLACE_ALL",
"audioItem": {
"stream": {
"token": "12345",
"url": "http://emit-media-production.s3.amazonaws.com/pbs/the-afterglow/2016/08/24/1700/201608241700_the-afterglow_64.m4a",
"offsetInMilliseconds": 0
}
}
}
],
"shouldEndSession": True
}
}
Say “Alexa, pair Bluetooth,” and your Echo will go into pairing mode. You can then connect any mobile device or computer to it over Bluetooth, and stream audio across the connection.
Stream music, videos, podcasts, audiobooks, and more and control it with Alexa. It's easy to pair a Bluetooth device with an Amazon Alexa speaker. Once paired, it's fast to pair it again with a simple voice command to stream audio via Bluetooth.
Connect Your Devices to Play YouTube Audio on Echo To do this easily, you can say "Alexa, connect Bluetooth." This will cause your Echo to connect to your phone, since it's a previously paired device. Alexa will make a sound and say "Now connected to [Device Name]" if it's successful.
The following code worked for me:
def lambda_handler(event, context):
return {
"response": {
"directives": [
{
"type": "AudioPlayer.Play",
"playBehavior": "REPLACE_ALL",
"audioItem": {
"stream": {
"token": "12345",
"url": "https://emit-media-production.s3.amazonaws.com/pbs/the-afterglow/2016/08/24/1700/201608241700_the-afterglow_64.m4a",
"offsetInMilliseconds": 0
}
}
}
],
"shouldEndSession": True
}
}
]
The only difference is that the URL is https rather than http.
Don't be put off if it doesn't work in the skill simulator. That hasn't been upgraded yet to work with streaming audio. You won't even see your directives there. But it should work when used with your device.
We created a really simple project on Github that shows the easiest possible way to use the AudioPlayer:
https://github.com/bespoken/super-simple-audio-player
We also created a writeup for it here:
https://bespoken.tools/blog/2017/02/27/super-simple-audioplayer
The project shows how to play a track, as well pausing and resuming.
Here is the code that shows the actual playing of an audio file:
SimplePlayer.prototype.play = function (audioURL, offsetInMilliseconds) {
var response = {
version: "1.0",
response: {
shouldEndSession: true,
directives: [{
type: "AudioPlayer.Play",
playBehavior: "REPLACE_ALL", // Setting to REPLACE_ALL means that this track will start playing immediately
audioItem: {
stream: {
url: audioURL,
token: "0", // Unique token for the track - needed when queueing multiple tracks
expectedPreviousToken: null, // The expected previous token - when using queues, ensures safety
offsetInMilliseconds: offsetInMilliseconds
}
}
}]
}
}
this.context.succeed(response);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With