Documentation for Text to Speech Library Python

By LMS TTS Guide editorial team · Updated 2026-11-19

This page provides a practical guide for product teams integrating synthetic speech into online courses and LMS content. We focus on the Python workflow, showing you how to connect the OpenAI SDK to our API, handle audio responses, and scale efficiently for educational audio generation.

You will learn how to manage your API key, understand rate limits, and choose the right voice and format for your modules. The documentation covers essential fields, error handling, and cost-effective scaling, ensuring you can generate high-quality audio files directly into your learning platform.

Documentation for Text to Speech Library Python

Frequently asked questions

How do I get an API key?

Sign up on the /get-api-key/ page using Google or an email and password. Your account is specific to okwe.info. The dashboard displays your active API key, starting balance, and usage statistics immediately after creation.

Can I use the official OpenAI Python SDK?

Yes. The API endpoint matches the OpenAI speech format. You can use the official OpenAI Python SDK by changing the base_url to https://api.okwe.info/v1 and providing your API key for authentication.

What is the base URL for the API?

The API base URL is https://api.okwe.info/v1. You send POST requests to https://api.okwe.info/v1/audio/speech for synthesis. Other endpoints like /v1/voices and /v1/models are also available under this base path.

Which audio formats are supported?

You can request audio in mp3, wav, opus, flac, or pcm formats. Specify your preferred format using the response_format field in your JSON request body. These options cover most LMS audio player requirements.

What is the difference between tts-1 and tts-1-hd?

Both models use the same underlying engine and incur the same price of $10 per 1 million characters. The choice between tts-1 and tts-1-hd is purely based on your quality preference, with no cost difference.

How do I specify a language in the request?

Include the optional language field with an ISO code in your request. If omitted, the system guesses the language, defaulting to English for Latin script. Explicitly setting it ensures accuracy for non-English Latin texts.

What happens if I exceed the rate limit?

The limit is 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 is processed.

Are failed requests returned with an error code?

Yes. If synthesis fails, you receive an error response. Crucially, the charge for that request is returned in full, so you are not billed for failed audio generations.

Can I use the API with async Python?

Yes. Since the API is a standard REST endpoint, you can use any Python HTTP library, including async ones like httpx or aiohttp. The official OpenAI SDK also supports async operations via the base_url override.

How do I handle long texts over 4096 characters?

Split your text into chunks of up to 4096 characters. Generate audio for each chunk separately, then join the resulting audio files. This ensures each request stays within the character limit per synthesis call.

Is the audio returned in the response body?

Yes. The generated audio file is returned directly in the response body. The audio is not stored on our servers; it is delivered immediately upon successful synthesis for your LMS integration.

Do I need to install any special libraries?

No special proprietary libraries are required. You can use the official OpenAI Python SDK or any standard HTTP client. Just point the SDK to our base URL and use your API key.

What is the maximum speed setting?

The speed parameter accepts values between 0.25 and 4.0. This allows you to adjust the speech rate to suit different learning contexts, from slow instructional clarity to faster review sessions.

Are there any limits on the number of voices?

You can choose from 8 preset voices: Aria, Nova, Luna, Sage, Felix, Milo, Atlas, and Orion. There is no limit on how many different voices you can use across your requests or projects.

First request

curl

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

Quickstart: Get Your Key

Sound wave illustration for: Quickstart: Get Your Key

Ready to add synthetic speech to your LMS course? Start by visiting the /get-api-key/ page to create your account. You can sign up using Google or your email. This account is specific to okwe.info and gives you access to the TTS API.

Once registered, you will receive a unique Bearer token. This token authenticates your API requests. Keep it secure, as it grants access to your account's credit and usage data.

Sign Up on /get-api-key/

Sign Up on /get-api-key/

Navigate to /get-api-key/ on okwe.info. You can create an account using Google for quick access or via email and password. Accounts are tied to this specific site.

Sign-up is the first step to generating audio for your educational content. No credit card is required to begin.

  • Google or email sign-up options
  • Account created per site

Retrieve Your Bearer Token

Retrieve Your Bearer Token

After signing up, you will be issued a Bearer token starting with 'tts-'. This token is used in the Authorization header of every API request.

You can issue a new key at any time. The old key stops working immediately, ensuring security if your token is exposed.

  • Token format: tts-...
  • Instant invalidation on new key generation

