我希望能够执行以下操作:
让Alexa说些什么
播放音频文件
让Alexa说些别的
我尝试了以下无效的代码:
const IntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === "IntentRequest" &&
handlerInput.requestEnvelope.request.intent.name === "MyIntent";
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak("Say something")
.addAudioPlayerPlayDirective('REPLACE_ALL', audioFile, 'token', 0)
.speak("Say something else")
.getResponse();
}
}
上面代码的结果是这样的:
“说些别的”
audioFile播放
我该如何实现?
最佳答案
我通过使用ssml-builder
包创建了SSML字符串并修改了使用该字符串发送回的响应来解决了这个问题。
const AmazonSpeech = require('ssml-builder/amazon_speech');
const speech = new AmazonSpeech();
speech.say('Start of the story')
.audio(audioFile)
.say('Finish the story');
const ssml = speech.ssml();
const response = handlerInput.responseBuilder.getResponse();
response.outputSpeech = {
type: 'SSML',
ssml: ssml
};
return response;
关于node.js - Alexa Skill NodeJS-结合语音和addAudioPlayerPlayDirective,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54149519/