Text to Speech API: Quick Start Guide for Developers

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

This guide helps game developers and content creators generate consistent NPC dialogue and tutorial audio via a simple REST API. You will find clear examples for authentication, request formatting, and error handling, along with details on supported voices, languages, and audio formats.

The API mirrors the OpenAI speech endpoint structure, allowing you to use existing OpenAI SDKs with a minor base URL adjustment. Whether you are building immersive game worlds or creating instructional content, this documentation provides the concrete steps needed to integrate high-quality synthetic voiceovers into your workflow efficiently.

Text to Speech API: Quick Start Guide for Developers

Frequently asked questions

What is the base URL for the API?

The API base URL is https://api.p4xbetcasino.com/v1. You send POST requests to https://api.p4xbetcasino.com/v1/audio/speech to generate speech. Other endpoints like /v1/voices and /v1/models are also available under this base path for retrieving voice details and model information.

How do I get my API key?

Sign up on the /get-api-key/ page using Google or an email and password. Your account is specific to this site. Once registered, you receive a single active Bearer key starting with 'tts-'. You can issue a new key at any time, which immediately invalidates the old one.

Does the API support streaming audio?

No, the API does not support streaming, WebSockets, or real-time partial audio. You send a text payload and receive the complete audio file in the response. For long texts, you must split them into parts of up to 4096 characters and join the resulting audio files manually.

Can I use SSML tags in the input text?

No, the API does not support SSML tags. It accepts plain text input for the input field. There are no phoneme dictionaries or custom pronunciation lexicons available either. You control pacing and tone by adjusting the speed parameter between 0.25 and 4.0.

What is the maximum text length?

Each request supports up to 4096 characters of text. Spaces and punctuation count toward this limit. For longer scripts, split your text into chunks of 4096 characters or less, generate audio for each chunk, and join the files. Failed requests are free.

How do I handle rate limit errors?

The limit is 60 requests per minute per key (10 per minute before the first top-up). Requests are processed sequentially, so under load, your request may wait in a queue. If you exceed the limit, you will receive an error. Implement exponential backoff in your integration logic.

Is the OpenAI SDK required?

No, the OpenAI SDK is not required. However, the request shape matches the OpenAI speech endpoint, so you can use the official OpenAI SDKs by changing the base_url to https://api.p4xbetcasino.com/v1 and providing your NPC Voice Lab key. You can also use plain HTTP requests.

Do I need to install any libraries?

No specific library is required. You can use any HTTP client capable of sending JSON payloads. If you prefer using the OpenAI SDK, you must install that library, but it is not mandatory. The API works with standard POST requests containing the JSON body and Bearer token.

How do I specify a different language?

Include the language field in your request body with the ISO code. If omitted, the system guesses the language from the script, defaulting to English for Latin text. For non-English Latin-script text, always set the language field to ensure correct pronunciation by the selected voice.

What happens if the server is down?

There is no SLA or uptime guarantee. If synthesis fails, the charge is returned in full. Requests are processed one after another, so high load may cause delays. If the server is unavailable, your request will fail, and you will not be billed for the attempt.

Can I request a custom audio format?

Yes, specify the response_format field with one of the supported formats: mp3, wav, opus, flac, or pcm. There is no custom format option beyond these five. Each generated file also carries an inaudible watermark to mark it as synthetic speech, regardless of the format chosen.

Is there a webhook for completion?

No, there is no webhook for completion. The API is synchronous: you send a request and wait for the audio file in the response. For long texts, you must handle splitting and joining yourself. There are no real-time notifications or asynchronous callbacks provided by the service.

How do I check my API usage?

Visit the /get-api-key/ page on the site. It displays your current balance, trial status, characters left, and usage history. You can also check the GET /v1/voices endpoint for pricing details and the /get-api-key/ page for balance. Request metadata like time and status is kept for billing purposes and visible in your dashboard.

Can I rotate my API key immediately?

Yes, you can issue a new key at any time from your account page. When you generate a new key, the old one stops working immediately. You can use the new key in your applications right away. This allows you to revoke access instantly if needed.

First request

curl

curl https://api.p4xbetcasino.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.p4xbetcasino.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.p4xbetcasino.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 and Keys

Sound wave illustration for: Authentication and Keys

NPC Voice Lab provides a reliable API to generate audio files without the hassle of recording sessions or licensing conflicts. To start, generate your API key on the /get-api-key/ page using Google or an email account.

Generate key on /get-api-key/

Generate key on /get-api-key/

Sign up on the site's /get-api-key/ page with Google or with email + password. Accounts are per site.

Use Bearer token in Authorization header

Use Bearer token in Authorization header

