Alexa Skill NodeJS - Combine speak and addAudioPlayerPlayDirective

467 Views Asked by At

I want to be able to do the following:

  1. make alexa say something
  2. play audio file
  3. make alexa say something else

I have tried the following code which does not work:

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();
  }
}

The result of the code above is this:

  1. "Say something else"
  2. audioFile plays

How can I achieve this?

1

There are 1 best solutions below

0
On BEST ANSWER

I solved this by using the ssml-builder package to create a SSML string and modifying the response sent back with that string.

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;