Complete Python Integration Guide for Cloud Text-to-Speech API

By CashBlox editorial team · Updated 2026-11-19

This guide provides the technical specifications for integrating the ScriptRead text-to-speech API into Python applications, specifically for LMS administrators and development teams. It covers the complete request lifecycle, including authentication, endpoint configuration, and error handling, ensuring reliable audio generation for online course content.

Readers will find concrete examples for the openai Python SDK, detailing how to manage voice selection, speed adjustments, and format outputs like MP3 and WAV. The documentation addresses rate limits, character constraints, and language handling to help teams scale audio narration efficiently without operational overhead.

Complete Python Integration Guide for Cloud Text-to-Speech API

Frequently asked questions

How do I authenticate with the API?

Include an Authorization header with your Bearer token: Authorization: Bearer tts-.... Each account holds one active key. You can issue a new key at any time, which immediately invalidates the previous one. Ensure your key is sent with every request to the API endpoint for proper verification and billing attribution.

Can I use the OpenAI Python SDK?

Yes. The API uses the same request shape as the OpenAI speech endpoint. You can use the official OpenAI Python SDK by changing the base_url to https://api.cashblox.info/v1 and providing your site-specific API key. This allows you to leverage existing OpenAI client code with minimal configuration changes.

What is the base URL for the API?

The base URL is https://api.cashblox.info/v1. Use POST https://api.cashblox.info/v1/audio/speech for synthesis. Other endpoints include GET /v1/voices and GET /v1/models. Ensure your SDK or HTTP client is configured to point to this specific domain for all API interactions.

How do I specify a voice?

Pass the voice parameter in the JSON body with one of eight presets: aria, nova, luna, sage, felix, milo, atlas, or orion. These voices are based on licensed recordings from LibriTTS-R and LibriVox. You can retrieve the full list of available voices and their details via the GET /v1/voices endpoint.

What happens if I exceed the rate limit?

The limit is 60 requests per minute per key (10 per minute before the first top-up). Exceeding this may cause requests to fail. Failed requests are free, so you will not be charged for audio that fails to synthesize due to rate limiting or other errors.

How do I handle long texts?

Split your text into parts of up to 4096 characters. Send each part as a separate request and join the resulting audio files. Typical speed is roughly real-time, so long texts will take time to process. Requests are processed sequentially, so under load, you may experience queueing delays.

Is SSML supported?

No. The API does not support SSML, phoneme dictionaries, or custom pronunciation lexicons. You must provide plain text input. The system guesses the language from the script if not specified, but you cannot control prosody or pauses via markup. For precise control, manage pacing by splitting your text manually.

How do I set the language?

Include the language field with an ISO code in your request. If omitted, the system guesses the language, defaulting to English for Latin script. For non-English Latin text, explicitly set the language to ensure correct synthesis. 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.

What is the character limit per request?

Each request accepts up to 4096 characters in the input field. Spaces and punctuation count toward this limit. For longer texts, you must split the content into multiple requests, synthesize each part, and then concatenate the resulting audio files to create the final output.

How do I detect errors?

Check the HTTP status code and response body for error details. Failed requests are free, and any charges are returned in full if synthesis fails. Monitor your response codes to handle rate limits or invalid parameters appropriately. You can also check your account balance and usage via the dashboard.

Can I change my API key?

Yes, you can issue a new key at any time from your account dashboard. This is useful for security or rotation. When you generate a new key, the old one stops working immediately. Ensure your applications are updated to use the new key before the old one is invalidated.

What happens to the old key when I rotate?

The old key stops working immediately upon issuing a new one. There is no overlap period. Update your integration to use the new key as soon as possible. You can generate a new key from the /get-api-key/ page in your account settings at any time.

Is the response format configurable?

Yes. You can specify the response_format parameter as mp3, wav, opus, flac, or pcm. This allows you to choose the appropriate audio format for your application. You can override the format to suit your storage or playback requirements.

How do I test the API quickly?

Use the ready curl example provided on the /get-api-key/ page. You can also use the OpenAI Python SDK by setting the base_url to https://api.cashblox.info/v1. Your free trial includes $0.50 credit (about 50,000 characters) valid for 7 days if you signed in with Google.

First request

curl

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

Authentication

Sound wave illustration for: Authentication

Authentication for the ScriptRead TTS API relies on a single active Bearer token per account. This key is generated via the /get-api-key/ page and must be included in the HTTP Authorization header as Bearer tts-.... The token authenticates all requests to the https://api.cashblox.info/v1 base URL.

Each account maintains exactly one valid key at any time. You can rotate keys directly from the dashboard without downtime, as the new key becomes active immediately while the previous one stops working at once. This ensures strict control over API access for your LMS team.

Bearer token usage

