【发布时间】:2015-03-29 15:20:23
【问题描述】:
我正在使用 Python,我决定分解并制作大量短语,以供语音识别模块的结果进行比较。到目前为止,我得到了:
phrases = [
"what time is it",
"what's the weather",
"what's the date",
"hello",
"hi",
"what's up",
"how are you"
]
(我几分钟前才开始做这个,所以我还没有很多......主要只是一个大纲)但无论如何,我想要一个这样的函数......
def match(phrase):
#match_greatest will start at zero but continuously update if the string
#being compared has a higher percentage match
match_greatest = 0
#match will store the actual string that is closest
match = ""
for i in phrases:
#this is the part I need help with...
match_current = #somehow get the percentage that the argument phrase matches the phrase it's comparing to
#if the current phrase is a closer match than before, update it
if match_current > match_greatest:
match_greatest = match_current
match = i
return match
...举个例子,如果我调用 match("what time it a") 或 match("what time sit") -- 这些是语音识别可能给出的误读示例 -- 并使用我当前的一组短语,它会返回“现在几点”。
【问题讨论】:
-
迭代每个字符,如果两个位置的字符相同,即在输入的字符串和匹配的字符串中,增加一些变量并在末尾将该变量除以字符串的总长度你想匹配。换句话说,创建一个百分比匹配
-
你用什么麦克风输入?
标签: python compare speech-recognition phrase