Include your key in the Authorization: Bearer tts-... header for every request. This authenticates your account for all API calls.

One active key per account

There is one active key per account. A new key can be issued any time, and the old one stops at once.

Speech Endpoint

Sound wave illustration for: Speech Endpoint

The /v1/audio/speech endpoint accepts a POST request with a JSON body containing your text and voice selection. It is designed for straightforward text-to-audio conversion without the complexity of streaming protocols.

POST /v1/audio/speech

Send your request to https://api.p4xbetcasino.com/v1/audio/speech. Include the Authorization: Bearer header with your API key. The endpoint processes standard TTS parameters and returns the generated audio file directly in the response body.

  • Endpoint: https://api.p4xbetcasino.com/v1/audio/speech
  • Method: POST
  • Content-Type: application/json

JSON body with input and voice

Structure your request with the input field (up to 4096 characters) and a voice preset. You may also specify model (tts-1 or tts-1-hd), response_format, and speed. The system handles language guessing or uses your explicit language code.

  • input: Text string (max 4096 chars)
  • voice: One of 8 presets (e.g., aria, atlas)
  • model: "tts-1" or "tts-1-hd"
  • speed: 0.25–4.0

Returns audio file directly

The response contains the binary audio data in your requested format (mp3, wav, opus, flac, or pcm). There is no intermediate JSON wrapper for the audio data itself, allowing immediate saving or playback in your game engine or application.

Request Parameters

Sound wave illustration for: Request Parameters

Configure your TTS requests with three core parameters: model, voice, and speed. These settings determine the audio engine quality, the character’s tonal personality, and the playback pace. Each parameter is passed as a JSON field in the POST body.

Choosing the right combination ensures your NPC dialogue or tutorial narration matches the intended mood. The API processes these settings sequentially, so precise configuration reduces the need for re-generation.

Model: tts-1 or tts-1-hd

Select either tts-1 for standard generation or tts-1-hd for higher fidelity. Both models use the same engine and pricing structure, so your choice affects only audio quality, not cost.

Use tts-1-hd for close-up NPC monologues where subtle vocal nuances matter. Use tts-1 for background dialogue or rapid tutorial instructions where speed is prioritized.

Voice: one of 8 presets

Choose from eight distinct voices, each designed for specific narrative roles. Female presets include aria (warm narrator), nova (upbeat), luna (storytelling), and sage (instructional). Male presets include felix (energetic promo), milo (conversational), atlas (neutral news), and orion (deep documentary).

Each voice is derived from licensed recordings, ensuring consistent tone across your project. You can select any voice regardless of the input language, though setting the language field improves accuracy for non-English text.

  • 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

Speed: 0.25 to 4.0

Adjust the speed parameter between 0.25 and 4.0 to control playback rate. A value of 1.0 represents normal speech. Lower values slow down the audio for dramatic effect or clarity in tutorials. Higher values accelerate narration for quick updates or background ambiance.

Speed changes do not affect pricing or character limits.

Supported Audio Formats

Sound wave illustration for: Supported Audio Formats

NPC Voice Lab’s API generates audio files in five distinct formats, allowing you to choose the best balance of quality and file size for your game assets or video content. Each generated file is returned directly in the API response, ready for immediate integration into your pipeline.

MP3, WAV, FLAC, OPUS, PCM

You can specify any of these five formats using the response_format parameter in your request. MP3 offers efficient compression for general use, while WAV and FLAC provide lossless quality for high-fidelity voiceovers. OPUS is efficient for small file sizes, and PCM provides raw, uncompressed audio data.

  • MP3: Compressed, widely compatible
  • WAV: Lossless, standard for editing
  • FLAC: Lossless, smaller file size
  • OPUS: Efficient, low latency
  • PCM: Raw, uncompressed data

Select format in response_format

To set the output format, include the response_format field in your JSON body. The API will return the audio file in the specified format, ensuring your development workflow remains consistent regardless of the target platform or engine requirements.

No streaming or WebSocket support

Unlike some real-time services, NPC Voice Lab does not support streaming or WebSocket connections. The API returns the complete audio file after synthesis is finished. For long texts, you must split the input into chunks of up to 4096 characters and join the resulting audio files manually.

Rate Limits and Queuing

Sound wave illustration for: Rate Limits and Queuing

Rate limits protect the service during peak usage. Each API key allows 60 requests per minute, ensuring fair access for all developers generating NPC dialogue or tutorial audio.

When demand exceeds capacity, requests are processed sequentially. This means your synthesis jobs wait in a queue until resources are available, rather than failing immediately.

60 requests per minute limit

