Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you recognize speech with the Python module 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.

like image 953
Gabe Avatar asked Sep 04 '10 21:09

Gabe


2 Answers

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)
like image 82
user1110728 Avatar answered Sep 19 '22 19:09

user1110728


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.

like image 39
synkarius Avatar answered Sep 23 '22 19:09

synkarius