2

I have 12 short (3 second) audio files stored in an S3 bucket. I'm trying to develop an Alexa app where you can say "play (sound name)", and it'll play that one of those audio files. I already created my alexa app, I created my aws lambda function, however, I am unsure of how to retrieve and play an audio file from my S3 bucket through my AWS lambda function. Does anyone have any ideas of how to do this? I'm pretty new with Node.js, AWS, S3 Buckets.

  • If your S3 bucket contents are public, you can just use the URL to the item on S3 directly. If your bucket contents are not public and the request needs to be verified in some way, you can sign a URL to the private item on S3 and redirect the client to it. Either way, don't retrieve it and send it to the client... let S3 take care of that for you. – Brad Dec 18 '18 at 20:42
  • @Brad Thank you for replying! My S3 buckets are public. I understand that I can use the URL to the item but do you know how exactly I would make that request? How do I create a client in my code to make that request? Sorry, I'm new to Node.js and writing lambda functions... Thanks again! – Robert Pelican Dec 18 '18 at 20:48
  • I don't understand what this has to do with Lambda. – Brad Dec 18 '18 at 20:50
  • @Brad I'm playing the audio through my lambda function. My alexa skill invokes my lambda function. – Robert Pelican Dec 18 '18 at 21:23
  • @Brad I'm just having trouble getting/playing the audio because I don't know the node.js syntax and I can't seem to find it anywhere. – Robert Pelican Dec 18 '18 at 21:24

2 Answers2

2

Here is the documentation for the audio player:

https://developer.amazon.com/docs/custom-skills/audioplayer-interface-reference.html

Like Brad said, if it's public then you can use the url per the instructions in that documentation. There are built-in intents to handle things like "skip", and "stop" and you can use AudioPlayer's methods to handle the actual playing of the audio:

AudioPlayer.Play: Sends Alexa a command to stream the audio file identified by the specified audioItem.

AudioPlayer.Stop: Stops any currently playing audio stream.

AudioPlayer.ClearQueue: Clears the queue of all audio streams.

Essentially, you will write some logic in your Lambda function to direct the session into your desired intent handler, and use these methods along with an object pointing to your url.

dillon.harless
  • 427
  • 4
  • 16
1

What you are doing is pointing your speech responses to a s3 uri which as mentioned in the comments needs to have public access then you will build your responses play sound and your response will be using ssml tags.

    <speak> <audio src="   "</speak> 

your s3 url of the sound clip going between the "". The documentation if you get stuck is here: https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html#audio

Chuck LaPress
  • 278
  • 1
  • 10
  • 18
  • Where would I add these ssml tags? Not in the lambda function right? – Robert Pelican Dec 20 '18 at 00:28
  • https://developer.amazon.com/docs/custom-skills/speech-synthesis-markup-language-ssml-reference.html#use-ssml Read through section using sank in your response and if you need or not use the tags , and yes you are providing the ssml responses in your lambda code. This is what is what is returned to the users request or utterance – Chuck LaPress Dec 20 '18 at 05:47
  • Robert this video may clear it up for you as well. https://m.youtube.com/watch?v=FucapfzyVKM – Chuck LaPress Dec 20 '18 at 05:57