Bearer token usage

Include your API key in the Authorization header of every request. Format the header as Authorization: Bearer YOUR_KEY_HERE. This token authorizes your account to send text inputs and receive audio files.

The token is tied to your account’s balance and rate limits. Ensure your CI/CD pipelines or LMS plugins store this credential securely to prevent unauthorized usage charges.

  • Header format: Authorization: Bearer tts-...
  • Base URL: https://api.cashblox.info/v1
  • Token type: Bearer string

Key rotation

Key rotation

Generate a new key from the /get-api-key/ dashboard page. The new key becomes active immediately upon creation.

The previous key stops working instantly. This allows for zero-downtime rotation in production environments where multiple services use the same API key.

  • Generate via dashboard
  • Instant activation
  • Old key invalid immediately

Single key limit

Each account is limited to one active API key at a time. This simplifies access management for large teams by centralizing credential control.

If you lose your key, simply generate a new one. The old key is invalidated immediately, ensuring no stale credentials remain active in your systems.

  • One key per account
  • Instant invalidation
  • Dashboard generation

Speech Endpoint

Sound wave illustration for: Speech Endpoint

The core functionality of the API is delivered through the speech endpoint, which accepts text input and returns generated audio files. This endpoint operates synchronously, processing requests sequentially, so under load, synthesis may queue. Long texts exceeding 4096 characters must be split by the client into smaller segments, which are then joined to form the final audio output.

Requests are structured as standard JSON payloads sent to the designated API base. The system processes these inputs to produce high-quality narration suitable for online course libraries, ensuring consistency across large educational content batches without requiring manual audio engineering.

POST /v1/audio/speech

Send a POST request to https://api.cashblox.info/v1/audio/speech with your Bearer token in the Authorization header. The endpoint accepts standard JSON bodies, compatible with the OpenAI SDK structure if you adjust the base URL to https://api.cashblox.info/v1.

Each request processes a single text segment up to 4096 characters. For longer course modules, split the text programmatically, generate each part, and concatenate the resulting audio files to maintain seamless playback for learners.

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

JSON body structure

The request body must include the text content, the voice model identifier, and the desired audio format. Optional parameters allow fine-tuning of the output speed and specifying the language to ensure correct pronunciation for non-English content.

All string fields must be properly encoded. The API validates the input character count against the 4096 limit before processing, ensuring predictable billing and delivery times for bulk generation tasks.

  • model: string ("tts-1" or "tts-1-hd")
  • input: string (text content)
  • voice: string (e.g., "aria", "nova")
  • response_format: string (mp3, wav, opus, flac, pcm)
  • speed: number (0.25–4.0)
  • language: string (optional ISO code)

Required fields

The model, input, voice, and response_format fields are mandatory for every request. Omitting any of these will result in an immediate error response, preventing unnecessary character consumption from your balance.

The input field accepts plain text up to 4096 characters. Spaces and punctuation count toward this limit. Ensure your client code strips or handles special characters appropriately before submission to avoid synthesis errors.

  • model: Required. Select "tts-1" or "tts-1-hd".
  • input: Required. Max 4096 characters.
  • voice: Required. Choose from 8 presets.
  • response_format: Required. Select audio codec.

Voice Models

Sound wave illustration for: Voice Models

Two model variants handle all synthesis requests. Both deliver identical audio quality and processing speed, differing only in the underlying encoding parameters.

tts-1 model

Standard model for general narration and course content. Suitable for most educational materials where minimal file size is preferred.

tts-1-hd model

High-definition model optimized for clarity. Recommended for complex instructional content or non-native speakers requiring precise articulation.

Same engine and price

Both models use the identical synthesis engine. Pricing remains constant at $0.01 per 1,000 characters regardless of the selected model variant.

  • Model selection does not affect billing.
  • Character count limits apply equally to both.
  • Audio quality differences are subtle.

Audio Formats

Sound wave illustration for: Audio Formats

The API returns audio in five supported formats: mp3, wav, opus, flac, and pcm. Selecting the appropriate format ensures compatibility with your LMS player and minimizes bandwidth usage for your course libraries.

Each format serves a specific technical need. MP3 and Opus are compressed formats, while WAV and FLAC provide uncompressed or lossless audio suitable for archival or professional editing workflows.

MP3 support

MP3 is the default and most widely compatible format for web-based audio players. It offers a balance between file size and audio quality, making it ideal for standard online course delivery.

Use the response_format: mp3 parameter to generate files that play seamlessly in most LMS environments without requiring additional codecs.

WAV support

WAV provides uncompressed PCM audio, preserving the full fidelity of the generated speech. This format is suitable when you need lossless audio for editing or high-quality playback.

Select response_format: wav if your audio pipeline requires raw data without compression artifacts.

