Predict Speech Duration

By predicting the duration of speech, you can be sure that your script is the right length for your audio ad or video, saving you time and credits when creating content using AudioStack API.

Using over 4 million data points, AudioStack API predicts the duration of Speech for each individual voice, so you can edit your script to the correct length and choose a voice that best meets your needs.

Try out this code example to see it in action:

import audiostack
import os

# First, paste your API key inside the quotation marks below:

audiostack.api_key = "API KEY"

long_text="""Parrots are truly fascinating creatures that captivate both scientists and bird enthusiasts alike. Known for their vibrant plumage and remarkable intelligence, parrots have earned a special place in the world of avian wonders. With over 393 species scattered across tropical and subtropical regions, these colorful birds have adapted to diverse habitats, from lush rainforests to arid deserts. Parrots are renowned for their remarkable ability to mimic human speech and other sounds, making them popular pets and entertaining companions. 

voices = audiostack.Speech.Predict.list()
for v in voices:
    data = audiostack.Speech.Predict.predict(text=long_text, voice=v)
    print(v, data.length)

Try entering your API key in Line 6, and then editing the script in Line 8 to add your own content before running this Python code from your Terminal.


Struggling to get up and running?

Check out our Getting Started guides before trying AudioStack code examples.

What’s Next

Find out more about the different Text-to-Speech providers AudioStack offers: