Python SDK Guide for Cloud Text-to-Speech API

By VoxMold editorial team · Updated 2026-11-19

This documentation outlines the integration of VoxMold’s cloud text-to-speech API, designed specifically for startups constructing synthetic speech datasets for machine learning. It covers authentication, endpoint structures, and request parameters required to generate deterministic audio files using standard formats like MP3 and WAV.

The guide provides concrete code examples in Python and cURL, detailing rate limits, error handling, and data formats. It is intended for engineers who need to automate voice generation pipelines without managing infrastructure, ensuring reliable input-output cycles for dataset production.

Python SDK Guide for Cloud Text-to-Speech API

Frequently asked questions

How do I authenticate my requests?

Include your API key in the Authorization header as a Bearer token: Authorization: Bearer tts-.... Each account holds one active key; issuing a new key immediately invalidates the previous one. Ensure the key is sent with every request to the API endpoint.

What is the base URL for the OpenAI SDK?

Set your SDK's base URL to https://api.xxx444.cc/v1. This allows standard OpenAI SDKs to function by routing requests to our endpoint while maintaining the same request body structure and authentication methods required by the service.

Can I use the official OpenAI Python SDK?

Yes. Configure the OpenAI Python SDK to use https://api.xxx444.cc/v1 as the base URL. Pass your tts-... key as the API key. The request shape matches the OpenAI speech endpoint, enabling direct integration without custom client libraries.

What happens if I exceed the rate limit?

The limit is 60 requests per minute per key (10 per minute before the first top-up). Exceeding this limit results in requests entering a queue rather than immediate failures. Failed requests are free, so you will not be charged for audio that was not generated due to throttling.

How do I handle audio streaming in Python?

Streaming is not supported. The API returns the complete audio file in the response body. You must wait for the full response to receive the audio data. Use standard HTTP client methods to read the entire response content into memory or a file.

Is SSML supported in the request body?

No. The API does not support SSML, phoneme dictionaries, or custom pronunciation lexicons. Input is plain text up to 4096 characters. You cannot control intonation or pauses via markup; use the speed parameter to adjust overall generation speed.

What are the valid values for the voice parameter?

Use one of eight presets: aria, nova, luna, sage, felix, milo, atlas, or orion. These voices are based on licensed recordings from LibriTTS-R and LibriVox. Each voice has a distinct tone, ranging from warm narrators to deep documentary styles.

How do I specify the language explicitly?

Include the language field with an ISO code in the request body. If omitted, the system guesses the language, defaulting to English for Latin script. Explicitly setting the language ensures correct synthesis for non-English texts using Latin characters.

Can I generate multiple voices in one request?

No. Each request generates audio for a single voice. To produce multi-voice audio, send separate requests for each voice and concatenate the resulting audio files. The API processes requests sequentially, so queueing may occur under load.

What is the maximum input length?

The input field supports up to 4096 characters per request. For longer texts, split the content into chunks of 4096 characters or less, generate audio for each chunk, and join the resulting audio files to create the final output.

How do I check my API usage?

Visit the /get-api-key/ page after signing in. The dashboard displays your current balance, trial status, characters remaining, and usage history. You can also view request metadata, including time, character count, and status, which are retained for billing purposes.

Is there a webhook for long-running jobs?

No. There are no webhooks or asynchronous job endpoints. Requests are processed synchronously. You receive the audio file directly in the HTTP response. Long texts may take time due to sequential processing, but the response is returned upon completion.

How are errors returned in the JSON response?

Errors are returned as JSON objects indicating the status and error code. Failed requests are free, meaning no charge is applied if synthesis fails. The response includes details about the error, allowing you to handle rate limits or invalid parameters programmatically.

Can I cancel a request in progress?

No. There is no mechanism to cancel a request once it has been submitted. The system processes requests sequentially. If you need to stop generation, close the connection. The server will continue processing until completion.

First request

curl

curl https://api.xxx444.cc/v1/audio/speech \
  -H "Authorization: Bearer $TTS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"tts-1","voice":"aria","input":"Hello from the API.","response_format":"mp3"}' \
  --output hello.mp3

