Text-to-Speech API for Game Developers: Generate Voice Lines

By Cartoon Voice Lab editorial team · Updated 2026-11-18

This page documents the Cartoon Voice Lab API, designed specifically for indie game developers and freelance animators who need to turn character scripts into audio files quickly. You will find clear instructions on how to authenticate, structure your requests, and choose from our eight distinct voices across twenty-three languages. We cover everything from model selection to response formats, ensuring you can integrate voice lines into your game engine without hassle.

We explain how to use the standard OpenAI SDKs by simply changing the base URL, making it easy to adopt our service into your existing workflow. You’ll also learn about rate limits, error handling, and how failed requests are refunded. Whether you are building a single-player game or a multi-language cartoon, this guide helps you generate consistent, usable audio files efficiently.

Text-to-Speech API for Game Developers: Generate Voice Lines

Frequently asked questions

What is the API endpoint for generating speech?

Send a POST request to https://api.tkb399thai.com/v1/audio/speech. The JSON body requires the model, input text, voice, response_format, and optional speed or language fields. This endpoint handles the synthesis and returns the audio file directly in the response, allowing you to integrate it quickly into your game engine or animation pipeline.

How do I authenticate my requests?

Include your API key in the request header using the format Authorization: Bearer tts-.... You receive one active key per account, which you can find on your dashboard. If you generate a new key, the old one stops working immediately, ensuring secure access to your character voice synthesis resources.

Which model should I use for game audio?

Choose between tts-1 and tts-1-hd. Both use the same engine and pricing, so switch freely based on your quality needs. Generation is roughly real-time for long texts, but requests process sequentially. Under load, your synthesis may wait in a queue, so plan your asset generation accordingly rather than expecting instant, parallel results.

Can I use the OpenAI Python SDK?

Yes, the official OpenAI SDKs work perfectly. You simply need to change the base_url to https://api.tkb399thai.com/v1 and use your site's key. This allows you to use familiar code structures for generating speech without learning a new library, making integration into your existing Python-based game tools seamless and straightforward.

What are the rate limits per minute?

Your API key allows 60 requests per minute. However, before your first top-up, the limit is lower at 10 requests per minute. Requests are processed sequentially, so under heavy load, your requests may wait in a queue. Plan your batch generations accordingly to avoid delays during asset creation.

Do I need to send the language code?

It is optional but recommended for non-English Latin-script text. If omitted, the system guesses the language, defaulting to English for Latin text. Since any voice can speak any of the 23 supported languages, explicitly setting the language field ensures accurate pronunciation for your characters, especially for languages like Greek, Hebrew, or Hindi.

What happens if I exceed the character limit?

Each request supports up to 4096 characters of input text. If your script exceeds this limit, you must split the text into smaller parts. The API does not automatically handle this split, so you should manage the segmentation in your code and join the resulting audio files to create the full voice line.

Is the audio returned as a stream?

No, the API does not support streaming or WebSocket connections. You receive the complete audio file in the response. Supported formats include mp3, wav, opus, flac, and pcm. This synchronous approach simplifies integration for game engines that expect complete audio assets rather than real-time partial audio streams.

Can I change the API key after creation?

Yes, you can issue a new key at any time from your account dashboard. When you generate a new key, the previous one stops working immediately. This feature allows you to rotate keys for security without downtime, ensuring that only your current active key can access the synthesis services.

What is the maximum text length?

The maximum input length per request is 4096 characters. Spaces and punctuation count toward this limit. For longer scripts, you need to split the text into chunks of this size. This constraint applies to both tts-1 and tts-1-hd models, so plan your text segmentation accordingly for efficient batch processing.

How do I handle long scripts?

Split your text into parts of up to 4096 characters. Send each part as a separate request to the API. Once you receive the audio files for each chunk, join them together in your project. This method ensures you stay within limits while generating complete dialogue lines for your characters efficiently.

Are there any SDKs for mobile development?

We do not offer a dedicated mobile SDK. Instead, use the official OpenAI SDKs or plain HTTP requests by setting the base_url to https://api.tkb399thai.com/v1. This works on iOS, Android, and game engines via standard networking libraries. No proprietary mobile SDK is available.