Opus and FLAC

Opus offers high-quality audio at lower bitrates than MP3, reducing storage costs for large course libraries. FLAC provides lossless compression, smaller than WAV but fully reversible.

Use Opus for efficient storage and FLAC for archival purposes. Both formats ensure audio integrity while optimizing storage requirements.

Speed Control

Sound wave illustration for: Speed Control

Speed control allows your LMS to adjust narration pacing for different course types. The API accepts a speed value between 0.25 and 4.0, enabling precise synchronization with visual slides or detailed instructional segments. This ensures consistent audio quality across large-scale content libraries.

Range 0.25 to 4.0

The speed parameter accepts values from 0.25 (half speed) to 4.0 (quadruple speed). Standard narration operates at 1.0. Adjusting speed affects generation time; slower speeds may slightly increase processing duration, while faster speeds reduce it.

Default speed

If the speed field is omitted from the JSON body, the API defaults to 1.0. This provides a neutral, natural pacing suitable for most educational content without requiring explicit configuration for standard lecture videos.

Adjustment examples

For complex technical explanations, set speed to 0.8 to aid comprehension. For quick summaries or intro modules, increase speed to 1.5 to reduce total audio duration. Test pacing with short samples before batch processing large course catalogs.

Speed Control

Language Handling

Sound wave illustration for: Language Handling

Language handling in ScriptRead ensures accurate audio generation across 23 supported languages. You can explicitly define the language for precise control or rely on automatic detection for standard workflows.

ISO code setting

Set the language field in your request body using a valid ISO code (e.g., de, fr, es). This guarantees the engine selects the correct phonetic rules for any of the 23 supported languages, regardless of the voice preset used.

Auto-detection

If the language field is omitted, the API analyzes the input text script to determine the language. This reduces configuration overhead for multilingual content where the language varies per request.

Latin script default

Text written in Latin script defaults to English if no language is specified. For non-English Latin-script text (e.g., German or Spanish), you must explicitly set the language parameter to avoid incorrect English pronunciation.

Rate Limits

Sound wave illustration for: Rate Limits

Each API key supports a standard throughput of 60 requests per minute. This capacity accommodates batch processing for large course libraries without requiring complex queuing logic on the client side.

60 requests per minute

The standard limit allows your integration to process audio files at a consistent rate. This is sufficient for most LMS synchronization tasks where texts are segmented into 4096-character chunks.

10 requests initially

New accounts begin with a lower threshold of 10 requests per minute. This constraint applies immediately upon key generation to manage initial load on the infrastructure.

Limit increases after top-up

Upon successful top-up via USDT (TRC-20), the rate limit automatically scales to the standard 60 requests per minute. No manual verification or support ticket is required to lift the initial restriction.

Error Handling

Sound wave illustration for: Error Handling

Robust error handling ensures your LMS integration remains stable during high-volume course generation. Understanding response codes and implementing appropriate retry logic prevents unnecessary character consumption and maintains audio delivery consistency for your learners.

The API clearly distinguishes between client errors and server-side issues, allowing your system to react precisely without manual intervention or wasted credits on failed synthesis attempts.

HTTP status codes

Use standard HTTP status codes to determine the next step in your workflow. A 200 OK response confirms successful audio generation, while 400-level errors indicate invalid input, such as text exceeding the 4096-character limit.

Server errors (5xx) suggest temporary infrastructure issues. Your integration should log these events for later review without assuming permanent failure.

  • 200 OK: Audio generated successfully.
  • 400 Bad Request: Invalid parameters or character limit exceeded.
  • 401 Unauthorized: Invalid or expired API key.
  • 429 Too Many Requests: Rate limit exceeded (60 req/min).
  • 500-599 Server Error: Temporary infrastructure issue.

Retry logic

Implement exponential backoff for transient errors. Requests are processed sequentially, so under load a request may wait in a queue. Retry after 1-2 seconds for 429 errors, increasing delay up to 30 seconds for 5xx errors.

Avoid infinite loops. Stop retries after three attempts to prevent resource exhaustion in your LMS batch processing jobs.

  • Retry on 429 with 1-second delay.
  • Retry on 5xx with 2-second delay.
  • Maximum 3 retry attempts per request.
  • Log all retry events for audit trails.

Free failed requests

If synthesis fails due to a server error or invalid input that prevents audio generation, the charge is returned in full. You are not billed for characters processed in failed requests.

This ensures cost efficiency for large-scale course production, where occasional network glitches do not impact your monthly budget.

  • Failed requests are free.
  • Charge is returned in full.
  • No impact on character balance.
  • Ideal for high-volume batch processing.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. We prioritize email communication to handle detailed technical queries and billing questions efficiently.

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

More on this site