[Python] How to call the module pocketshinx within the module pocketsphinx for python?

Discussão em 'Python' iniciado por Stack, Janeiro 6, 2025.

  1. Stack

    Stack Membro Participativo

    So I'm trying to use a method in the pocketsphinx.py within the pocketsphinx module folder, but it gives me an error of:


    ModuleNotFoundError: No module named 'pocketsphinx.pocketsphinx'; 'pocketsphinx' is not a package
    ​
    I don't know what is going on because it works fine doing the same thing for sphinxbase. And 'import pocketsphinx' works, but doesn't input the exact method I need call decoder_default_config. Here is the code:


    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()

    Continue reading...

Compartilhe esta Página