Once your account is established, you can send up to 60 synthesis requests every minute. This limit applies per key, so manage your concurrency accordingly if you split work across multiple keys. Note that each account has only one active key at a time.

  • Limit resets every 60 seconds.
  • Applies per API key, not per account.

Initial limit of 10 requests/min

New accounts start with a lower limit of 10 requests per minute. This helps verify your integration setup before scaling up. The limit increases to 60 requests per minute after your first top-up.

  • Applies until first top-up.
  • Increases to 60 req/min after funding.

Requests processed sequentially

Requests are handled one after another. Under heavy load, a request may wait in a queue before synthesis begins. Plan your generation batches to avoid unnecessary delays during high-traffic periods.

Rate Limits and Queuing

Error Handling

Sound wave illustration for: Error Handling

Error handling is straightforward: check the HTTP status code for failures, and review the input text length constraints to avoid silent truncation. Failed requests are free: if synthesis fails, the charge is returned in full.

Check status codes for failures

Inspect the response status code to determine if the synthesis failed. Non-200 status codes indicate issues such as invalid parameters or temporary service unavailability.

Failed requests refund automatically

If synthesis fails, the charge is returned in full. You are only billed for successfully generated audio files, ensuring you pay strictly for usable output.

Review input text length constraints

Each request supports up to 4096 characters. Exceeding this limit will result in an error. For longer NPC dialogues or tutorials, split the text into parts and join the audio files manually.

OpenAI SDK Compatibility

Sound wave illustration for: OpenAI SDK Compatibility

You can integrate our TTS API using the official OpenAI SDKs by changing the base URL. Simply point the SDK’s base URL to our API endpoint and authenticate with your NPC Voice Lab key. This approach lets you use the same code structure you already know, reducing integration time for your game or content creation pipeline.

The request shape mirrors the OpenAI speech endpoint exactly. You send a JSON body containing the model, input text, voice preset, and optional parameters like speed or language. The API processes the request and returns the generated audio file directly, ensuring a familiar developer experience with minimal boilerplate code.

Use official OpenAI SDKs

Leverage the official OpenAI SDKs for Python, Node.js, or other supported languages. No additional proprietary client is required.

This compatibility allows you to swap between OpenAI’s speech endpoint and NPC Voice Lab’s endpoint by changing only the base URL configuration.

  • Official SDKs work out of the box
  • No custom client library needed
  • Standard JSON request/response format

Change base_url to api endpoint

Update your SDK configuration to use https://api.p4xbetcasino.com/v1 as the base URL. This directs all requests to our infrastructure while maintaining the standard OpenAI request structure.

Ensure your authentication header uses your NPC Voice Lab Bearer token (tts-...) instead of an OpenAI key.

  • Base URL: https://api.p4xbetcasino.com/v1
  • Standard Authorization header
  • No code rewrites needed

Same request shape as OpenAI

The JSON body expects the same fields: model, input, voice, response_format, and speed. This parity means you can reuse your existing generation logic for NPC dialogue or tutorial voiceovers with zero structural changes.

Supported models are tts-1 and tts-1-hd, both using the same engine and pricing structure.

  • Field parity with OpenAI
  • Supports tts-1 and tts-1-hd
  • Identical JSON structure

Voices and Languages List

Sound wave illustration for: Voices and Languages List

Retrieve the full list of available voices and languages by calling the GET /v1/voices endpoint. This returns metadata including voice IDs, supported languages, and pricing details, allowing you to dynamically populate your game’s audio settings or content creation tools without hardcoding values.

GET /v1/voices for available options

The endpoint provides a structured JSON response detailing every voice preset and its associated capabilities. Use this data to map specific character roles or tutorial styles to the most suitable voice, ensuring consistency across your NPC dialogues or instructional content.

8 presets with distinct tones

Select from eight licensed voice presets, ranging from warm narrators to energetic promo styles. Each voice is based on licensed recordings: LibriTTS-R (CC BY 4.0), from LibriVox public-domain audiobook readings.

  • 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

23 languages supported

Any voice can speak any of the 23 supported languages, including English, Spanish, German, Japanese, and Hindi. If the language parameter is omitted, the system guesses from the script, defaulting to English for Latin text; explicitly set the language code for non-English Latin-script text to ensure accuracy.

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

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Crafting memorable NPCs transforms your game world, letting content creators generate endless unique stories and engaging player interactions.

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. curl documentation
  3. FFmpeg documentation
  4. Tether (USDT)
  5. OpenAI API reference: create speech
  6. MDN: Web Speech API
  7. TRON developer hub: TRC-20
  8. Python documentation
  9. LibriTTS-R corpus (OpenSLR 141)
  10. ISO 639 language codes
  11. LibriTTS-R paper (arXiv 2305.18802)
  12. Node.js documentation

More on this site