Developer Guide: Integrate Text-to-Speech with OpenAI SDK

By DubbingScale editorial team · Updated 2026-11-18

This guide documents the DubbingScale text-to-speech API, designed for developers integrating synthetic voice generation into localization and dubbing pipelines. It details the OpenAI SDK-compatible endpoint structure, allowing you to send text and receive audio files with minimal code changes. You will find precise specifications for models, voices, and supported formats to streamline your automation workflows.

The documentation covers essential operational details, including authentication via Bearer tokens, rate limits, and error handling strategies. It also explains how to handle text splitting for longer inputs and configure speed or language parameters. Whether you are using cURL, Python, or Node.js, this reference provides the concrete technical facts needed to implement reliable, high-volume audio generation.

Developer Guide: Integrate Text-to-Speech with OpenAI SDK

Frequently asked questions

Which SDK should I use?

Use standard OpenAI SDKs by setting the base_url to https://api.77acthai.com/v1. The API accepts the same request shape as the OpenAI speech endpoint, ensuring compatibility. Alternatively, use any HTTP client to send POST requests to https://api.77acthai.com/v1/audio/speech with parameters like model, input, voice, and your Bearer token.

Can I stream the audio?

No streaming is supported. The API returns the complete audio file in the response body upon successful synthesis. You must wait for the full file to be generated before processing it. This synchronous approach ensures reliable delivery of the entire audio segment without partial data chunks or WebSocket connections.

Is SSML supported?

No, SSML is not supported. You can only pass plain text in the input field. There are no SSML tags for controlling pronunciation, pauses, or emphasis. For precise control, you must manage text segmentation and timing in your application logic before sending requests to the API.

How do I handle long texts?

Split your text into parts of up to 4096 characters. Send each part as a separate request to the speech endpoint. Then, join the resulting audio files in your application. This ensures each request stays within the character limit and allows you to manage generation queues effectively for large volumes.

What is the character limit?

Each request supports a maximum of 4096 characters in the input field. Spaces and punctuation count toward this limit. If your text exceeds this length, you must split it into multiple requests. Each request is processed independently, so ensure your application handles the sequential generation and concatenation of audio files.

Can I change the language mid-request?

No, you cannot change the language mid-request. Each request processes a single input text with one voice and one language code. If you need different languages, you must split the text into separate requests, each specifying the appropriate language ISO code or relying on automatic script detection.

Do voices support all languages?

Any of the 8 voices can speak any of the 23 supported languages. These include Arabic, Chinese, English, French, German, Japanese, Spanish, and others. If you do not set the language parameter, the system guesses it from the script, defaulting to English for Latin text. Set it explicitly for non-English Latin scripts.

How do I rotate my API key?

Generate a new key via your account dashboard. The new key becomes active immediately, and the old one stops working at once. You can issue a new key at any time. Update your application configuration to use the new key, ensuring seamless transition without downtime for your TTS services.

What happens if I exceed rate limits?

You are limited to 60 requests per minute per key. If you exceed this, requests may queue or fail. New accounts start with a 10 requests per minute limit until the first top-up. Failed requests are free, but successful ones consume your balance. Monitor your usage to avoid delays in generation.

Is the API RESTful?

Yes. The API is RESTful, using POST for speech generation and GET for retrieving voices or models. Requests are sent as JSON, and responses return audio data or JSON metadata. This design allows easy integration with any modern programming language and HTTP client library.

Can I use WebSocket?

No, WebSocket is not supported. The API uses standard HTTP POST requests to return audio files. There is no real-time partial audio streaming or WebSocket endpoint. You must use HTTP to send text and receive the complete audio response, which may take a few seconds for short phrases.

Do you provide webhooks?

No, we do not provide webhooks. The API is synchronous: you send a POST request and receive the audio file directly in the response. There is no mechanism to notify your application when synthesis completes. You must handle the request-response cycle directly in your client code without asynchronous notifications.

How do I debug errors?

Check the HTTP status code and response body for error details. Failed requests are free, so no charge is incurred. Ensure your API key is valid and your JSON body matches the required schema. Use the GET /v1/voices endpoint to verify available voices and formats. Monitor your rate limit status to avoid throttling.

Is there a sandbox environment?

No separate sandbox is provided; testing uses the same production endpoints. You can use your $0.50 free trial credit to test functionality, but note this credit is only granted when signing in with Google, not with email/password. All voices, formats, and models are available in this environment, ensuring consistent behavior between testing and live usage.

First request

curl

curl https://api.77acthai.com/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.77acthai.com/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.77acthai.com/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 is handled via a Bearer token included in the Authorization header of every API request. You receive a single active key per account, which provides access to the text-to-speech endpoint and allows you to monitor usage and balance details.

Bearer token authorization

Include the header Authorization: Bearer tts-... in your requests. The key must be valid and associated with your account to process synthesis jobs. Failed requests are free, but authentication failures will prevent any attempt at generation.

One key per account

