我正在使用卡内基梅隆大学的发音字典,致力于在Python中检测押韵,并想知道:如何估计两个单词之间的语音相似性?换句话说,是否有一种算法可以确定“hands”和“plans”比“hands”和“fries”更接近韵律?
一些背景信息:起初,我希望说如果两个单词的重读音节及其后续的所有音节都相同,则它们是押韵的(如果您想在Python中复制,请参考c06d):
def create_cmu_sound_dict():
final_sound_dict = {}
with open('resources/c06d/c06d') as cmu_dict:
cmu_dict = cmu_dict.read().split("\n")
for i in cmu_dict:
i_s = i.split()
if len(i_s) > 1:
word = i_s[0]
syllables = i_s[1:]
final_sound = ""
final_sound_switch = 0
for j in syllables:
if "1" in j:
final_sound_switch = 1
final_sound += j
elif final_sound_switch == 1:
final_sound += j
final_sound_dict[word.lower()] = final_sound
return final_sound_dict
如果我接着运行
print cmu_final_sound_dict["hands"]
print cmu_final_sound_dict["plans"]
我发现hands和plans听起来非常相似。虽然我可以自己努力估算它们之间的相似度,但我想询问一下:是否有复杂的算法可以将这种声音(或听觉)相似度与数学值联系起来?也就是说,有哪些算法或软件包可以用来数值化两个单词之间的音位相似度?我知道这是一个大问题,但如果其他人能够提供任何建议,我将不胜感激。