Как реализовать Alexa Audio Player Подсказки - PullRequest
0 голосов
/ 05 июня 2018

Я пытаюсь внедрить проигрыватель Alexa Audio в node.js с поддержкой Echo Show.Я могу транслировать аудио и отображать метаданные, но не могу изменить «подсказки», отражающие мои навыки.

Я действительно не хочу подсказки о курсах обмена евро (см. Фотониже), которые не имеют ничего общего с моим умением ...

В моем объекте ответа я даже включил шаблон отображения, который не должен быть необходим, но включен, потому что я попробовал все, что я знаю, чтобы попробовать.

Может кто-нибудь взглянуть на это и указать мне в правильном направлении.

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

enter image description here

1 Ответ

0 голосов
/ 06 июня 2018

Похоже, что вы добавляете все директивы в один объект, а не отдельные объекты в массиве директив.Я предполагаю, что 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
                                }
                            ]
                        }
                    }
                }
            }
        ]
    }
}

Обратите внимание, как я настроил ваш ответ насодержит каждую отдельную директиву (в данном случае директиву воспроизведения аудиопроигрывателя и директиву подсказки), содержащуюся в своем собственном наборе фигурных скобок.Я также избавился от директивы шаблона визуализации, потому что, как вы сказали, она вам не нужна!

...