Text-to-Speech API: Integration Guide & SDK Examples

By LexiaFlow editorial team · Updated 2026-11-18

This guide explains how to integrate the LexiaFlow text-to-speech API into your online course platform or LMS. You will find concrete examples for authenticating requests, selecting voices, and handling responses using standard HTTP or the official OpenAI SDK.

Engineers can quickly implement speech synthesis for e-learning content by following these steps. We cover key parameters like model selection, language codes, and rate limits, ensuring you understand the technical constraints before production deployment.

Text-to-Speech API: Integration Guide & SDK Examples

Frequently asked questions

How do I get an API key?

Sign up on /get-api-key/ using Google or email. Accounts are per site. You receive one active key, visible on the dashboard. A new key issued stops the old one immediately. Google sign-ups include a $0.50 trial valid for 7 days. Email accounts start without trial credit.

Can I use the Python OpenAI SDK?

Yes. The endpoint matches the OpenAI speech endpoint shape. Change the base_url to https://api.bd7777apk.com/v1 and use your site’s key. The official OpenAI SDKs work directly with this configuration. No custom SDK is required for integration.

What is the maximum text length?

Each request supports up to 4096 characters. For longer texts, split the input into parts of this size and join the resulting audio files. Spaces and punctuation count toward the character limit. This ensures consistent processing and billing accuracy.

How do I specify a language?

Pass the optional ISO code in the request body. If omitted, the system guesses the language, defaulting to English for Latin script. For non-English Latin text, always set the language parameter. Supported languages include English, Spanish, German, and 20 others.

Is the response format configurable?

Yes. Use the response_format field to select mp3, wav, opus, flac, or pcm. This parameter is part of the standard request JSON. The API returns the audio file in the chosen format directly in the response body.

What happens if I exceed the rate limit?

The limit is 60 requests per minute per key. Requests are processed sequentially, so excess requests may wait in a queue. If synthesis fails, the charge is returned in full. Ensure your integration handles potential delays during high load.

Do I need a header for the API key?

Yes. Include the header Authorization: Bearer tts-... with your key. This authenticates your requests to the API endpoint. Without this header, requests will be rejected. Ensure the key is active and matches your account.

Can I generate audio in parallel?

Requests are processed one after another. Under load, a request may wait in a queue. While you can send multiple requests, they are handled sequentially. This affects total generation time for large batches.

Is there a SDK for mobile apps?

No. There is no official mobile SDK. Use the OpenAI SDK or plain HTTP requests. The API endpoint is standard, so any HTTP client can integrate directly. No specific mobile library is provided.

How do I handle long texts?

Split texts into parts of up to 4096 characters. Generate audio for each part separately. Then join the resulting audio files. This ensures each request stays within the character limit and processes correctly.

What is the audio generation speed?

Typical speed is roughly real time, about 25 characters per second. Short phrases take a few seconds. Requests are processed sequentially, so under load, generation may wait in a queue. Actual speed depends on system load.

Can I use my own voice model?

No. Custom voice cloning is not offered. You can choose from 8 preset voices based on licensed recordings. Voices cannot be customized or uploaded by customers. The system uses fixed presets for all generations.

Is SSML supported in requests?

No. SSML is not supported. The API accepts plain text input. There are no emotion tags or phoneme dictionaries. Use the standard text field for your content. Voice selection and speed are the only customization options.

How do I check my balance via API?

The dashboard shows balance, characters left, and usage. There is no specific API endpoint for balance checks. View your account details on /get-api-key/ or the dashboard page. Request metadata is kept for billing but not exposed via API.

First request

curl

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

Secure access to the LexiaFlow TTS API requires a valid API key. You can generate your key on the /get-api-key/ dashboard, where you will also find your current balance and usage statistics.

Include the key in every request header using the format Authorization: Bearer tts-.... This token authenticates your account and tracks your character consumption against your paid balance.

Generate key on /get-api-key/

Generate key on /get-api-key/

