首页 > 解决方案 > python - 如何在模块pocketsphinx for python中调用模块pocketshinx?

问题描述

所以我试图在 pocketsphinx 模块文件夹中的 pocketsphinx.py 中使用一种方法,但它给了我一个错误:

ModuleNotFoundError:没有名为“pocketsphinx.pocketsphinx”的模块;'pocketsphinx' 不是一个包

我不知道发生了什么,因为它可以很好地为 sphinxbase 做同样的事情。并且“import pocketsphinx”可以工作,但没有输入我需要调用decoder_default_config的确切方法。这是代码:

import pyaudio as py
from pocketsphinx.pocketsphinx import *
from sphinxbase.sphinxbase import *
import glob
import os, sys
model=(r'C:\Users\ellag\AppData\Local\Programs\Python\Python36\Lib\site-packages\pocketsphinx\model')
config = Decoder_default_config()
config.set_string('-hmm', os.path.join(model, 'en-us\en-us'))
config.set_string('-dict', os.path.join(model, 'en-us\cmuict-en-us.dict'))
config.set_string('-kws', os.path.join(model, 'kws_file'))
decoder = Decoder(config)
p = py.PyAudio()
stream = p.open(format=py.paInt16,channels=1,rate=16000,input=True)
stream.start_stream()
While True:
    buf=stream.read(1024)
    Decoder.process_raw(buf, False, False)
    if Decoder.hyp() != None:
        print(seg.word, seg.prob)
        letter=seg.word()

标签: pythonpython-3.6pocketsphinx

解决方案


推荐阅读