Applying Filters

APL-A provides a handful of filters that can be applied to any of APL-A’s components to make adjustments to how they sound. The available filters include:

  • Volume—Sets the audio volume. This is especially useful when two or more sounds are used with Mixer to set the volume lower for sounds intended to be in the background.

  • FadeIn and FadeOut—Enables sounds to fade in and out rather than start or stop abruptly

  • Repeat—Specifies how many times that an audio clip should repeat

  • Trim—Starts or stops an audio clip at specified times

One or more filters can be applied to a component via the filters property. You’ll probably find the filters most useful when applied to the Audio component, but they can be used on any of APL-A’s components, including Speech or the multi-child components. Let’s see how to apply filters, starting with the Volume filter.

Adjusting Volume

As we’ve seen (or heard) with the previous example, a sound that plays too loudly might overpower another sound playing concurrently when using the Mixer component. Or when using Sequencer, some child components may have a higher volume and feel out of place from sounds that are more subtle. These are the kinds of problems that the Volume filter was made to address.

The Volume filter lets you set the playback volume of any component, whether it be sound and speech components or one of the multi-child components. By default, the volume of a component is considered to be 100%, but using the Volume filter, you can adjust the volume relative to the component’s full volume.

For example, to soften the volume on the sound clip in the previous example, we can use the Volume filter like this:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "items"​: [
  {
 "type"​: ​"Mixer"​,
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​:
 "soundbank://soundlibrary/musical/amzn_sfx_musical_drone_intro_02"​,
 "filters"​: [
  {
 "type"​: ​"Volume"​,
 "amount"​: ​"25%"
  }
  ]},
  {
 "type"​: ​"Speech"​,
 "content"​: ​"Welcome to Star Port 75 Travel"
  }
  ]
  }
  ]
  }
 }

The Volume filter’s amount property specifies how loud the sound should be played, relative to its default volume. In this case, we’ve asked that it be played at 25% of full volume. Meanwhile the Speech component doesn’t have a Volume filter, so it plays at full volume.

The amount property can be set as a percentage or as a number. Either way, the value given in amount will be multiplied against the full volume to arrive at the volume that the sound should be played at. Thus, another way to specify 25% volume is to set amount to 0.25, as shown in this snippet:

 "filters"​: [
  {
 "type"​: ​"Volume"​,
 "amount"​: 0.25
  }
 ]

You can also set “amount” to values greater than 1, resulting in the sound being played at a volume louder than full volume. For example, the following snippet shows how to play sound at 150% of full volume:

 "filters"​: [
  {
 "type"​: ​"Volume"​,
 "amount"​: 1.5
  }
 ]

There is no upper limit on the amount property, though it’s best to keep the number reasonably low. Extremely high values result in distorted sounds that may be unpleasant.

Fading Sound In and Out

Maybe you don’t need to alter the volume for an entire time a sound or speech component is playing, but just need it to fade in at the beginning or fade out at the end. A sound clip that starts or ends abruptly may be jarring for the user. By using the FadeIn and FadeOut filters you can ease them into the sound, as shown here:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​:​"soundbank://soundlibrary/weather/rain/rain_03"​,
 "filters"​: [
  {
 "type"​: ​"FadeIn"​,
 "duration"​: 3000
  },
  {
 "type"​: ​"FadeOut"​,
 "duration"​: 3000
  }
  ]
  }
  ]
  }
 }

The sound effect chosen here is almost eight seconds long and starts and stops abruptly without the FadeIn and FadeOut filters. But with a three-second fade-in and fade-out, specified by the duration property, the sound clip is easier on the ears.

Trimming Audio

Sometimes an audio file may be too long for your needs. Or maybe you only need a small section of the audio from the middle. Using the Trim filter, you can cut an audio clip down to just the bit you need.

For example, the sound effect used in the following template is 9.14 seconds long. If you only need five seconds of audio, then you can use the Trim filter like this:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​:
 "soundbank://soundlibrary/backgrounds_ambience/traffic/traffic_06"​,
 "filters"​: [
  {
 "type"​: ​"Trim"​,
 "end"​: 5000
  }
  ]
  }
  ]
  }
 }

By setting the filter’s end property to 5000, you are asking that the sound should play from the beginning and stop playing after 5000 milliseconds, or five seconds.

