Hey everyone so I'm having a difficult time trying to implement an audio playback. Here's the docs
So what I really want to do seems quite simple but came out to be very confusing where everything is suppose to go.
I want to be able to say a command. Alexa will respond will a little outputSpeech and then proceed to play a small audio track mp3 that I would provide. I don't mind uploading it locally(When I zip the files and import them into a lamda function) or using S3 Buckets SDK to stream the mp3 file. Which ever is easier for you guys.
Here's what I got so far.
With the codes below I'm able to get Alexa to respond to be voice and output a speech.
I'm only using the IntentRequest to reduce codes for you guys.
- I'm going to say "Alexa open myApp and play my music"
- "play my music" is the command i'm going to list as my utterance when I set up my skill in the alexa developer console
exports.handler = (event, context, callback) => {
try {
if (event.request.type === 'IntentRequest') {
onIntent(event.request,
event.session,
(sessionAttributes, speechletResponse) => {
callback(null, buildResponse(sessionAttributes, speechletResponse));
});
}
} catch (err) {
callback(err);
}
};
My function that will be called when the Intent request goes through
- My intent name will be PlayMyMusic
function onIntent(intentRequest, session, callback) {
console.log(`onIntent requestId=${intentRequest.requestId}, sessionId=${session.sessionId}`);
const intent = intentRequest.intent;
const intentName = intentRequest.intent.name;
if (intentName === 'PlayMyMusic') {
PlayMyMusic(intent, session, callback);
} else if (intentName === 'AMAZON.StopIntent' || intentName === 'AMAZON.CancelIntent') {
handleSessionEndRequest(callback);
} else {
throw new Error('Invalid intent');
}
}
This is the output Message
function PlayMyMusic(intent, session, callback) {
const repromptText = null;
const sessionAttributes = {};
let shouldEndSession = true;
let speechOutput = '';
speechOutput = `I'm Alexa and I will output speech in this area. After I'm done talking I will play an audio track`;
callback(sessionAttributes,
buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
}
This is my simple Intent Schema
{
"intents": [
{
"intent": "PlayMyMusic"
},
{
"intent": "AMAZON.HelpIntent"
}
]
}
Sample Utterances
PlayMyMusic play my music
Everything works as of right now where Amazon can talk to me back and end the session.
How would I be able to have Amazon responds to me and then play some audio? The docs are kind of not working for me.