0

I try to run simple example of using pocketsphinx. I have installed all libraries, plugins that was needed... Python 2.7.6. But still get an error:

pocketsphinx 'module' object has no attribute 'Decoder'

import sys,os 
import pocketsphinx as ps 
import sphinxbase


def decodeSpeech(hmmd,lmdir,dictp,wavfile):
    speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp)
    wavFile = file(wavfile,'rb')
    wavFile.seek(44)
    speechRec.decode_raw(wavFile)
    result = speechRec.get_hyp()
    return result[0]


if __name__ == "__main__":
    hmdir = '/usr/share/pocketsphinx/model/hmm/wsj1'
    lmd   = '/usr/share/pocketsphinx/model/lm/wsj/wlist5o.3e-7.vp.tg.lm.DMP'
    dictd = '/usr/share/pocketsphinx/model/lm/wsj/wlist5o.dic'
    wavfile = "msg_12c3da80-c6be-11e3-9430-eb6ba5ab4d1f.wav"
    recognised = decodeSpeech(hmdir,lmd,dictd,wavfile)
Arti
  • 7,356
  • 12
  • 57
  • 122
  • Is this Python 3.x? Have you read https://github.com/bambocher/pocketsphinx-python#import? – jonrsharpe Apr 12 '15 at 20:00
  • Python 2.7.6. Yes i have done all instructions. – Arti Apr 12 '15 at 20:07
  • 2
    What does `print dir(ps)` show? `print ps.__file__`? – jonrsharpe Apr 12 '15 at 20:07
  • /usr/local/lib/python2.7/dist-packages/pocketsphinx-0.0.4-py2.7-linux-x86_64.egg/pocketsphinx/__init__.pyc – Arti Apr 12 '15 at 20:09
  • It looks like you're importing the right file, at least - and the `dir`? – jonrsharpe Apr 12 '15 at 20:11
  • I have viewed source of pocketsphin.py and he have ```Decoder``` class :( – Arti Apr 12 '15 at 20:11
  • That's not what I asked; *what does `print dir(ps)` show?!* – jonrsharpe Apr 12 '15 at 20:12
  • ['__builtins__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__'] – Arti Apr 12 '15 at 20:12
  • Then the error message isn't lying; `Decoder` isn't specified at the module level (i.e. in `__init__.py`). Why don't you try the `import` form *actually shown in the documentation*? – jonrsharpe Apr 12 '15 at 20:13
  • you mean: ```from sphinxbase import Config from pocketsphinx import Decoder``` ? – Arti Apr 12 '15 at 20:14
  • That's the one! It doesn't look like you're using anything else from `ps`. – jonrsharpe Apr 12 '15 at 20:15
  • I tried. Got the same error: ```from sphinxbase import Config ImportError: cannot import name Config``` – Arti Apr 12 '15 at 20:15
  • ```from pocketsphinx import Decoder ImportError: cannot import name Decoder``` – Arti Apr 12 '15 at 20:17
  • Well if you're using it as documented without success, why not raise it with the developer - https://github.com/bambocher/pocketsphinx-python/issues/new? – jonrsharpe Apr 12 '15 at 20:18
  • what you mean ? i tried this tutorial too: https://mattze96.safe-ws.de/blog/?p=640 – Arti Apr 12 '15 at 20:21
  • I mean *this is possibly a bug*, so we can't help you fix it. If you've followed the instructions provided and are still having issues, open an issue on the project. Note that information about what precisely you've done will be helpful, in more detail than *"I have installed all libraries, plugins that was needed..."* – jonrsharpe Apr 12 '15 at 20:21
  • Have you tried to literally follow the import recipe form the [bottom of the readme](https://github.com/cmusphinx/pocketsphinx-python)? They might have merged py 2.x and py 3.x import approaches at some moment. – 9000 Apr 12 '15 at 20:25
  • yes: ```File "speech.py", line 9, in from sphinxbase.sphinxbase import Config``` – Arti Apr 12 '15 at 20:34
  • Now i'm trying to use python 3 and this code: http://pastebin.com/m6PHWJ48 but get an error: ```TypeError: in method 'Decoder_decode_raw', argument 2 of type 'FILE *'``` – Arti Apr 13 '15 at 09:30

1 Answers1

0

You are using old API in your code. New API implemented in pocketsphinx-python works like this:

https://github.com/cmusphinx/pocketsphinx/blob/master/swig/python/test/decoder_test.py

Decoder is initialized with the help of configuration object. Models are also different.

Nikolay Shmyrev
  • 24,897
  • 5
  • 43
  • 87
  • can you give a example, how to upgrade it ? – Arti Apr 13 '15 at 08:34
  • Now i'm trying to use python 3 and this code: http://pastebin.com/m6PHWJ48 but get an error: ```TypeError: in method 'Decoder_decode_raw', argument 2 of type 'FILE *'``` – Arti Apr 13 '15 at 09:30
  • Python3 does not support file operations, you have to decode in streaming mode. – Nikolay Shmyrev Apr 13 '15 at 09:35
  • do you have an example ? i ran this one: http://sourceforge.net/p/cmusphinx/discussion/help/thread/ce372c57/#4d10/b3ea but ```TypeError: in method 'Decoder_process_raw', argument 2 of type 'void const *' ``` – Arti Apr 13 '15 at 09:40
  • This is because decoder was not created properly and there were earlier errors. For example it failed to load models. You can check logs for details. – Nikolay Shmyrev Apr 13 '15 at 10:03
  • In logs only "info" messages... I got models from here: https://github.com/cmusphinx/pocketsphinx/tree/master/model/en-us – Arti Apr 13 '15 at 10:11
  • You can provide the log to get help on this issue. – Nikolay Shmyrev Apr 13 '15 at 10:12
  • Your code does not really make sense. You end utterance after processing 44 bytes and then continue while loop. Try to run existing example as is first, then do you modifications. I linked you the working demo above. – Nikolay Shmyrev Apr 13 '15 at 10:35
  • Yes i know that code does not make sense. But i want to show you the problem is in this line: ```decoder.process_raw(buf, False, False)``` it returns error: ```TypeError: in method 'Decoder_process_raw', argument 2 of type 'void const *'```. And the https://github.com/cmusphinx/pocketsphinx/blob/master/swig/python/test/decoder_test.py doesn't wok too ! – Arti Apr 13 '15 at 10:45
  • ```# Decode streaming data.``` http://pastebin.com/UD30YMFJ this code fails with error: ```TypeError: in method 'Decoder_process_raw', argument 2 of type 'void const *'``` – Arti Apr 13 '15 at 10:52
  • on python 2, i have the issue from 1-st post – Arti Apr 13 '15 at 11:28