TN converts written expressions into their spoken forms, for example 12 → 十二. It is commonly used before speech synthesis.
Inverse text normalization
ITN converts spoken expressions into written forms, for example 十二 → 12. It is commonly used after speech recognition.
Supported languages
Language
CLI code
TN
ITN
Python package
Arabic
ar
Yes
Yes
arabic
Armenian
hy
Yes
Yes
armenian
Chinese
zh
Yes
Yes
chinese
English
en
Yes
Yes
english
French
fr
Yes
Yes
french
German
de
Yes
Yes
german
Hebrew
he
Yes
Yes
hebrew
Hindi
hi
Yes
Yes
hindi
Hindi–English (code-mixed)
hi_en
No
Yes
hindi_english
Hungarian
hu
Yes
Yes
hungarian
Italian
it
Yes
Yes
italian
Japanese
ja
Yes
Yes
japanese
Kinyarwanda
rw
Yes
Yes
kinyarwanda
Korean
ko
Yes
Yes
korean
Marathi
mr
Yes
Yes
marathi
Portuguese
pt
Yes
Yes
portuguese
Russian
ru
Yes
Yes
russian
Spanish
es
Yes
Yes
spanish
Spanish–English (code-mixed)
es_en
No
Yes
spanish_english
Swedish
sv
Yes
Yes
swedish
Vietnamese
vi
Yes
Yes
vietnamese
Chinese is the CLI default. Rule coverage and configurable options vary by language and direction.
The published package includes Chinese, English, and Japanese. The other languages are included in this source checkout; install from source to use them before the next package release.
Quick start
Install
Install the published package:
pip install WeTextProcessing
For the latest rules, including every language beyond Chinese, English, and Japanese, install from source:
git clone https://github.com/wenet-e2e/WeTextProcessing.git
cd WeTextProcessing
pip install -e .
Pynini/OpenFst must be available in your Python environment. If a compatible wheel is unavailable, follow the Pynini installation instructions. On Windows, the project's CI uses conda install -c conda-forge pynini before installing WeTextProcessing.
Run the CLI
wetn --text "2.5平方电线"
weitn --text "二点五平方电线"
wetn --language en --text "13 dollars"
weitn --language en --text "thirteen dollars"
wetn --language de --text "23"
weitn --language de --text "dreiundzwanzig"
wetn --language ja --text "12時"
weitn --language ja --text "十二時"
wetn --language ko --text "오후 3시 30분"
weitn --language ko --text "오천원"
Each input produces two lines: the tagged representation, then the verbalized result. The tagger preserves raw field values; the verbalizer performs the conversion.
The same interfaces are available as python -m tn and python -m itn. Both accept --text, --file PATH, or UTF-8 text from standard input when neither option is supplied:
python -m tn --language en --file input.txt
python -m itn --language ko < input.txt
Only input line endings are removed before processing. Other spaces are passed to the selected language's rules.
Language-specific options
Inspect the options for the selected language and direction:
wetn --language zh --help
weitn --language ko --help
The hours and minutes remain written values in the tags, rather than being replaced with their Korean readings.
Input/output span mapping
normalize_with_mapping() returns normalized text and the spans matched by grammar rules:
from tn.chinese.normalizer import Normalizer
normalizer = Normalizer()
result = normalizer.normalize_with_mapping("今天中午12点")
print(result.output_text)
for mapping in result.mappings:
print(mapping.token_type, mapping.input_text, "=>", mapping.output_text)
Output:
今天中午十二点
math 12 => 十二
Offsets are half-open Unicode character offsets, not UTF-8 byte offsets. Use include_identity=True to include unchanged tokens, or result.as_dict() to obtain a serializable representation. Mappings are traced through the WFSTs, not inferred from a text diff.
nbest=1 returns a string or a single NormalizationResult; nbest>1 returns a list of up to that many unique outputs. The mapping API follows the same output ranking.
FST caching
Graphs are cached automatically outside the source tree. Cache bundles record the pipeline's configuration and grammar-source fingerprint; changing either causes a new bundle to be built.
Setting
Behavior
cache_dir=None
Use the platform's default user cache
cache_dir="/path/to/cache"
Choose an explicit cache root
cache_dir=False
Build in memory without persistent caching
overwrite_cache=True
Force rebuilding the selected bundle
from tn.chinese.normalizer import Normalizer
normalizer = Normalizer(cache_dir="/path/to/wetext-cache")
uncached = Normalizer(cache_dir=False)
The CLI exposes --cache-dir PATH and --overwrite-cache. Normal use does not require forced rebuilds.
Development and deployment
Install development dependencies and run the tests:
Before adding or changing a language rule, read the Python rule architecture guide. Rules preserve raw fields in the tagger, apply semantic conversion in the verbalizer, and use pipeline-owned rule inventories and field-order schemas.
Python cache bundles are not C++ runtime exports. Follow the runtime's model and build instructions for native deployment.
Community
Use GitHub Issues for questions, bug reports, and feature requests.
For Chinese users, follow the WeNet official account using the QR code on the left. Scan the personal QR code on the right to contact the person who can invite you to the WeChat discussion group.