Hi – I'm trying to enhance the Audio Player Sample Project so users can ask for a specific track by name. I understand conceptually how to do it, but I'm new to development and my Javascript chops are pretty limited...
I created a PlaySpecificAudio intent in my interaction model with a custom slot type Item with all my track names as the custom slot values of Item. Sample utterances include: listen to {Item}, to play {Item}, I want to hear {Item}, etc.
But on the Lambda side, I'm struggling to configure my new intent to feed into the AudioPlayer.
I think I'm close, but can't figure out exactly how to map the title and url of the specified audio Item into the subsequent player code.
Here's my broken code as-is:
'PlaySpecificAudio' : function () { var itemSlot = this.event.request.intent.slots.Item; var itemName; if (itemSlot && itemSlot.value) { itemName = itemSlot.value.toLowerCase(); } var songs = audioData.title; var song = songs[itemName]; var songURL = song; if (song) {if (!this.attributes['playOrder']) { // Initialize Attributes if undefined. this.attributes['playOrder'] = Array.apply(null, {length: audioData.length}).map(Number.call, Number); this.attributes['index'] = 0; this.attributes['offsetInMilliseconds'] = 0; this.attributes['loop'] = true; this.attributes['shuffle'] = true; this.attributes['playbackIndexChanged'] = true; // Change state to START_MODE this.handler.state = constants.states.START_MODE; }} controller.play.call(this); },
Here's the format of audioData:
var audioData = [ { 'title' : 'song one', 'url' : 'https://s3.amazonaws.com/.......' }, { 'title' : 'song two', 'url' : 'https://s3.amazonaws.com/.......' } ];
And here's the functioning PlayAudio intent from the tutorial for reference (within stateHandlers.js):
'PlayAudio' : function () { if (!this.attributes['playOrder']) { // Initialize Attributes if undefined. this.attributes['playOrder'] = Array.apply(null, {length: audioData.length}).map(Number.call, Number); this.attributes['index'] = 0; this.attributes['offsetInMilliseconds'] = 0; this.attributes['loop'] = true; this.attributes['shuffle'] = false; this.attributes['playbackIndexChanged'] = true; // Change state to START_MODE this.handler.state = constants.states.START_MODE; } controller.play.call(this); },
I'm thinking PlaySpecificAudio just needs a few tweaks. Any guidance would be much appreciated. THANK YOU!
Audio Player Sample Project on Github
https://github.com/alexa/skill-sample-nodejs-audio-player/tree/mainline/multiple-streams