如何使用 Python 模块 Dragonfly 识别语音?

发布于 2024-09-18 03:15:55 字数 76 浏览 6 评论 0原文

我一直在试图弄清楚如何使用 Dragonfly 模块。我查看了文档,但似乎不知道如何使用它。我只想能够识别一些短语并根据这些短语采取行动。

I have been trying to figure out how to use the Dragonfly module. I have taken a look at the documentation, but I can't seem to figure out how to use it. I just want to be able to recognize a few phrases and act upon those phrases.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

马蹄踏│碎落叶 2024-09-25 03:15:55

是的,这个例子将终止。我已经看过这个特定的例子很多了,它缺少一些关键功能。

首先是 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)

That's correct, this example will terminate. I've seen this particular example quite a bit, and it is missing a number of key features.

The first thing is that pythoncom is not imported. This provides a main loop for the program. The above

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)
野侃 2024-09-25 03:15:55

首先,如果您使用的是 Linux,您应该知道 Dragonfly 仅适用于 Windows 语音识别或 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 时自动激活它们。

First, in case you're using Linux, you should know that Dragonfly only works with Windows Speech Recognition or Dragon NaturallySpeaking + Natlink. (It is possible to get it working on Linux with a virtual machine and Aenea, but that seems out of the scope of this question.)

If you're using it with WSR, it should be as simple as making sure that Dragonfly is in your Python path and calling the following at the end of your main script:

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

If you're using it with Dragon NaturallySpeaking, follow the link above to the Natlink website and follow the instructions there to install and activate Natlink before trying to use Dragonfly. Once it is installed (use all the defaults), you should be able to put Dragonfly scripts in your C:\NatLink\NatLink\MacroSystem folder and have them activate automatically when you start Dragon NaturallySpeaking.

紫罗兰の梦幻 2024-09-25 03:15:55

我发现本文档中给出的用法示例是非常简单且不言自明:

Dragonfly 用法的一个非常简单的示例是创建静态语音
带有回调的命令,该回调将在命令执行时被调用
说。操作如下:::

   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.

I find the usage example given in this document to be pretty simple and self-explaining:

A very simple example of Dragonfly usage is to create a static voice
command with a callback that will be called when the command is
spoken. This is done as follows: ::

   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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文