Alexa (ASK): Как воспроизвести несколько аудио с разных URL? - PullRequest
0 голосов
/ 06 апреля 2020

Я новичок в разработке ASK и в настоящее время застрял на проигрывании аудио с нескольких разных URL-адресов, используя .addAudioPlayerPlayDirective из handlerInput.responseBuilder. Поэтому, если я добавлю несколько addAudioPlayerPlayDirective в responseBuilder, он вернет ошибку. Например:

handlerInput.responseBuilder
    .speak(speakOutput)
    .addAudioPlayerPlayDirective('REPLACE_ALL', podcastBeginning.url, podcastBeginning.token, 0, null, podcastBeginning.metadata)
    .addAudioPlayerPlayDirective('REPLACE_ALL', podcastBeginning.url, podcastBeginning.token, 0, null, podcastBeginning.metadata);

Кроме того, я добавил метод вопроса ниже.

const LatestHeadlinesIntentHandler = {
    canHandle(handlerInput) {
        return handlerInput.requestEnvelope.request.type === 'LaunchRequest' ||
          handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
            (
              handlerInput.requestEnvelope.request.intent.name === 'LatestHeadlinesIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ResumeIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.LoopOnIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.NextIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.PreviousIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.RepeatIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ShuffleOnIntent' ||
              handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StartOverIntent'
          );
    },
    async handle(handlerInput) {
        const response = await httpGet();
        let responseBuilder = handlerInput.responseBuilder;
        let speakOutput;
        let podcastBeginning = audio[0];
        let podcastNext = audio[1];
        let podcastEnd = audio[2];
        let audioCount = 0;
        let podcast = {
            "token": response.audios[audioCount].intId,
            "url": response.audios[audioCount].url,
            "metadata" : {
              "title": response.audios[audioCount].title,
            }
          }

        if (sucessfulGet === true){
            speakOutput = 'Alright, reading you the latest headlines!';
            handlerInput.responseBuilder
                .speak(speakOutput)
                .addAudioPlayerPlayDirective('REPLACE_ALL', podcastBeginning.url, podcastBeginning.token, 0, null, podcastBeginning.metadata)

        }else {
            speakOutput = "No stories found. Response Code: " + responseCode;
        }

        return handlerInput.responseBuilder
            .getResponse();
    }
};

Любая помощь будет принята с благодарностью. Спасибо.

...