AudioPlayer “PlaybackNearlyFinished” Request of Alexa Skills Kit, Not Working

狂风中的少年 提交于 2019-12-07 13:48:45

问题


I've written an Alexa Skill that uses a Lambda Function to play unique audio from a given URL.

The Intent called "PlayAudio" is working and plays the first audio item from our JSON-formatted API.

The Intent called "PlaybackNearlyFinished" does not work, aka, does not play the audio file I am feeding it. Can anybody crack exactly why this doesn't work?

Here is a section from my Lambda Function, which contains the two Intents:

Fact.prototype.intentHandlers = {
    "PlayAudio": function (event, context, response) {
          fetchEnseParse("/latest", function(body) {
            if(body == "error") {
            } 
            else {
                var directives = body.enses.map(function(ense) {
                    var a = ense[1].fileUrl;
                    return {
                         'playBehavior': 'REPLACE_ALL', 
                         'audioItem': 
                             {
                                 'stream': 
                                     {
                                         'url': 'https://s3.amazonaws.com/media.ense.nyc/enses/2017_01_13T16_57_20.190Z/30312/0', 
                                         'token': '33529', 
                                         'offsetInMilliseconds': 0
                                     }
                             }, 
                             'type': 'AudioPlayer.Play'
                    };
                })
            }
            var jsonresponse = {
                'outputSpeech': {
                     'text': '', 
                     'type': 'PlainText'
                    }, 
                'directives': [directives[0]]
            };     
            response.justUseThisJsonPlease( { response: jsonresponse } );
        });
    },


    "AudioPlayer.PlaybackNearlyFinished" : function(event, context, response) {
            var second = 
            {
              "type": "AudioPlayer.Play",
              "playBehavior": "REPLACE_ENQUEUED",
              "audioItem": {
                "stream": {
                  "url": "https://s3.amazonaws.com/media.ense.nyc/enses/violetindigoviolet/30034/0",
                  "token": "33530",
                  "offsetInMilliseconds": 0
                }
              }
            }
            response.justUseThisJsonPlease( { response: second } );
    },

回答1:


It seems that you are including outputSpeech in your response.

This is okay for regular intents, but not for AudioPlayer requests, per this page: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/custom-audioplayer-interface-reference

And this note specifically:

Seeing the exact payload can help as well. You can use to test it locally and get those: https://bespoken.tools/blog/2016/08/24/introducing-bst-proxy-for-alexa-skill-development

You should be seeing an additional request from Alexa, SystemExceptionEncountered, that should provide more information about what was wrong. It will send this when there is improper response to an AudioPlayer request.



来源:https://stackoverflow.com/questions/41641008/audioplayer-playbacknearlyfinished-request-of-alexa-skills-kit-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!