python 汉字转拼音

# 办法1
from xpinyin import Pinyin
pin = Pinyin()
chars = "随着宋"
ss = pin.get_pinyin(chars)
print(ss) # 输出 sui-zhao-song

#办法2
import pypinyin
chars = "随着宋"
ss = pypinyin.pinyin(chars, style=pypinyin.NORMAL)
print(ss) # 输出 [['sui'], ['zhe'], ['song']]

现在感觉第二个办法要准确一点

 

你可能感兴趣的:(自然语言处理)