Each account is issued one active API key. This key serves as the sole credential for all requests made to the API. There is no concept of multiple simultaneous keys or role-based access controls within the standard account structure.

Key rotation policy

You can issue a new key at any time from your dashboard. When a new key is generated, the previous key becomes invalid immediately. This allows for instant revocation without waiting for a session timeout or expiration period.

Endpoint structure

Sound wave illustration for: Endpoint structure

Send text to the speech endpoint to receive synthesized audio. The API follows the OpenAI request shape, allowing direct integration with standard SDKs by adjusting the base URL. This structure supports high-volume localization workflows where consistent payload formats simplify pipeline automation.

POST /v1/audio/speech

Submit JSON payloads to this endpoint to generate audio files. The request must include the desired model, input text, and voice preset. Responses return binary audio data with appropriate content-type headers.

  • Base URL: https://api.77acthai.com/v1
  • Method: POST
  • Content-Type: application/json

JSON request body

Structure your request with standard fields like model, input, and voice. The input field accepts up to 4096 characters per request. For longer texts, split the input and join the resulting audio files. Failed requests return zero charges.

  • model: "tts-1" or "tts-1-hd"
  • voice: one of 8 presets
  • input: string, max 4096 chars
  • response_format: mp3, wav, opus, flac, pcm

OpenAI SDK compatibility

The endpoint mirrors the OpenAI speech structure, enabling use of official OpenAI SDKs. Simply change the base_url to https://api.77acthai.com/v1 and supply your API key. This eliminates the need for custom HTTP clients or custom SDKs.

Endpoint structure

Request parameters

Sound wave illustration for: Request parameters

Configure the synthesis request by specifying the model, input text, and voice. The API accepts two model variants, tts-1 and tts-1-hd, which use the same engine and pricing. You must provide the text to convert, ensuring it stays within the 4096 character limit per request.

Model selection (tts-1, tts-1-hd)

Choose between "tts-1" and "tts-1-hd" for synthesis. Both models utilize the same underlying engine and incur identical pricing, so select based on your preference without worrying about cost differences. The model field accepts these exact string values in your JSON body.

Input text limit (4096 chars)

The input text field accepts up to 4096 characters per request. Spaces and punctuation count toward this limit. For longer content, split the text into chunks of this size and join the resulting audio files sequentially to create a complete file.

Voice selection (8 presets)

Select from eight licensed presets based on recordings from LibriVox. Female voices include aria (warm, clear narrator), nova (bright, upbeat), luna (soft, storytelling), and sage (calm, instructional). Male voices include felix (energetic, promo), milo (friendly, conversational), atlas (neutral, news), and orion (deep, documentary).

Every generated file carries an inaudible watermark marking it as synthetic speech. You can specify a voice that does not match the text language; the system will guess the language from the script if not explicitly provided.

  • Female: aria, nova, luna, sage
  • Male: felix, milo, atlas, orion

Response formats

Sound wave illustration for: Response formats

Select your preferred output format by setting the response_format field in the JSON request body. Available options include MP3, WAV, OPUS, FLAC, and PCM, allowing you to balance file size and compatibility with your dubbing pipeline requirements.

MP3, WAV, OPUS, FLAC, PCM

The API accepts MP3, WAV, OPUS, FLAC, and PCM as valid formats. Each format is generated directly from the synthesis engine without additional post-processing layers, ensuring the audio file matches the specified parameters exactly. Choose the format that best integrates with your existing media storage or editing tools.

  • MP3: Standard compressed audio
  • WAV: Uncompressed wave file
  • OPUS: Efficient codec
  • FLAC: Lossless compression
  • PCM: Raw linear audio

Binary audio data

The response body contains the raw binary audio data corresponding to the selected format. Unlike JSON-wrapped audio, the binary stream is returned directly, allowing immediate piping into files or playback buffers without parsing overhead. This structure supports standard HTTP clients and the OpenAI SDK for direct file saving or streaming.

Content-Type headers

The server sets the Content-Type header to match the requested format (e.g., audio/mpeg for MP3, audio/wav for WAV). This ensures that client-side libraries and media players correctly interpret the binary payload. Always verify the header to prevent decoding errors when handling the response stream.

Speed and language

Sound wave illustration for: Speed and language

Adjust the voice speed between 0.25 and 4.0 to fit your dubbing timeline. The engine maintains natural voice quality across this range without requiring manual pitch adjustments.

Specify the language using an ISO code for precise control. This ensures the correct accent and pronunciation for your target market, avoiding guesswork in high-volume localization workflows.

Speed range 0.25 to 4.0

Set the speed parameter from 0.25 (slow) to 4.0 (fast). This allows you to match the pacing of original audio or adjust for readability. The engine handles pitch adjustments automatically to maintain natural voice quality across the entire range.

ISO language code support

