python-pinyin icon indicating copy to clipboard operation
python-pinyin copied to clipboard

有没有to_bopomofo ?

Open SRbone opened this issue 2 years ago • 2 comments

运行环境

  • 操作系统(Linux/macOS/Windows):win10
  • Python 版本:3.8.10
  • pypinyin 版本:0.49.0

问题描述

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

问题复现步骤

SRbone avatar Aug 14 '23 05:08 SRbone

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

mozillazg avatar Aug 14 '23 13:08 mozillazg

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

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

SRbone avatar Aug 15 '23 12:08 SRbone