我试着做一个Alexa技能,Alexa说了一些已经标记了SSML的东西。我试图在这个存储库中模仿这个例子,但是我总是收到
{
...
"response": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak> [object Object] </speak>"
},
...
}Alexa字面上说“对象对象”。
这就是我向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
“严格使用”;
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")
}
};,有人知道我哪里出错了吗?
发布于 2017-01-23 01:36:32
按照response.js的alexa源代码 on GitHub,代码中的speechOutput对象应该是一个字符串。Response.js负责构建您试图在代码中构建的响应对象:
this.handler.response = buildSpeechletResponse({
sessionAttributes: this.attributes,
output: getSSMLResponse(speechOutput),
shouldEndSession: true
});更深入地讲,buildSpeechletResponse()调用了createSpeechObject(),后者直接负责在Alexa响应中创建outputSpeech对象。
因此,对于没有高级SSML功能的简单响应,只需在:tell上发送一个字符串作为第一个参数,然后让alexa从那里处理它。
对于高级ssml功能,如暂停,请查看ssml建造者 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); 此示例发出询问响应,其中语音输出和重新提示语音被设置为相同的值。SSML将正确地解析符号(在SSML中是一个无效的字符),并在这两个say语句之间插入一个暂停100 is的暂停。
示例响应:
Alexa技能工具包将为上面的代码发出以下响应对象:
{
"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>"
}
}
}https://stackoverflow.com/questions/41776014
复制相似问题