diff options
| author | yum <yum.food.vr@gmail.com> | 2022-11-12 15:02:34 -0800 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2022-11-12 15:02:34 -0800 |
| commit | 9921697816c9f9473bac54444793f702e54d24a6 (patch) | |
| tree | 4b786d400405669916b8d6922394771529ecba88 | |
| parent | 3b038d23ec7621e0164c1901b416bf77a27d8cf3 (diff) | |
Fix reset button
Board would lock up if you reset after the first page. osc_ctrl.clear()
was assigning the wrong member :)
Tweak continuous transcription logic: now we only commit if the
transcription remains identical for N seconds.
| -rw-r--r-- | osc_ctrl.py | 2 | ||||
| -rw-r--r-- | transcribe.py | 19 |
2 files changed, 17 insertions, 4 deletions
diff --git a/osc_ctrl.py b/osc_ctrl.py index 2e7ef39..be853dc 100644 --- a/osc_ctrl.py +++ b/osc_ctrl.py @@ -290,7 +290,7 @@ def clear(client, tx_state): addr="/avatar/parameters/" + generate_utils.getClearBoardParam() client.send_message(addr, False) - tx_state.last_message_encoded = [] + tx_state.last_msg_encoded = [] if __name__ == "__main__": parser = argparse.ArgumentParser() diff --git a/transcribe.py b/transcribe.py index 1327515..c92825c 100644 --- a/transcribe.py +++ b/transcribe.py @@ -2,6 +2,7 @@ import argparse import copy +from datetime import datetime import os import osc_ctrl # python3 -m pip install pydub @@ -44,6 +45,7 @@ class AudioState: text = "" committed_text = "" + text_ts = datetime.now() frames = [] # Locks access to `text`, `frames`, and audio stored on disk. lock = threading.Lock() @@ -244,8 +246,12 @@ def transcribeAudio(audio_state, model): audio_state.lock.release() continue - # Hack: two consecutive identical transcriptions get "committed". - if text == audio_state.text: + # Hack: transcriptions that remain the same for N seconds get + # committed. + now = datetime.now() + dt = now - audio_state.text_ts + dt_s = dt.seconds + float(dt.microseconds) / (1000 * 1000) + if dt_s >= 1 and text == audio_state.text: print("Commit!") old_commit = audio_state.committed_text resetAudioLocked(audio_state) @@ -253,6 +259,8 @@ def transcribeAudio(audio_state, model): audio_state.lock.release() continue else: + if text != audio_state.text: + audio_state.text_ts = now print("text: {}".format(text)) print("audio_state.text: {}".format(audio_state.text)) @@ -285,6 +293,7 @@ def sendAudio(audio_state): continue audio_state.lock.acquire() + text = audio_state.committed_text + " " + audio_state.text osc_ctrl.sendMessageLazy(audio_state.osc_client, text, audio_state.tx_state) audio_state.lock.release() @@ -339,8 +348,12 @@ def transcribeLoop(mic: str, language: str): print("Press enter or say 'Clear' to start a new message. Say 'Over' to " + "pause the display (saying 'Clear' resets it again).") for line in sys.stdin: - resetAudio(audio_state) + audio_state.lock.acquire() + resetAudioLocked(audio_state) resetDisplayLocked(audio_state) + audio_state.drop_transcription = True + audio_state.display_paused = False + audio_state.lock.release() if "exit" in line or "quit" in line: break |