Check Your Balance

Your dashboard displays your current balance, trial status, and characters used. The free trial provides $0.50 credit (approx. 50,000 characters) for 7 days if signed up via Google.

Check this page to monitor your usage and ensure you have sufficient funds for your course audio production.

  • View real-time usage stats
  • See available credit

First Request with Curl

Sound wave illustration for: First Request with Curl

Before writing Python code, verify your API key works with a simple command-line call. This ensures your authentication and billing setup are correct before integrating into your LMS workflow.

Basic POST Request

Send a POST request to the speech endpoint with your text payload. Replace YOUR_API_KEY with your actual token from the dashboard.

  • Endpoint: https://api.okwe.info/v1/audio/speech
  • Method: POST
  • Header: Authorization: Bearer YOUR_API_KEY
  • Content-Type: application/json

Required JSON Fields

The request body must include the model and input fields. The voice parameter defaults to a preset if omitted, but specifying it ensures consistent course narration styles.

  • model: "tts-1" or "tts-1-hd"
  • input: Your course text (max 4096 chars)
  • voice: e.g., "aria", "nova", "felix"

Response Format

On success, the API returns the audio file directly in the response body with the specified response_format (e.g., mp3). Failed requests return an error JSON object and do not charge your balance.

Python Integration

Sound wave illustration for: Python Integration

Integrate synthetic speech into your LMS modules by pointing the OpenAI Python SDK to our API. This allows you to reuse familiar code structures for generating audio assets for online courses.

Using OpenAI SDK

Install the standard openai package and initialize the client. Since we mirror the OpenAI speech endpoint shape, you can use the official library without writing custom HTTP logic.

  • pip install openai
  • from openai import OpenAI

Setting Base URL

Configure the client to use https://api.okwe.info/v1 as the base URL. This directs requests to our infrastructure while maintaining compatibility with standard SDK methods.

Handling Audio Response

The API returns binary audio data. Save the response content directly to a file or stream it into your learning module player. Failed requests return zero balance deduction.

Supported Formats

Sound wave illustration for: Supported Formats

For online courses, MP3 offers a balance of quality and bandwidth efficiency, ensuring smooth playback across most LMS players and mobile devices. WAV files provide lossless audio, ideal for archival or high-fidelity editing needs, though they increase storage costs significantly.

Choose the format that aligns with your platform’s capabilities and your users’ connectivity. MP3 remains the standard for web delivery, while WAV suits local processing or strict quality requirements.

MP3 for Web

MP3 is a common choice for learning modules. It compresses audio efficiently without noticeable quality loss, making it perfect for streaming in standard LMS environments. Most modern browsers and learning platforms support MP3 out of the box, ensuring broad compatibility.

  • Recommended for web-based courses
  • Balances file size and audio clarity
  • Supported by nearly all LMS players

WAV for Quality

WAV files are uncompressed and deliver pristine audio quality. They are ideal if you need to edit the generated speech further or require lossless retention for academic or training materials. Be aware that WAV files are significantly larger than MP3s, which may impact download speeds.

Use WAV when audio fidelity is critical, such as in language learning modules where phonetic precision matters.

  • Lossless audio quality
  • Larger file sizes
  • Ideal for editing or archival

OPUS, FLAC, PCM Options

OPUS offers compression. Note that streaming or real-time partial audio is not supported by this API. FLAC provides lossless compression, retaining full quality while reducing file size compared to WAV. PCM is an uncompressed raw format, useful for specific audio processing pipelines or when minimal processing overhead is required.

Select these formats based on your specific technical requirements, such as bandwidth constraints or processing capabilities.

  • OPUS: efficient compression, low latency
  • FLAC: lossless compression
  • PCM: raw, uncompressed audio

Model Selection

Sound wave illustration for: Model Selection

Choose between the standard tts-1 and high-definition tts-1-hd models. Both utilize the same underlying engine and price. The choice depends on your specific production needs for online course narration versus high-fidelity learning materials.

tts-1 Model

The tts-1 model offers efficient synthesis for general educational content. It processes text at typical speeds, making it ideal for standard voiceovers where latency is less critical than cost efficiency.

tts-1-hd Model

Select tts-1-hd when clarity is paramount, such as for language learning modules or technical tutorials. The high-definition output provides slightly richer audio texture without changing the integration workflow.

