Python API Quickstart Guide for Text to Speech Synthesis

By LinguaSpeak editorial team · Updated 2026-11-19

This guide helps online course creators and LMS admins generate clear, human-like narration for lessons using a simple Python module. You will learn how to turn written content into audio files with minimal setup, leveraging the OpenAI SDK (by changing the base URL) or basic HTTP requests. We cover practical workflows, from authenticating with your API key to handling long texts that exceed the 4,096-character limit.

You will also find details on selecting from eight voice presets, adjusting speech speed, and choosing audio formats like MP3 or WAV. The documentation explains rate limits, error handling, and pricing specifics so you can integrate audio generation seamlessly into your course materials without needing complex voice design tools or custom cloning features.

Python API Quickstart Guide for Text to Speech Synthesis

Frequently asked questions

How do I get my API key?

Sign up on the /get-api-key/ page using Google or email. Your key starts with tts- and is used for authentication. You can issue a new key at any time, which immediately invalidates the old one. Accounts are specific to this site.

What is the base URL for the API?

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

Can I use the OpenAI Python SDK?

Yes. The endpoint shape matches the OpenAI speech endpoint. You can use the official OpenAI SDK by changing the base_url to https://api.mw306r.info/v1 and providing your site-specific API key. No custom module is required.

What audio formats are supported?

You can choose from mp3, wav, opus, flac, or pcm. Set the response_format field in your request body to select your preferred output format. All formats are generated using the same underlying engine.

What is the rate limit for requests?

You are limited to 60 requests per minute per key. If you have not topped up your account, the limit is 10 requests per minute. Exceeding the limit will result in errors until the window resets.

How do I handle errors in Python?

Standard HTTP error codes are returned for issues like rate limits or invalid input. Failed synthesis requests are free, and the charge is returned in full. Check the response status code to determine if the request succeeded.

Can I change the speaking speed?

Yes, you can adjust the speed between 0.25 and 4.0. Set the speed field in your request body. This allows you to make narration faster for quick reviews or slower for detailed lessons.

How do I set the language?

Pass the ISO code in the language field. If omitted, the system guesses the language, defaulting to English for Latin script. For non-English Latin text, always set the language to ensure correct pronunciation.

What is the character limit per request?

Each request supports up to 4096 characters of input text. Spaces and punctuation count toward this limit. For longer texts, you must split the content into chunks of this size and join the resulting audio files.

How do I split long texts?

Split your text into parts of up to 4096 characters. Send each part as a separate request to the speech endpoint. Then, join the returned audio files to create the final narration for your course.

Is there a difference between tts-1 and tts-1-hd?

No. Both model values use the same engine and have the same price. You can use either tts-1 or tts-1-hd in your requests without any difference in cost or processing speed.

Do I need to install a specific module?

No. You can use the official OpenAI Python SDK or plain HTTP requests. There is no dedicated LinguaSpeak module required. Just configure the base URL and authentication header in your existing library setup.

How do I pass the API key in Python?

Include the header Authorization: Bearer tts-... in your requests. Replace ... with your actual key obtained from the dashboard. This authenticates your account and allows you to generate speech from your text input.

What happens if I exceed the rate limit?

Requests will fail with an error status code. You must wait for the rate limit window to reset before sending more requests. Ensure your code handles these errors gracefully to avoid unnecessary retries during high load.

First request

curl

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

Get Your API Key

Sound wave illustration for: Get Your API Key

To start generating audio for your online courses, visit the /get-api-key/ page on mw306r.info. You can sign up using your Google account or create a standard email and password account. This gives you immediate access to the API key needed for authentication.

Sign Up via Google or Email

Sign Up via Google or Email

Google sign-ups include a $0.50 free trial valid for 7 days, allowing you to test the service with about 50,000 characters. Email-based accounts start with zero credit. You can top up later using USDT on the TRON network.

Locate Key in Dashboard

Locate Key in Dashboard

Once logged in, the dashboard displays your active API key, current balance, and usage statistics. The key starts with tts- and is used in the Authorization: Bearer header. You can copy this directly into your Python scripts or LMS integrations.

Issue New Key if Needed

If your key is compromised or you want to rotate credentials, you can issue a new key from the dashboard. The old key stops working immediately, ensuring your course audio generation remains secure without downtime.

Make Your First Request

Sound wave illustration for: Make Your First Request

Once you have your API key, you can verify it works with a simple request. This quick test confirms your credentials and credits are active before you integrate the API into your LMS workflow.

