我正在使用pocketsphinx将语音编程到文本解码器。
程序运行正常但当我尝试进行关键字定位时会发生错误。
当我试图获得hypstr
时,问题似乎出现在最后的印刷品中。
我收到错误。
AttributeError: 'NoneType' object has no attribute 'hypstr'
我该如何解决?
# Decoder config
config = Decoder.default_config()
config.set_string('-hmm', os.path.join(MODEL_DIR, 'es/es'))
config.set_string('-dict', os.path.join(MODEL_DIR, 'voxforge_es_sphinx.dic'))
config.set_string('-lm', os.path.join(MODEL_DIR, 'es-20k.lm'))
#config.set_string('-keyphrase', 'escucha')
#config.set_float('-kws_threshold', 1e+20)
#config.set_string('-jsgf', GRAMMAR)
decoder = Decoder(config)
#decoder.set_jsgf_file('grammar', GRAMMAR)
decoder.set_keyphrase('keyphrase', 'escucha')
decoder.set_search('keyphrase')
# Pyaudio config
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=1024)
stream.start_stream()
in_speech_bf = False
decoder.start_utt()
while True:
buf = stream.read(1024, exception_on_overflow = False)
if buf:
decoder.process_raw(buf, False, False)
if decoder.get_in_speech() != in_speech_bf:
in_speech_bf = decoder.get_in_speech()
if not in_speech_bf:
decoder.end_utt()
#Print hypothesis
print 'Result:', decoder.hyp().hypstr
if decoder.get_search() == 'keyphrase':
decoder.set_search('lm')
else:
decoder.set_search('keyphrase')
decoder.start_utt()
else:
break
decoder.end_utt()
INFO: ngram_search_fwdtree.c(323): Max nonroot chan increased to 55041
INFO: ngram_search_fwdtree.c(333): Created 233 root, 54913 non-root channels, 30 single-phone words
INFO: ngram_search_fwdflat.c(157): fwdflat: min_ef_width = 4, max_sf_win = 25
INFO: kws_search.c(406): KWS(beam: -1080, plp: -23, default threshold 0, delay 10)
INFO: cmn_live.c(120): Update from < 40.00 3.00 -1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 >
INFO: cmn_live.c(138): Update to < 25.82 -4.30 -6.09 0.55 -2.52 -1.35 1.77 -1.72 -2.17 0.29 0.35 -2.03 -0.39 >
INFO: kws_search.c(656): kws 0.20 CPU 0.048 xRT
INFO: kws_search.c(658): kws 4.35 wall 1.055 xRT
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1599, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1026, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Users/tonydelalg/PycharmProjects/untitled/markdown.py", line 43, in <module>
print 'Result:', decoder.hyp().hypstr
Result:
AttributeError: 'NoneType' object has no attribute 'hypstr'
INFO: kws_search.c(448): TOTAL kws 0.20 CPU 0.048 xRT
INFO: kws_search.c(451): TOTAL kws 4.35 wall 1.058 xRT