Agustin
Agustin

Reputation: 161

Skill Loop Audio

I am trying in my skill of Alexa play a 5-second loop 1 hour audio but I cannot find the way.

Does anyone know how to perform this action?

const LoopAudioHandler = {
    canHandle(handlerInput) {
      const request = handlerInput.requestEnvelope.request;
      return request.type === 'IntentRequest'
        && request.intent.name === 'LoopAudio';
    },
    handle(handlerInput) {

        const audio = "<audio src='https://audio-alexa-ang.s3.amazonaws.com/perro-ladrando-v2.mp3' />"

      return handlerInput.responseBuilder
        .speak(audio)
        .reprompt(HELP_REPROMPT)
        .getResponse();
    },
  };

The result is that only plays 1 time only. and I need it to play in loop for an hour.

Upvotes: 0

Views: 175

Answers (1)

R. Vait
R. Vait

Reputation: 958

Unfortunately audio tags have some limitations (docs). One of them is that maximum amount of audio length in one response which is 240s. Another limitation is amount of audio tags in one response which is 5.

In your case, you could make audio files longer, merging them and making them ~48s long, so in this case, you will be able to add 5 audio tags and play 240s of audio, or just make audio file of length 240s and use only that alone, it's up to you.

There is another way though. To play up to an hour of audio you would have to go another route and use audio player interface, which acts a little bit different than regular skill, but it would allow you to loop audio indefinitely. An example skill using audio player interface can be found here.

Upvotes: 1

Related Questions