Now let’s say that you don’t want the first two seconds of audio, but still want a five-second sound. Then you can use the start and end properties together like this:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​:
 "soundbank://soundlibrary/backgrounds_ambience/traffic/traffic_06"​,
 "filters"​: [
  {
 "type"​: ​"Trim"​,
 "start"​: ​"2000"​,
 "end"​: 7000
  }
  ]
  }
  ]
  }
 }

This combination of start and end trim off the first two seconds of audio, plays the next five seconds, and then stops playing at the seven-second mark of the original audio.

Repeating Sounds

Trimming sounds to make them shorter is easy enough. But what if you need a sound to be longer? The Repeat filter can play a sound (or even spoken text) on repeat. It is especially effective when the sound is used as ambient background sound.

For example, let’s say you want to use the sound of rain in your skill. The ASK sound library has several rain sounds, including soundbank://soundlibrary/nature/amzn_sfx_rain_on_roof_01, which sounds exactly like what you need. The only problem is that it is only 2.15 seconds long and you need it to be at least 20 seconds long. Using the Repeat filter, you can extend it like this:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​: ​"soundbank://soundlibrary/nature/amzn_sfx_rain_on_roof_01"​,
 "filters"​: [
  {
 "type"​: ​"Repeat"​,
 "repeatCount"​: 9
  }
  ]
  }
  ]
  }
 }

The repeatCount property specifies how many times the sound should repeat in addition to the first time. By setting it to 9, the sound will be played 10 times, totalling 21.5 seconds. If you test this in the APL-A editor, however, you may notice that although the repeated sound clip is long enough, the audio drops out approximately every 2.15 seconds between each repeated iteration. That’s because the sound has built-in fade-in and fade-out.

To fix that, we’ll need to do some clever mixing of Repeat with Trim, as show in the following APL-A template:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​: ​"soundbank://soundlibrary/nature/amzn_sfx_rain_on_roof_01"​,
 "filters"​: [
  {
 "type"​: ​"Trim"​,
 "start"​: 500,
 "end"​: 1900
  },
  {
 "type"​: ​"Repeat"​,
 "repeatCount"​: 14
  }
  ]
  }
  ]
  }
 }

Here, the Trim filter is used to cut the first 500 milliseconds and the last 215 milliseconds off of the source clip. That leaves 1.4 seconds that, when repeated 14 times gives 21 seconds of continuous rain sounds with no dropouts.

Note that it’s important that the Trim filter come before the Repeat filter, so that it gets applied first. If Repeat comes before Trim, then the longer repeated sound will be what is trimmed, resuling in a short 1.4-second sound clip.

One challenge you may encounter when deciding how long a sound should be comes when you use the Mixer component to put a sound in the background of some spoken text. Precisely matching the length of the repeated audio clip with the length of the spoken text can be challenging. And even if you get it right, you’ll need to readjust should you change what Alexa is speaking.

But this becomes less challenging by setting repeatCount to -1 and using the duration property on the Audio component that plays the background sound, as shown in the following APL-A template:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "mainTemplate"​: {
 "item"​: {
 "type"​: ​"Mixer"​,
 "items"​: [
  {
 "type"​: ​"Audio"​,
 "source"​:
 "soundbank://soundlibrary/nature/amzn_sfx_rain_on_roof_01"​,
 "filters"​: [
  {
 "type"​: ​"Trim"​,
 "start"​: 500,
 "end"​: 1900
  },
  {
 "type"​: ​"Repeat"​,
»"repeatCount"​: -1
  },
  {
 "type"​: ​"Volume"​,
 "amount"​: 0.5
  }
  ],
»"duration"​: ​"trimToParent"
  },
  {
 "type"​: ​"Speech"​,
 "content"​: ​"Today's forecast calls for buckets of rain"
  }
  ]
  }
  }
 }

When repeatCount is set to -1, the audio will repeat infinitely (or up to the maximum content length). This is much longer than how long it takes for Alexa to say, “Today’s forecast calls for buckets of rain.” To trim it back down to the length of the audio produced by the Speech component, the “duration” has been set to “trimToParent”. This automatically trims the sound produced by Audio to be no longer than the longest child of the Mixer component. Now, no matter what text is spoken as a result of the Speech component, the length of rain sounds will match perfectly.

Now that we’ve seen how to create all kinds of sounds and speech, mix them, and apply filters to them, let’s see how we can package them in custom components that can be reused anytime we need them.

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

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