Python Quickstart Guide for Text to Speech API

By NarrativeNode editorial team · Updated 2026-11-19

This guide shows self-publishing freelancers how to convert manuscripts into audiobooks using the NarrativeNode TTS API. You will learn to install the OpenAI SDK, configure the base URL, and send text for synthesis. The examples use Python 3.8+ to generate narration files.

You will discover how to select from eight distinct voices, choose audio formats like MP3 or WAV, and manage rate limits. The documentation covers error handling and character-based pricing, ensuring you understand the costs for long-form content. Follow these steps to integrate reliable text-to-speech directly into your self-publishing pipeline.

Python Quickstart Guide for Text to Speech API

Frequently asked questions

How do I install the OpenAI SDK for Python?

Install the library using pip: pip install openai. This standard package allows you to interact with the NarrativeNode API by configuring the base URL. It is a way to send requests and receive audio files without writing custom HTTP code from scratch.

What is the correct base URL for the API?

Set your base URL to https://api.rx115.cc/v1. This endpoint replaces the default OpenAI URL in your SDK configuration. All requests, including speech synthesis and voice listing, are directed to this specific domain to ensure your API key works correctly with the NarrativeNode service.

Can I use the official OpenAI Python library?

Yes, the official OpenAI Python SDK works perfectly. You only need to change the base_url to https://api.rx115.cc/v1 and use your NarrativeNode API key. The request shape is identical to the OpenAI speech endpoint, so your existing code structure remains valid with minimal adjustments.

How do I set the API key in Python?

Set the key using the Authorization: Bearer tts-... header. In the OpenAI SDK, initialize the client with api_key="tts-your-key-here". Ensure you use the single active key issued to your account. If you generate a new key, the old one stops immediately.

What format is the audio response?

The response returns an audio file in your chosen format: mp3, wav, opus, flac, or pcm. You specify this using the response_format field in your JSON body. The SDK delivers the binary audio data directly, which you can then save to a file on your system.

How do I handle rate limits in Python?

You are limited to 60 requests per minute per key (10 before the first top-up). Implement retry logic with exponential backoff in your Python code. If you exceed the limit, the API returns an error. Monitor your usage via the dashboard to avoid interruptions during bulk generation.

Can I generate audio in the background?

The API processes requests sequentially, so long texts may queue. You can generate audio in the background by running your Python script asynchronously or using threading. Since requests are processed one after another, high concurrency might increase wait times for individual synthesis jobs.

What happens if I exceed the character limit?

Each request supports up to 4096 characters. If your text exceeds this, split it into parts and send multiple requests. Join the resulting audio files afterward. The API does not automatically truncate or split text; you must handle the chunking logic in your Python application.

Is the API key case sensitive?

Yes, API keys are case sensitive. Ensure you copy the key exactly as shown in your dashboard. The key format starts with tts-. Using an incorrect case or missing characters will result in authentication errors when you attempt to send a speech synthesis request.

Do I need to close the HTTP connection manually?

If you use the OpenAI SDK, it handles connection management automatically. For raw HTTP requests, ensure you close the response object to free resources. The SDK simplifies session handling.

Can I stream the audio response?

No, streaming is not supported. You receive the complete audio file after synthesis finishes. There is no WebSocket or real-time partial audio delivery. You must wait for the full response before saving or playing the audio file in your Python application.

How do I detect the language automatically?

The API guesses the language from the script if you do not set the language field. Latin text defaults to English. For non-English Latin text, explicitly set the language parameter to the ISO code. This ensures accurate pronunciation.

What is the maximum input length?

The maximum input length is 4096 characters per request. Spaces and punctuation count toward this limit. For longer manuscripts, split your text into chunks of this size, generate audio for each, and concatenate the files. This ensures consistent quality and avoids truncation errors.

Are there any Python version requirements?

The official OpenAI Python library supports standard modern Python versions. There are no specific version requirements beyond what the library itself supports. Ensure your environment has pip installed and can resolve dependencies. The API itself is language-agnostic, relying only on standard HTTP requests.

First request

curl

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

Start by creating an account on the NarrativeNode platform at /get-api-key/. You can sign up using your Google account for an instant $0.50 trial credit, or use an email and password which starts with zero balance. This account is specific to the rx115.cc site.

Once registered, log in to your dashboard to view your unique API key, current balance, and usage statistics. You will also find a ready-to-use cURL example to help you verify your connection immediately after setup.

Sign Up on Site

Sign Up on Site

Visit the registration page and choose Google or email authentication. Google sign-ups receive a $0.50 trial credit valid for 7 days, perfect for testing your first audiobook chapter. Email accounts begin without trial credit and require a top-up to start generating audio.

Accounts are independent per site, so ensure you are registering on rx115.cc. Your key is tied to this specific domain, allowing you to manage separate credentials if you use multiple storefronts.

Locate Key in Dashboard

Locate Key in Dashboard

Your API key appears prominently on the main dashboard alongside your current balance and character count. It begins with 'tts-' and is used for authentication in all API requests. Keep this key secure, as it provides access to your billing and generation capabilities.

The dashboard also displays your usage history and a quick cURL example. This visual confirmation helps you verify that your key is active and ready to send requests to the /v1/audio/speech endpoint.

Rotate Key if Needed

You can issue a new API key at any time from your dashboard settings. When you generate a new key, the old one stops working immediately, ensuring that only your current credential is valid.

This feature is useful if you suspect a key has been exposed or if you want to reset access for a specific project. The transition is instant, so update your application configuration immediately after rotation.

Install OpenAI SDK

Sound wave illustration for: Install OpenAI SDK

Install the official OpenAI Python library using pip. This library is already compatible with our API, allowing you to send requests using standard methods without needing a custom client. Ensure your environment uses Python 3.8 or higher for full compatibility.

pip install openai

Run pip install openai in your terminal to add the client to your project. This single command installs the necessary dependencies to interact with the text-to-speech endpoint.

Python 3.8+ Support

The library requires Python 3.8 or later. This ensures modern type hinting and async support, which are helpful for managing multiple audiobook chapters efficiently.

Library Compatibility

The standard library handles authentication, JSON serialization, and audio response handling automatically. You do not need to manage multipart form data or raw HTTP connections manually. Just configure the base URL and call the speech endpoint.

Configure Base URL

Sound wave illustration for: Configure Base URL

To ensure your Python client communicates with the correct NarrativeNode infrastructure, you must override the default OpenAI base URL. This directs requests to our dedicated endpoints rather than OpenAI’s servers.

The API base URL for this site is https://api.rx115.cc/v1. Setting this variable correctly ensures that your authentication keys and request shapes are interpreted by our TTS engine.

Set api_base Variable

In your Python code, initialize the OpenAI client by explicitly setting the base_url parameter. This ensures all API calls, including speech generation, route through our infrastructure.

Example: client = OpenAI(api_key="YOUR_KEY", base_url="https://api.rx115.cc/v1")

  • Use the exact domain: api.rx115.cc
  • Do not omit the /v1 suffix
  • Verify the key matches your account

Use HTTPS Endpoint

Always use HTTPS for secure transmission of your API key and text data. Our endpoint is exclusively available over HTTPS.

This prevents interception of credentials and ensures data integrity during transmission.

  • Protocol: https
  • Port: 443 (default)

Environment Variables

For production reliability, store your base_url and API key in environment variables. This avoids hardcoding credentials in your source code.

Example: os.environ["OPENAI_BASE_URL"] = "https://api.rx115.cc/v1"

  • Use .env files for local development
  • Securely inject variables in CI/CD pipelines

Make First Request

Sound wave illustration for: Make First Request

Generating audio with NarrativeNode is straightforward using the standard OpenAI Python SDK. By pointing the client to our API base URL, you can convert text into speech with a few lines of code. This approach leverages existing tools familiar to Python developers, ensuring a smooth integration into your self-publishing workflow.

The API accepts your manuscript text and returns a binary audio file. You can handle the response directly in memory or save it to disk for later processing. This simple request-response cycle fits seamlessly into batch processing scripts for long-form content.

Python Code Example

