-
Notifications
You must be signed in to change notification settings - Fork 213
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
Shutdown issue #20
Comments
You are right, it's a bug, thanks for pointing this out. Will release new version soon with a bugfix. |
I think I have a similar problem. I have a recorder per WebSocket connection in a setup, and I can't seem to clean up the recorder. recorder.shutdown() hangs forever, and if I don't call it, I get a resource leak. Here's my code:
In the websocket endpoint:
|
Please try calling shutdown only once: output = asyncio.Queue()
audio = RealtimeAudio(output)
asyncio.get_event_loop().create_task(
output_websockets(output, ws))
try:
async for chunk in ws.iter_bytes():
audio.feed_chunk(chunk)
except WebSocketDisconnect:
print("Websocket disconnected!")
finally:
audio.shutdown() Does it still happen then? |
So I actually tried this in a shell to make sure:
the last call hangs |
Ok, I'll check that |
@KoljaB I know this isn't directly related to this issue, but now that my code is up, would you be able to speak to the scalability of this approach? I appreciate the examples in this codebase but I am not sure how many recorder objects are intended to coexist in one Python application. Because of the separation of read and write to the recorder object and its internal state, I don't think it's possible to have fewer than one recorder object per websocket connection for the transcription-over-websocket architecture. Am I wrong? |
I thought about how far I want to develop each of my projects. For both RealtimeSTT and RealtimeTTS I want to provide a comfortable and stable webserver solution that works in a browser and covers full functionality. But serving multiple users is where I draw the line, because testing this is out of my scope and I did not find a personal use case for this. So currently I decided to focus on delivering core functionality. I currently may have too many project to bring every single one to its full potential. |
Found the issue. The recording worker need chunks to be feeded into. Currently otherwise it blocks in data = self.audio_queue.get(). This not perfect and I should integrate a timeout. In all my use cases currently it was kind of guaranteed that the microphone delivers chunks (or an external source does that uses feed_audio method). Will prob change that soon so that is safe to use in all cases. Currently you should be able to shutdown as soon as chunks come in, so might feed silence on shutdown if you don't want to process chunks all the time. |
I am very grateful for the solution you built! It will help me build an MVP and inspire how we scale. |
@KoljaB I changed the def shutdown(self):
# self.recorder_active.clear()
self.recorder.feed_audio(b'AAAAAAAAAAA')
self.recorder.shutdown()
# self.processor.join()
self.loop.call_soon_threadsafe(self.loop.stop) And it still hangs on recorder.shutdown(). The strange thing is, when I ran the following code: In [10]: from RealtimeSTT import AudioToTextRecorder
In [11]: a = AudioToTextRecorder(**{})
In [12]: a.feed_audio(b'AAAAAAAAAAA')
In [13]: a.shutdown() it runs just fine. Do you have advice? I keep getting issues with resource leaks when I don't shut this down:
|
Hello, I have problem with shutdown method when using microphone =False, it always stuck on
Example code:
The text was updated successfully, but these errors were encountered: