Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak for very long stream #83

Closed
nshmyrev opened this issue May 3, 2020 · 7 comments
Closed

Memory leak for very long stream #83

nshmyrev opened this issue May 3, 2020 · 7 comments

Comments

@nshmyrev
Copy link
Collaborator

nshmyrev commented May 3, 2020

As reported by Sebastian Dunnink

i've been trying out your vosk api and it's working great so far, very
easy to install and use. however i came across one problem, which is
that after about 20 seconds of runtime (a script based on your
microphone example) it uses up one more megabyte of ram. i found it by
chance while trying to understand why it stopped after several hours
of runtime. below is my script, i run it inside a screen instance.

@MikeyBeez
Copy link

You need to close the stream.

@dpny518
Copy link

dpny518 commented May 18, 2020

I want to leave the stream open indefinitely, my goal is to use the asr as wake word system, and when it recognizes certain words trigger an action.
Any suggestions on how to use offline asr with continuous stream running indefinitely and avoid memory leaks?

@MikeyBeez
Copy link

MikeyBeez commented May 18, 2020

Take a look at my program, Juliet. https://github.com/MikeyBeez/Juliet

@dpny518
Copy link

dpny518 commented May 20, 2020

@MikeyBeez thank you, i checked it out, it seems you just check the output to see if a string is in it.

 while True:
        # listen for command. Speech to text listener logic is called from inside the myCommand function.
        output = mycommand.myCommand()[3:]
        # Remember,  the mycommand function takes in 
        # audio from the microphone and returns text.
        # Therefore, the "output" variable is text.
        if 'juli' in output:
            print('Julia responds:\n')

But I don't see any code for resetting, or handling memory issues

@MikeyBeez
Copy link

import pyaudio
from vosk import Model, KaldiRecognizer

def myCommand():
# "listens for commands"
# We imported vosk up above.
p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8000)
stream.start_stream()
model = Model("model-en")
rec = KaldiRecognizer(model, 16000)
while True:
data = stream.read(2000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
#print(rec.Result())
# I commented out this line and added the 3 lines below
myResult = rec.Result()
myList = myResult.split("text")
command = myList[1]
stream.stop_stream()
stream.close()
p.terminate()
return command

@MikeyBeez
Copy link

I rewrote this: from vosk import Model, KaldiRecognizer

import pyaudio

p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=16000, input=True, frames_per_buffer=8000)

model = Model("model-en")
rec = KaldiRecognizer(model, 16000)

while True:
stream.start_stream()
data = stream.read(2000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
#print(rec.Result())
# I commented out this line and added the 3 lines below
myResult = rec.Result()
myList = myResult.split("text")
print(myList[1])
stream.stop_stream()

@nshmyrev
Copy link
Collaborator Author

This should be fixed in commit ee9bacb and version 0.3.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants