GUIDE

Text to speech in Python: offline, free and with natural voices

Python has several ways to turn text into speech. Some libraries read with the robotic voices of the operating system, some send your text to an online service, and some run a neural model on your own computer. The last kind now sounds close to a human and still works without internet.

This guide compares the options and then shows working code for the SuperClonica engine, a pip package built on the open Supertonic 3 model: installation, a first script, custom voices, long texts and a local HTTP API in Docker. The engine is ours, so we say where something is.

Ways to do text to speech in Python

Before you choose a library, decide two things: whether your text may leave the computer, and how natural the voice has to sound.

  • pyttsx3 drives the speech engine built into the system: SAPI5 on Windows, NSSpeechSynthesizer on macOS and eSpeak on Linux. It works offline and installs in seconds, but the voices sound robotic and differ from one machine to another.
  • gTTS sends the text to the speech service of Google Translate and saves an MP3. It sounds clearer, but it needs internet, offers languages and accents rather than voices, and is an unofficial interface that can stop working.
  • Cloud APIs from Google, Amazon, Microsoft or ElevenLabs sound very good, but they need an account and a key, are paid per character and send every text to the provider.
  • Local neural models such as Supertonic 3, Kokoro and Piper run on your own CPU or GPU. After a one-time model download they work offline, cost nothing per character and sound far more natural than system voices. Our comparison pages cover them in detail.

Install the SuperClonica engine

The engine is one pip package in two builds. For any CPU on Windows, macOS or Linux with Python 3.10 or newer: python -m pip install superclonica-cpu. For an NVIDIA GPU on Windows or Linux with Python 3.11 or newer: python -m pip install superclonica-gpu-cuda. Install only one of them per environment; both provide the same superclonica module.

The GPU build brings CUDA and cuDNN through pip, so the only system requirement is an NVIDIA driver with CUDA 12 support; without a working GPU it falls back to the CPU. On the first run the Supertonic 3 model, about 385 MB, is downloaded once into ~/.cache/supertonic3. Set SUPERTONIC_CACHE_DIR to keep it elsewhere.

Your first script

Import the engine, synthesize a phrase and save it: from superclonica import Superclonica, then tts = Superclonica(), audio, sample_rate = tts.synthesize("Hello! This voice runs on my own computer.", voice="F1", lang="en", seed=7) and tts.save("hello.wav", audio). The model comes with ten voices, M1 to M5 and F1 to F5, which need no extra files.

Create the engine once and reuse it: loading takes a few seconds, while each later phrase takes a fraction of a second. In our measurements the median short phrase took 0.12 s on an RTX 5070 Ti and 0.43 s on a Ryzen 7 5800X with four threads.

Use a custom voice

A Supertonic 3 voice is a JSON file of about 0.3 MB. Free voices with audio samples are in the superclonica/supertonic-voices repository on GitHub, and the SuperClonica catalog has 170+ more, from game characters to narrators, each with a free online demo.

Pass the file instead of a preset name: tts.synthesize("Good morning!", voice="ciri.json", lang="en", seed=7). From the command line: superclonica --text "Good morning!" --voice ciri.json --lang en --output morning.wav. Every voice speaks all 31 languages of the model; set lang to the language of the text, for example de, es, ja or ru. Chinese is not supported.

Long texts, dialogues and file formats

A few options cover most real projects.

  • A long text, such as a chapter, goes into one call: the engine splits it into natural pieces of at most 160 characters, which keeps words from being repeated or swallowed.
  • normalize=True evens the loudness to −18 LUFS, which helps when you join many files.
  • tts.synthesize_batch() voices several lines at once, each with its own voice, for example the lines of a dialogue; the results keep the input order.
  • The same text, voice and seed give the same audio again, so you can redo one line without changing the rest.
  • Numbers are spoken as words, common chat abbreviations are spelled out, and emoji or unknown symbols are cleaned up instead of causing an error.
  • tts.save() writes WAV, FLAC or OGG, chosen by the file extension.

Text to speech as a local HTTP API

If the program that needs speech is not written in Python, run the engine in Docker: docker run -d -p 8000:8000 -v superclonica-models:/models superclonica/superclonica:cpu, or the cuda tag with --gpus all on an NVIDIA GPU. The model downloads into the volume on the first start.

Send POST /synthesize with JSON that holds the text, the language and the content of the voice file, and a WAV comes back. A voice is about 0.3 MB, so build the request in a file and send it with curl -d @request.json.

Licenses and responsible use

Supertonic 3 is released under OpenRAIL-M, a royalty-free license with a list of prohibited uses rather than a non-commercial clause. Do not use speech to impersonate someone without consent, to deceive or to harass, and say that audio is machine-generated where that matters.

Some catalog voices are inspired by well-known people. They are not their real voices, so do not present such audio as their real words.