---
updatedAt: 2025-11-27T15:54:03.000Z
agentTools:
  projectIndex: https://docs.audiostack.ai/llms.txt
---

# Create an ad instantly with AI - finding the perfect voice

```python Python
import requests
import json
from time import sleep

API_KEY = "Your API Key"

brief = {
    "script": {
        "productName": "AudioStack Voice Library",
        "scriptText": "AudioStack's voice library provides an unbeatable selection of voices, styles, languages, and accents from the best text-to-speech providers.",
        "adLength": None,
    },
    "voices": [
        {"alias": "elora"},
        {"alias": "alyxander", "voicePreset": "standard"},
        {"alias": "alyxander", "voicePreset": "expressive", "speed": 0.8},
        {"alias": "alyxander", "voicePreset": "expressive", "speed": 1.2},
        {
            "accent": ["american"],
            "gender": ["female"],
            "tone": ["upbeat", "confident"],
            "voicePreset": "expressive",
        },
    ],
}

print(f"Calling the brief endpoint with the following brief:")
print(json.dumps(brief, indent=4))

r = requests.post(
    url="https://v2.api.audio/creator/brief",
    json={
        "audioformVersion": "2",
        "brief": brief,
        "numAds": 5,
    },
    headers={"x-api-key": API_KEY},
)

audioforms = r.json()["data"]["audioforms"]

print(
    f"The brief endpoint builds your ads with AI and returns a list of audioforms. Received the following audioform:\n"
)
print(json.dumps(audioforms, indent=4))

for audioform in audioforms:
    count = 0
    while count < 20:
        get_audioform_response = requests.get(
            url=f"https://v2.api.audio/audioforms/{audioform['audioformId']}",
            headers={"x-api-key": API_KEY},
        )
        if get_audioform_response.status_code == 202:
            sleep(1)
            count += 1
        elif get_audioform_response.status_code == 200:
            audioform = get_audioform_response.json()["data"]["audioform"]
            break
        else:
            print(f"Audioform build failed: {get_audioform_response.text}")

    print("\n########################\n")
    for asset in get_audioform_response.json()["data"]["audioform"]["assets"].values():
        if asset["type"] == "voice":
            print(f"\nThis ad using the following voice and settings: \n")
            print(json.dumps(asset, indent=4))
    audio_url = get_audioform_response.json()["data"]["result"]["delivery"]["uri"]
    print(f"\nListen to your new ad at the following : {audio_url}.")

```

```json Response Example
{"success":true}
```

# Setup

<!-- python@1-5 -->

Setup your imports and API key.

# Define a brief with a pre-written script

<!-- python@10 -->

When you have already know what your script is, you can skip the AI script writing and provide your own copy.

# Fit the ad to the script

<!-- python@11 -->

In cases when you don't need to target a specific length of ad, you can let the ad fit naturally to the script.

# Define a selection of voices to try

<!-- python@13-25 -->

With the brief endpoint, you can define a selection of voices to pick from.

Our API will draw from this selection without repeating.

# Pick a specific voice from the voice library

<!-- python@14 -->

When you know the voice you want, you can select it with by alias.

Explore our Voice Library to try out different voices.

# Pick a specific voice with special settings

<!-- python@15-17 -->

You can also set the voice settings. In this example, we try two different speeds and also compare out standard and expressive presets.

# Get recommended voices

<!-- python@18-23 -->

You can also get recommended voices which meet your specific needs.

In this case, we get the API to pick an American, female voice that supports expressive delivery and speaks in either an upbeat or confident tone.

# Call the brief endpoint

<!-- python@27-45 -->

This endpoint will create 5 versions of the ad. Because we've provided 5 options for voices, it will use each once.

It will also recommend some music.

# Poll for each of the audioforms

<!-- python@47-63 -->

We poll for all 5 audioforms while they build

# Listen to our finished ad and compare the voices

<!-- python@63-69 -->

Check out the 5 ads and can compare Elora and Alyxander.

Also hear the impact of speed and voicePreset on Alyxander's delivery.

Finally, see how AudioStack's AI recommendation has done.