你如何识别Python模块Dragonfly的演讲?

Gab*_*abe 10 python speech-recognition python-dragonfly

我一直试图弄清楚如何使用Dragonfly模块.我看了一下文档,但我似乎无法弄清楚如何使用它.我只是想能够识别一些短语并对这些短语采取行动.

小智 5

这是正确的,这个例子将终止.我已经看到了这个特殊的例子,它缺少一些关键功能.

第一件事是没有导入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)
Run Code Online (Sandbox Code Playgroud)