Search code examples
pythonwindowsimporterrorspeech-to-textcmusphinx

Importing pocketsphinx not working python 3.2 (Windows). "ImportError: No module named pocketsphinx"


I'm trying to use pocketsphinx on python 3.2 but I'm very confused. I've placed the builded packages in the site-packages directory, made sure I'm using the right audio file format .According to the documentation python is supported because there are python bindings. I've looked around the forum and it seems that an _init_.py file is needed which is not included so that may be an issue? Any suggestions on how to fix this problem?

I am currently using pocketsphinx and sphinxbase v 0.8 downloaded link and link. The files I put into site packages are all files contained in the Debug folder of the pocketsphinx directory. namely:

  • sphinxbase.dll
  • pocketsphinx(.dll, .exp,.ilk,.lib,.pdb)
  • pocketsphinx_batch(.exe,.ilk,.pdb)
  • pocketsphinx_continuous(.exe,.ilk,.pdb)
  • pocketsphinx_mdef_convert(.exe,.ilk,.pdb)

I am using the following Python code:

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])

Solution

  • To compile python module do the following:

    1. Build sphinxbase and pocketsphinx with Visual Studio as needed
    2. copy sphinxbase.lib and sphinxbase.dll from sphinxbase/bin/Release to sphinxbase/python and to pocketsphinx/python
    3. copy pocketsphinx.lib and pocketsphinx.dll from pocketsphinx/bin/Release to sphinxbase/python and to pocketsphinx/python
    4. Open terminal
    5. Change directory to sphixnbase/python
    6. Run the command

      python setup_win32.py install

    7. Change directory to pocketsphinx/python

    8. Run the command

      python setup_win32.py install

    9. Run the command to test python

      python ps_test.py