【问题标题】:Why is python pocketsphinx giving TypeError?为什么 python pocketsphinx 会给出 TypeError?
【发布时间】:2016-03-19 18:35:37
【问题描述】:

我正在使用 Python 袖珍狮身人面像教程,根据

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

(此处为完整代码):

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

当我运行它时,我收到以下错误消息:

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'

你能帮帮我吗?

【问题讨论】:

  • 检查您可以将什么参数传递给 init
  • @galaxyan 已编辑。很抱歉身份识别。
  • 我的意思是错误告诉你,嗯不是你可以在 init 中传递的参数
  • 从我在example file bundled with the project 中可以看到,Decoder() 类只需要一个config 参数。我怀疑您的教程已过时,请查找其他教程。
  • 如果你这样做help(ps.Decoder),它是否提到了它所需要的论点?正如 Martijn Pieters 所说,您的教程可能是针对不同版本的。

标签: python pocketsphinx


【解决方案1】:

查看 GitHub 上的 pocketsphinx 代码,在 decoder_test.py 我们有一个如何将选项传递给解码器的示例。

所以看起来您的教程是针对旧版本的,而您实际上想要:

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

speechRec = ps.Decoder(config)

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2011-04-22
    相关资源
    最近更新 更多