Simplest example for streaming audio with Alexa

后端 未结 3 1875
夕颜
夕颜 2021-01-01 23:26

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 devic

3条回答
  •  梦谈多话
    2021-01-02 00:16

    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);
    };
    

提交回复
热议问题