bambocher / pocketsphinx-python

Python interface to CMU Sphinxbase and Pocketsphinx libraries
https://pypi.python.org/pypi/pocketsphinx
Other
373 stars 187 forks source link

RuntimeError: new_Decoder returned -1 #42

Open vipulsurya opened 5 years ago

vipulsurya commented 5 years ago

hi i want speech recognition using sphinx but as the accuracy of sphinx is not good at all. so need to decode the wav file but getting some error into the file....can any one please help me on this. please tell me any alternate way to achieve offline speech recognition...

from pocketsphinx.pocketsphinx import from sphinxbase.sphinxbase import import speech_recognition as sr
from os import environ,path from itertools import izip from pocketsphinx import from sphinxbase import

MODELDIR = "C:/ProgramData/Anaconda2/Lib/site-packages/pocketsphinx/model/" DATADIR = "C:/ProgramData/Anaconda2/Lib/site-packages/pocketsphinx/data/"

AUDIO_FILE = path.join(path.dirname(path.realpath(file)), "seriously.wav")

r = sr.Recognizer()

config = Decoder.default_config() config.set_string('-hmm', path.join(MODELDIR, 'hmm/en_US/hub4wsj_sc_8k')) config.set_string('-lm', path.join(MODELDIR, 'lm/en_US/hub4.5000.DMP')) config.set_string('-dict', path.join(MODELDIR, 'lm/en_US/hub4.5000.dic'))

decoder = Decoder(config)

decoder = decoder.decode_raw(open(AUDIO_FILE, 'rb'))

hypothesis = decoder.hyp()

for best, i in izip(decoder.nbest(), range(10)): print best.hyp().best_score, best.hyp().hypstr

decoder = Decoder(config)

decoder.start_utt('goforward')

decoder.start_utt() stream = open(path.join(DATADIR, 'goforward.raw'), 'rb') while True: buf = stream.read(1024) if buf: decoder.process_raw(buf, False, False) else: break decoder.end_utt()

with sr.AudioFile(decoder) as source: audio = r.record(source) # read the entire audio file

try: print("TEXT : " + r.recognize_sphinx(audio)) except sr.UnknownValueError: print("Sphinx could not understand audio") except sr.RequestError as e: print("Sphinx error; {0}".format(e))

error - File "SR_decoder.py", line 35, in decoder = Decoder(config) File "C:\ProgramData\Anaconda2\lib\site-packages\pocketsphinx\pocketsphinx.py" , line 273, in init this = _pocketsphinx.new_Decoder(*args) RuntimeError: new_Decoder returned -1

vipulsurya commented 5 years ago

hi i want speech recognition using sphinx but as the accuracy of sphinx is not good at all. so need to decode the wav file but getting some error into the file....can any one please help me on this. please tell me any alternate way to achieve offline speech recognition...

from pocketsphinx.pocketsphinx import from sphinxbase.sphinxbase import import speech_recognition as sr from os import environ,path from itertools import izip from pocketsphinx import from sphinxbase import

MODELDIR = "C:/ProgramData/Anaconda2/Lib/site-packages/pocketsphinx/model/" DATADIR = "C:/ProgramData/Anaconda2/Lib/site-packages/pocketsphinx/data/"

AUDIO_FILE = path.join(path.dirname(path.realpath(file)), "seriously.wav")

r = sr.Recognizer()

config = Decoder.default_config() config.set_string('-hmm', path.join(MODELDIR, 'hmm/en_US/hub4wsj_sc_8k')) config.set_string('-lm', path.join(MODELDIR, 'lm/en_US/hub4.5000.DMP')) config.set_string('-dict', path.join(MODELDIR, 'lm/en_US/hub4.5000.dic'))

decoder = Decoder(config)

decoder = decoder.decode_raw(open(AUDIO_FILE, 'rb'))

hypothesis = decoder.hyp()

for best, i in izip(decoder.nbest(), range(10)): print best.hyp().best_score, best.hyp().hypstr

decoder = Decoder(config)

decoder.start_utt('goforward')

decoder.start_utt() stream = open(path.join(DATADIR, 'goforward.raw'), 'rb') while True: buf = stream.read(1024) if buf: decoder.process_raw(buf, False, False) else: break decoder.end_utt()

with sr.AudioFile(decoder) as source: audio = r.record(source) # read the entire audio file

try: print("TEXT : " + r.recognize_sphinx(audio)) except sr.UnknownValueError: print("Sphinx could not understand audio") except sr.RequestError as e: print("Sphinx error; {0}".format(e))

error - File "SR_decoder.py", line 35, in decoder = Decoder(config) File "C:\ProgramData\Anaconda2\lib\site-packages\pocketsphinx\pocketsphinx.py" , line 273, in init this = _pocketsphinx.new_Decoder(*args) RuntimeError: new_Decoder returned -1

ismailryt commented 4 years ago

Hello @vipulsurya, are you already find the solution? If yes can you tell me how to fix that error

And btw, if we mix sphinx and speech recognition library , we can use it offline?

Thanks