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 English, German, Spanish, French, Italian, Portuguese, Japanese, Mandarin Chinese and Korean. These are hand-written Rust ports of the NeMo-text-processing r1.2.0 grammars. 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.

Every grammar call and every end-to-end output equals the NeMo pipeline on a differential corpus of 92,953 lines (see Parity), at 13-20 µs per 100 characters.

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 (NeMo's names; zh is Mandarin). 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 the NeMo grammars produce, quirks included: they are ported as they are, and parity is the contract. On top of the grammars come the fixes of the wrapper the goldens were dumped with (oracle/reference_textnorm.py, the wrapper of ZONOS3): sentence punctuation after a digit is spaced off where it breaks a grammar (pt, de, es, fr, it, ko, en), ja drops the ASCII space between CJK characters, and en reads 24/7 and $20k as speech.

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: the vendored NeMo r1.2.0 package, the frozen reference wrapper, the Docker image, 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 the outputs of the NeMo r1.2.0 pipeline (pynini) behind the reference 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) plus the upstream r1.2.0 test cases and handcrafted lines. The calls test checks every NeMo grammar call the wrapper made, the golden test every end-to-end row. The only exceptions are 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).

pynini has no macOS wheel, so the oracle runs in a linux/amd64 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 the original code; the grammars and tables ported from NeMo-text-processing are Apache-2.0, and the Moses detokenizer port is MIT (sacremoses). See NOTICE and licenses/.

Metadata

Release files for zyphra-textnorm 0.1.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.1.0
File Size Uploaded Provenance Actions
zyphra_textnorm-0.1.0.tar.gz 549.5 kB Without provenance Details for zyphra_textnorm-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for zyphra-textnorm 0.1.0
File Actions
zyphra_textnorm-0.1.0-cp39-abi3-win_arm64.whl CPython 3.9 abi3 Windows ARM64 Details for zyphra_textnorm-0.1.0-cp39-abi3-win_arm64.whl
zyphra_textnorm-0.1.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for zyphra_textnorm-0.1.0-cp39-abi3-win_amd64.whl
zyphra_textnorm-0.1.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.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
zyphra_textnorm-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for zyphra_textnorm-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
zyphra_textnorm-0.1.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for zyphra_textnorm-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
zyphra_textnorm-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for zyphra_textnorm-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 8.4 MB

Release files / zyphra_textnorm-0.1.0.tar.gz

Download URL zyphra_textnorm-0.1.0.tar.gz
Size 549.5 kB
Tags Source
SHA-256 checksum
How to use checksums
02cd3cc09c8670ecfa86c611563ff0ca6a4c2fe4b2faae1256a40e3edbbff8ce
BLAKE2b-256 checksum
How to use checksums
2292838cbb9bb93327a3c36b7f3215a2492fb3ba31738790285a8b42444db999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL zyphra_textnorm-0.1.0-cp39-abi3-win_arm64.whl
Size 1.2 MB
Tags CPython 3.9 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
378bc77471fedc07278705ca1b97bc9fc6055b81386c6d4a5e7aac9a62aaf473
BLAKE2b-256 checksum
How to use checksums
826614321b2397461d99867b1e457aae48f1601cfa5f755d231b058da0c5c41f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL zyphra_textnorm-0.1.0-cp39-abi3-win_amd64.whl
Size 1.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
9f376b109e97cb19728dbccdb9965a52dd5bce315d9bd82f3f5e91f3a130a258
BLAKE2b-256 checksum
How to use checksums
b3774d54d5a8ed315fb2706d6b046e1f57adb4a0d1db15c1bcb0f4657a66880c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL zyphra_textnorm-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
12dd8e79ed0bcd65fa1450fd420e7268b6dd2bd63d713f5dca04ec1924c552cd
BLAKE2b-256 checksum
How to use checksums
2c331e7c1e1659c2f1556eb2d788c3b146f621127d8e55d0ebfb316feef352a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL zyphra_textnorm-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 1.4 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
fcb6dc5a7022c30d591b8bb5f608134d12e69064535c4769fce6269111e292d3
BLAKE2b-256 checksum
How to use checksums
809cd70b06a198f6017c51da38b76fe3d550785ec4d1748d3e80c124bee519c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL zyphra_textnorm-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 1.3 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
886144098a94bd081e737ce3cace51d1d4c59824054317a06035aa61bca2eaa0
BLAKE2b-256 checksum
How to use checksums
dc6a2e46f057b6e5680c7113a6697b59d5ea135ee3e9d45bf57e587df8d5b6f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

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

Download URL zyphra_textnorm-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
efb99aefeb2547d538eae13449145a7aee94f9cd22e62e9259ea1bc91c08631d
BLAKE2b-256 checksum
How to use checksums
ce28261f7f95fc151db13b798f211cf951cf47c0bd20da75030f601d363b027d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for zyphra-textnorm 0.1.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