First request

curl

curl https://api.tkb399thai.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.tkb399thai.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.tkb399thai.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

Secure your API access with a Bearer token passed in the Authorization header. This single key authenticates all requests to the speech endpoint, ensuring your account details and usage are protected while you generate voice lines for your indie games.

Bearer Token Setup

Include your key exactly as Authorization: Bearer tts-... in every HTTP request. You can find this token on your /get-api-key/ dashboard after signing in. It acts as your password for the API, so keep it out of public client-side code if possible.

One Key Per Account

Each account holds only one active key at a time. This simplifies integration for freelance animators who manage a single project workflow. There is no need to track multiple credentials or manage complex permission scopes for different team members.

Key Rotation Policy

If you suspect your key has been exposed, you can issue a new one immediately from your dashboard. The old key stops working instantly, preventing unauthorized use. The new key becomes active right away, so you can resume generating audio without delay.

Speech Endpoint

Sound wave illustration for: Speech Endpoint

The core of your workflow is the POST https://api.tkb399thai.com/v1/audio/speech endpoint. Send your character’s dialogue text here, and the API returns the synthesized audio file directly in the response. This simple request-response cycle integrates easily into Unity, Unreal, or Godot pipelines for rapid prototyping.

JSON Body Structure

Send a JSON object containing the model, input text, voice, and format preferences. You can also optionally specify a language code or adjust the speech speed between 0.25 and 4.0. Each request handles up to 4096 characters; for longer scripts, split the text and join the resulting audio files.

  • Input text: up to 4096 characters per request
  • Speed: 0.25–4.0 multiplier
  • Language: optional ISO code (auto-detected if omitted)
  • Response format: mp3, wav, opus, flac, or pcm

Required Fields

You must provide the model, input, voice, and response_format fields. The model is either "tts-1" or "tts-1-hd". The voice must be one of the 8 presets (e.g., "aria", "nova", "felix"). The input is your raw text string, and response_format defines the output container.

  • model: "tts-1" or "tts-1-hd"
  • input: your dialogue text string
  • voice: one of the 8 preset voice IDs
  • response_format: mp3, wav, opus, flac, or pcm
Speech Endpoint

Available Models

Sound wave illustration for: Available Models

The API offers two model variants, tts-1 and tts-1-hd, both powered by the same underlying engine. You can switch between them without changing your integration logic, allowing you to adjust quality settings on the fly based on your project's needs.

tts-1 Standard

This model provides efficient synthesis for standard voice lines. It is well-suited for background dialogue or numerous NPC interactions where processing speed matters more than nuanced audio texture.

tts-1-hd High Quality

Use tts-1-hd when you need richer audio fidelity for main characters or cinematic cutscenes. It delivers higher quality output directly from the engine, removing the need for post-processing to fix generation artifacts.

Same Price for Both

Both models cost $0.01 per 1,000 characters. There is no price difference between standard and high-quality modes, so you can choose based on creative preference without worrying about budget spikes.

Supported Voices

Sound wave illustration for: Supported Voices

Cartoon Voice Lab provides eight distinct voice presets designed for consistent character dialogue. Each voice is based on licensed recordings from LibriTTS-R (CC BY 4.0) and LibriVox public-domain audiobooks, ensuring a reliable audio foundation for your game’s narrative.

8 Preset Voices

Our library includes eight unique voices, split evenly between female and male presets. These are not custom clones but established character types ready for immediate integration into your engine.

  • Aria: warm, clear narrator
  • Nova: bright, upbeat
  • Luna: soft, storytelling
  • Sage: calm, instructional
  • Felix: energetic, promo
  • Milo: friendly, conversational
  • Atlas: neutral, news
  • Orion: deep, documentary

Female and Male Options

Choose from four female voices for heroines, narrators, or magical characters, and four male voices for protagonists, villains, or commentators. This mix covers most standard RPG and adventure game archetypes without needing additional casting.

Voice Descriptions

