diff options
| author | yum <yum.food.vr@gmail.com> | 2022-12-24 12:37:22 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2022-12-24 12:37:22 -0800 |
| commit | 6490a8a5db0a7eb8b3906765cd7ea26ad4b2824a (patch) | |
| tree | ee4e0df9012e9f597bffe8f1d16d05b239b9ed8b | |
| parent | 50d327b83b496085ec91e31100d12f5f60c7d4ac (diff) | |
Make transcription sleeps interruptible
This reduces the expected delay to wake up the board & start
transcribing from 750 milliseconds to 2.5 milliseconds.
| -rw-r--r-- | Scripts/transcribe.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Scripts/transcribe.py b/Scripts/transcribe.py index 00ab82f..ba7d8fe 100644 --- a/Scripts/transcribe.py +++ b/Scripts/transcribe.py @@ -59,7 +59,7 @@ class AudioState: run_app = True transcribe_sleep_duration_min_s = 0.05 - transcribe_sleep_duration_max_s = 1.50 + transcribe_sleep_duration_max_s = 5.00 transcribe_no_change_count = 0 transcribe_sleep_duration = transcribe_sleep_duration_min_s @@ -78,6 +78,12 @@ class AudioState: osc_client = osc_ctrl.getClient() + def sleepInterruptible(self, dur_s, stride_ms = 5): + dur_ms = dur_s * 1000.0 + timeout = time.time() + dur_s + while self.audio_paused and time.time() < timeout: + time.sleep(stride_ms / 1000.0) + def dumpMicDevices(): p = pyaudio.PyAudio() info = p.get_host_api_info_by_index(0) @@ -239,7 +245,7 @@ def transcribeAudio(audio_state, model): while audio_state.run_app == True: # Pace this out if audio_state.audio_paused: - time.sleep(audio_state.transcribe_sleep_duration) + audio_state.sleepInterruptible(audio_state.transcribe_sleep_duration) else: time.sleep(0.05) |