Pass the language parameter with an ISO 639-1 code (e.g., 'en', 'th', 'de') to ensure accurate synthesis. While any voice can speak any supported language, explicitly setting the language prevents ambiguity, especially for Latin-script texts that are not English.

  • Arabic, Chinese, Danish, Dutch, English, Finnish, French, German, Greek, Hebrew, Hindi, Italian, Japanese, Korean, Malay, Norwegian, Polish, Portuguese, Russian, Spanish, Swahili, Swedish, Turkish.

Auto-detection fallback

If you omit the language field, the engine guesses the language from the script. Latin script defaults to English. For non-English Latin text, always set the language parameter to avoid incorrect synthesis.

Speed and language

Rate limits

Sound wave illustration for: Rate limits

The API enforces a strict rate limit of 60 requests per minute per active key. This cap ensures stable performance for high-volume localization workflows, allowing agencies to process large batches of text efficiently without overwhelming the synthesis engine. Requests are processed sequentially, meaning the system handles them one after another to maintain consistency and audio quality.

If you exceed the limit, the API returns a 429 error. You should implement exponential backoff or queue your requests to stay within the boundary. This predictable throttling helps you plan your dubbing pipeline accurately, avoiding unexpected delays during peak usage times.

60 requests per minute

After your first top-up, each API key is allowed 60 requests per minute. This throughput is sufficient for most professional dubbing tasks, where texts are typically split into segments of up to 4096 characters. Monitor your usage via the dashboard to ensure you do not hit this ceiling during bulk generation.

  • Limit: 60 requests/minute/key
  • Applies to all successful and failed requests
  • Resets every 60 seconds

10 req/min before first top-up

New accounts start with a reduced limit of 10 requests per minute. This applies even if you have free trial credit. Once you perform a top-up of at least $5 via USDT (TRC-20), the limit automatically increases to 60 requests per minute. This allows you to test the API at a lower volume before committing to higher throughput.

  • Default limit: 10 requests/minute
  • Increases to 60 req/min after first top-up
  • No manual upgrade required

Queue behavior under load

Requests are processed one after another. Under heavy load, additional requests may wait in a queue before synthesis begins. This means generation time can increase if many requests are submitted simultaneously. Plan your submission rate to avoid queuing delays, especially when generating long texts that require multiple split requests.

  • Processed sequentially
  • Queues form under high volume
  • No parallel processing guarantee

Error handling

Sound wave illustration for: Error handling

Errors return standard HTTP status codes with a JSON body detailing the issue. Failed synthesis charges are refunded in full, ensuring you only pay for successful outputs. Common issues include invalid parameters, rate limit exhaustion, or temporary service queues.

The API returns specific error codes to help you debug integration issues quickly. Understanding these responses allows for robust error handling in your localization pipeline.

HTTP status codes

Use standard HTTP codes to determine request success or failure. 200 indicates success, while 400-level codes signal client errors like invalid JSON or missing fields. 429 indicates rate limit exhaustion, and 500-series codes denote server-side issues.

  • 400: Bad Request (invalid input format)

JSON error responses

Error responses include a JSON object with an error key containing a message and code. This structure allows easy parsing in any language. Always check the message field for specific details about what went wrong, such as character limits or unsupported voices.

  • error: { message: string, code: string }

Retry strategies

Implement exponential backoff for 429 (rate limit) and 5xx (server) errors. Since requests are processed in queue under load, brief delays prevent overwhelming the system. Failed requests are free, so retrying without penalty is safe if the input remains valid.

  • Retry on 429 with exponential backoff
  • Retry on 5xx errors
  • Failed requests are free to retry
Error handling

Code examples

Sound wave illustration for: Code examples

The API returns the complete audio file in the response body, not a stream. This simplifies integration for high-volume localization workflows where you need immediate access to the full file for verification or storage.

cURL quickstart

Send a POST request to the speech endpoint with your bearer token. The response contains the binary audio data directly, allowing you to save it immediately without handling partial streams.

  • Use curl -X POST with Authorization: Bearer tts-...
  • Set Content-Type: application/json
  • Receive binary audio in the response body

Python with OpenAI SDK

Configure the OpenAI SDK with base_url=https://api.77acthai.com/v1. The method returns the complete audio file in the response body, ensuring you have the full asset ready for your dubbing pipeline without waiting for partial chunks.

  • Install openai package
  • Set base_url to our API endpoint
  • Use standard client.audio.speech.create

Node.js integration

Initialize the OpenAI client with the custom base URL. Since the API returns the full file in the response body, you can easily pipe the data to a file or buffer without managing stream events.

  • Import openai library
  • Pass baseUrl in configuration
  • Handle the complete response object

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Publishers seek our expert dubbing services to deliver authentic local voices that deeply resonate with their global audiences.

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. ISO 639 language codes
  3. OpenAI API reference: create speech
  4. Python documentation
  5. openai-python on GitHub
  6. LibriTTS-R corpus (OpenSLR 141)
  7. Node.js documentation
  8. LibriVox public-domain audiobooks
  9. MDN: Web Speech API
  10. Creative Commons Attribution 4.0
  11. IETF RFC 7845: Ogg Opus
  12. FFmpeg documentation

More on this site