Selaa lähdekoodia

fix: make sure shutdown() wakes up the recording_thread

Also ensure that the reader_process is not accessed if
it hasn't been initialized due to use_microphone=False
oddlama 10 kuukautta sitten
vanhempi
commit
fd6ddc32db
1 muutettua tiedostoa jossa 9 lisäystä ja 6 poistoa
  1. 9 6
      RealtimeSTT/audio_recorder.py

+ 9 - 6
RealtimeSTT/audio_recorder.py

@@ -1019,19 +1019,22 @@ class AudioToTextRecorder:
 
         logging.debug('Finishing recording thread')
         if self.recording_thread:
+            # Submit a single byte to the audio buffer to force the thread to wake up
+            # and notice the shutdown.
+            self.audio_queue.put(bytes(1))
             self.recording_thread.join()
 
         logging.debug('Terminating reader process')
 
         # Give it some time to finish the loop and cleanup.
-        if self.use_microphone:
+        if self.use_microphone.value:
             self.reader_process.join(timeout=10)
 
-        if self.reader_process.is_alive():
-            logging.warning("Reader process did not terminate "
-                            "in time. Terminating forcefully."
-                            )
-            self.reader_process.terminate()
+            if self.reader_process.is_alive():
+                logging.warning("Reader process did not terminate "
+                                "in time. Terminating forcefully."
+                                )
+                self.reader_process.terminate()
 
         logging.debug('Terminating transcription process')
         self.transcript_process.join(timeout=10)