我正在尝试在node.js中实现一个支持Echo Show的Alexa Audio播放器。我能够流式传输音频并显示元数据,但似乎无法改变"提示"反映我的技能。
我真的不想暗示欧元汇率(见下图)与我的技能无关......
在我的响应对象中,我甚至包含了一个不必要的显示模板,但是包括在内,因为我已经尝试了其他所有尝试的内容。
有人可以看看这个并指出我正确的方向。
'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;
}
答案 0 :(得分:0)
看起来你要在一个对象中添加所有指令,而不是在指令数组中添加单独的对象。我猜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
}
]
}
}
}
}
]
}
}
请注意我是如何调整您的响应以包含其自己的花括号中包含的每个单独指令(在本例中为音频播放器播放指令和提示指令)。我也摆脱了渲染模板指令,因为正如你所说,你不应该需要它!