Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

Loop a mp3 file in an Alexa skill

This is one of my very first attempts (besides Purge time I made before)

I want to play an mp3 file until I ask Alexa to stop. This is was I have so far (The same code I used for the Purge one)

const Alexa = require('ask-sdk-core');
const Util = require('./util.js');

const LaunchRequestHandler = {
    canHandle(handlerInput) {
        return Alexa.getRequestType(handlerInput.requestEnvelope) === 'LaunchRequest';
    },
    handle(handlerInput) {
        const audioUrl = Util.getS3PreSignedUrl("Media/white_noise_500_hz_formatted.mp3").replace(/&/g,'&');
        return handlerInput.responseBuilder
                .speak(`<audio src="${audioUrl}"/>`)
                .getResponse();
    }
};

exports.handler = Alexa.SkillBuilders.custom().addRequestHandlers(LaunchRequestHandler).lambda();

As a complete noob, I'm a bit lost. I'd need to wait to put the MP3 in a queue before it finishes or something.

Any idea is welcome, thanks!

PS. I know there are skills for white noise and rain sounds and so on, this one if for learning purposes :D

question from:https://stackoverflow.com/questions/65910485/loop-a-mp3-file-in-an-alexa-skill

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Where you're using it as a speak item, you're limited to 240 seconds and have to send the whole thing.

You want the audio player directive. https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...