KoljaB / RealtimeSTT

A robust, efficient, low-latency speech-to-text library with advanced voice activity detection, wake word activation and instant transcription.
MIT License
2.09k stars 190 forks source link

Interval error #6

Closed szriru closed 1 year ago

szriru commented 1 year ago

Almostly working fine, but I got an error several times when I was using this function AudioToTextRecorder.text(on_transcription_finished=on_transcription_finished)

The error:

Traceback (most recent call last):
  File "C:\ooba-voice\prod\main.py", line 32, in <module>
- transcribing    main()
  File "C:\ooba-voice\prod\main.py", line 27, in main
    recorder.text(on_transcription_finished=on_transcription_finished)
  File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\RealtimeSTT\audio_recorder.py", line 543, in text
    threading.Thread(target=on_transcription_finished, args=(self.transcribe(),)).start()
  File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\RealtimeSTT\audio_recorder.py", line 506, in transcribe
    self._set_state("transcribing")
  File "C:\Users\name\AppData\Roaming\Python\Python310\site-packages\RealtimeSTT\audio_recorder.py", line 1004, in _set_state
    self.halo._interval = 50
AttributeError: 'NoneType' object has no attribute '_interval'

What is the problem?

And this has nothing to do with above one but it often stops recording while I'm still speaking. Could you teach me how to solve this problem too? ...and I cannot kill a process completely with Ctrl+C from windows 11 cmd

summary

KoljaB commented 1 year ago

First one looks like a bug. I need to investigate this tomorrow. For a quick fix, please set spinner parameter to False:

recorder = AudioToTextRecorder(spinner = False)

If it stops recording while you are still speaking, please raise the post_speech_silence_duration to a higher value. I suggest trying something around 1.5:

recorder = AudioToTextRecorder(post_speech_silence_duration = 1.5)

Last one, please try to use the recorder either in a with statement:

with AudioToTextRecorder(spinner = False, post_speech_silence_duration = 1.5) as recorder:
    # your code

Or, alternatively, catch the KeyboardInterrupt Exception and shutdown the recorder manually:

try:
    # your code
except KeyboardInterrupt:
    recorder.shutdown()

I'll try to pin down the bug tomorrow and release a fixed version.

Thank you for reporting the issue. Please let me know if this helps. Have a nice evening!

szriru commented 1 year ago

Thank you for your reply.

The quick fix worked. Now I hope it'll be patched with a real fix soon.

I didn't notice the option. It worked. Thank you.

Still Ctrl+C cannot kill a process completely. I think it's possible because I'm using it in while statement. like:

  try:
    while True:
      recorder.text(on_transcription_finished=on_transcription_finished)

  except KeyboardInterrupt:
    recorder.shutdown()

I checked that all threading instances of AudioToTextRecorder have daemon=True attribute. So I don't know why. This is not a main problem but its a little bit of troublesome for me.

(P.S. I noticed that you are creating LocalAIVoiceChat too. I'm also creating local llm ai voice chat things now but using oobabooga API, so its interesting for me. I'm looking forward to your works.)

KoljaB commented 1 year ago

Tried it for myself, you are right. I also can't terminate gracefully, I need to look deeper into this. Need some sleep now, I will investigate later. Thanks a lot for pointing this out.

KoljaB commented 1 year ago

Bugfixes for "AttributeError: 'NoneType' object has no attribute '_interval'" and "Cannot kill a process complety with Ctrl+C from windows 11 cmd" are now implemented.

Please upgrade to latest version with "pip install --upgrade realtimestt==0.1.7".

szriru commented 1 year ago

Everything works fine now! Thank you very much.