When working with Amazon Alexa audio/mp3 files and using SSML there are a few simple rules.
This blog assumes, awscli,wget and ffmepg are installed and configured.
Here are the must haves for using mp3 audio in your Alexa skill;
- Public access file (S3 is a good location), see below for upload tips
- HTTPS endpoint
- MP3 format
- less than 90 seconds
- 48 kbps
- 16000 Hz
Now, let’s give it a try.
Download a sample audio file
We’ll use this Crowd Excited free sample
cd /tmp wget http://www.pacdv.com/sounds/people_sound_effects/crowd-excited.mp3
Convert it to the right Alexa format
Use this ffmpeg command for an easy cli converter and then use awscli to upload to a S3 bucket and set a public read ACL on the object.
OUTFILE=crowd-excited-alexa.mp3 ffmpeg -i crowd-excited.mp3 -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 $OUTFILE BUCKET=bucketName aws s3 cp $OUTFILE s3://$BUCKET/ --storage-class REDUCED_REDUNDANCY aws s3api put-object-acl --bucket $BUCKET --key $OUTFILE --acl public-read
Extra Tip — Working with the Alexa SDK Node.js
I got caught out when working with Alexa-SDK-NodeJs. Make sure declaration string ends with a space slash ” /” (without quotes). This might go in your index.js
// in index.js cheerAudio = `<audio src="https://s3.amazonaws.com/bucketName/crowd-excited-alexa.mp3" />`;