Defining Custom Components

What if you want to reuse that same arrangement of rain sounds and filters over and over for several different excerpts of spoken text. While you could copy-and-paste the APL-A and tweak the content property of the Speech component, a much cleaner option is to capture multiple components into a single, easy-to-use custom component.

The following APL-A template defines a custom RainyDayTalk component that makes it really easy to put rain sounds in the background of anything Alexa may say:

 {
 "type"​: ​"APLA"​,
 "version"​: ​"0.9"​,
 "compositions"​: {
 "RainyDayTalk"​: {
 "parameters"​: [
  {
 "name"​: ​"speechContent"​,
 "type"​: ​"string"
  }
  ],
 "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"​: 8
  },
  {
 "type"​: ​"Volume"​,
 "amount"​: 0.5
  }
  ],
 "duration"​: ​"trimToParent"
  },
  {
 "type"​: ​"Speech"​,
 "content"​: ​"${speechContent}"
  }
  ]
  }
  }
  },
 "mainTemplate"​: {
 "item"​: {
 "type"​: ​"RainyDayTalk"​,
 "speechContent"​: ​"Today's forecast calls for a little bit of rain."
  }
  }
 }

The compositions property is where custom components are defined. In this example, there is only one custom component, the RainyDayTalk component. It has all of the Audio and Speech components that our previous example employed, along with the filters we used to make the rain sounds sound good in the background. But instead of hard-coding the spoken text, the RainyDayTalk references a “${speechContent}” parameter, which could contain any text that we want to put into it when using RainyDayTalk.

Meanwhile, the item property of mainTemplate references a single component of type RainyDayTalk, whose speechContent specifies the text we want Alexa to speak while the rain pours in the background.

Unfortunately, there currently isn’t a way to define custom components external to an APL-A template and then reuse the component across multiple templates. But the Alexa team has an item in their backlog to enable this, so hopefully it will be possible soon.

We’ve seen many ways of using APL-A components and filters to mix sound and speech into custom arrangements. And we’ve used the APL-A editor to test them and hear how they sound. But ultimately, the goal of creating APL-A templates is to return them as the result of a skill’s request handler. Let’s use what we’ve learned so far about APL-A to create a response from the Star Port 75 Travel skill.

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

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