【问题标题】:How do you recognize speech with the Python module Dragonfly?您如何使用 Python 模块 Dragonfly 识别语音?
【发布时间】:2010-09-04 21:50:20
【问题描述】:

我一直在尝试弄清楚如何使用 Dragonfly 模块。我查看了文档,但似乎无法弄清楚如何使用它。我只是希望能够识别一些短语并根据这些短语采取行动。

【问题讨论】:

  • 您必须决定是希望 Dragon NaturallySpeaking 提供语音到文本的翻译,还是希望依赖内置的 Windows 语音识别应用程序。

标签: python speech-recognition python-dragonfly


【解决方案1】:

没错,这个例子将终止。这个特殊的例子我已经看过很多次了,它缺少一些关键特性。

首先是没有导入pythoncom。这为程序提供了一个主循环。以上

from dragonfly.all import Grammar, CompoundRule

# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    spec = "do something computer"                  # 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()
    sleep(.1)

【讨论】:

  • 小修复:使用前需要添加“import pythoncom”。
  • 这里的消息泵其实是NaturallySpeaking应用程序在natlink.pyd dll绑定到注册表中的NaturallySpeaking应用程序时自己提供的。这是语音计算站点上记录的设置过程的一部分。一旦设置了注册表和相关路径,就不需要外部消息泵,应用程序应该直接响应语音。请注意,此评论仅适用于您使用 NaturallySpeaking 提供语音到文本翻译的情况。
  • 修复现有答案而不是复制其内容并在单独的帖子中进行修改不是更好吗?
【解决方案2】:

首先,如果您使用的是 Linux,您应该知道 Dragonfly 仅适用于 Windows Speech Recognition 或 Dragon NaturallySpeaking + Natlink。 (可以通过虚拟机和Aenea 在 Linux 上运行它,但这似乎超出了这个问题的范围。)

如果你将它与 WSR 一起使用,它应该就像确保 Dragonfly 在你的 Python 路径中并在你的主脚本末尾调用以下代码一样简单:

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

如果您将它与 Dragon NaturallySpeaking 一起使用,请点击上面的链接到 Natlink 网站并按照那里的说明安装和激活 Natlink,然后再尝试使用 Dragonfly。安装完成后(使用所有默认设置),您应该能够将 Dragonfly 脚本放在 C:\NatLink\NatLink\MacroSystem 文件夹中,并在您启动 Dragon NaturallySpeaking 时自动激活它们。

【讨论】:

    【解决方案3】:

    我发现this document 中给出的用法示例非常简单且不言自明:

    蜻蜓使用的一个非常简单的例子是创建一个静态声音 带有回调的命令,该回调将在命令执行时调用 说。这是按如下方式完成的:::

       from dragonfly.all import Grammar, CompoundRule
    
       # Voice command rule combining spoken form and recognition processing.
       class ExampleRule(CompoundRule):
           spec = "do something computer"                  # 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.
    

    【讨论】:

    • 这是因为 - 如上面 user1110728 的回答中所述,没有等待发送消息的 while 循环。
    • 在我的情况下,这个模块问我有关 win32gui 的问题,而我在 Debian 上运行它:V
    猜你喜欢
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    相关资源
    最近更新 更多