【问题标题】:How to implement Alexa Audio Player Hints如何实现 Alexa 音频播放器提示
【发布时间】:2018-06-06 07:33:24
【问题描述】:

我正在尝试在 node.js 中实现一个支持 Echo Show 的 Alexa 音频播放器。我能够流式传输音频并显示元数据,但似乎无法更改“提示”以反映我的技能。

我真的不想暗示与我的技能无关的欧元汇率(见下图)......

在我的响应对象中,我什至包含了一个不需要的显示模板,但包含在内是因为我已经尝试了我知道要尝试的所有其他方法。

有人可以看看这个并指出我正确的方向。

'metaDataTestIntent': function() {
    console.log("begin meta data test");
    const { slots } = this.event.request.intent;

    this.attributes.streamURL = 'https://dl.dropboxusercontent.com/s/rglage21wwfv1vj/A%20Satisfied%20Mind.mp3?dl=0';
    this.attributes.testTitle = "Stream Slots Title";
    this.attributes.testSubTitle = "Stream Slots SubTitle";
    try {
        switch (parseInt(slots.selectionNumber.value)) {
            case 1:
                this.attributes.streamURL = 'https://dl.dropboxusercontent.com/s/11cvh79rcgvqdkt/slippinaway.mp3?dl=0';
                this.attributes.testTitle = "Stream 1 Title";
                this.attributes.testSubTitle = "Stream 1 SubTitle";
                break;
            case 2:
                this.attributes.streamURL = 'https://dl.dropboxusercontent.com/s/rglage21wwfv1vj/A%20Satisfied%20Mind.mp3?dl=0';
                this.attributes.testTitle = "Stream 2 Title";
                this.attributes.testSubTitle = "Stream 2 SubTitle";
                break;
            default:
                this.attributes.streamURL = `https://dl.dropboxusercontent.com/s/11cvh79rcgvqdkt/slippinaway.mp3?dl=0`;
                this.attributes.testTitle = "Stream Default Title";
                this.attributes.testSubTitle = "Stream Default SubTitle";
        }
    } 
    catch (err) {
        console.log(`ERROR:${err.message}`);
    }

    //check to see if the device we're working with supports display directives or if simulator
    if(supportsDisplay.call(this)||isSimulator.call(this)) {
        console.log("has display:"+ supportsDisplay.call(this));
        console.log("is simulator:"+isSimulator.call(this));
        console.log(`streamURL=${this.attributes.streamURL}`);
        var content = {
            "streamURL" : this.attributes.streamURL,
            "title" : this.attributes.testTitle,
            "subtitle": this.attributes.testSubTitle,
            "templateToken" : "countryStrangerTemplate",
            "artwork" : 'https://dl.dropboxusercontent.com/s/nphebzfzlfmfw1o/CountryStranger480x480.png?dl=0',
            "background" : 'https://dl.dropboxusercontent.com/s/gddtwefakcon325/Background1024x640.png?dl=0',
            "hint" : 'Alexa, tell Country Stranger to Play my Playlist.',
            "askOrTell" : ":ask",
            "endSession" : false,
            "sessionAttributes": this.attributes
        };
        console.log('call renderAudio to process devices with cards');
        renderAudio.call(this, content);           
    } else {
        console.log('process response for devices without cards');
        this.response.audioPlayerPlay('REPLACE_ALL', streamDynamic.url, streamDynamic.url, null, 0);
        this.emit(':responseReady');
    }
},
.    
.
.
.
.
.
function renderAudio (content) {
console.log(`renderAudio: ${content.streamURL}`);
switch(content.templateToken) {
    case 'countryStrangerTemplate':
        var response = {
            "version": "1.0",
            "response": {
                "shouldEndSession": content.endSession,
                "sessionAttributes": content.sessionAttributes,
                "directives": [
                    {
                        "type": "Display.RenderTemplate",
                        "template": {
                            "type": "BodyTemplate2",
                            "token": "token",
                            "backButton": "HIDDEN",
                            "backgroundImage": content.background,
                            "title": "template title",
                            "textContent": {
                                "primaryText": {
                                    "text": "primaryText",
                                    "type": "PlainText"
                                },
                                "secondaryText": {
                                    "text": "secondaryText",
                                    "type": "PlainText"
                                },
                                "tertiaryText": {
                                    "text": "tertiaryText",
                                    "type": "PlainText"
                                },
                            },
                        },  
                        "type" : 'Hint',
                        "hint" : {
                            "type" : 'PlainText',
                            "text" : content.hint
                        },
                        "type": "AudioPlayer.Play",
                        "playBehavior": "REPLACE_ALL",
                        "audioItem": {
                            "stream": {
                                "url": content.streamURL,
                                "token": content.streamURL,
                                "offsetInMilliseconds": 0
                            },
                            "hint" : {
                                "type" : 'PlainText',
                                "text" : content.hint
                            },
                            "metadata": {
                                "title": content.title,
                                "subtitle": content.subtitle,
                                "art": {
                                    "sources": [
                                        {
                                            "url": content.artwork
                                        }
                                    ]
                                },
                                "backgroundImage": {
                                    "sources": [
                                        {
                                            "url": content.background
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ]
            }              
        };

        this.context.succeed(response);
    break;


    default:
        console.log("default case taken");
        this.response.speak("Thanks for visiting, goodbye");
        this.emit(':responseReady');
    break; 
}

【问题讨论】:

    标签: alexa alexa-skill


    【解决方案1】:

    看起来您将所有指令添加到一个对象中,而不是指令数组中的单独对象。我猜 Alexa 只是忽略了所有以前的指令,只查看最后一个(音频播放器指令)。试试这个来代替你的回应:

    var response = {
        "version": "1.0",
        "response": {
            "shouldEndSession": content.endSession,
            "sessionAttributes": content.sessionAttributes,
            "directives": [
                {  
                    "type" : 'Hint',
                    "hint" : {
                        "type" : 'PlainText',
                        "text" : content.hint
                    },
                },
                {
                    "type": "AudioPlayer.Play",
                    "playBehavior": "REPLACE_ALL",
                    "audioItem": {
                        "stream": {
                            "url": content.streamURL,
                            "token": content.streamURL,
                            "offsetInMilliseconds": 0
                        },
                        "metadata": {
                            "title": content.title,
                            "subtitle": content.subtitle,
                            "art": {
                                "sources": [
                                    {
                                        "url": content.artwork
                                    }
                                ]
                            },
                            "backgroundImage": {
                                "sources": [
                                    {
                                        "url": content.background
                                    }
                                ]
                            }
                        }
                    }
                }
            ]
        }
    }
    

    请注意我是如何调整您的响应以包含每个单独的指令(在本例中为音频播放器播放指令和提示指令)包含在它自己的一组花括号中。我也摆脱了渲染模板指令,因为正如你所说,你不应该需要它!

    【讨论】:

    • 相同的结果。背景、图片、标题和副标题都显示正确,但提示仍然是亚马逊提供的随机说法。似乎无法覆盖它。我读到您必须重新启动设备,因为它缓存了一些数据,但我在每次更改后都这样做了,但仍然无法使用它。
    • 我也尝试过使用响应生成器添加提示,但得到相同的结果。
    • @FlashSolutions 完全删除提示指令后会发生什么?提示是否仍然显示?
    • @FlashSolutions 你也试过在开发者门户中测试这个技能吗?我怀疑问题出在你的 Show 缓存数据上,但如果你有可能在那儿测试它以确保。
    • 这不起作用,因为它是不支持音频的设备。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    相关资源
    最近更新 更多