如何在Python的pocketsphinx模块中调用pocketshinx模块?

问题描述 投票:0回答:1

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

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

我不知道发生了什么,因为它可以很好地为 sphinxbase 做同样的事情。并且“导入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()
python python-3.6 pocketsphinx
1个回答
0
投票

尝试使用

在终端上安装

sudo apt-get install pocketsphinx

© www.soinside.com 2019 - 2024. All rights reserved.