Visit the /get-api-key/ page to create your API key. New accounts receive a $0.50 trial credit valid for 7 days if signed in with Google. Email-based accounts start without trial credit.

Bearer token authorization

Bearer token authorization

Pass your key as a Bearer token in the Authorization header. The API validates this token before processing your speech synthesis request. Keep this key secure and do not expose it in client-side code.

Single active key per account

Each account holds one active key at a time. You can issue a new key from the dashboard at any time; the previous key becomes invalid immediately. This ensures tight control over access if a key is compromised.

  • Revoking a key stops access instantly.
  • Issuing a new key invalidates the old one immediately.

Endpoint and Request Structure

Sound wave illustration for: Endpoint and Request Structure

The synthesis endpoint accepts POST requests to https://api.bd7777apk.com/v1/audio/speech. You send a JSON payload containing the text to convert and receive an audio file. This structure mirrors the OpenAI speech endpoint, allowing you to use existing OpenAI SDKs by simply updating the base_url.

Each request supports up to 4096 characters. For longer texts, split the input into chunks and join the resulting audio files. Failed requests incur no charge, ensuring you only pay for successful synthesis.

POST /v1/audio/speech

Send a POST request to https://api.bd7777apk.com/v1/audio/speech. Include your API key in the Authorization header as a Bearer token. The response returns the generated audio file directly.

JSON body with model, input, voice

The request body requires model, input, and voice. Use tts-1 or tts-1-hd for the model. The input field contains your text (max 4096 characters). Select one of the 8 preset voices for the output style.

  • model: "tts-1" or "tts-1-hd"
  • input: string, max 4096 characters
  • voice: one of 8 presets (e.g., aria, nova)

Optional speed and language fields

Adjust speed between 0.25 and 4.0 to control playback rate. Specify language using an ISO code for accurate synthesis, especially for non-English Latin script text. If omitted, the system guesses the language from the script.

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

Model Selection

Sound wave illustration for: Model Selection

To select the synthesis engine, choose either tts-1 or tts-1-hd in the model field. Both utilize the same underlying engine and voice presets, differing only in audio fidelity settings.

tts-1 standard engine

The tts-1 model is the default choice for most integrations. It provides clear, natural speech suitable for standard e-learning modules and LMS voiceovers without unnecessary overhead.

tts-1-hd high definition

Use tts-1-hd when higher audio fidelity is required. This setting is ideal for premium course content where clarity and nuance are critical, though it does not change the engine behavior.

Same price and speed for both

Both models generate audio at roughly the same speed (approx. 25 characters per second) and incur identical charges. Since pricing is based on character count, switching between tts-1 and tts-1-hd does not affect your billing or rate limits.

  • Character count remains the only billing metric
  • Processing time is consistent across both models
  • No performance difference in queue wait times

Voice and Language Parameters

Sound wave illustration for: Voice and Language Parameters

Configure voice and language parameters to match your course content’s tone and audience. The API supports 8 preset voices, including female options like Aria and Luna, and male options like Felix and Atlas. These voices are designed for clarity and reliability in educational contexts.

8 preset voices (Aria, Felix, etc.)

Select from eight distinct voice profiles tailored for different instructional styles. Options include Aria (warm narrator), Nova (upbeat), Luna (storytelling), Sage (instructional), Felix (energetic), Milo (conversational), Atlas (neutral news), and Orion (deep documentary). Each voice is based on licensed recordings from LibriVox.

  • Female: Aria, Nova, Luna, Sage
  • Male: Felix, Milo, Atlas, Orion

Optional ISO language code

Specify the language parameter using an ISO 639-1 code (e.g., en, de, ja). This ensures accurate pronunciation for the 23 supported languages, including Arabic, Chinese, French, German, Hindi, Japanese, Korean, Russian, Spanish, and others. Explicitly setting the language prevents misinterpretation, especially for mixed-language content.

Automatic detection for Latin script

