You can use's Text-To-Speech (TTS) API for tasks that generate large amounts of audio, such as rendering an audiobook from raw text. In this example, we'll load text from a book, and run inference in parallel using the API to produce a result


  • Python installation: Ensure you have Python version 3.8 or newer installed on your computer to run the code effectively..
  • Book as a text file: Make sure to have your desired book as a text file. You can prepare your book as a text file by doing the following in shell:
wget -O alice.txt

Setting Up:

  1. Open your terminal: Launch your terminal and navigate to your desired directory where you want to set up the project.
  2. Install Python dependencies: You need to install two Python packages. Execute the following commands in your terminal:
pip install requests
pip install requests tqdm

Creating Your Script

  1. Code preparation: Open your desired code editor. Copy and paste the code provided from our API documentation below:
from concurrent.futures import ThreadPoolExecutor
import pathlib

import requests
from tqdm import tqdm


def chunk(parts: list[str], n: int):
  chunks = []

  chunk = ""
  for sentence in parts:
    chunk += sentence
    if len(chunk) > n:
      chunks.append(chunk + " ")
      chunk = ""

  if len(chunk) > 0:

  return chunks

def generate_audio(
  api_key: str,
  book_path: str,
  output_path: str,
  chunk_size: int = 500,
  output_p = pathlib.Path(output_path)
  output_p.mkdir(parents=True, exist_ok=True)

  book_text = open(book_path, "r")
  sentences ="\n", " ").replace("\r", "").split(".")
  trimmed_sentences = [sentence.strip() + "." for sentence in sentences]

  chunks = chunk(trimmed_sentences, chunk_size)

  def generate_chunk_audio(chunk: tuple[int, str]):
    index, text = chunk
    filename = f"{str(index).zfill(4)}.mp3"

    response = requests.request(
        "Content-Type": "application/json",
        "X-API-Key": api_key
        "text": text,
        "voice_id": "us-female-2",
        "params": {
          "model": "style-diff-500"

    # Check API status

    (output_p / filename).write_bytes(response.content)

  with ThreadPoolExecutor(max_workers=5) as executor:
      tqdm(, enumerate(chunks)),
        desc="Generating audio",


  1. Save your script: Ensure you save the file with a clear name. For example:

Running Your Script

  1. Execute the script: In your terminal, run the script using the command python
  2. Enter your API Key: When prompted, enter your NEETS_API_KEY. You can find this on your API Keys page here.

Now you're all set! Follow these steps for tasks requiring generation of large amounts of audio using's easy-to-use APIs