MandarinG2P
Models & Types · AiDotNet.TextToSpeech.FrontEnd
Converts Mandarin Chinese text to IPA phonemes, as VALL-E X’s reference front end does (Plachtaa/VALL-E-X,
utils/g2p/mandarin.py, chinese_to_ipa).
For Beginners
Chinese characters do not spell their sounds, so this looks words up in a dictionary to find each character’s pronunciation (and tone) and writes it in the International Phonetic Alphabet.
How It Works
The pipeline is the reference’s: Arabic numerals become Chinese numerals (cn2an’s an2cn, “low” mode), jieba
segments the text into words (its prefix dictionary, maximum-probability route and HMM for unknown words), pypinyin
reads each word in BOPOMOFO (its phrase dictionary first, by forward maximum matching, then each character’s first
reading), Latin letters are spelled in bopomofo, and a table maps bopomofo to IPA with tone contours
(→ ↑ ↓↑ ↓), followed by the reference’s four rewrite rules (glides, apical vowels). The dictionaries are jieba 0.42.1’s
and pypinyin 0.55.0’s (MIT), exported by tools/reference-data/mandarin_g2p_resources.py.
Phonemize splits the IPA into the reference tokenizer’s base symbols: one symbol per character, with
spaces as the word separator _.
Properties
| Property | Summary |
|---|---|
IReadOnlyList<string> Symbols { get; } |
Every symbol Phonemize produces from Chinese, punctuation and Latin letters (characters it passes through unchanged, such as other symbols, are outside it). |
MandarinG2P Default { get; } |
The shared instance (the dictionaries load once, on first use). |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<string> Phonemize(string text) |
The phonemes of text: one symbol per IPA character, words separated by _. |
string ToIpa(string text) |
The reference’s chinese_to_ipa of text. |