Pocketsphinx voice recognition - Python 3.5

Asked

Viewed 851 times

1

I am doing voice recognition with the modules pocketsphinx and Speech recognition, but when I went to make the code available offline, the program returns the following error:

Traceback (most recent call last):
  File "C:\Users\anonm\Desktop\Pastas\Programação\Jarvis\main.py", line 55, in <module>
    decoder = pocketsphinx.Decoder(config)
  File "C:\Users\anonm\AppData\Local\Programs\Python\Python35\lib\site-packages\pocketsphinx\pocketsphinx.py", line 272, in __init__
    this = _pocketsphinx.new_Decoder(*args)
RuntimeError: new_Decoder returned -1

Could someone help me solve this problem? Here’s the code:

from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
import os
import speech_recognition as sr
import pyttsx3
from pocketsphinx import Pocketsphinx, Jsgf, FsgModel

speaker=pyttsx3.init()

bot=ChatBot('Jarvis', read_only=True)


def speak(text):
    speaker.say(text)
    speaker.runAndWait()

config = Pocketsphinx.Decoder.default_config()
config.set_string("-hmm", 'model')  
config.set_string("-lm", 'model.lm.bin')
config.set_string("-dict", 'model.dic')
config.set_string("-logfn", os.devnull)  
decoder = Pocketsphinx.Decoder(config) 

def recognize_pt(audio):
    raw_data = audio.get_raw_data(convert_rate=16000, convert_width=2)
    decoder.start_utt() 
    decoder.process_raw(raw_data, False, True)
    decoder.end_utt() 

    hypothesis = decoder.hyp()
    if hypothesis is not None: 
        return hypothesis.hypstr
    return None

r=sr.Recognizer()

with sr.Microphone() as s:
    r.adjust_for_ambient_noise(s)

    while True:

        try:
            audio=r.listen(s)

            speech=recognize_pt(audio)

            print('Você disse: ', speech)

            response=bot.get_response(speech)
            print('Bot: ', response)
            speak(response)

        except:
            print('Ocorreu algum erro')
  • from pocketsphinx import Pocketsphinx, Jsgf, FsgModel change minuscule p to uppercase p

  • Now it returns the following error: "Import: No module named 'Pocketsphinx'"

  • In the same line as before? The way I passed it to you is the same as in the documentation

  • Sorry, had not read your change, I changed the 'p' of pocketsphinx that is just in front of 'from', now it returns: "config = pocketsphinx.Decoder.default_config() Nameerror: name 'pocketsphinx' is not defined"

  • I think it’s the same question, you’re importing the Pocketsphinx module, so if you want to use it, it has to be capitalized, not the minuscule that’s the library.

  • In the same error block, I changed all pocketsphinx by capitalizing the initial p, and now it returns another error -I’m almost giving up: config = Pocketsphinx.Decoder.default_config() Attributeerror: type Object 'Pocketsphinx' has no attribute 'Decoder'

  • edits the question and puts the code you changed

  • I’m with this mistake someone can explain the mistake?

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.