我正在尝试使用 python 将英语词典中的单词转换为简单的音素。我使用的是 python 3.5,而所有示例都是针对 python 2 + 的。
例如在文件 test.txt 的以下文本中:
what a joke
is your name
this fall summer singer
well what do I call this thing mister
在这里,我首先要提取每个单词,然后将它们转换为音素。这是我想要的结果
what WH AT
a AE
joke JOH K
is ES
....and so on
这是我的 python 代码,但它太早而且太少。您能否建议我更多地将什么转换为WH AT我需要先查找是否有字母wh然后将其替换为WH
with open ('test.txt',mode='r',encoding='utf8')as f:
for line in f:
for word in line.split():
phenome = word.replace('what', word + ' WH AT')
print (phenome)