利用python实现汉字转拼音

pip install xpinyin
from
xpinyin import Pinyin # 实例拼音转换对象 p = Pinyin() # 进行拼音转换 ret = p.get_pinyin(u"汉语拼音转换", tone_marks='marks') ret1 = p.get_pinyin(u"汉语拼音转换", tone_marks='numbers') print(ret + '\n' + ret1)

hàn-yǔ-pīn-yīn-zhuǎn-huàn
han4-yu3-pin1-yin1-zhuan3-huan4

 
print(p.get_pinyin(u"上海"))
'shang-hai'
# 得到转化后的结果 # hàn-yǔ-pīn-yīn-zhuǎn-huàn # han4-yu3-pin1-yin1-zhuan3-huan4
来自:https://www.jb51.net/article/167461.htm

 

你可能感兴趣的:(利用python实现汉字转拼音)