Python 3 Text to Speech API: Quickstart Guide

By Route 168 editorial team · Updated 2026-11-19

This guide walks you through integrating SonicCopy’s text-to-speech API into your Python workflow. You will learn how to generate high-quality voiceovers for radio spots and advertising content directly from your scripts. We cover essential steps from obtaining your API key to handling responses, ensuring you can automate voice generation efficiently without manual uploads.

Designed for content creators and developers, this documentation provides concrete examples using standard tools like requests and the OpenAI SDK. You will find clear explanations of supported models, voice presets, and rate limits. By the end, you will be ready to synthesize audio files programmatically, leveraging our straightforward endpoint structure for reliable, scalable production.

Python 3 Text to Speech API: Quickstart Guide

Frequently asked questions

How do I get an API key?

Sign up on /get-api-key/ using Google or email. You receive one active key per account. You can issue a new key at any time, which immediately invalidates the old one. The dashboard displays your key, balance, and usage details for easy access during integration.

What is the base_url?

The API base URL is https://api.route168.cc/v1. Use this endpoint for all requests, including POST /v1/audio/speech for synthesis, GET /v1/voices for voice details, and GET /v1/models for model information. Ensure your requests target this specific domain to authenticate correctly with your Bearer token.

Can I use the OpenAI SDK?

Yes. The request shape matches the OpenAI speech endpoint. Configure your OpenAI SDK by changing the base_url to https://api.route168.cc/v1 and using your SonicCopy API key. This allows you to use official OpenAI SDKs seamlessly without rewriting your integration logic or learning a new client.

What models are available?

Two models are available: tts-1 and tts-1-hd. Both use the same engine and price. Selecting either model provides identical audio quality and generation characteristics. The choice is purely for compatibility with existing codebases that expect specific model identifiers in the request body.

How do I set the voice?

Include the voice parameter in your JSON body with one of eight presets: aria, nova, luna, sage, felix, milo, atlas, or orion. Voices are based on licensed recordings from LibriVox. Each voice has a distinct tone, from warm narrators to energetic promo styles, suitable for various advertising needs.

What is the speed range?

The speed parameter accepts values between 0.25 and 4.0. This allows you to slow down narration for clarity or speed up content for quick updates. Adjusting speed affects the duration of the generated audio file proportionally to the set value.

Which audio formats are supported?

Supported formats are mp3, wav, opus, flac, and pcm. Choose the format that best fits your playback environment or editing workflow. MP3 is ideal for web delivery, while WAV and FLAC offer lossless quality for professional radio production. PCM is available for raw audio processing.

What is the rate limit?

The limit is 60 requests per minute per key. Before your first top-up, the limit is 10 requests per minute. Requests are processed sequentially, so high volume may cause queuing. Monitor your usage via the dashboard to avoid hitting limits during peak production times for your campaigns.

How do I handle errors?

Failed requests are free: if synthesis fails, the charge is returned in full. If synthesis fails, you receive an error response without cost. Ensure your text is under 4096 characters and your key is valid. Handle HTTP error codes appropriately in your Python script to manage retries or notifications.

Does the API support Python 3?

Yes, the API is fully compatible with Python 3. You can use the official OpenAI Python SDK or standard HTTP libraries like requests. The JSON request body structure is straightforward, making integration into existing Python scripts for automated voice generation simple and reliable for your production pipeline.

Can I use custom parameters?

You can set the language, response_format, speed, and voice. The language parameter is optional; if omitted, the system guesses the language from the script. For non-English Latin text, explicitly set the language to ensure accurate synthesis. Other parameters like model and input are required for every request.

Is the API RESTful?

Yes, the API follows RESTful principles. It uses standard HTTP methods like POST for speech synthesis and GET for retrieving voices and models. Requests are sent as JSON, and responses return audio files or metadata. This design ensures easy integration with modern web services and automation tools.

How do I test the API?

Use the ready curl example provided on the /get-api-key/ dashboard page. You can also use the OpenAI SDK with the correct base_url. Start with a short text to verify audio quality and format. Check your balance and key validity before running larger batches for your advertising spots.

What happens if I exceed the limit?

Requests are processed one after another, so exceeding the limit may cause your request to wait in a queue. If the queue fills or a timeout occurs, the request may fail. Failed requests are free. Monitor your usage to ensure smooth integration during high-volume production periods.

First request

curl

curl https://api.route168.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.route168.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.route168.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 signing up on our /get-api-key/ page using Google or an email and password. Once registered, you will see your unique API key, current balance, and a ready-to-use cURL example on the dashboard.

You can generate a new key at any time. When you do, the previous key stops working immediately, ensuring clean access control for your advertising workflows.

Sign up on the site

Sign up on the site

Visit the /get-api-key/ page to create your account. You can sign in with Google for instant access or use a standard email and password. Accounts are specific to this site, so ensure you are on route168.cc.

Generate a new key

Generate a new key

Navigate to the dashboard to issue a fresh API key. This is useful when you suspect a key has been exposed or when rotating credentials for different production and staging environments.

  • New keys are active immediately.
  • Old keys stop working at once upon generation.

Reuse or rotate keys

You may reuse your key across multiple Python scripts or radio automation tools. If you need to change access, simply generate a new key from the dashboard, and the old one becomes invalid instantly.

First Request with Curl

Sound wave illustration for: First Request with Curl

Use cURL to send a direct POST request to the speech endpoint. This method requires no external libraries, making it ideal for quick tests or simple scripts. You will receive the audio file directly in the response body, ready to be saved or played.

The request body is a standard JSON object. Ensure your API key is included in the Authorization header. This basic command works for all models and voices, providing immediate feedback on your integration.

The API returns the audio file with appropriate headers. Save the output to a file using the -o flag to verify the download.

subs: [{

Using the OpenAI SDK

Sound wave illustration for: Using the OpenAI SDK

The official OpenAI Python SDK works directly with SonicCopy by pointing to our API base. This allows you to use familiar library structures for your radio automation scripts without learning a new client.

You only need to configure three settings: the installation, the base URL, and your authentication key. The request shape remains identical to the standard OpenAI speech endpoint.

Install the SDK

Install the library using your standard package manager. This provides the core HTTP client and JSON handling required for API communication.

  • pip install openai

Set base_url

Configure the client to target our endpoint. Replace the default base URL with our specific API domain to route requests correctly.

  • base_url="https://api.route168.cc/v1"

Pass your API key

Authenticate using your unique key generated from the dashboard. Include it in the header so the service identifies your account and balance.

  • Authorization: Bearer tts-...

Supported Models

Sound wave illustration for: Supported Models

The API offers two model identifiers, tts-1 and tts-1-hd, which drive the exact same synthesis engine. You can switch between them in your Python scripts by changing the model parameter, allowing you to test audio quality without altering your core logic or voice settings.

Both models support all eight voice presets and handle the full range of speed adjustments. The choice depends on your project’s specific requirements for audio fidelity versus processing characteristics, though the underlying generation mechanism remains consistent across both options.

tts-1 standard

The standard model provides reliable, clear speech suitable for most advertising and radio spot needs. It processes text efficiently, making it a solid default for high-volume content generation where consistent clarity is prioritized.

Use tts-1 for general voiceovers, narrations, and quick prototyping. It handles the full character limit and supports all audio formats available through the API.

  • Ideal for standard radio spots
  • Consistent performance across all voices
  • Default choice for most use cases

tts-1 hd high quality

The hd variant is designed for projects requiring enhanced audio detail. While it uses the same engine, it is categorized for high-fidelity output, making it suitable for premium advertising content where every nuance matters.

Select tts-1-hd when the production value of the voiceover is critical.

  • Enhanced detail for premium content
  • Best for final master recordings
  • Ideal for high-value advertising spots

Same engine, different price

Both models utilize the identical underlying synthesis technology and pricing. The distinction is purely in the model identifier used in the request.

You can swap between models in your Python code without changing the voice or speed parameters. This flexibility allows you to optimize costs while maintaining the same audio style and tone for your campaigns.

  • Identical synthesis engine
  • Different pricing tiers
  • Easy switching in code

Voices and Parameters

Sound wave illustration for: Voices and Parameters

Choose from eight distinct voice presets tailored for advertising and radio production. Options range from the warm, clear narrator Aria to the energetic, promo-focused Felix. Each voice is built from licensed recordings, ensuring consistent quality for your spot.

Fine-tune the delivery speed between 0.25 and 4.0 to match your script’s pacing. Adjust the optional language parameter to ensure accurate pronunciation for non-English scripts, as the API defaults to English for Latin text if unspecified.

Select a voice preset

Pick a voice that fits your brand’s tone. Female options include Aria (warm narrator), Nova (bright), Luna (soft storytelling), and Sage (calm instruction). Male options feature Felix (energetic promo), Milo (friendly conversation), Atlas (neutral news), and Orion (deep documentary).

All voices support all 23 languages. You can mix and match voices across campaigns without extra cost.

  • Aria: warm, clear narrator
  • Nova: bright, upbeat
  • Luna: soft, storytelling
  • Sage: calm, instructional
  • Felix: energetic, promo
  • Milo: friendly, conversational
  • Atlas: neutral, news
  • Orion: deep, documentary

Adjust speed (0.25–4.0)

Set the speed parameter to control the voice’s pace. Values range from 0.25 (slow) to 4.0 (fast). Use slower speeds for detailed instructions or faster rates for energetic promo spots.

Adjusting speed does not affect quality, but extreme values may alter natural intonation slightly.

Set optional language

Specify the ISO language code to ensure accurate pronunciation. If omitted, the API guesses the language from the text script. Latin script text defaults to English.

For non-English Latin text, always set the language parameter to avoid mispronunciation.

Voices and Parameters

Audio Formats

Sound wave illustration for: Audio Formats

SonicCopy supports five audio formats: mp3, wav, opus, flac, and pcm. Each format serves different technical needs for advertising and radio production, from web delivery to broadcast mastering.

mp3, wav, opus, flac, pcm

MP3 and Opus are compressed formats ideal for web delivery and quick previews. WAV and FLAC provide uncompressed or lossless quality for professional editing. PCM offers raw audio data for immediate integration into digital audio workstations.

  • mp3: compressed, widely compatible
  • wav: uncompressed, standard for editing
  • opus: efficient compression for web
  • flac: lossless, high fidelity
  • pcm: raw binary data

Choose based on use case

Select MP3 for fast loading in web players or Opus for bandwidth-efficient delivery. Use WAV or FLAC when you need pristine audio for final radio spot mastering or further post-production. PCM is best for systems requiring immediate, uncompressed audio streams.

Format selection in request

Specify your preferred format in the response_format field of your JSON body. The API returns the audio file in the exact format you requested, ensuring compatibility with your existing production workflow.

Rate Limits

Sound wave illustration for: Rate Limits

Rate limits protect the service’s stability during peak usage. By default, each API key is allowed 60 requests per minute. This limit applies to all endpoints, including voice listing and model info, so plan your automation scripts accordingly.

60 requests per minute

After your account is funded and the minimum top-up is processed, you can send up to 60 requests per minute. This allows for rapid synthesis of radio spots or ad variants without immediate throttling.

  • Limit resets every 60 seconds.
  • Applies per API key, not per account.

10 requests before top-up

New accounts or those with a $0.50 trial start with a lower limit of 10 requests per minute. Once you top up with USDT on the TRON network (TRC-20), the limit increases to 60 requests per minute.

  • Trial accounts: 10 requests/minute.
  • Top-up accounts: 60 requests/minute.

Queue behavior under load

Requests are processed sequentially. Under heavy load, requests may wait in a queue. Short phrases take a few seconds to generate, while longer texts process at roughly real-time speed (25 characters per second). Be patient during high-traffic periods.

  • Sequential processing ensures quality.
  • Delays may occur during peak usage.

Error Handling

Sound wave illustration for: Error Handling

Handling errors correctly ensures your radio spots are generated without wasted credits. This API returns standard HTTP status codes to indicate success or failure, allowing your scripts to react appropriately.

Understanding these responses helps you maintain smooth automation workflows, whether you are processing a single ad spot or a batch of voiceovers for a campaign.

Common error codes

Use standard HTTP status codes to determine the next step. A 4xx error usually indicates an issue with your request, such as an invalid API key or a malformed JSON body. A 5xx error suggests a temporary server issue, which you can often resolve by retrying.

  • 400 Bad Request: Check your JSON structure and voice names.
  • 401 Unauthorized: Verify your Bearer token is correct.
  • 429 Too Many Requests: You have exceeded the rate limit.
  • 500 Server Error: Try again in a few seconds.

Retry logic

Implement exponential backoff for 5xx errors to avoid overwhelming the server during high load. Since requests are processed sequentially, brief pauses help ensure your voiceovers are queued correctly without causing bottlenecks.

Do not retry failed requests immediately if the error is due to invalid input, as this will yield the same result.

Character limit errors

The API accepts up to 4096 characters per request. If your script exceeds this limit, split the text into smaller chunks before sending. Join the resulting audio files to create the final voiceover.

Exceeding the limit results in a 400 error, so validate your input length before each API call.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Its clear, upbeat delivery makes it ideal for radio spots where you need to convey enthusiasm and positivity without sounding artificial.

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. TRON developer hub: TRC-20
  3. W3C WAI: making audio and video accessible
  4. Tether (USDT)
  5. curl documentation
  6. FFmpeg documentation
  7. openai-python on GitHub
  8. MDN: Web Speech API
  9. OpenAI API reference: create speech
  10. Python documentation
  11. IETF RFC 7845: Ogg Opus
  12. Node.js documentation

More on this site