Python (openai)

from openai import OpenAI

client = OpenAI(base_url="https://api.xxx444.cc/v1", api_key="tts-...")

with client.audio.speech.with_streaming_response.create(
    model="tts-1", voice="nova", input="Hello from Python.", response_format="mp3"
) as response:
    response.stream_to_file("hello.mp3")

Node.js (openai)

import OpenAI from "openai";
import fs from "node:fs";

const client = new OpenAI({ baseURL: "https://api.xxx444.cc/v1", apiKey: process.env.TTS_API_KEY });
const res = await client.audio.speech.create({ model: "tts-1", voice: "milo", input: "Hello from Node.js." });
fs.writeFileSync("hello.mp3", Buffer.from(await res.arrayBuffer()));
voice
ariafemale
novafemale
lunafemale
sagefemale
felixmale
milomale
atlasmale
orionmale
language
arالعربية
zh中文
daDansk
nlNederlands
enEnglish
fiSuomi
frFrançais
deDeutsch
elΕλληνικά
heעברית
hiहिन्दी
itItaliano
ja日本語
ko한국어
msBahasa Melayu
noNorsk
plPolski
ptPortuguês
ruРусский
esEspañol
swKiswahili
svSvenska
trTürkçe

Authentication

Sound wave illustration for: Authentication

Authentication for the VoxMold API relies on a single active Bearer token per account, issued via the /get-api-key/ dashboard. This key authorizes all requests to the base URL https://api.xxx444.cc/v1 and must be included in the HTTP header.

API Key Format

API Key Format

Keys are issued as strings prefixed with "tts-" (e.g., tts-abc123). Each account maintains exactly one active key; generating a new key immediately invalidates the previous one, ensuring only one valid credential exists at any time.

Bearer Token Usage

Bearer Token Usage

Include the token in every request header: Authorization: Bearer tts-<your_key>. The API validates this header before processing the JSON body. If the key is missing or invalid, the server returns a 401 Unauthorized error.

  • Header: Authorization: Bearer tts-<your_key>

Key Rotation

Rotate keys instantly via the dashboard. The old key stops working immediately upon issuance of the new one. This allows zero-downtime rotation for production pipelines by updating the environment variable in your synthetic speech data generation script.

Endpoints

Sound wave illustration for: Endpoints

The API exposes three primary HTTP endpoints for integration. The speech endpoint handles audio synthesis, while the voices and models endpoints provide metadata for configuration. All requests use standard JSON bodies and require Bearer token authentication.

These endpoints enable deterministic audio generation suitable for machine learning dataset pipelines. Developers can query available voices and formats before issuing synthesis requests, ensuring consistent output formats like MP3, WAV, or PCM.

Speech Endpoint

POST /v1/audio/speech accepts text and returns an audio file. The request body mirrors the OpenAI speech endpoint structure, allowing the use of official OpenAI SDKs by adjusting the base URL. Input text is limited to 4096 characters per request.

Voices Endpoint

GET /v1/voices returns a list of available voice presets, supported languages, and audio formats. This endpoint allows clients to verify supported configurations before synthesis. Voices include options for different tonal qualities, all capable of speaking any of the 23 supported languages.

Models Endpoint

GET /v1/models lists the available synthesis models. Currently, "tts-1" and "tts-1-hd" are available, both using the same engine and pricing structure. This endpoint helps clients confirm model availability and versioning for their data pipeline requirements.

Request Body

Sound wave illustration for: Request Body

The request body defines the synthesis parameters for generating synthetic audio. The API requires specific fields to ensure deterministic output suitable for machine learning datasets. Incorrect formatting may cause request failures, which are billed as zero-cost if synthesis fails.

All requests must include the model identifier, input text, and voice selection. The input text is limited to 4096 characters per request. Longer texts should be split and concatenated by the client to ensure consistent audio generation.

Required Fields

Each request must specify the model, input, and voice fields. The model accepts either 'tts-1' or 'tts-1-hd', which share the same engine and pricing. The input field contains the raw text string. The voice field selects one of the eight available presets, such as 'aria' or 'atlas'.

