API Documentation for Text-to-Speech Integration

By CivicVoice editorial team · Updated 2026-11-18

This guide helps government agencies and NGOs integrate text-to-speech audio into their digital services. You will learn how to generate accessible audio files from published text using simple HTTP requests or the OpenAI SDK. We cover authentication, parameter configuration, and error handling with concrete examples.

The documentation is designed for technical teams managing public-facing content. You will find clear instructions for setting up your API key, selecting voices, and handling rate limits. All examples use real-world parameters to help you convert text into compliant audio formats efficiently.

API Documentation for Text-to-Speech Integration

Frequently asked questions

How do I get an API key?

Visit /get-api-key/ to sign up with Google or email. Accounts are per site. You receive one active key per account. A new key stops the old one immediately. You can issue a new key anytime. Failed requests are free, ensuring no charge for errors.

What is the base URL?

The API base URL is https://api.pigpgthai.com/v1. Use this for all requests. The speech endpoint is POST https://api.pigpgthai.com/v1/audio/speech. Voices and models are accessible via GET /v1/voices and GET /v1/models. Ensure your requests target this specific domain for correct routing.

Which SDKs work?

The request shape matches the OpenAI speech endpoint. Official OpenAI SDKs work by changing the base_url to https://api.pigpgthai.com/v1. Use your site’s key with the SDK. Plain HTTP requests also work. No official custom SDK is provided, but standard libraries are compatible.

How do I authenticate?

Include your key in the Authorization header. Use the format: Authorization: Bearer tts-... . One active key exists per account. If you issue a new key, the old one stops immediately. Ensure the key is valid and associated with your account for successful requests.

What is the model parameter?

Use model "tts-1" or "tts-1-hd". Both use the same engine and price. The input text must be up to 4096 characters. Specify the voice, response format, and speed. The model parameter determines the quality tier, though pricing remains identical for both options.

What voices are available?

Eight presets are available: aria, nova, luna, sage, felix, milo, atlas, orion. Voices are based on licensed recordings from LibriVox. Each has a distinct tone, from warm narrator to deep documentary. Any voice can speak any of the 23 supported languages without restriction.

How do I set the language?

Set the optional language parameter to an ISO code. If omitted, the system guesses from the script. Latin text defaults to English. For non-English Latin text, explicitly set the language. Supported languages include Arabic, Chinese, English, French, German, Spanish, and others listed in the docs.

What formats are supported?

Supported response formats are mp3, wav, opus, flac, and pcm. Specify the format in your request body. The audio is returned directly in the response. Generated audio is not stored. Failed requests return no charge, ensuring you only pay for successful synthesis outputs.

How do I handle errors?

If synthesis fails, the charge is returned in full. Check your request body for valid parameters. Ensure the text is under 4096 characters. Verify your API key is active. Failed requests are free, so retrying is safe. Support is by email.

What are the rate limits?

The limit is 60 requests per minute per key. Before the first top-up, the limit is 10 requests per minute. Requests are processed sequentially, so queues may form under load. Longer texts take time proportional to length. Monitor your usage to avoid delays.

Can I change speed?

Yes, set the speed parameter between 0.25 and 4.0. This allows adjusting the playback rate of the generated audio. The default speed is typically 1.0. Adjusting speed helps match specific accessibility needs or presentation styles without re-synthesizing the entire text.

Is the API RESTful?

Yes, the API uses standard HTTP methods. POST for speech generation, GET for voices and models. It follows RESTful conventions. Use JSON for request bodies. The structure mirrors OpenAI’s speech endpoint, making it easy to integrate with existing web applications and government systems.

Do I need JSON?

Yes, the request body must be JSON. Include fields like model, input, voice, and response_format. The API expects structured data for parameters. Use standard JSON formatting. This ensures compatibility with OpenAI SDKs and other HTTP clients that support JSON payloads for API requests.

How do I list voices?

Send a GET request to /v1/voices. This endpoint returns available voices, languages, formats, and price information. Use this to discover supported options before generating speech. The response helps you select the appropriate voice and format for your agency’s accessibility requirements.

First request

curl

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

Get your API key

Sound wave illustration for: Get your API key

Accessing the CivicVoice API begins with creating an account on the /get-api-key/ page. You can sign up using your Google credentials, or use a standard email and password combination. Each account is tied to this specific site, ensuring your usage and billing are tracked independently.

Once registered, you will receive a unique API key starting with tts-. This key authenticates all your requests. If needed, you can generate a new key at any time, which immediately invalidates the previous one for security.

Sign up with Google

Sign up with Google

Click the Google sign-in button on the registration page. After authenticating, you are instantly assigned a trial credit of $0.50, valid for 7 days, which covers approximately 50,000 characters. This allows you to test the API immediately without adding funds.

  • Instant account creation
  • $0.50 trial credit included
  • No credit card required