Same Price for Both

Both models charge $10 per 1 million characters. You can switch between them freely without cost implications. This allows you to prototype with tts-1 and switch to tts-1-hd for final releases without budget adjustments.

Model Selection

Voice and Language

Sound wave illustration for: Voice and Language

Choosing the right voice ensures your learners stay engaged without feeling disconnected from the material. We offer eight distinct presets designed for educational clarity, ranging from warm narrators to calm instructional guides.

Each voice supports all 23 available languages, allowing you to maintain consistent tone across diverse course modules while keeping production costs predictable.

8 Preset Voices

Select from four female and four male voices optimized for clarity. Options include Aria for warm narration, Sage for instructional content, or Atlas for neutral news-style delivery.

Voices are derived from licensed LibriTTS-R recordings, ensuring high quality without licensing ambiguities for your LMS content.

  • Aria: Warm, clear narrator
  • Sage: Calm, instructional
  • Atlas: Neutral, news
  • Orion: Deep, documentary
  • Nova: Bright, upbeat
  • Felix: Energetic, promo
  • Luna: Soft, storytelling
  • Milo: Friendly, conversational

Optional Language Code

You can explicitly set the language parameter using ISO codes. This is recommended for non-English Latin-script text to prevent misinterpretation.

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

Automatic Language Guessing

If the language field is omitted, the API guesses the language based on the input script.

Latin script text defaults to English if no language is specified. For accurate delivery of non-English Latin text, always provide the language code.

Rate Limits

Sound wave illustration for: Rate Limits

Managing your API usage is straightforward with clear limits that prevent unexpected charges. You can generate up to 60 requests per minute using your active key, which is sufficient for most batch processing tasks in learning modules.

Be aware that requests are processed sequentially. If you send too many concurrent requests, they will wait in a queue until processing resources are available. This ensures fair access but may increase latency during high demand.

60 Requests per Minute

Your single active key allows 60 requests per minute. This limit applies to the POST /v1/audio/speech endpoint. Plan your batch sizes accordingly to stay within this threshold.

10 Requests Before Top-Up

New accounts start with a restricted rate limit of 10 requests per minute. This applies until you make your first top-up. Once you add funds via USDT (TRC-20), the limit increases to the full 60 requests per minute.

Queueing Under Load

Requests are processed one after another. Under heavy load, your request may wait in a queue. Long texts take roughly real-time to generate, so plan your integration to handle potential delays gracefully without blocking your application.

Error Handling

Sound wave illustration for: Error Handling

Handling errors ensures your LMS audio generation pipeline remains robust. Most issues stem from network timeouts, invalid JSON, or exceeding your account's usage limits. Always check the HTTP status code and read the error message body to diagnose the problem quickly.

We recommend implementing exponential backoff for transient network errors. For persistent issues like character limits or invalid voices, fix the input data before retrying to avoid wasting credits on repeated failures.

Common HTTP Errors

A 401 Unauthorized error indicates your Bearer token is missing or invalid. Ensure you are sending the correct key from your dashboard. A 429 Too Many Requests error means you have exceeded the rate limit (60 requests per minute for funded accounts, 10 before top-up). You must wait or split your batch into smaller chunks.

  • 401: Check your API key validity
  • 429: Implement exponential backoff
  • 500: Retry after a short delay

Character Limit Exceeded

Each request supports a maximum of 4096 characters. If your text exceeds this limit, the API returns an error. You should split longer texts into smaller segments in your Python code before sending them to the API.

Ensure you count spaces and punctuation as characters. Failed requests do not consume your balance, so you can safely retry after fixing the input length.

Invalid Voice Name

Using an unsupported voice name results in a 400 Bad Request. The eight valid presets are aria, nova, luna, sage, felix, milo, atlas, and orion. Verify your voice parameter against the /v1/voices endpoint before generating audio.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. This ensures consistent acoustic properties across all eight presets, making them reliable for educational content.

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. LibriVox public-domain audiobooks
  3. LibriTTS-R paper (arXiv 2305.18802)
  4. LibriTTS-R corpus (OpenSLR 141)
  5. Node.js documentation
  6. MDN: Web Speech API
  7. curl documentation
  8. ISO 639 language codes
  9. Python documentation
  10. Tether (USDT)
  11. openai-python on GitHub
  12. FFmpeg documentation

More on this site