我一直在努力弄清楚如何使用 Dragonfly 模块。我已经查看了文档,但似乎无法弄清楚如何使用它。我只想能够识别一些短语并根据这些短语采取行动。
最佳答案
没错,这个例子将会终止。我已经多次看到这个特定示例,但它缺少一些关键功能。
首先是没有导入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)
关于python - 您如何使用 Python 模块 Dragonfly 识别语音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3644129/