Thursday 15 August 2013

Python speech recognition 'module' object has no attribute 'VARIANT' -



Python speech recognition 'module' object has no attribute 'VARIANT' -

i'm trying started using speech recognition in python. first tried pyspeech (https://code.google.com/p/pyspeech/) using code:

def listen(): while 1: said = speech.input() print said if said == "off": break

and got next traceback:

traceback (most recent phone call last): file "c:/users/redacted/documents/python projects/listen.py", line 59, in <module> useful.listen() file "c:/users/redacted/documents/python projects/listen.py", line 48, in hear said = speech.input() file "c:\python27\lib\site-packages\speech.py", line 162, in input listener = listenforanything(response) file "c:\python27\lib\site-packages\speech.py", line 193, in listenforanything homecoming _startlistening(none, callback) file "c:\python27\lib\site-packages\speech.py", line 223, in _startlistening grammar = context.creategrammar() file "c:\users\redacted\appdata\local\temp\gen_py\2.7\c866ca3a-32f7-11d2-9602-00c04f8ee628x0x5x4.py", line 2298, in creategrammar ret = self._oleobj_.invoketypes(14, lcid, 1, (9, 0), ((12, 49),),grammarid attributeerror: 'module' object has no attribute 'variant'

then tried dragonfly per suggestion @ top of googlecode page pyspeech using next illustration code commonly found on dragonfly docs:

from dragonfly.all import grammar, compoundrule # voice command rule combining spoken form , recognition processing. class examplerule(compoundrule): spec = "do computer" # spoken form of command. def _process_recognition(self, node, extras): # callback when command spoken. print "voice command spoken." # create grammar contains , loads command rule. grammar = grammar("example grammar") # create grammar contain command rule. grammar.add_rule(examplerule()) # add together command rule grammar. grammar.load() # load grammar.

and got similar traceback:

traceback (most recent phone call last): file "c:/users/redacted/documents/python projects/listen.py", line 14, in <module> grammar.load() # load grammar. file "c:\python27\lib\site-packages\dragonfly\grammar\grammar_base.py", line 302, in load self._engine.load_grammar(self) file "c:\python27\lib\site-packages\dragonfly\engines\engine_sapi5.py", line 79, in load_grammar handle = self._compiler.compile_grammar(grammar, context) file "c:\python27\lib\site-packages\dragonfly\engines\compiler_sapi5.py", line 68, in compile_grammar grammar_handle = context.creategrammar() file "c:\users\redacted\appdata\local\temp\gen_py\2.7\c866ca3a-32f7-11d2-9602-00c04f8ee628x0x5x4.py", line 2298, in creategrammar ret = self._oleobj_.invoketypes(14, lcid, 1, (9, 0), ((12, 49),),grammarid attributeerror: 'module' object has no attribute 'variant'

both modules installed using pip , run using python 2.7 interpreter. seems python version issue me given same error thrown 2 different modules implementing same thing i'm pretty stuck on how proceed.

any help appreciated , i'm happy provide more code/info requested. thanks!

edit 1: experiencing similar problem happens stumble across post, seek https://pypi.python.org/pypi/speechrecognition/ alternative on py2.7. if runs without error behaves inconsistently or infinite loops, seek modifying init method of recognizer class in init.py around line 100. energy threshold required tinkering me (100->300) due specifics of mic setup. increased quiet duration (0.5->0.7) because cutting me off sometimes. after these changes works me, returning accurate text of input speech in ~2 seconds after capture ends.

python python-2.7 speech-recognition attributeerror dragonfly

No comments:

Post a Comment