Advanced Timing Example: Add a Tag to the end of an Advert
One common use case where you might need to use AudioStack's advanced timing parameters is to add a "tag" to the end of an existing audio advert.
Make sure your development environment is set up before continuing
If aren't already up and running using the AudioStack Python SDK, you can use our Getting Started guides to get going.
This tutorial assumes you have an existing sound design and you wish to add a tag to the end of it, alongside pre-existing recorded speech.
Do you want to create an advert using an AudioStack sound design?
Refer to our Sound Templates section instead for examples that involve adding generated speech to AudioStack sound designs.
Step One - Create a Custom Sound Design Template
Creating a sound design template from an existing WAV file is really simple. Simply create a python file, and add the following code at the top. You'll need to insert your API key where it says "APIKEY".
import audiostack
import os
# First, paste your API key inside the quotation marks below:
audiostack.api_key = "APIKEY"
# If you haven't already created a sound template, use the code below to create one, adding your own name and file path. You can delete lines 9-11 after running the code once.
template = audiostack.Production.Sound.Template.create(templateName="template1")
media = audiostack.Content.Media.create(filePath="template1_main.wav")
template = audiostack.Production.Sound.Segment.create(templateName="template1", mediaId=media.mediaId, soundSegmentName="main")
Every Sound Template is Unique!
You can only create your template once, so if you're running this code for a second time, you won't need to include lines 9-11 again - you can comment these lines out by putting hashes at the beginning of the line (#), or remove them altogether. If you need to delete your template, or want to create a template from a format other than WAV, see our extended guidance here.
Step Two - Add the Tag Text and Specify Desired Timing
Below the code you've already added, copy and paste the following snippet:
print("Creating script")
script = audiostack.Content.Script.create(
scriptText="""<as:section name="main" soundSegment="main"> Insert your tag text here, leaving the section tags as they are.</as:section>"""
)
print("Generating speech")
speech = audiostack.Speech.TTS.create(scriptItem=script, voice="sara") # Change the voice here
tagDuration = 5 # How long should the tag be, in seconds, including padding?
desiredPaddingBeforeTag = 1 # How many seconds of padding do you want between the main text and the tag?
advertDuration = 15.0 # How long should the advert be in total, including the tag?
target_Length=tagDuration-desiredPaddingBeforeTag
print("Reducing length to meet target")
tts = audiostack.Speech.TTS.reduce(speechId=speech.speechId, targetLength=target_Length)
timelineProperties= {
"forceLength":advertDuration,
"soundTail":0,
"fadeOut":0,
}
sectionProperties= {
"main": {
"alignment":"right",
"endAt":advertDuration,
}
}
print("Mixing and mastering")
mix = audiostack.Production.Mix.create(
speechItem=tts,
soundTemplate="template1", # If you chose a different name for your sound template, enter it here
masteringPreset="musicenhanced",
timelineProperties=timelineProperties,
sectionProperties=sectionProperties
)
print("Downloading WAV")
mix.download(fileName="CustomTemplatewithTag")
There are a few things you might want to change in the code to configure the timing or sound of your tag. Read through the code, and consider changing any of the parameters that are noted in the commented code.
This example assumes that you want to add a 5 second long tag at the end of a 15 second advert.
Congratulations
You should now have an audio file containing your finished advert, complete with tag. Hint: if you want to change the timing of when your tag begins, you can add padding (to make it start later) in Line 10.
Updated 7 months ago
Find out more about what you can do with Advanced Timing Parameters