If the language field is omitted, the system guesses the language based on the input script. Latin script text defaults to English. For non-English Latin-script text (e.g., German or French), always set the language parameter to ensure correct accent and prosody. Non-Latin scripts are handled automatically where supported.

Response Formats

Sound wave illustration for: Response Formats

The API returns synthesized audio in five supported formats: mp3, wav, opus, flac, and pcm. You specify the desired format via the response_format field in the JSON request body.

MP3 for web delivery

MP3 is the standard choice for web playback due to its balance of quality and file size. It is ideal for embedding audio directly into LMS course players or streaming to mobile devices where bandwidth efficiency matters.

WAV and FLAC for high quality

WAV provides uncompressed PCM audio, while FLAC offers lossless compression. Use these formats when you need pristine audio for archival purposes, professional voiceovers, or further editing in post-production pipelines without generational loss.

PCM and Opus for streaming prep

PCM returns raw linear audio data, useful for low-level processing. Opus provides efficient compression suitable for streaming applications. Note that while these formats support streaming workflows, this API does not offer real-time WebSocket streaming; audio is generated and returned upon completion.

Response Formats

Rate Limits and Queuing

Sound wave illustration for: Rate Limits and Queuing

The API enforces a strict limit of 60 requests per minute per key to ensure stable processing for engineering teams. This throughput is sufficient for most LMS content generation workflows without requiring complex client-side rate limiting logic.

60 requests per minute per key

After account activation, you can send up to 60 requests per minute. This limit applies globally to the single active key associated with your account.

10 requests/min before top-up

New accounts or those without recent top-ups are limited to 10 requests per minute. This restricts rapid bulk generation until a USDT (TRC-20) top-up is processed.

Requests processed in queue order

Requests are processed sequentially. Under high load, your request may wait in a queue before synthesis begins. Plan your batch sizes accordingly to avoid latency spikes during peak usage.

Error Handling and Retries

Sound wave illustration for: Error Handling and Retries

Synthesis errors return standard HTTP error codes (4xx/5xx). Failed requests are free: if the engine cannot generate audio, the character count is not deducted from your balance.

Failed requests are free

When a request fails, the charge is returned in full. You can retry the same text without incurring additional costs for the failed attempt.

  • Zero cost for failed synthesis
  • Automatic refund to balance

Standard HTTP error codes

The API returns standard HTTP status codes to indicate success or failure. Use these codes to trigger retry logic in your engineering workflows.

No charge on synthesis failure

Character consumption only occurs on successful audio generation. This ensures you only pay for usable output, reducing waste during integration testing.

OpenAI SDK Integration

Sound wave illustration for: OpenAI SDK Integration

Use the official OpenAI SDKs by pointing them to our API base. This allows engineering teams to integrate LexiaFlow with minimal code changes, leveraging familiar libraries for seamless deployment in their LMS or course platforms.

Change base_url to api domain

Update your SDK configuration to use https://api.bd7777apk.com/v1 as the base URL. Ensure your Authorization header includes your unique Bearer token (tts-...) obtained from the /get-api-key/ dashboard.

Use official OpenAI SDKs

Standard OpenAI client libraries (Python, Node.js, etc.) work directly with this endpoint. No proprietary SDK is required; simply import the standard speech module and configure the environment variables for your API key and base path.

Compatible request shape

The JSON body matches the standard speech endpoint structure. Pass model, input, voice, and optional speed or language fields exactly as you would for OpenAI, ensuring your existing integration scripts remain valid.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Our platform empowers startups to deliver engaging online courses through an intuitive learning management system.

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. openai-python on GitHub
  3. OpenAI API reference: create speech
  4. TRON developer hub: TRC-20
  5. Python documentation
  6. Creative Commons Attribution 4.0
  7. LibriVox public-domain audiobooks
  8. LibriTTS-R corpus (OpenSLR 141)
  9. curl documentation
  10. FFmpeg documentation
  11. Node.js documentation
  12. ISO 639 language codes

More on this site