如何使用Python模块蜻蜓识别语音? [英] How do you recognize speech with the Python module Dragonfly?

查看:20
本文介绍了如何使用Python模块蜻蜓识别语音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图弄清楚如何使用蜻蜓模块。我已经看了文档,但我似乎不知道如何使用它。我只希望能够识别几个短语,并根据这些短语采取行动。

推荐答案

正确,此示例将终止。我已经见过这个特定的例子很多,但它缺少许多关键功能。

第一件事是不导入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模块蜻蜓识别语音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