在Python 3.2(Windows)中导入pocketsphinx失败:"ImportError: No module named pocketsphinx
我正在尝试在 Python 3.2 上使用 pocketsphinx,但我感到很困惑。我把构建好的包放在了 site-packages 目录里,并确保我使用的是正确的音频文件格式。根据文档,Python 是被支持的,因为有 Python 的绑定。我在论坛上查了一下,似乎需要一个 _init_.py
文件,但这个文件没有包含在内,这可能是个问题?有什么建议可以解决这个问题吗?
我目前使用的是 pocketsphinx 和 sphinxbase 版本 0.8,下载链接和链接。我放入 site-packages 的文件都是 pocketsphinx 目录下 Debug 文件夹中的文件,具体包括:
- sphinxbase.dll
- pocketsphinx(.dll, .exp, .ilk, .lib, .pdb)
- pocketsphinx_batch(.exe, .ilk, .pdb)
- pocketsphinx_continuous(.exe, .ilk, .pdb)
- pocketsphinx_mdef_convert(.exe, .ilk, .pdb)
我使用的 Python 代码如下:
import pocketsphinx as ps
from pocketsphinx import sphinxbase
hmmd = 'C:\Python32\Lib\site-packages\pocketsphinx\model\hmm\en_US\hub4wsj_sc_8k'
lmd = 'C:\Python32\Lib\site-packages\pocketsphinx\model\lm\en_US\hub4.5000.DMP'
dictd = 'C:\Python32\Lib\site-packages\pocketsphinx\model\lm\en_US\hub4.5000.dic'
fraw1 = file(r'C:\Users\Stefan\Documents\2012\40I6\test1.wav', 'rb')
fraw1.seek(44)
speechRec = ps.Decoder(hmm = hmmd, lm = lmd, dict = dictd) speechRec.decode_raw(fRaw1)
result = speechRec.get_hyp()
print (result[0])
1 个回答
1
要编译Python模块,可以按照以下步骤操作:
- 根据需要,用Visual Studio构建sphinxbase和pocketsphinx。
- 把sphinxbase.lib和sphinxbase.dll从sphinxbase/bin/Release文件夹复制到sphinxbase/python和pocketsphinx/python文件夹。
- 把pocketsphinx.lib和pocketsphinx.dll从pocketsphinx/bin/Release文件夹复制到sphinxbase/python和pocketsphinx/python文件夹。
- 打开终端。
- 切换到sphinxbase/python目录。
运行以下命令:
python setup_win32.py install
切换到pocketsphinx/python目录。
运行以下命令:
python setup_win32.py install
运行命令来测试Python:
python ps_test.py