The response_format field determines the output container. Supported formats include mp3, wav, opus, flac, and pcm. Selecting the appropriate format ensures compatibility with your data pipeline storage requirements.

  • model: 'tts-1' or 'tts-1-hd'
  • input: text string (max 4096 characters)
  • voice: one of 8 presets
  • response_format: mp3, wav, opus, flac, or pcm

Optional Parameters

The language parameter accepts an ISO code to force language detection. Without it, the system guesses based on the script, defaulting to English for Latin text. Explicitly setting the language ensures accurate synthesis for non-English content.

Audio speed can be adjusted using the speed parameter. This allows you to control the duration of the generated audio file without altering the voice characteristics. Adjusting speed is useful for standardizing dataset timing.

  • language: optional ISO code
  • speed: 0.25–4.0

Speed Range

The speed parameter accepts values between 0.25 and 4.0. A value of 1.0 represents normal playback speed. Values below 1.0 slow the audio, while values above 1.0 accelerate it. This range allows precise control over audio duration for training data.

Extreme speed values may affect perceptual quality. For machine learning datasets, standard speeds (0.8–1.2) are typically preferred to maintain natural prosody while adjusting for volume constraints.

Response Handling

Sound wave illustration for: Response Handling

Upon successful synthesis, the API returns the audio file in the requested format (mp3, wav, opus, flac, or pcm) within the response body. Each generated file contains an inaudible watermark identifying it as synthetic speech, which is useful for dataset labeling in ML pipelines. No audio is stored server-side; you must handle the binary data immediately.

Audio Response

The response body contains the raw audio bytes. Ensure your client handles binary data correctly to avoid corruption. The file format matches the response_format parameter sent in the request.

Error Codes

Standard HTTP status codes indicate success or failure. Failed requests (e.g., invalid model or text too long) return a 4xx or 5xx code with a JSON error object. Crucially, if synthesis fails, the character charge is returned in full, so you are not billed for unsuccessful attempts.

  • 400: Bad Request (e.g., invalid voice ID)

Retry Logic

Implement exponential backoff for transient errors. Since requests are processed sequentially, under load a request may wait in a queue, increasing latency. Do not assume real-time response times; short phrases may take a few seconds to generate. Respect the 60 requests per minute limit to avoid rate-limit errors.

Rate Limits

Sound wave illustration for: Rate Limits

Your API key allows 60 requests per minute under normal conditions. This limit applies uniformly regardless of the model chosen. Each request consumes one unit of your quota, so efficient batching or splitting long texts into chunks under 4,096 characters helps maintain throughput.

60 Requests per Minute

Once your account is funded, you can process up to 60 synthesis jobs every minute. New accounts without a top-up are restricted to 10 requests per minute.

Pre-Top-up Limits

New accounts or those without sufficient balance are restricted to 10 requests per minute. This lower limit ensures fair resource distribution while you await automatic USDT top-up confirmation. You can still test connectivity and voice quality within this constraint.

  • Standard limit: 60 req/min after funding
  • Restricted limit: 10 req/min before top-up

Queue Behavior

Requests are processed sequentially. If you exceed the per-minute limit, additional requests enter a queue rather than failing immediately. Processing typically takes roughly 25 characters of text per second for long inputs, meaning short phrases may complete in seconds while longer texts require proportional time.

Rate Limits

Code Examples

Sound wave illustration for: Code Examples

The API supports standard HTTP methods and language-specific SDKs. This guide provides executable examples for immediate integration into your data pipeline.

All examples assume a valid Bearer token and a text input under 4,096 characters. Adjust the base URL to match your region.

Curl Example

Use cURL to send a POST request to the speech endpoint. Replace YOUR_API_KEY with your generated key and INPUT_TEXT with your string.

The response contains the audio file in the requested format, such as MP3 or WAV, suitable for direct storage.

  • Endpoint: POST https://api.xxx444.cc/v1/audio/speech
  • Auth: Bearer YOUR_API_KEY
  • Body: JSON with model, input, voice