For developers preferring a standard HTTP library, the Python requests module offers a straightforward way to send text and receive audio files directly in your scripts.

cURL Example for Quick Test

Use this command to verify your key and balance. Replace YOUR_API_KEY with your actual token.

```bash curl -X POST https://api.mw306r.info/v1/audio/speech \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "tts-1", "input": "Hello from LinguaSpeak", "voice": "nova", "response_format": "mp3"}' \ -o speech.mp3 ```

  • Ensure YOUR_API_KEY starts with tts-
  • The output file speech.mp3 contains the generated audio
  • Check the terminal for a 200 OK status

Python Requests Library Example

Import the requests library to handle the HTTP POST. Set the base URL to https://api.mw306r.info/v1 and include your authorization header.

Send the JSON payload and save the binary response to a file. This method works well for batch processing lesson scripts in your LMS.

  • import requests
  • headers = {'Authorization': 'Bearer YOUR_API_KEY'}
  • response = requests.post(url, json=payload, headers=headers)
  • open('audio.mp3', 'wb').write(response.content)

JSON Body Structure

The request body is a JSON object containing four required fields: model, input, voice, and response_format.

model accepts tts-1 or tts-1-hd. input is your text (max 4096 characters). voice selects from eight presets. response_format supports mp3, wav, opus, flac, or pcm. Optional fields include speed (0.25–4.0) and language (ISO code).

  • model: 'tts-1' or 'tts-1-hd'
  • input: string, max 4096 chars
  • voice: e.g., 'nova', 'aria'
  • response_format: 'mp3', 'wav', etc.

Using the OpenAI SDK

Sound wave illustration for: Using the OpenAI SDK

The OpenAI Python SDK handles text-to-speech seamlessly by simply redirecting its base URL. This lets you use the same client.audio.speech method without learning new classes or complex configurations.

You only need to point the SDK to our API endpoint. The request shape matches the official standard, so your existing code structure works immediately.

Change Base URL

Set the base_url to https://api.mw306r.info/v1 when initializing your OpenAI client. This directs all speech requests to our infrastructure while keeping the familiar SDK interface.

This single change allows you to use the official openai Python package to generate audio files for your online courses.

  • base_url="https://api.mw306r.info/v1"
  • No need to install a custom library

Use Official SDK Methods

Call client.audio.speech.create() exactly as you would for OpenAI. Pass your model, input text, voice, and response_format parameters.

The SDK handles the JSON serialization and HTTP POST to https://api.mw306r.info/v1/audio/speech automatically.

Pass API Key Correctly

Provide your API key via the api_key parameter in the client initialization. Use your tts-... key from the dashboard.

Ensure the key is passed as a string without the Bearer prefix; the SDK adds it automatically.

Supported Audio Formats

Sound wave illustration for: Supported Audio Formats

For most online course workflows, MP3 is the go-to format because it plays smoothly in any browser or LMS player while keeping file sizes manageable. It is the default choice for delivering audio lessons to students without requiring extra plugins.

MP3 for Web Playback

Use MP3 when you need broad compatibility across devices. It is a common choice for delivering audio lessons to students without requiring extra plugins.

WAV for High Quality

WAV provides uncompressed audio, ideal if your LMS requires lossless files for editing or archival purposes. It results in larger files but ensures no data loss during playback.

OPUS and FLAC Options

OPUS offers efficient compression suitable for low-bandwidth student connections, while FLAC provides lossless compression for professional-grade audio needs. Choose these if your specific workflow demands either extreme efficiency or perfect fidelity.

Handling Errors and Limits

Sound wave illustration for: Handling Errors and Limits

This API enforces usage limits. You can send up to 60 requests per minute per key. New accounts start with a lower limit of 10 requests per minute until the first top-up is processed.

Rate Limit: 60 Requests/Min

Each API key allows a maximum of 60 requests per minute. If you exceed this threshold, subsequent requests will be rejected with a 429 status code. This limit applies to all endpoints, including speech synthesis and voice listing.

  • Standard limit: 60 requests per minute.
  • New accounts start at 10 requests per minute.
  • Limit resets automatically after 60 seconds.

Queue Behavior Under Load

Requests are processed sequentially. During high traffic, your request may wait in a queue before synthesis begins. Short phrases typically take a few seconds to generate, while longer texts process at roughly real-time speed (25 characters per second).

  • Processing is sequential, not parallel.
  • Queues may form during peak usage.
  • No SLA or uptime guarantee is provided.

Character Limit: 4096 Chars

