2016-03-19 10 views
3

ich die Python Tasche Sphinx Tutorial verwende, nachWarum gibt Python pocketsphinx TypeError?

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

(vollständige Code hier):

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 "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" 

und wenn ich es benutze ich erhalte die folgende Fehlermeldung:

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' 

Können Sie mir helfen?

+0

überprüfen, was Argument kann man vorbei an den __init__ – galaxyan

+0

@galaxyan Edited. Entschuldigung wegen der Identität. – Hugo

+0

Ich meine der Fehler sagte Sie das hmm ist nicht das Argument, das Sie in init übergeben können – galaxyan

Antwort

8

Betrachten wir den Taschensphinx-Code auf GitHub, in decoder_test.py haben wir ein Beispiel, wie Optionen an Decoder übergeben werden.

So sieht es aus wie Ihre Tutorial für eine alte Version ist und Sie wollen tatsächlich:

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

speechRec = ps.Decoder(config) 
Verwandte Themen