Menu

Pocket sphinx + python 3

Help
A.B.C.
2015-05-02
2015-05-02
  • A.B.C.

    A.B.C. - 2015-05-02

    I am trying to run pocketsphinx with Python 3: https://github.com/bambocher/pocketsphinx-python

    More specifically, I am trying to decode streaming data with the following code on a Mac:

    from os import environ, path
    
    from sphinxbase.sphinxbase import Config
    from pocketsphinx.pocketsphinx import Decoder
    
    MODELDIR = "../../../model"
    DATADIR = "../../../test/data"
    
    # Create a decoder
    config = Decoder.default_config()
    config.set_string('-hmm', path.join(MODELDIR, 'en-us/en-us'))
    config.set_string('-lm', path.join(MODELDIR, 'en-us/en-us.lm.dmp'))
    config.set_string('-dict', path.join(MODELDIR, 'en-us/cmudict-en-us.dict'))
    decoder = Decoder(config)
    
    # Decode streaming data.
    decoder = Decoder(config)
    decoder.start_utt()
    decoder.set_rawdata_size(100000);
    stream = open(path.join(DATADIR, 'goforward.raw'), 'rb')
    while True:
      buf = stream.read(1024)
      print(type(buf))
      if buf:
        decoder.process_raw(buf, False, False)
      else:
        break
    decoder.end_utt()
    print('Stream decoding result:', decoder.hyp().hypstr)
    

    However, I am receiving the following error message:

    <class 'bytes'="">
    Traceback (most recent call last):
    File "test_dec.py", line 84, in <module>
    decoder.process_raw(buf, False, False)
    File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pocketsphinx-0.0.4-py3.4-macosx-10.6-intel.egg/pocketsphinx/pocketsphinx.py", line 389, in process_raw
    return _pocketsphinx.Decoder_process_raw(self, SDATA, no_search, full_utt)
    TypeError: in method 'Decoder_process_raw', argument 2 of type 'void const *</module></class>

    The same happens when I decode data from the microphone. Any thoughts on this?

     
    • Nickolay V. Shmyrev

      Python3 is not well supported yet. You can use Python2

       
      • Nickolay V. Shmyrev

        FYI, I've just committed the support for python3 in trunk. If you compile pocketsphinx-python as part of pocketsphinx package or from http://cmusphinx/pocketpshinx/pocketsphinx-python it will work with Python3.

         

        Last edit: Nickolay V. Shmyrev 2015-05-02

Log in to post a comment.