From 6490a8a5db0a7eb8b3906765cd7ea26ad4b2824a Mon Sep 17 00:00:00 2001 From: yum Date: Sat, 24 Dec 2022 12:37:22 -0800 Subject: Make transcription sleeps interruptible This reduces the expected delay to wake up the board & start transcribing from 750 milliseconds to 2.5 milliseconds. --- Scripts/transcribe.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Scripts/transcribe.py') 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) -- cgit v1.2.3