Here is a minimal script to generate speech. Replace YOUR_API_KEY with your key from the dashboard. The code sets the base URL to https://api.rx115.cc/v1 and sends a request for the tts-1 model.

```python import openai client = openai.OpenAI( api_key="YOUR_API_KEY", base_url="https://api.rx115.cc/v1" ) with client.audio.speech.with_streaming_response.create( model="tts-1", voice="nova", input="Hello, world. This is a test of the NarrativeNode API.", response_format="mp3" ) as response: response.stream_to_file("output.mp3") ```

Note that while we recommend the OpenAI SDK, you can also use standard HTTP libraries like requests if you prefer. The endpoint remains POST /v1/audio/speech.

  • Install the library using pip install openai.
  • Ensure you are using Python 3.8 or higher.
  • Set the base_url to https://api.rx115.cc/v1.

JSON Body Structure

The request body is a JSON object containing the essential parameters for synthesis. You must specify the model, input text, and voice. Optional fields like response_format and speed allow you to customize the output.

The input field supports up to 4096 characters per request. For longer manuscripts, split your text into chunks and concatenate the resulting audio files. Spaces and punctuation count towards the character limit.

```json { "model": "tts-1", "input": "Your text here", "voice": "nova", "response_format": "mp3", "speed": 1.0 }```

  • model: "tts-1" or "tts-1-hd".
  • input: String up to 4096 characters.
  • voice: One of the 8 available presets.
  • response_format: mp3, wav, opus, flac, or pcm.

Response Handling

Upon successful synthesis, the API returns the audio file in the requested format. The response includes standard HTTP headers and the binary audio data. If you use the streaming response method, the data is written to a file incrementally.

In case of an error, such as a bad request or rate limit, the API returns an error JSON object with a code and message. Check the status code to determine if you need to adjust your request parameters or wait before retrying.

Remember that failed requests are free, so you can retry without worrying about costs. The audio is not stored on our servers after delivery, ensuring your manuscript data remains private.

  • Status 200: Audio file returned.
  • Status 400: Invalid request parameters.
  • Status 429: Rate limit exceeded.
  • Status 500: Server error.

Voice Selection

Sound wave illustration for: Voice Selection

Choosing the right voice is critical for audiobook narration. NarrativeNode offers eight distinct presets optimized for long-form content, from warm narrators to energetic promo styles. You can browse available voices via the API or the dashboard to find the perfect fit for your manuscript.

Each voice carries a specific tonal character that influences listener engagement. Use the GET /v1/voices endpoint to retrieve the full list of available options, including voice IDs, gender, and supported languages, ensuring you select the best auditory experience for your self-published work.

List Available Voices

Retrieve the complete list of voices and their attributes using the GET /v1/voices endpoint. This returns details for all eight presets, allowing you to programmatically match voice characteristics to your book’s genre.

Voices are consistent across all 23 supported languages, meaning you can maintain a single narrator’s voice even if your manuscript includes multilingual passages. Simply select the appropriate voice ID for the primary narrative language.

  • Use GET /v1/voices to fetch voice metadata.
  • All voices support 23 languages including English, Spanish, and German.
  • Voice attributes include gender, tone, and language support.

Select Voice ID

In your Python request, pass the chosen voice ID (e.g., aria, nova, atlas) as the voice parameter. The API accepts only these eight presets, ensuring consistent audio quality and predictable character counts for billing.

If you are unsure which voice fits your text, test short samples using the dashboard’s curl example. The input field accepts up to 4096 characters, allowing you to preview how the voice handles your specific manuscript excerpt before processing the full file.

  • Use standard voice IDs like aria, nova, sage, atlas.
  • Pass the ID directly in the voice JSON field.
  • Test with the dashboard’s curl example first.

Gender and Tone

NarrativeNode categorizes voices by gender and tone to help self-publishing freelancers match content style. Female voices include Aria (warm narrator), Nova (upbeat), Luna (storytelling), and Sage (instructional). Male voices include Felix (energetic), Milo (conversational), Atlas (neutral news), and Orion (deep documentary).