Each request supports a maximum of 4096 characters in the input field. This includes spaces and punctuation. For longer lessons, split your text into smaller parts and join the resulting audio files later.

  • Max input: 4096 characters per request.
  • Spaces and punctuation count towards the limit.
  • Split long texts manually or via script.
Handling Errors and Limits

Voice and Language Parameters

Sound wave illustration for: Voice and Language Parameters

To tailor your course narration, pick from eight distinct voice presets. Female voices include Aria for clear narration, Nova for upbeat content, Luna for storytelling, and Sage for instructional modules. Male options feature Felix for energetic promos, Milo for conversational tones, Atlas for neutral news, and Orion for deep documentary styles.

Any voice can speak any of the 23 supported languages. You can also adjust the playback speed between 0.25 and 4.0 to match your audience’s preference, ensuring lessons are neither too slow nor too rushed.

Select Voice from 8 Presets

Each voice offers a specific tone suitable for different lesson types. Use Aria for clear, warm narration or Sage for calm, instructional segments. For promotional course updates, Felix provides an energetic boost, while Orion suits deeper, documentary-style content.

  • Aria: Warm, clear narrator
  • Nova: Bright, upbeat
  • Luna: Soft, storytelling
  • Sage: Calm, instructional
  • Felix: Energetic, promo
  • Milo: Friendly, conversational

Set Language ISO Code

The API supports 23 languages, including English, Spanish, German, French, Japanese, and Chinese. While the system guesses the language from the script, it is best practice to explicitly set the language parameter for non-English Latin text to ensure accurate pronunciation.

Not all languages are supported. Vietnamese, Thai, and Ukrainian are not available. If you need one of these, you may need to handle pronunciation manually or use a different tool.

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

Adjust Speed from 0.25 to 4.0

The speed parameter allows you to control the playback rate from 0.25 to 4.0. This is useful for adjusting the pacing of complex lessons or speeding up repetitive content. Faster speeds do not significantly reduce processing time, but character counts remain the same.

Speed adjustments do not affect the audio quality or the character count billed to your account. You can experiment with different speeds to find the optimal listening experience for your students.

Models: tts-1 and tts-1-hd

Sound wave illustration for: Models: tts-1 and tts-1-hd

The API offers two model identifiers, "tts-1" and "tts-1-hd," which are functionally identical. They use the same underlying engine and incur the same price of $10 per 1 million characters. You can switch between them without affecting your audio quality or billing.

Same Engine, Same Price

Both model strings trigger the exact same synthesis process. The pricing remains constant at $0.01 per 1,000 characters regardless of which identifier you send.

Choose Based on Preference

Since the output is identical, you can simply pick one and stick with it, or toggle between them for testing purposes. Most developers find it easier to standardize on "tts-1" for simplicity, but either string works perfectly with our API.

No Performance Difference

There is no difference in generation speed, latency, or audio fidelity between the two options. Your request will be processed at the same rate, and the resulting MP3 or WAV file will be indistinguishable in quality. Use whichever fits your code style best.

Splitting Long Texts

Sound wave illustration for: Splitting Long Texts

For lessons longer than 4096 characters, split your text into chunks and send each part separately. This ensures every segment stays within the single-request limit while maintaining consistent audio quality across your entire course module.

After generating all parts, join the audio files into one continuous file. This workflow lets you create seamless narration for long articles or multi-part lessons without hitting API constraints.

Split into 4096 Char Parts

Divide your text into segments of up to 4096 characters. Spaces and punctuation count toward this limit. Send each chunk as a separate request to the API.

Join Audio Files Later

Collect the returned audio files for each part. Concatenate them in your preferred editor or script to form a single, continuous lesson track. This keeps your LMS file structure clean.

Handle Part Boundaries

Split at natural pauses, like sentence ends, to avoid awkward cuts. The API processes requests sequentially, so longer texts may take time. Plan your splitting logic to minimize gaps between parts.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Premium voice models within these SDKs usually cost more than our standard or HD engines, increasing the budget for high-volume audio generation.

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. LibriTTS-R corpus (OpenSLR 141)
  3. LibriVox public-domain audiobooks
  4. IETF RFC 7845: Ogg Opus
  5. Node.js documentation
  6. Creative Commons Attribution 4.0
  7. LibriTTS-R paper (arXiv 2305.18802)
  8. ISO 639 language codes
  9. openai-python on GitHub
  10. MDN: Web Speech API
  11. W3C WAI: making audio and video accessible
  12. Python documentation

More on this site