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

时间:2021-05-02 23:18:27

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.

我一直在想如何使用蜻蜓模块。我看了一下文档,但是我似乎不知道如何使用它。我只是想要能够识别出一些短语并对这些短语采取行动。

3 个解决方案

#1


5  

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

首先,python没有导入。这为程序提供了一个主循环。上面的

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)

#2


3  

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.)

首先,如果您使用的是Linux,您应该知道蜻蜓只适用于Windows语音识别或Dragon NaturallySpeaking + Natlink。(可以用虚拟机和Aenea在Linux上工作,但这似乎超出了这个问题的范围。)

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:

如果您正在与WSR一起使用它,那么它应该非常简单,只需确保Dragonfly位于您的Python路径中,并在主脚本末尾调用以下内容:

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.

如果你正在使用它与龙自然地说,遵循上面的链接到Natlink网站,并按照那里的指示安装和激活Natlink,然后尝试使用蜻蜓。安装好后(使用所有默认设置),您应该能够在C:\NatLink\NatLink\ NatLink\MacroSystem文件夹中放置蜻蜓脚本,并在启动Dragon时自动激活它们。

#3


1  

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.

#1


5  

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

首先,python没有导入。这为程序提供了一个主循环。上面的

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)

#2


3  

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.)

首先,如果您使用的是Linux,您应该知道蜻蜓只适用于Windows语音识别或Dragon NaturallySpeaking + Natlink。(可以用虚拟机和Aenea在Linux上工作,但这似乎超出了这个问题的范围。)

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:

如果您正在与WSR一起使用它,那么它应该非常简单,只需确保Dragonfly位于您的Python路径中,并在主脚本末尾调用以下内容:

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.

如果你正在使用它与龙自然地说,遵循上面的链接到Natlink网站,并按照那里的指示安装和激活Natlink,然后尝试使用蜻蜓。安装好后(使用所有默认设置),您应该能够在C:\NatLink\NatLink\ NatLink\MacroSystem文件夹中放置蜻蜓脚本,并在启动Dragon时自动激活它们。

#3


1  

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.