2015-09-19 40 views
2

我正在玩python中的Dragonfly lib。我正在使用Windows7 + python2.6。然而,当我尝试运行演示代码(这是从蜻蜓为例)在python2.6上使用python蜻蜓python2.6问题

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. 

我收到以下错误:

Traceback (most recent call last): 
    File "test.py", line 2, in <module> 
    from dragonfly.all import Grammar, CompoundRule 
ImportError: No module named all 

我怎样才能解决呢?

+0

上面的演示脚本是否保存为“dragonfly.py”? –

+0

它被保存为test.py – SKulibin

回答

1

摆脱.all。这个例子似乎已经过时了。它应该看起来像这样:

from dragonfly import Grammar, CompoundRule 
+1

回溯(最近一次调用最后一次): 文件“test.py”,第12行,在 语法=语法(“示例语法”)#创建包含命令规则的语法。 文件“d:\ server \ usr \ local \ python \ lib \ site-packages \ dragonfly-0.6.6b1-py2.6.egg \ dragonfly \ grammar \ grammar_base.py”,第81行,在__init__中 self._engine = get_engine() get_engine中的第86行的文件“d:\ server \ usr \ local \ python \ lib \ site-packages \ dragonfly-0.6.6b1-py2.6.egg \ dragonfly \ engines \ __ init__.py” raise EngineError(“没有找到可用的引擎”) dragonfly.engines.base.engine.EngineError:没有找到可用的引擎 – SKulibin

+0

“从蜻蜓导入语法,复合规则”后出现此错误 – SKulibin

+0

您是否尝试运行此脚本直? “python test.py”?这不是这些脚本如何运行的。你需要natlink,当你的语音识别系统加载时,它会加载宏。这里的方向应该有很大的帮助:http://qh.antenna.nl/unimacro/installation/installation.html - 你不需要启用unimacro或vocola,只需获得natlink设置 –