【问题标题】:python dragonfly to recognize similar wordspython蜻蜓识别相似词
【发布时间】:2014-12-03 06:03:50
【问题描述】:

我正在使用 wsr 与 Dragon fly 一起做一个程序,它必须分析一个单词,任何匹配该单词的语音都应该输出“是的,它匹配”

如果我说“czechoslovakia”,那么即使对于这个世界上所有类似的匹配,它也必须打印为 true,例如“circle slovakia, cat on slavia,seko vakia...”的单词。

具体的方法,我应该使用什么方法?

我的程序

from dragonfly.all import *
import pythoncom
import time
# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    spec = "czechoslovakia|circle slovalia|sceko bakia|cat on ania"                 # Spoken form of command.

    def _process_recognition(self, node, extras):   # Callback when command is spoken.
         print "Voice command spoken."

# Create a grammar which contains and loads the command rule.
grammar = Grammar("example grammar")                # Create a grammar to contain the command    rule.
grammar.add_rule(ExampleRule())                     # Add the command rule to the grammar.
grammar.load()                                      # Load the grammar.

while True:
    pythoncom.PumpWaitingMessages()
    time.sleep(.1)

【问题讨论】:

  • 那你如何定义“相似”。你可能想详细说明一下。

标签: python speech-recognition speech python-dragonfly


【解决方案1】:

Dragonfly 中没有任何内置功能可以让您执行此操作,但您还有其他一些选择。

  1. 如果您希望动态生成规范,您可能需要 看看Fuzzy。你可以给它一个词并用它来生成 该词的其他类似发音词。然后你可以创建 他们的规格。
  2. Here is the WSR engine class 在蜻蜓。 我对 SAPI5 了解不多,但you might be able to ask it for alternatives。如果可以,您也许可以扩展 Dragonfly GrammarWrapper 公开替代方案,然后使用 笼统的语法来保存所有的话语,然后过滤掉你的 想要(可能使用模糊)。
  3. 如果您使用的是 Natlink,我会推荐 查看结果对象。如您所见here,结果 对象可以访问 Dragon 的所有不同假设 你在给定的话语中说。就像我的第二个建议一样, 您可以捕获所有内容,然后过滤您想要的内容:

.

from natlinkutils import GrammarBase

class CatchAll(GrammarBase):

    # this spec will catch everything
    gramSpec = """
        <start> exported = {emptyList};
    """

    def initialize(self):
        self.load(self.gramSpec, allResults=1)
        self.activateAll()

    def gotResultsObject(self, recogType, resObj):
        for x in range(0, 100):
            try:
                possible_interpretation = resObj.getWords(x)
                # do whatever sort of filtering you want here
            except Exception:
                break

c = CatchAll()
c.initialize()

def unload():
    global c
    if c:
        c.unload()
    c = None

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多