Alexa Skill NodeJS - 结合 speak 和 addAudioPlayerPlayDirective
Alexa Skill NodeJS - Combine speak and addAudioPlayerPlayDirective
我希望能够做到以下几点:
- 让 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();
}
}
上面代码的结果是这样的:
- "Say something else"
- 音频文件播放
我怎样才能做到这一点?
我通过使用 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;
我希望能够做到以下几点:
- 让 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();
}
}
上面代码的结果是这样的:
- "Say something else"
- 音频文件播放
我怎样才能做到这一点?
我通过使用 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;