alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
8.06k stars 1.11k forks source link

AttributeError: 'KaldiRecognizer' object has no attribute '_handle' #1243

Open DaniPolishchuk opened 1 year ago

DaniPolishchuk commented 1 year ago

Hello, i would be so thankful if you help me to find a problem in my code. Thank you in advance!!!!

File "C:\Users\danpl\PycharmProjects\курсова\stt.py", line 28, in kozak_listen rec = KaldiRecognizer(model, samplerate) File "C:\Users\danpl\PycharmProjects\курсова\venv\lib\site-packages\vosk__init.py", line 147, in init self._handle = _c.vosk_recognizer_new(args[0]._handle, args[1]) AttributeError: 'str' object has no attribute '_handle' Exception ignored in: <function KaldiRecognizer.del at 0x00000279025D9EA0> Traceback (most recent call last): File "C:\Users\danpl\PycharmProjects\курсова\venv\lib\site-packages\vosk\init.py", line 161, in del__ _c.vosk_recognizer_free(self._handle) AttributeError: 'KaldiRecognizer' object has no attribute '_handle'

the code is below:

from vosk import KaldiRecognizer from sys import stderr from sounddevice import RawInputStream from queue import Queue from json import loads from joblib import load

samplerate = 48000 device = 1

file = "vosk_ua_model_big.pkl" model = load(file)

q = Queue()

def q_callback(indata, frames, time, status): if status: print(status, file=stderr) q.put(bytes(indata))

def kozak_listen(callback): with RawInputStream(samplerate=samplerate, blocksize=8000, device=device, dtype='int16', channels=1, callback=q_callback):

    rec = KaldiRecognizer(model, samplerate)
    while True:
        data = q.get()
        if rec.AcceptWaveform(data):
            callback(loads(rec.Result())["text"])
DaniPolishchuk commented 1 year ago

I want to download vosk.model into computer memory, so that the code then uses less, is it possible?

nshmyrev commented 1 year ago

It is not possible actually, you have to use files.

DaniPolishchuk commented 1 year ago

ah, okay, maybe there are some another ways, how could i decrease RAM usage?

ruohoruotsi commented 1 year ago

Your samplerate==48000 will use more memory than 16kHz. I'm just learning VOSK but perhaps reducing the decoder beam-size/width.