Select voices that match your character’s role. Aria provides a clear narrative voice, while Nova brings bright energy. Luna is soft for storytelling, and Sage is calm for instruction. Felix is energetic for promos, Milo is friendly for conversation, Atlas is neutral for news, and Orion is deep for documentary styles.

Response Formats

Sound wave illustration for: Response Formats

The API returns audio files in your chosen format via the response_format parameter. Select the container that best fits your game engine’s playback requirements, balancing file size and quality for your specific use case.

MP3 Compression

MP3 is the most widely supported audio format for game engines and web browsers. It offers a good balance between file size and audio quality, making it ideal for background voice lines or UI sounds where storage space is a concern.

  • Small file size reduces bandwidth usage
  • Universal compatibility with Unity, Unreal, and web players

WAV Lossless

WAV provides uncompressed, high-fidelity audio. Choose this format if you need the highest possible quality for critical dialogue or if your pipeline requires lossless input for further processing or mastering.

  • No data loss during generation
  • Ideal for high-quality cutscenes

OPUS, FLAC, PCM Support

OPUS provides efficient compression suitable for web-based delivery. FLAC offers lossless compression for archival quality. PCM returns raw, uncompressed audio data, which is useful for specific low-level audio pipelines.

  • OPUS: efficient web delivery
  • FLAC: lossless archival
  • PCM: raw data stream
Response Formats

Rate Limits

Sound wave illustration for: Rate Limits

Your API key allows 60 requests per minute, which is sufficient for generating character dialogue during active development or small-scale localization batches.

60 Requests Per Minute

After your initial top-up, you can send up to 60 synthesis requests each minute. This capacity handles typical indie game workflows where you generate voice lines for multiple characters sequentially.

10 RPM Before Top-Up

When you first create an account, the limit is 10 requests per minute. This lower rate applies until you add funds via USDT. Once topped up, the limit increases to 60 RPM immediately.

Queued Processing

Requests are processed sequentially. If you exceed the limit or send many requests quickly, new requests wait in a queue. This ensures stability but means longer texts may take time to generate during high load.

Error Handling

Sound wave illustration for: Error Handling

When synthesis fails, you receive a standard HTTP error code indicating the issue. The API returns a JSON object with a clear error message to help you debug the request quickly. Failed requests are free, and the charge is returned in full if synthesis fails.

HTTP Status Codes

We use standard HTTP status codes to indicate success or failure. A 200 OK confirms your audio file is ready. Other codes signal issues like invalid authentication or rate limits.

Check the response body for details on why the request failed.

JSON Error Responses

Every error response includes a JSON object describing the problem. This helps you adjust your request parameters or API key immediately.

Refund on Failure

If audio synthesis fails, the charge is returned in full. You are not billed for characters processed in failed requests.

This ensures you only pay for successfully generated voice lines.

Error Handling

OpenAI SDK Integration

Sound wave illustration for: OpenAI SDK Integration

Leverage the official OpenAI SDKs by simply pointing them to our API base URL. This allows you to use familiar libraries in your preferred environment without writing custom HTTP clients from scratch.

Base URL Configuration

Update your SDK client’s base_url property to https://api.tkb399thai.com/v1. This single change redirects all standard TTS requests to our infrastructure while maintaining the established request shape.

SDK Compatibility

The endpoint matches the official OpenAI speech schema, ensuring seamless integration with existing OpenAI SDKs. You can use the same libraries you already trust for character generation.

Code Examples

Initialize your client with your tts-... bearer token. Pass the model, voice, and input text exactly as you would for OpenAI, but receive audio from our dedicated engine.

  • Use standard JSON bodies for model, input, voice, and response_format.
  • No extra parameters needed; the SDK handles the rest.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Capturing your unique style with fluid motion brings freelance animation dreams to life for every client.

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. Node.js documentation
  3. MDN: Web Speech API
  4. LibriTTS-R corpus (OpenSLR 141)
  5. openai-python on GitHub
  6. ISO 639 language codes
  7. TRON developer hub: TRC-20
  8. openai-node on GitHub
  9. LibriTTS-R paper (arXiv 2305.18802)
  10. W3C WAI: making audio and video accessible
  11. Creative Commons Attribution 4.0
  12. curl documentation

More on this site