Selecting the right gender and tone directly impacts listener retention. For example, use Atlas for non-fiction or Orion for dramatic readings. The voice remains consistent regardless of the language, provided you specify the language parameter for non-English Latin scripts to avoid default English pronunciation.

  • Female: aria, nova, luna, sage.
  • Male: felix, milo, atlas, orion.
  • Match tone to content genre.
  • Specify language for non-English Latin text.
Voice Selection

Audio Formats

Sound wave illustration for: Audio Formats

NarrativeNode supports multiple audio formats to suit your audiobook production workflow. Choose the format that balances quality, file size, and compatibility with your preferred editing software or distribution platform.

MP3 Output

MP3 is the default format and offers excellent compression for easy sharing. It is widely supported by all audiobook platforms and media players. Use this format for final exports or quick previews.

  • Small file sizes for faster uploads
  • Universal compatibility with all players
  • Default output for standard use cases

WAV Output

WAV provides uncompressed, lossless audio quality. This format is ideal for professional editing workflows where you need to process the audio further without losing quality. Choose WAV when working with high-end audio software.

  • Lossless audio quality
  • Ideal for post-production editing
  • Higher file sizes than MP3

OPUS and FLAC

OPUS offers high-quality compression with smaller file sizes than MP3. FLAC provides lossless compression, preserving all audio details. These formats are suitable for specific technical requirements or archival purposes.

  • OPUS: Efficient compression
  • FLAC: Lossless compression for archiving
  • Support for advanced audio workflows

Rate Limits

Sound wave illustration for: Rate Limits

Rate limits ensure fair usage for long-form audiobook generation. You get 60 requests per minute with an active key, but new accounts start at 10 requests per minute until the first top-up.

60 Requests per Minute

Once funded, your account scales to 60 requests per minute. This handles typical splitting of long manuscripts efficiently without overwhelming the API.

10 Requests Initial Limit

New keys begin with a 10 requests per minute limit. Top up with USDT (TRC-20) to immediately unlock the full 60 requests/minute capacity.

Queue Behavior

Requests process sequentially. If you exceed the limit, new requests wait in a queue. Short phrases may take a few seconds; longer texts generate at roughly real-time speed.

Error Handling

Sound wave illustration for: Error Handling

Handling errors correctly ensures your audiobook generation pipeline doesn’t stall. When requests fail, the API returns specific HTTP status codes to help you diagnose and resolve issues quickly, keeping your production workflow smooth.

Understanding these codes helps you implement proper retry logic and validation checks, minimizing wasted characters and ensuring your self-published titles are delivered without unexpected interruptions.

429 Too Many Requests

If you exceed the 60 requests per minute limit, the API returns a 429 status. Your initial 10 requests per minute limit applies before the first top-up. Implement exponential backoff to wait before retrying.

Requests may also queue if the server is under load, causing delays that might be interpreted as a timeout if not handled properly.

  • Check the Retry-After header if provided.
  • Respect the 60 RPM limit for smooth processing.

400 Bad Request

This error occurs when the JSON body is invalid or contains unsupported parameters. Ensure the input text is under 4096 characters and the voice ID is one of the eight available presets.

Common causes include missing required fields like 'model' or 'input', or passing an unsupported response format like 'ogg' instead of 'opus'.

  • Validate text length before sending.
  • Verify voice IDs match the /v1/voices endpoint.

500 Server Errors

Internal server errors indicate a temporary issue on our side. These are rare but may occur during peak usage. Failed synthesis attempts are free, so you won’t be charged for retries.

If the error persists, wait a few minutes and retry. Support is available via email.

  • No charge for failed requests.
  • Contact support via email for persistent issues.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. For English-language manuscripts, the system defaults to English if the language parameter is omitted.

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 API reference: create speech
  3. Python documentation
  4. curl documentation
  5. W3C WAI: making audio and video accessible
  6. TRON developer hub: TRC-20
  7. openai-node on GitHub
  8. Node.js documentation
  9. IETF RFC 7845: Ogg Opus
  10. LibriTTS-R paper (arXiv 2305.18802)
  11. Creative Commons Attribution 4.0
  12. FFmpeg documentation

More on this site