g2p-mix

raw JSON →
0.6.5 verified Sat May 09 auth: no python

A grapheme-to-phoneme conversion library with mixed models (rule-based and neural). Version 0.6.5. Irregular releases.

pip install g2p-mix
error ModuleNotFoundError: No module named 'g2p_mix'
cause Installed package named 'g2p-mix' but import uses underscore.
fix
Use 'from g2p_mix import G2pMix' (underscore, not hyphen).
error ImportError: cannot import name 'G2pMix' from 'g2p_mix'
cause Outdated installation or different version where class name changed.
fix
Upgrade: pip install --upgrade g2p-mix
error ValueError: not enough values to unpack (expected 2, got 1)
cause Old code expects tuple (phoneme, tone) but newer version returns dict.
fix
Update result access: result[0]['phonemes'] instead of phoneme, tone = result[0]
breaking In version 0.5.x, the return format changed from list of tuples to list of dicts. Code relying on tuple unpacking will break.
fix Access phonemes via dict keys (e.g., result[0]['phonemes']) instead of tuple indexing.
gotcha Non-Chinese characters (e.g., English letters, digits) may be silently dropped or converted incorrectly. The library is designed primarily for Chinese text.
fix Pre-process text to ensure only Chinese characters are passed, or handle non-Chinese separately.
gotcha The default model may require downloading data on first run, which can be slow and may fail behind a proxy.
fix Set environment variable G2PMIX_DATA_DIR to a custom path to control cache location.

Initialize G2pMix and convert Chinese text to phonemes.

from g2p_mix import G2pMix

g2p = G2pMix()
text = "中华人民共和国于1949年成立。"
result = g2p(text)
print(result)