I was learning how to add audio clips to an Alexa skill today, and it’s simpler than I was expecting! I thought I would have to memorize 20 lines of code, but it’s not that difficult.
Here is a quick overview:
Sound effects are a great way to enhance your user’s skill experience. For example, let’s say you want to create a trivia skill. Whenever the user answers correctly, you play the sound of someone clapping. If they answer incorrectly, you play the sound of a buzzer. This would be a great use for sound effects.
The Alexa Skills Kit (ASK) SDK makes adding short audio clips very simple. All you need is the SSML audio tag.
There are a few requirements for audio clips to work on Alexa-enabled devices.
- The MP3 must be hosted at an Internet-accessible HTTPS endpoint. HTTPS is required, and the domain hosting the MP3 file must present a valid, trusted SSL certificate. Self-signed certificates cannot be used.
- The MP3 must not contain any customer-specific or other sensitive information.
- The MP3 must be a valid MP3 file (MPEG version 2).
- The audio file cannot be longer than 240 seconds.
- The bit rate must be 48 kbps.
- The sample rate must be 22050Hz, 24000Hz, or 16000Hz.
You can easily convert an audio file into the Alexa-friendly format using tools such as Audacity, FFmpeg, etc. Personally, I prefer using an online converter made by Jovo.
How to use:
You can create a new skill or you can add sound effects to your current skill.
- Create a regular fact skill. If you don’t know how to create one, Amazon has an awesome tutorial for you.
- Decide where you want to place your audio. You might want to add audio to the stop message or maybe the start message.
- Then, click on the Services tab in the top left corner, near the AWS logo. Type S3 in the search box and choose the first option.
- Then click on “Create a New Bucket” and type in your bucket name. The name of the bucket should be simple.
- Click “Next” twice and then click Create Bucket.
- Click on “Upload” to upload an MP3 file.
- Next, click on your file. There should be an Object URL. Copy that code. Then, go back to your Lambda function.
- Place this code in your chosen message: ‘<audio src=”https://s3.amazonaws.com/your-bucket-name/sound-file.mp3″/>’.
- Save and test!
I hope you have a clearer understanding of adding sound effects to your Alexa skills. They can greatly improve your skill and make it more likable and fun.