Download examples/quickstart.py from baicai1145/g2pS: direct link, hf CLI and curl.
- Browser
- Download file 378 Bytes
-
https://huggingface.co/baicai1145/g2pS/resolve/main/examples/quickstart.py
- Command line
-
hf download hf://baicai1145/g2pS/examples/quickstart.py
-
curl -L -o quickstart.py https://huggingface.co/baicai1145/g2pS/resolve/main/examples/quickstart.py
378 Bytes
| """Full-sentence pinyin with g2pS + pypinyin fallback for monophonic chars.""" | |
| from g2ps import G2pS | |
| import pypinyin | |
| g = G2pS('models/nano') | |
| def full_pinyin(text): | |
| used, pairs = g.convert(text) | |
| return [p or pypinyin.pinyin(c, style=pypinyin.Style.TONE3, heteronym=False)[0][0] | |
| for c, p in pairs] | |
| print(full_pinyin('他在银行工作,行踪不定。')) | |