Adding Sound Effects and Music

Although Alexa SSML is primarily concerned with voice and how Alexa speaks and utters words, nothing adds pizazz to a skill’s response quite like a little music or a sound effect. In a trivia game skill, for instance, you might play a bell sound just before Alexa announces that the answer is correct, or a buzzer before she says that the answer is wrong. Or if you’re building a skill for some well-known brand, you might launch the skill with a brief snippet of that brand’s theme song.

SSML’s <audio> tag can be used to add small sound clips to a response. And to help you get started, Amazon offers a vast library of ready-to-use sound effects for you to use in your skills.[32] Once you’ve found a sound clip you like, you can add it to your SSML by copying the URL into the src attribute of the <audio> tag like this:

 <speak>
  Welcome to Star Port 75 Travel, your source for <audio src=
 "soundbank://soundlibrary/scifi/amzn_sfx_scifi_small_zoom_flyby_01"​/>
  out-of-this world adventures.
 
  Where do you want to blast off to?
 </speak>

In this particular example, the sound of a futuristic vehicle plays in the middle of the first sentence.

You can also play custom sounds with <audio>. The sounds must be encoded as MP3 files (MPEG version 2), no longer than 240 seconds, with a bit rate of 48kbps and a sample rate of 22050Hz, 24000Hz, or 16000Hz. You can use any audio tool, such as Audacity[33] or ffmpeg[34] to create the file. You’ll also need to host your MP3 file at an HTTPS endpoint whose SSL certificate is signed by an Amazon-approved certificate authority. Amazon S3 is an easy option that meets this requirement.

For example, suppose that Star Port 75 were a recognized brand and that their television and radio advertisements have resulted in a well-recognized musical branding. If we were hosting an MP3 of that musical branding on Amazon S3, then we could have Alexa play it at the start of the launch response like this:

 <speak>
  <audio src=​"https://starport75.dev/audio/SP75.mp3"​/>
  Welcome to Star Port 75 Travel, your source for <audio src=
 "soundbank://soundlibrary/scifi/amzn_sfx_scifi_small_zoom_flyby_01"​/>
  out-of-this world adventures.
 
  Where do you want to blast off to?
 </speak>

Notice that you can use multiple <audio> tags in a single SSML response, as long as the total length of all sound clips and music does not exceed 240 seconds.

You’ve probably had a lot of fun trying out the various SSML tags in the text-to-speech simulator. As much fun as that can be, at some point we need to inject the SSML we’ve crafted into the responses from our skill. So, for now, playtime is over and it’s time to see how to use SSML in our skill code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset