DEV Community

Cover image for Making open-source text to speech sound right: ranked voices, text normalization and one engine for Python and the browser
Asad Shehzad
Asad Shehzad

Posted on AI-assisted

Making open-source text to speech sound right: ranked voices, text normalization and one engine for Python and the browser

Open text-to-speech models have become small and fast enough to run anywhere. Piper voices run faster than real time on a laptop CPU. But when we built the text-to-speech tool on Loudness.ai, three problems stood between “it runs” and “it sounds right”. loudness-tts is what we built to solve them, and it is free and open source.

1. Which voice?

Piper has more than 170 voice files, some with hundreds of speakers. Their quality varies a lot, and many are licensed for non-commercial use only. We tested every one: 1,683 voices that a business may use, scored for naturalness (UTMOS22) and clarity (character error rate with Whisper large-v3). The full study, data and a voice explorer are public:

Chart: the overall score of every speaker in each Piper model with ten or more speakers, with the best and the median voice of each model. Scores within one model range from about 24 to 96.
The speaker you pick matters more than the model.

In loudness-tts, voice="auto" picks the best voice with a clear licence for your language, and every voice tells you the credit line its licence asks for.

2. Reading text the way a person does

Piper does no text normalization. “$5.50” becomes “dollar five point five zero”, “4/5/2026” becomes “four slash five slash two thousand twenty-six”, and “Dr. Smith” ends a sentence after “Dr.”. loudness-tts runs a rule layer first: money, dates, times, units, phone numbers, ranges, fractions, abbreviations and Roman numerals become words, in English and Spanish.

Every spoken word keeps a pointer to the text it came from, so subtitles and word highlighting stay aligned with what was written. We measured the effect on our own test suite and on an independent one: Teaching Piper TTS to Read.

Diagram: written text and how it is read aloud, word by word. “Dr.” becomes “Doctor”, “$5.50” becomes “5 dollars and 50 cents” and “4/5/2026.” becomes “April 5th, 2026”, each with the time it is spoken.
Every spoken word points back to what was written.

3. Output you can publish

Every result is loudness-normalized to −16 LUFS with true peak at or below −1.5 dBTP, which suits podcasts and video. Word timings come from the model’s own phoneme durations, so SRT and VTT subtitles are exact. Joins between speech and silence get short fades, so there are no clicks.

One engine, two languages

The Python edition is a normal package (pip install loudness-tts). The JavaScript edition had to give the same speech without Python, in Node, Bun, Deno and the browser. We compiled espeak-ng from the commit Piper uses to WebAssembly, ran the voices on onnxruntime-web, and ported the text rules line by line, with a small helper that gives JavaScript regular expressions Python’s Unicode behaviour. Parity tests compare both editions on 8,609 text cases and all 78 voice models.

Use it

From the command line:

pip install loudness-tts
loudness-tts "Dr. Smith paid $5.50 on 4/5/2026." -o speech.wav --srt speech.srt
Enter fullscreen mode Exit fullscreen mode

From Python:

import loudness_tts
loudness_tts.speak("Hello! The meeting starts at 9:30 AM.", "hello.wav")
Enter fullscreen mode Exit fullscreen mode

For chat apps there is an OpenAI-compatible server (loudness-tts serve, or the Docker image), with step-by-step guides for Open WebUI, LibreChat and AnythingLLM.

What’s next: reading rules for more languages, and npm. Issues and pull requests are welcome.

Top comments (0)