mozillazg / python-pinyin

汉字转拼音(pypinyin)
https://pypinyin.readthedocs.io
MIT License
4.83k stars 607 forks source link

有没有to_bopomofo ? #304

Open SRbone opened 1 year ago

SRbone commented 1 year ago

运行环境

问题描述

没啥bug, 请问从拼音风格怎么转到bopomofo啊? 比如: pinyin = lazy_pinyin('衣裳', style=Style.TONE3, neutral_tone_with_five=True) bopomofo = to_bopomofo(pinyin) 有没有to_bopomofo的风格转化啊?

问题复现步骤

mozillazg commented 1 year ago

@SRbone 目前没有单独的 to_bopomofo 函数,不过参考一下 https://github.com/mozillazg/python-pinyin/blob/master/pypinyin/style/bopomofo.py 这个文件里的相关内容。

SRbone commented 1 year ago

多谢多谢,果然里面两句话就搞定了。

for find_re, replace in BOPOMOFO_REPLACE:
    pinyin = find_re.sub(replace, pinyin)
pinyin = ''.join(BOPOMOFO_TABLE.get(x, x) for x in pinyin)