1 #pip install pypinyin汉字转换汉语拼音
 2 from pypinyin import lazy_pinyin,TONE,TONE2,TONE3
 3 str="你知道我是谁吗?"
 4 res=lazy_pinyin(str)
 5 res1=lazy_pinyin(str,style=TONE)
 6 res2=lazy_pinyin(str,style=TONE2)
 7 res3=lazy_pinyin(str,style=TONE3)
 8 print(res)
 9 print(res1)
10 print(res2)
11 print(res3)
12 
13 # ['ni', 'zhi', 'dao', 'wo', 'shi', 'shei', 'ma', '?']
14 # ['nǐ', 'zhī', 'dào', 'wǒ', 'shì', 'shéi', 'ma', '?']
15 # ['ni3', 'zhi1', 'da4o', 'wo3', 'shi4', 'she2i', 'ma', '?']
16 # ['ni3', 'zhi1', 'dao4', 'wo3', 'shi4', 'shei2', 'ma', '?']

可应用在同音汉字模糊匹配,比如在ai领域的语音识别方向

相关文章:

  • 2021-11-16
  • 2021-10-18
  • 2021-08-18
  • 2022-12-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-17
  • 2021-12-12
  • 2022-12-23
  • 2021-11-30
  • 2021-05-26
  • 2021-08-11
相关资源
相似解决方案