Sign up with email

Sign up with email

Enter your email address and create a password. This method creates an account without the trial credit. You will need to top up using USDT on the TRON network (TRC-20) to start making requests. Accounts are created per site, so this key is specific to pigpgthai.com.

  • Standard email registration
  • No automatic trial credit
  • Requires manual top-up

View your key

View your key

After signing up, the dashboard displays your active API key, current balance, and usage statistics. You can copy the key directly from the interface for use in your code or curl commands. The key format begins with tts- and is required in the Authorization header.

  • Dashboard shows key and balance
  • One active key per account
  • Copy-paste ready for integration

First request with curl

Sound wave illustration for: First request with curl

Once you have your API key from the dashboard, you can immediately start converting text to audio. The process is straightforward: send a POST request to the speech endpoint with your credentials and the text you wish to convert. This quick start demonstrates the core functionality required for basic accessibility integration.

The API accepts standard JSON payloads. You simply provide the text, select a voice, and receive the audio file directly in the response.

Authentication

Include your API key in the HTTP header. Use the format Authorization: Bearer YOUR_API_KEY where YOUR_API_KEY is the string starting with tts- found in your account dashboard.

Ensure the key is sent with every request to authenticate your usage against your balance. If the key is invalid or expired, the API will return a 401 Unauthorized error.

  • Header: Authorization: Bearer tts-...
  • Format: Standard Bearer token
  • Source: Account dashboard

JSON body

The request body must be a valid JSON object containing the model, input, voice, and response_format fields. The model field accepts either tts-1 or tts-1-hd for standard or high-definition quality.

The input field holds your text, which can be up to 4096 characters. Each character, including spaces and punctuation, counts toward your usage limit. The voice field specifies one of the eight available presets, such as aria or atlas.

You may optionally include a language code (e.g., en, th) to ensure correct pronunciation, as the API guesses the language by default for Latin script text.

  • model: "tts-1" or "tts-1-hd"
  • input: String up to 4096 characters
  • voice: One of 8 presets (e.g., aria, atlas)
  • response_format: mp3, wav, opus, flac, or pcm
  • language: Optional ISO code

Response format

On success, the API returns the audio file directly in the response body with the appropriate content type (e.g., audio/mpeg). You can save this binary data directly to your server or serve it immediately for playback.

Using the OpenAI SDK

Sound wave illustration for: Using the OpenAI SDK

The CivicVoice API mirrors the OpenAI speech endpoint structure, allowing agencies to leverage familiar tooling without learning a new syntax. By simply adjusting the base URL, you can direct requests to our infrastructure using existing code patterns.

This compatibility allows development teams to use standard HTTP clients or the official OpenAI libraries.

Base URL change

Point your client to https://api.pigpgthai.com/v1 instead of the default OpenAI endpoint. This single configuration change routes all speech requests to the CivicVoice API while maintaining the same JSON request and response shapes.

The API key remains the standard Bearer token in the Authorization header, ensuring seamless authentication without additional middleware.

Client setup

Initialize your OpenAI SDK client by passing the new base URL and your unique API key. This allows you to use standard methods like client.audio.speech.create() to generate audio files from text inputs.

Ensure your key starts with tts- and is set in the environment or passed directly to the client constructor for immediate use in your agency’s internal tools.

SDK compatibility

The official OpenAI SDKs work correctly with this API because the request payload structure is identical. You can use tts-1 or tts-1-hd as the model value just as you would with OpenAI.

Use standard voice IDs like 'aria' or 'nova' as documented in the voices section.

Request parameters

Sound wave illustration for: Request parameters

Configure the core behavior of your synthesis requests by selecting the appropriate model, voice, and speed. These parameters determine the audio quality, character, and pacing of the generated speech, ensuring the output aligns with your accessibility standards.

Model selection

Choose between "tts-1" for standard efficiency or "tts-1-hd" for higher fidelity. Both models use the same engine and pricing, so you can switch based on your specific clarity needs without changing your cost structure.

Voice selection

Select from eight presets, such as "aria" for warm narration or "atlas" for neutral news delivery. Each voice can speak all 23 supported languages.

Speed control

Adjust the speed parameter between 0.25 and 4.0 to control playback rate. Slower speeds may improve comprehension for auditory learners, while faster rates help reduce processing time for large document batches.

Response formats

Sound wave illustration for: Response formats

The API returns audio files directly in the response body, allowing your agency’s systems to receive and store sound files without additional steps. You can choose the format that best fits your accessibility requirements or storage constraints.

All generated files include an inaudible watermark to identify them as synthetic speech, which is useful for transparency in public communications.

MP3

MP3 is the default and most widely supported format. It is widely supported.

