Reputation: 21
I have installed the latest versions of pocketsphinx and sphinxbase (0.8). I try to import pocketsphinx into python code (version 3.4.2 of Python) and to use the "Decoder" like this:
try:
import sphinxbase
import pocketsphinx as ps
except:
print ("Pocket sphinx and sphixbase is not installed in your system.
Please install it with package manager.")
speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp, beam = '1e-80')
wavFile = file(wavfile,'rb')
wavFile.seek(44)
speechRec.decode_raw(wavFile)
However, I get the following error:
AttributeError: 'module' object has no attribute 'Decoder'
Does somebody know what's wrong?
Upvotes: 2
Views: 1607
Reputation: 1073
I ran into that same issue again and could solve it for me. Just for anyone who has this problem in the future, too:
First, I installed a pocketsphinx release from http://downloads.sourceforge.net/cmusphinx/pocketsphinx-5prealpha.tar.gz. The corresponding swig/python/__init__.py
which gets installed to /usr/lib/python<ver>/site-packages/pocketsphinx/__init__.py
contains the following:
from pocketsphinx import *
When I install pocketsphinx from https://pypi.org/project/pocketsphinx/, the corresponding __init__.py
contains:
from .pocketsphinx import *
It seems that the tiny dot makes the difference if an import statement like from pocketsphinx import *
works or if you have to use from pocketsphinx.pocketsphinx import *
Upvotes: 0
Reputation: 180540
As Bhargav has already mentioned, you have named your file pocketsphinx.py
or have a pocketsphinx.py
in your path so you need to rename the file and make sure to delete the pocketsphinx.pyc
file also. You are trying to import from that file not the pocketsphinx module.
Upvotes: 2