How do you recognize speech with the Python module Dragonfly?

Gabe picture Gabe · Sep 4, 2010 · Viewed 9.5k times · Source

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.

Answer

user1110728 picture user1110728 · Apr 10, 2013

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)