Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rmtuckerphx/e823cd4d09b05f649a3c1ec934d3cbb7 to your computer and use it in GitHub Desktop.
Save rmtuckerphx/e823cd4d09b05f649a3c1ec934d3cbb7 to your computer and use it in GitHub Desktop.
SpeechMarkdownResponseInterceptor for ASK SDK2
const smd = require('speechmarkdown-js');
module.exports = {
process(handlerInput, responseOutput) {
const options = {
platform: 'amazon-alexa'
};
const speech = new smd.SpeechMarkdown(options);
if (responseOutput.outputSpeech && responseOutput.outputSpeech.ssml) {
let speechOutput = responseOutput.outputSpeech.ssml;
// .speak assumes SSML and adds <speak> tags,
// remove <speak> tags as it is really Speech Markdown
speechOutput = speechOutput.replace('<speak>', '').replace('</speak>', '');
responseOutput.outputSpeech.ssml = speech.toSSML(speechOutput);
} // else no outputSpeech.ssml;
if (responseOutput.reprompt && responseOutput.reprompt.ssml) {
let reprompt = responseOutput.reprompt.ssml;
// .reprompt assumes SSML and adds <speak> tags,
// remove <speak> tags as it is really Speech Markdown
reprompt = reprompt.replace('<speak>', '').replace('</speak>', '');
responseOutput.reprompt.ssml = speech.toSSML(reprompt);
} // else no reprompt.ssml;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment