How to Add Sound Effects to your Alexa Skill

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.

<audio src="https://s3.amazonaws.com/your-bucket-name/sound-file.mp3"/>

Requirements:

There are a few requirements for audio clips to work on Alexa-enabled devices.

  1. 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.
  2. The MP3 must not contain any customer-specific or other sensitive information.
  3. The MP3 must be a valid MP3 file (MPEG version 2).
  4. The audio file cannot be longer than 240 seconds.
  5. The bit rate must be 48 kbps.
  6. 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.

  1. Create a regular fact skill. If you don’t know how to create one, Amazon has an awesome tutorial for you.
  2. Decide where you want to place your audio. You might want to add audio to the stop message or maybe the start message.
  3. 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.
  4. Then click on “Create a New Bucket” and type in your bucket name. The name of the bucket should be simple.
  5. Click “Next” twice and then click Create Bucket.
  6. Click on “Upload” to upload an MP3 file.
  7. Next, click on your file. There should be an Object URL. Copy that code. Then, go back to your Lambda function.
  8. Place this code in your chosen message: ‘<audio src=”https://s3.amazonaws.com/your-bucket-name/sound-file.mp3″/>’.
  9. Save and test!

You can download the code of my unpublished Animals Jokes skill. It has some random sound effects already added along with a few funny jokes.

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. Here is the code for my skill.

Leave a Reply

Your email address will not be published. Required fields are marked *