Created
March 2, 2020 17:46
-
-
Save rmtuckerphx/e823cd4d09b05f649a3c1ec934d3cbb7 to your computer and use it in GitHub Desktop.
SpeechMarkdownResponseInterceptor for ASK SDK2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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