跳到正文
DEV Community· Asad Shehzad·· 3 小時前AI 評分63

loudness-tts 以語音排序和文字正規化改善開源文字轉語音,並支援 Python 與瀏覽器

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

AI 導讀

Loudness.ai 推出免費開源的 loudness-tts,提供 Python 與 JavaScript 版本,為 Piper 文字轉語音加入語音挑選及文字正規化。工具評估了 1,683 個可供商業使用的語音,並以英文和西班牙文規則正規化日期、金額等文字,讓語音內容與原文保持對應,方便字幕同步。兩個版本的 parity tests 比對了 8,609 個文字案例及全部 78 個語音模型。

正文

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:

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: https://loudness.ai/research/piper-tts-text-normalization/

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

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

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

Try it without installing anything: https://huggingface.co/spaces/Loudness-ai/text-to-speech-browser
Code: https://github.com/Loudness-ai/loudness-tts

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

來源:DEV Community · dev.to