Alexa Skill NodeJS - Объедините говорить и добавитьAudioPlayerPlayDirective - PullRequest
0 голосов
/ 11 января 2019

Я хочу иметь возможность сделать следующее:

  1. заставь Алексу что-то сказать
  2. Воспроизведение аудио файла
  3. заставь Алексу сказать что-то еще

Я пробовал следующий код, который не работает:

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

Результат кода выше выглядит так:

  1. «Скажи что-нибудь еще»
  2. audioFile воспроизводит

Как мне этого добиться?

1 Ответ

0 голосов
/ 15 января 2019

Я решил эту проблему с помощью пакета 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;
...