Use this format when you need to embed audio in web pages or send files via email.

  • Supported by all major browsers and devices
  • Smallest file size among lossy formats

WAV

WAV provides uncompressed audio, ensuring maximum fidelity for archival purposes or high-quality playback systems.

It is useful when you need to process the audio further with other tools that require raw data.

  • Lossless quality
  • Larger file size compared to MP3

Other formats

You can also request Opus, FLAC, or PCM formats. Opus offers efficient compression, FLAC provides lossless compression, and PCM gives raw audio data.

Select the format that aligns with your technical infrastructure and quality needs.

  • Opus: efficient compression
  • FLAC: lossless compression
  • PCM: raw audio data

Handling errors

Sound wave illustration for: Handling errors

Errors are categorized by their cause. Rate limits block excess requests, invalid input rejects malformed data, and server errors indicate temporary processing issues.

Always check the response status code to determine the appropriate handling strategy. Failed synthesis requests are free, ensuring you are not charged for errors.

Rate limits

Your key allows 60 requests per minute. Before your first top-up, this limit is 10 requests per minute.

  • Monitor the X-RateLimit-Remaining header.

Invalid input

Requests fail if the text exceeds 4096 characters, the voice is unknown, or the speed is outside 0.25–4.0.

  • Ensure input is a valid string.

Server errors

Temporary issues return a 5xx code. The charge is refunded automatically if synthesis fails completely.

  • Retry with exponential backoff.

Rate limits

Sound wave illustration for: Rate limits

CivicVoice API enforces a rate limit of 60 requests per minute per API key. This limit applies uniformly regardless of the model selected, ensuring predictable throughput for your accessibility workflows. New accounts without a top-up start with a lower limit of 10 requests per minute.

Understanding these constraints helps you plan batch conversions for public documents without hitting bottlenecks during peak usage hours. You can monitor your current usage and limits directly from your dashboard after signing in.

Requests per minute

The standard limit is 60 requests per minute. Before your first top-up, this limit is reduced to 10 requests per minute to manage load during the trial period.

Queue behavior

Requests are processed sequentially within the limit. Under heavy load, additional requests may wait in a queue before processing begins. Short phrases typically take a few seconds to generate, while longer texts process at roughly real-time speed (25 characters per second).

Backoff strategy

If you exceed the limit, you will receive a 429 Too Many Requests error. Implement exponential backoff in your integration to retry automatically. Increasing your limit to 60 requests per minute is immediate after topping up your balance via USDT on the TRON network (TRC-20).

Voices and languages

Sound wave illustration for: Voices and languages

CivicVoice API supports 23 languages, including English, Spanish, French, German, Arabic, Chinese, Japanese, and Hindi. Any voice can speak any supported language, ensuring consistent audio quality across diverse public communications. If the language field is omitted, the system guesses the language from the script; for Latin-script text outside English, explicitly set this parameter to avoid misidentification.

Unsupported languages include Vietnamese, Indonesian, Thai, Ukrainian, Romanian, Czech, and Bengali. For multi-language texts, you may need to split requests to ensure accurate pronunciation and tone for each segment.

List voices

The API provides eight distinct voice presets, divided into female and male options. These voices are available for reading public notices, emergency alerts, or informational content.

You can select any voice for any supported language. The voice selection is independent of the language code, allowing for flexible combinations in multilingual contexts.

  • 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

Language codes

Use standard ISO 639-1 language codes in the language field. While the API can guess the language from the input text, explicitly setting the code ensures accuracy, especially for less common languages or mixed-script texts.

Supported languages cover a broad range of global communication needs, from major European languages to key Asian and Middle Eastern tongues. This list is fixed and does not include all possible languages.

  • Arabic (ar)
  • Chinese (zh)
  • Danish (da)
  • Dutch (nl)
  • English (en)
  • Finnish (fi)

Voice descriptions

Each voice has a specific tone profile. For instance, atlas is neutral and suitable for news, while luna is soft and ideal for storytelling. Choose voices that match the context of your public communications.

The voices are based on licensed recordings from LibriTTS-R and LibriVox, ensuring high-quality, natural-sounding speech. Each generated audio file contains an inaudible watermark to identify it as synthetic speech.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Streamline public service delivery through transparent collaboration between government agencies and non-profit partners to enhance citizen trust and operational efficiency.

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. W3C WAI: making audio and video accessible
  3. TRON developer hub: TRC-20
  4. LibriVox public-domain audiobooks
  5. Tether (USDT)
  6. Node.js documentation
  7. MDN: Web Speech API
  8. LibriTTS-R corpus (OpenSLR 141)
  9. Creative Commons Attribution 4.0
  10. Python documentation
  11. curl documentation
  12. ISO 639 language codes

More on this site