Skip to main content
 首页 » 编程设计

Python 3.3 似乎无法在 pocketsphinx 库中找到解码器模块

2025年05月04日10jyk

我收到错误 AttributeError: 'module' object has no attribute 'Decoder'。 我正在使用以下代码。因为没有包含 setup.py 文件,所以我手动将 dll 和库移动到 python33 目录中它们各自的文件夹中。 (lib 中的库文件和 DLL 中的 dll)。我能够毫无错误地导入 pocketsphinx 和 sphinxbase 模块。任何帮助,将不胜感激。

import pocketsphinx  
import sphinxbase  
 
 
 
lmd="C:\Python33\Lib\site-packages\pocketsphinx\model\lm\HUB4_trigram_lm\language_model.arpaformat" 
hmd="C:\Python33\Lib\site-packages\pocketsphinx\model\hmm\en_US" 
dictd="C:\Python33\Lib\site-packages\pocketsphinx\model\lm\HUB4_trigram_lm\language_model.vocabulary" 
 
fh = open('test1.wav', 'rb') 
fh.seek(44) 
decoder = pocketsphinx.Decoder(hmmd,lmd, dictp) 
nsamp = Decoder.decode_raw(fh) 
 
hyp, uttid, score = decoder.get_hyp() 
print('Got result'+ hyp+'score'+score)  

请您参考如下方法:

nsamp = Decoder.decode_raw(fh)

这部分必须是decoder.decode_raw(fh)。您正在尝试在默认模块中寻找解码器,而不是在对象中寻找方法。