3

I am using the Python pocket sphinx tutorial, according to

https://metakermit.com/2011/python-speech-recognition-helloworld/

(complete code here):

import sys,os

def decodeSpeech(hmmd,lmdir,dictp,wavfile):
"""
Decodes a speech file
"""

try:
    import pocketsphinx as ps
    import sphinxbase

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)
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/en_US/"
lmd = "/usr/share/pocketsphinx/model/lm/en_US/hub4.5000.DMP"
dictd = "/usr/share/pocketsphinx/model/lm/en_US/cmu07a.dic"
wavfile = sys.argv[1]
recognised = decodeSpeech(hmdir,lmd,dictd,wavfile)

print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
print recognised
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"

and when I run it I get the following error message:

Traceback (most recent call last):
File "hello.py", line 30, in <module>
recognised = decodeSpeech(hmdir,lmd,dictd,wavfile)
File "hello.py", line 17, in decodeSpeech
speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp)
TypeError: __init__() got an unexpected keyword argument 'hmm'

Could you help me?

metakermit
  • 21,267
  • 15
  • 86
  • 95
Hugo
  • 1,558
  • 12
  • 35
  • 68

1 Answers1

8

Looking at the pocketsphinx code on GitHub, in decoder_test.py we have an example of how to pass options to Decoder.

So it looks like your tutorial is for an old version and you actually want:

config = ps.Decoder.default_config()
config.set_string('-hmm', hmmd)
config.set_string('-lm', lmdir)
config.set_string('-dict', dictp) 

speechRec = ps.Decoder(config)
emmagordon
  • 1,222
  • 8
  • 17