How to write an Audio Advert with two voices speaking

Introduction

Often when writing an audio advert you'll have a dialogue between two people. In this example we'll have two voices, and we'll have a marathon runner being interviewed. This is a stylistic example. At the end of this we'll also save the example in a youtube format because we'll assume that this is in accordance with the Advertisers needs.


Creating an Audio Dialogue with Audiostack

This tutorial will guide you through the process of creating an audio dialogue using the Audiostack API. We will cover script creation, text-to-speech (TTS) generation, mixing the TTS files, and encoding the final audio mix. The dialogue features two speakers and will be encoded using a high-quality MP3 preset suitable for YouTube.

Prerequisites

  • Audiostack API Key: Ensure you have an Audiostack API key set up in your environment variables.
  • Python Environment: Make sure you have Python installed with the necessary packages (audiostack).

Step 1: Setting Up Your Environment

First, import the Audiostack module and set the API key from your environment variables.

import audiostack
import os

audiostack.api_key = os.environ['AUDIOSTACK_API_KEY']

Step 2: Creating the Script

Create a script for the dialogue. The script consists of several sections, each marked with a unique identifier and speaker name.

# Create a script
script = audiostack.Content.Script.create(
    scriptName="Marathon Conversation",
    scriptText="""
<as:section name='m0'>
Good morning, Coco! How are you today?
</as:section>
<as:section name='s0'>
Hi Wren! I'm doing great, thanks for asking. How about you?
</as:section>
<as:section name='m1'>
I'm good, thanks. So, Coco, I heard you recently completed a marathon. How was the experience?
</as:section>
<as:section name='s1'>
Oh, it was incredible! Crossing that finish line after months of training was such a rewarding feeling. The atmosphere, the support from fellow runners and spectatorsโ€”it was all so motivating.
</as:section>
<as:section name='m2'>
That sounds amazing. What inspired you to take on such a challenge?
</as:section>
<as:section name='s2'>
Well, I've always been passionate about pushing my limits and staying active. Running a marathon was a personal goal of mine for a long time, and I finally decided to commit to it this year. Plus, I wanted to raise awareness and funds for a charity close to my heart.
</as:section>
<as:section name='m3'>
That's commendable.
</as:section>
""",
)

print("The script ID is:", script.scriptId)

This script features a conversation between two speakers, Wren and Coco.

Step 3: Generating Text-to-Speech (TTS) Files

Generate the TTS files for each section of the script. Assign voices to each section as needed.

# Create TTS files
tts = audiostack.Speech.TTS.create(
    scriptId=script.scriptId,
    sections={
        "m0": {"voice": "Wren"},
        "s0": {"voice": "Coco"},
        "m1": {"voice": "Wren"},
        "s1": {"voice": "Coco"},
        "m2": {"voice": "Wren"},
        "s2": {"voice": "Coco"},
        "m3": {"voice": "Wren"},
    },
)

print("The speechID is:", tts.speechId)

Step 4: Mixing the TTS Files

Mix the generated TTS files into a single audio production.

# Mix the TTS files
mix = audiostack.Production.Mix.create(speechId=tts.speechId)

print("The productionID is:", mix.productionId)

Step 5: Encoding the Final Audio Mix

Encode the mixed audio file using the mp3_high preset and apply the YouTube loudness preset for optimal quality on the platform.

# Encode the mix as mp3
encode = audiostack.Delivery.Encoder.encode_mix(
    productionId=mix.productionId,
    preset="mp3_high",
    public=True,
    loudnessPreset="youtube",
)

print("The URL to the mp3 file is:", encode.url)

Summary

In this tutorial, we walked through the process of creating an audio dialogue using the Audiostack API. We created a script featuring two speakers, generated TTS files, mixed the files, and encoded the final audio using a high-quality MP3 preset suitable for YouTube. The final output is a shareable URL to the MP3 file.

By following these steps, you can create your own audio dialogues or podcasts with customized settings for various platforms.