简体   繁体   中英

How to play an audio file from S3 Bucket on AWS Lambda function using Node.js?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM