Skip to main content

zyphra-textnorm

Text normalization for text-to-speech: written text to its spoken form ("$5.32" → "five dollars thirty two cents"), for 43 languages. The original nine packages are hand-written Rust ports of the NeMo-text-processing r1.2.0 grammars; the additional 34 port ZONOS3's production locale grammars and Unicode CLDR release-49 data. There is no FST runtime and no pynini: every grammar is Rust code, every table is embedded at compile time, and nothing is loaded at runtime. One library serves Rust, Python and C, with a 1024-entry memo per normalizer.

The differential corpora contain 179,669 rows: 92,953 for the original nine languages and 86,716 for the added locales, generated from vendored fixtures, lexical tables, and held-out rule boundaries (see Parity).

Use

use zyphra_textnorm::Normalizer;

assert_eq!(zyphra_textnorm::normalize("It costs $5.32.", "en"), "It costs five dollars thirty two cents.");
let tn = Normalizer::with_markup_tags(["laugh", "shouting"]);
assert_eq!(tn.normalize("So I said <laugh/> no way, $5.", "en"), "So I said <laugh/> no way, five dollars.");
import zyphra_textnorm

zyphra_textnorm.normalize("Am 3. Oktober kostete es 5,32 €.", "de")
# 'Am dritter oktober kostete es fünf komma drei zwei €.'
tn = zyphra_textnorm.Normalizer(markup_tags=["laugh"])
tn.normalize("So I said <laugh/> no way, $5.", "en")
#include "zyphra_textnorm.h"

zyphra_textnorm *tn = zyphra_textnorm_new("laugh\nshouting", 14);
char *out = zyphra_textnorm_normalize(tn, text, text_len, "en", 2);
/* ... */
zyphra_textnorm_free(out);
zyphra_textnorm_delete(tn);
  • Languages: LANGUAGES = en de es fr it pt ja zh ko nl pl tr uk cs da fi el nb ro sk bg he th tl ms ka ta gu kn ml pa or ru sv hu ar vi id hi bn te mr ur. zh is Mandarin, nb is Norwegian Bokmål, tl is Tagalog/Filipino, and or is Odia. supported(lang) says whether this build has a grammar. One cargo feature per language (lang-en …), all on by default.
  • Never fails: a language without a grammar comes back with its line breaks collapsed, and a sentence the grammar fails on is kept as typed (the rest of the text is still normalized).
  • Line breaks: every whitespace run holding a line break, tab or other non-space whitespace becomes one space first (collapse_line_breaks); runs of plain spaces are kept.
  • Markup (Normalizer::with_markup_tags): the markup of the given tag names stays as typed: point tags (<laugh/>, <laugh>) and span tags (<shouting>…</shouting>, \s* allowed before / or >), and the text between markers is normalized piece by piece. Without tags, <…> is text like any other.
  • Verbatim spans: anything between U+E000 and U+E001 (e.g. a pronunciation) is kept as typed.
  • Memo: each Normalizer remembers its last 1024 results, shared by every thread that calls it; normalize(text, lang) uses one shared normalizer without markup tags.

The output is the spoken form of the reference grammars, quirks included: parity is the contract. The original packages retain the frozen NeMo wrapper behavior (oracle/reference_textnorm.py); new locale packages use the locale-gated ZONOS3 wrapper (oracle/new_locale_wrapper.py). This covers sentence punctuation, native symbol and operator words, ordinal periods, numeric conventions, bracket spacing, and markup/verbatim preservation. Numeric dates follow locale conventions (tl uses month/day/year); ISO YYYY-MM-DD avoids ambiguity. Dutch million and billion remainders use the corrected fixed-width source grammar, preventing omitted zero groups from changing the number's scale.

Install

Rust cargo add zyphra-textnorm (MSRV 1.88)
Python (≥ 3.9) pip install zyphra-textnorm: abi3 wheels for Linux (manylinux, x86_64 and aarch64), macOS (x86_64, arm64) and Windows (x64, arm64); elsewhere pip builds the sdist, which needs cargo
C / C++ cargo rustc --release --lib --features capi --crate-type staticlib → target/release/libzyphra_textnorm.a (zyphra_textnorm.lib on MSVC), header include/zyphra_textnorm.h. Link the platform's Rust std libraries (-lpthread -ldl -lm on Linux, ws2_32 userenv ntdll bcrypt on MSVC).

The release profile keeps panic = "unwind": a panic inside a grammar is a grammar failure (the sentence kept as typed). A build with panic = "abort" aborts on one instead.

Layout

Path Contents
src/ The library: lib.rs (API), wrapper.rs (line breaks, markup, verbatim spans, per-language passes, sentence retry, memo), pipeline.rs (NeMo's Normalizer.normalize), lattice.rs (the tagger's Viterbi), tag.rs, permute.rs, moses.rs, punct_post.rs, ffi.rs (C ABI)
src/lang/<l>/ One grammar package: taggers/ and verbalizers/ mirror the upstream files one to one
data/ The upstream .tsv tables verbatim, the sacremoses perluniprops tables, frozen Unicode 15.0 tables
include/ The C header
python/ The Python extension zyphra_textnorm (PyO3; pyproject.toml at the root)
oracle/ The differential-test oracle: vendored NeMo r1.2.0 and ZONOS3 locale packages, reference wrappers, corpus and golden dump scripts
tests/ Differential tests; the corpus (corpus/), the oracle's outputs (golden/*.jsonl.zst) and the oracle-confirmed equal-cost ties the port resolves differently (ties/)
PORTING.md How a NeMo grammar becomes Rust, with the verified pynini semantics

Develop

cargo test --release --features capi       # unit tests + differential tests against the goldens
cargo run --release --example normalize -- en 'Save $20k.'
cargo bench                                # median µs per call and per 100 chars, allocations
cargo bench --no-default-features --features lang-de   # one language, faster to build
uv venv && uv pip install -e . && .venv/bin/python -c 'import zyphra_textnorm'

The bench warms every case before timing it and reports the median of 101 calls on a cleared memo. Run it at load below 4: medians swing by 1.5× on a busy machine. The target is ≤ 20 µs per 100 characters on every language's line.

Release

The crate and the Python package share the version ([workspace.package] in Cargo.toml). Pushing a v<version> tag runs .github/workflows/release.yml, which builds the wheels and the sdist and installs and runs each wheel on its platform. Then:

cargo publish -p zyphra-textnorm                                  # crates.io
gh run download <run id> -D dist && uv publish dist/*/*           # PyPI

Parity

The goldens in tests/golden/ are outputs of the vendored reference grammars (pynini) behind the locale-gated wrapper (oracle/reference_textnorm.py), committed zstd -19-compressed (the tests read the .zst directly; the plain .jsonl the dump scripts write are gitignored). The corpus is generated from every table of each language (oracle/gen_corpus.py for the original nine, oracle/gen_new_corpus.py for the added locales), upstream test cases, and handcrafted lines. oracle/dump_new_goldens.py compiles one new locale at a time and writes compressed goldens. The calls test checks every grammar call the wrapper made; the golden test checks every end-to-end row. The original corpus has 735 calls where the oracle picks among paths of equal float32 cost by its compiled arc order (tests/ties/, PORTING.md "Ties"); a listed call that no longer differs fails as stale. The English number-name FARs, which have no source, are checked against a 457k-row dump of the FSTs (tests/en_cardinal.rs).

Use a native Python environment with pynini, or the linux/amd64 oracle container (Rosetta on Apple silicon):

colima start --vz-rosetta --cpu 4 --memory 8
docker build --platform linux/amd64 -f oracle/Dockerfile -t zyphra-textnorm-oracle .
docker run --rm -v "$PWD":/repo -v "$HOME/.cache/zyphra-textnorm-oracle":/cache -w /repo zyphra-textnorm-oracle \
    python oracle/dump_golden.py --cache /cache --lang en --corpus tests/corpus/en.jsonl --out tests/golden/en.jsonl
zstd -19 -f tests/golden/en.jsonl -o tests/golden/en.jsonl.zst
docker run --rm -v "$PWD":/repo -v "$HOME/.cache/zyphra-textnorm-oracle":/cache -w /repo zyphra-textnorm-oracle \
    python oracle/triage.py --lang en --text 'Call me at 123 Main Street, please.'

zstd -d -k tests/golden/<l>.jsonl.zst restores the plain file for inspection. oracle/gen_corpus.py (host Python) regenerates tests/corpus/; oracle/gen_unicode_tables.py the Unicode tables (must run on CPython 3.12 / Unicode 15.0, like the oracle).

License

MIT (LICENSE) for original code; NeMo-derived grammars and tables are Apache-2.0, CLDR-derived locale data is Unicode-3.0, and the Moses detokenizer port is MIT (sacremoses). See NOTICE and licenses/.

Metadata

Release files for zyphra-textnorm 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for zyphra-textnorm 0.2.0
File Size Uploaded Provenance Actions
zyphra_textnorm-0.2.0.tar.gz 1.6 MB Without provenance Details for zyphra_textnorm-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for zyphra-textnorm 0.2.0
File Actions
zyphra_textnorm-0.2.0-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for zyphra_textnorm-0.2.0-cp39-abi3-win_arm64.whl
zyphra_textnorm-0.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for zyphra_textnorm-0.2.0-cp39-abi3-win_amd64.whl
zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
zyphra_textnorm-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for zyphra_textnorm-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
zyphra_textnorm-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for zyphra_textnorm-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 34.4 MB

Release files / zyphra_textnorm-0.2.0.tar.gz

Download URL zyphra_textnorm-0.2.0.tar.gz
Size 1.6 MB
Tags Source
SHA-256 checksum
How to use checksums
835735bfe9a18ed6139fe3679f30a0050e411462a81224918d16600fec53bcf3
BLAKE2b-256 checksum
How to use checksums
7d2f7343069d6e6cd91cf7dcbc49e3a567fbf53759627c79ba8d5952ea0b66ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / zyphra_textnorm-0.2.0-cp39-abi3-win_arm64.whl

Download URL zyphra_textnorm-0.2.0-cp39-abi3-win_arm64.whl
Size 5.3 MB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
47d76b873173c4eeec6e24a7534aa7038c77bfcc0939d1ae8bb7189c2157beaf
BLAKE2b-256 checksum
How to use checksums
bf6175668292ddce48d9775cc0df449a98abc2c70a0f6f572e9bae1061ac64d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / zyphra_textnorm-0.2.0-cp39-abi3-win_amd64.whl

Download URL zyphra_textnorm-0.2.0-cp39-abi3-win_amd64.whl
Size 5.8 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
dfe6dcb4a61f6f7443f47b09d8373895bb8787be611f272f811d0018f4a52047
BLAKE2b-256 checksum
How to use checksums
7e341d48dec871ea5cf772744583db18b07c0b5cf490e3abee1d5c71453637bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 5.7 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
fe6c6530190ae378fb357f22b6808b57c94aa1bc752f574a97ec0984a8bf43d2
BLAKE2b-256 checksum
How to use checksums
fe6e319b51d9fcbe933e231a32832084fd2f9bc32fd7d4bdc5cc2f4e15f894ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL zyphra_textnorm-0.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 5.5 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
619a6e173d004c69c585096469d1efcbb346f9d1a124efacbf1df46e3ee869ac
BLAKE2b-256 checksum
How to use checksums
ac38411ec0114e1c4b0c8da6cfff8852e0b2eb8ab260b85193cbfbc6ee9666db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / zyphra_textnorm-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL zyphra_textnorm-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 5.2 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
2412afd2bb71eb096c8cf9270e8748ee364daad5a720b09c72887942f9928fde
BLAKE2b-256 checksum
How to use checksums
d6d48d396500e8ed596bf915f5896547229a6f0bbedac220a9266b76c2ad2f81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Release files / zyphra_textnorm-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL zyphra_textnorm-0.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 5.4 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
237ae3ab94da7612fac953612ac757dad31a782b7709510e200f0041370d4372
BLAKE2b-256 checksum
How to use checksums
83815b2ceb2aa9201ac4cf3f62fe11a5bedb2450b2e47a5f10029dc26cd13346
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.10

Security for zyphra-textnorm 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page