How to Use Sound Templates

API.audio's sound design templates enable you to customise your script speech tracks with different sounds and effects.

API.audio currently offers over 40 different sound templates, with more added every week! The sound templates cover a vast array of different use cases and verticals ranging from fitness to advertising.

Sound Templates comprise sound segments and sound effects. Each template generally consists of 3 sound segments - intro, main and outro, and 3 sound effects (<<soundEffect::effect1>>), making it very convenient for you to pair speech with appropriate sounds, with no specialised audio knowledge required.

The difference between segments and effects is that sound segments play in the background of speech, whereas sound effects are standalone sounds to be used between speech sections and play without speech. Sound effect could be a whistle sound, an alarm clock ringing or dogs barking, for example.

To list all available sound templates:

#List all available sound design templates 
sound_templates = apiaudio.Sound.list()

Getting Started

In order to use a sound design template you first need to create a script annotated by sections.
Each sound design template is carefully crafted with 3 main segments (intro, main and outro) and 3 effects, that allow you to create perfect sounding audio without any audio engineering experience. Simply annotate your script in 3 sections, define sound segments as intro, main and outro, and add an effect to the beginning and/or the end. (In the near future version of sound design you will be able to use sound effects together with speech!)

There are 2 different ways to use sound templates in your script:

  1. Pairing a backing track with a speech section

<<soundSegment::intro>>
<<sectionName::intro>>

text= """
<<soundSegment::intro>>
<<sectionName::intro>>
Here goes your text
"""
  1. Use a sound effect (without speech)

<<soundEffect::effect1>>

Sound effects within speech is not available yet, so remember to split up your speech sections in order to add a sound effect in between like this:

text= """
<<soundEffect::effect1>> 
<<sectionName::bonus>> 
Here goes your text
"""

For creating speech without any sound, simply do:

<<sectionName::hello>>

Example

Let's look through an example. In this case we are an ad company, wanting to create ads programmatically, in a few easy steps. Let's get started with creating a script.

First, let's divide our script into 3 sections. Intro, main and outro, using the following convention:

<<soundSegment::intro>>
<<sectionName::intro>>

Let's also add a sound effect to the very end

text= """   
    <<soundSegment::intro>>
    <<sectionName::intro>>
    This really is the final call for Hyundai's massive clear out sale! Only until midnight tonight!
    <<soundSegment::main>>
    <<sectionName::main>> 
    We're clearing out all remaining 2021 Hyundais at Ottawa's top volume Hyundai dealers. 
    These are the last days for clear out pricing and amazing clear out incentives. 
    <<soundSegment::outro>>
    <<sectionName::outro>>
    Get into a new Hyundai today. At Hyundai, better cars for passionate car drivers. 
    <<soundEffect::effect1>>
"""
script = aflr.Script().create(scriptText=text)
print(script)

Now let's create speech. You can choose a speaker, change the speed or apply some silence padding.
Let's define a sound template. In this case we will use one called "hotwheels".
Notice that you can switch sound templates, while keeping the script unchanged! Try changing it to "headlines" for example.

r = aflr.Speech().create(
    scriptId=script.get("scriptId"),
    voice="en-US-GuyNeural",
    speed=120,
    silence_padding=0,
)
print(r)
template="hotwheels"
r = aflr.Mastering().create(
    scriptId=script.get("scriptId"), soundTemplate=template
)
print(r)
url = aflr.Mastering().retrieve(scriptId=script.get("scriptId"))
print(f"✨ Mastered file for template ✨")
print(url)

Listen To How It Sounds

These examples are fully produced with the API, using synthetic voices and sound templates.

Car Ad Example
Ad example

Complete Example

import aflr
# # Make sure to import your API key
aflr.api_key ="API_Key"
text = """
    <<soundSegment::intro>>
    <<sectionName::intro>>
    This really is the final call for Hyundai's massive clear out sale! Only until midnight tonight!
    <<soundSegment::main>>
    <<sectionName::main>> 
    We're clearing out all remaining 2021 Hyundais at Ottawa's top volume Hyundai dealers. 
    These are the last days for clear out pricing and amazing clear out incentives. 
    <<soundSegment::outro>>
    <<sectionName::outro>>
    Get into a new Hyundai today. At Hyundai, better cars for passionate car drivers. 
    <<soundEffect::effect1>>
"""
script = aflr.Script().create(scriptText=text)
print(script)
r = aflr.Speech().create(
    scriptId=script.get("scriptId"),
    voice="en-US-GuyNeural",
    speed=120,
    silence_padding=0,
)
print(r)
template="hotwheels"
r = aflr.Mastering().create(
    scriptId=script.get("scriptId"), soundTemplate=template
)
print(r)
url = aflr.Mastering().download(scriptId=script.get("scriptId"), destination=".")
print(f"✨ Mastered file for template ✨")
print(url)

Did this page help you?