Python Requests

Install the requests library and import it. Initialize your API key and payload structure for synchronous generation.

Send the POST request and save the binary response content to a local file for dataset preparation.

  • pip install requests
  • import requests
  • requests.post(url, headers=headers, json=payload)

OpenAI SDK Setup

The API follows the OpenAI speech endpoint schema. Configure the base URL to https://api.xxx444.cc/v1.

Use the official OpenAI Python SDK with your custom base URL and API key for seamless integration.

  • base_url=https://api.xxx444.cc/v1
  • api_key="tts-..."
  • model="tts-1"

Data Formats

Sound wave illustration for: Data Formats

VoxMold supports standard audio containers to simplify ingestion into ML pipelines. Selecting the appropriate format ensures compatibility with existing data processing tools without requiring additional conversion steps during synthetic dataset construction.

MP3 Output

MP3 is one of the supported formats, offering high compression with minimal quality loss.

  • Supported codecs: MP3 128kbps or higher
  • Optimal for general-purpose audio storage

WAV Output

WAV provides uncompressed audio data.

  • Uncompressed PCM audio
  • Preserves full spectral detail

PCM Raw Data

PCM returns raw binary audio samples.

  • Raw binary stream
  • No container metadata overhead

Troubleshooting

Sound wave illustration for: Troubleshooting

Troubleshooting focuses on resolving common integration hurdles with the VoxMold TTS API. Issues typically stem from character limits, voice availability, or transient network delays during synthesis.

Common Errors

Most failures result from exceeding the 4096-character limit per request or using an invalid voice ID. Ensure your input text is split correctly and all characters are counted, including spaces and punctuation.

  • 400 Bad Request: Input exceeds 4096 characters.
  • 401 Unauthorized: Invalid or expired API key.
  • 429 Too Many Requests: Exceeded 60 requests/minute limit.

Latency Issues

Generation speed is approximately real-time, averaging 25 characters per second. Short phrases may take a few seconds, while longer texts are processed sequentially. Requests may queue under load, increasing total wait time.

  • Average speed: ~25 chars/sec.
  • Requests process sequentially under load.
  • No streaming or partial audio support.

Validation Failures

Ensure the language field is set for non-English Latin text to prevent incorrect voice selection. Verify that the requested format (mp3, wav, opus, flac, pcm) matches your pipeline requirements.

  • Default language guesses English for Latin script.
  • Set language explicitly for non-English texts.
  • Invalid format strings cause 400 errors.

Data Formats

The API returns audio in the specified response_format. PCM provides raw uncompressed data, while MP3 and WAV are standard compressed formats suitable for most ML pipelines.

  • Supports mp3, wav, opus, flac, pcm.
  • PCM output is raw binary data.
  • MP3/WAV are compressed and smaller.

Retry Logic

Implement exponential backoff for rate limit errors (429). Failed synthesis requests are free, so retries do not incur additional costs. Ensure your client handles HTTP status codes appropriately.

  • Exponential backoff for 429 errors.
  • Failed requests are free.
  • Handle HTTP status codes correctly.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. The response headers may contain metadata about the character count processed.

Avatar of the voice aria
ariafemale
Avatar of the voice nova
novafemale
Avatar of the voice luna
lunafemale
Avatar of the voice sage
sagefemale
Avatar of the voice felix
felixmale
Avatar of the voice milo
milomale
Avatar of the voice atlas
atlasmale
Avatar of the voice orion
orionmale

23 languages

Any voice speaks any of these languages.

Sources and further reading

  1. Wikipedia
  2. Python documentation
  3. LibriTTS-R paper (arXiv 2305.18802)
  4. W3C WAI: making audio and video accessible
  5. TRON developer hub: TRC-20
  6. LibriVox public-domain audiobooks
  7. ISO 639 language codes
  8. Creative Commons Attribution 4.0
  9. openai-python on GitHub
  10. MDN: Web Speech API
  11. FFmpeg documentation
  12. Node.js documentation

More on this site