我正在尝试制作一个Alexa技能,其中Alexa说的是用SSML标记的东西。我试图模仿这个repo中的例子,但我总是收到一个lambda响应
{
...
"response": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak> [object Object] </speak>"
},
...
}
和Alexa字面上说&#34;对象&#34;。
这是我输入我的lambda函数(使用node.js):
var speechOutput = {
type: "SSML",
ssml: 'This <break time=\"0.3s\" /> is not working',
};
this.emit(':tellWithCard', speechOutput, SKILL_NAME, "ya best not repeat after me.")
像这样设置speechOutput也不起作用:
var speechOutput = {
type: "SSML",
ssml: 'This <break time=\"0.3s\" /> is not working',
};
<小时/> 编辑:
index.js
&#39;使用严格的&#39;;
var Alexa = require('alexa-sdk');
var APP_ID = "MY_ID_HERE";
var SKILL_NAME = "MY_SKILL_NAME";
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function () {
this.emit('Speaketh');
},
'MyIntent': function () {
this.emit('Speaketh');
},
'Speaketh': function () {
var speechOutput = {
type: "SSML",
ssml: 'This <break time=\"0.3s\" /> is not working',
};
this.emit(':tellWithCard', speechOutput, SKILL_NAME, "some text here")
}
};
任何人都知道我哪里出错了?
答案 0 :(得分:5)
GitHub上的每个the alexa-sdk source code for response.js,代码中的speechOutput
对象应该是一个字符串。 Response.js负责构建您尝试在代码中构建的响应对象:
this.handler.response = buildSpeechletResponse({
sessionAttributes: this.attributes,
output: getSSMLResponse(speechOutput),
shouldEndSession: true
});
深入挖掘,buildSpeechletResponse()调用createSpeechObject(),它直接负责在Alexa Skills Kit响应中创建outputSpeech
对象。
因此,对于没有高级SSML功能的简单响应,只需在:tell
上发送一个字符串作为第一个参数,然后让alexa-sdk从那里处理它。
对于高级ssml功能(如暂停),请查看ssml-builder npm包。它允许您将响应内容包装在SSML中,而无需自己实现或硬编码SSML解析器。
使用示例:
var speech = new Speech();
speech.say('This is a test response & works great!');
speech.pause('100ms');
speech.say('How can I help you?');
var speechOutput = speech.ssml(true);
this.emit(':ask', speechOutput , speechOutput);
此示例发出一个ask响应,其中语音输出和reprompt语音都设置为相同的值。 SSML Builder将正确解析&符号(这是SSML中的无效字符),并在两个说法语句之间暂停100ms暂停。
示例回复:
Alexa Skills Kit将针对以上代码发出以下response object:
{
"outputSpeech": {
"type": "SSML",
"ssml": "<speak> This is a test response and works great! <break time='100ms'/> How can I help you? </speak>"
},
"shouldEndSession": false,
"reprompt": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak> This is a test response and works great! <break time='100ms'/> How can I help you? </speak>"
}
}
}
答案 1 :(得分:5)
这是一个老问题,但我最近遇到了类似的问题,希望能够提供一个不需要额外依赖的答案。
如上所述,'Speaketh': function () {
var speechOutput = 'This <break time="0.3s" /> should work';
this.emit(':tellWithCard', speechOutput, SKILL_NAME, "some text here")
}
假设是一个字符串,所以alexa说&#34;对象对象&#34;是因为它是一个json。
按以下方式尝试处理程序
{
...
"response": {
"outputSpeech": {
"ssml": "<speak> This <break time=\"0.3s\" /> should work </speak>",
"type": "SSML"
},
...
}
返回此回复
protocol OrderSubItemTableDelegate {
associatedtype cellType // cell type either vc1 or vc2
static func tableViewDidSelectRowAt(object: cellType)
}
class VCCell1: UITableViewCell ,OrderSubItemTableDelegate {
typealias cellType = VCCell1
static func tableViewDidSelectRowAt(object: VCCell1) {
}
}
答案 2 :(得分:0)
您可以这样编写代码:
'BreakIntent':function(){
var speechOutput = 'She is better known as <break time="3s" /> Champion';
var reprompt = "How can I help?";
this.response.speak(speechOutput);
this.response.listen(reprompt);
this.emit(":responseReady");
},
我面临着同样的问题,可以通过这样编写代码来解决。