diff options
Diffstat (limited to 'Scripts')
| -rw-r--r-- | Scripts/osc_ctrl.py | 18 | ||||
| -rw-r--r-- | Scripts/transcribe.py | 50 |
2 files changed, 50 insertions, 18 deletions
diff --git a/Scripts/osc_ctrl.py b/Scripts/osc_ctrl.py index 7c7d0ae..e57a843 100644 --- a/Scripts/osc_ctrl.py +++ b/Scripts/osc_ctrl.py @@ -30,6 +30,7 @@ class OscState: self.client = getClient(ip, port) self.pager = MultiLinePager(chars_per_sync, rows, cols) self.encoding= generateEncoding() + self.builtin_msg = "" # The last message sent to the built-in chatbox def reset(self): self.pager.reset() @@ -137,6 +138,23 @@ def pageMessage(osc_state: OscState, msg: str) -> bool: addr="/avatar/parameters/" + generate_utils.getSpeechNoiseToggleParam() osc_state.client.send_message(addr, False) +# Like `pageMessage` but uses the built-in chatbox. The built-in chatbox +# truncates data at about 150 chars, so just send the suffix of the message for +# now. +def pageMessageBuiltin(osc_state: OscState, msg: str) -> bool: + msg_begin = max(len(msg) - 140, 0) + msg_suffix = msg[msg_begin:len(msg)] + + if osc_state.builtin_msg != msg: + addr="/chatbox/typing" + osc_state.client.send_message(addr, False) + + addr="/chatbox/input" + osc_state.client.send_message(addr, (msg_suffix, True)) + osc_state.builtin_msg = msg + + return False # Not paging + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-i", default="127.0.0.1", help="OSC server IP") diff --git a/Scripts/transcribe.py b/Scripts/transcribe.py index 7f07efe..1237334 100644 --- a/Scripts/transcribe.py +++ b/Scripts/transcribe.py @@ -303,17 +303,21 @@ def transcribeAudio(audio_state, model, use_cpu: bool): audio_state.transcribe_no_change_count = 0 audio_state.transcribe_sleep_duration = audio_state.transcribe_sleep_duration_min_s -def sendAudio(audio_state): +def sendAudio(audio_state, use_builtin: bool): while audio_state.run_app == True: text = audio_state.committed_text + " " + audio_state.text - ret = osc_ctrl.pageMessage(audio_state.osc_state, text) - is_paging = (ret == False) - osc_ctrl.indicatePaging(audio_state.osc_state.client, is_paging) + if use_builtin: + ret = osc_ctrl.pageMessageBuiltin(audio_state.osc_state, text) + time.sleep(1.5) + else: + ret = osc_ctrl.pageMessage(audio_state.osc_state, text) + is_paging = (ret == False) + osc_ctrl.indicatePaging(audio_state.osc_state.client, is_paging) - # Pace this out - time.sleep(0.01) + # Pace this out + time.sleep(0.01) -def readControllerInput(audio_state, enable_local_beep): +def readControllerInput(audio_state, enable_local_beep, use_builtin): session = None first = True while session == None and audio_state.run_app == True: @@ -343,8 +347,9 @@ def readControllerInput(audio_state, enable_local_beep): if now - last_rising > 0.5: # Long hold state = PAUSE_STATE - osc_ctrl.indicateSpeech(audio_state.osc_state.client, False) - osc_ctrl.toggleBoard(audio_state.osc_state.client, False) + if not use_builtin: + osc_ctrl.indicateSpeech(audio_state.osc_state.client, False) + osc_ctrl.toggleBoard(audio_state.osc_state.client, False) #playsound(os.path.abspath("../Sounds/Noise_Off.wav")) resetAudioLocked(audio_state) @@ -355,8 +360,9 @@ def readControllerInput(audio_state, enable_local_beep): # Short hold if state == RECORD_STATE: state = PAUSE_STATE - osc_ctrl.indicateSpeech(audio_state.osc_state.client, False) - osc_ctrl.lockWorld(audio_state.osc_state.client, True) + if not use_builtin: + osc_ctrl.indicateSpeech(audio_state.osc_state.client, False) + osc_ctrl.lockWorld(audio_state.osc_state.client, True) audio_state.transcribe_sleep_duration = audio_state.transcribe_sleep_duration_min_s audio_state.audio_paused = True @@ -365,9 +371,10 @@ def readControllerInput(audio_state, enable_local_beep): playsound(os.path.abspath("../Sounds/Noise_Off.wav")) elif state == PAUSE_STATE: state = RECORD_STATE - osc_ctrl.indicateSpeech(audio_state.osc_state.client, True) - osc_ctrl.toggleBoard(audio_state.osc_state.client, True) - osc_ctrl.lockWorld(audio_state.osc_state.client, False) + if not use_builtin: + osc_ctrl.indicateSpeech(audio_state.osc_state.client, True) + osc_ctrl.toggleBoard(audio_state.osc_state.client, True) + osc_ctrl.lockWorld(audio_state.osc_state.client, False) resetAudioLocked(audio_state) resetDisplayLocked(audio_state) @@ -379,7 +386,8 @@ def readControllerInput(audio_state, enable_local_beep): # model should correspond to one of the Whisper models defined in # whisper/__init__.py. Examples: tiny, base, small, medium. -def transcribeLoop(mic: str, language: str, model: str, enable_local_beep: bool, use_cpu: bool): +def transcribeLoop(mic: str, language: str, model: str, + enable_local_beep: bool, use_cpu: bool, use_builtin: bool): audio_state = getMicStream(mic) audio_state.language = whisper.tokenizer.TO_LANGUAGE_CODE[language] @@ -396,11 +404,11 @@ def transcribeLoop(mic: str, language: str, model: str, enable_local_beep: bool, transcribe_audio_thd.daemon = True transcribe_audio_thd.start() - send_audio_thd = threading.Thread(target = sendAudio, args = [audio_state]) + send_audio_thd = threading.Thread(target = sendAudio, args = [audio_state, use_builtin]) send_audio_thd.daemon = True send_audio_thd.start() - controller_input_thd = threading.Thread(target = readControllerInput, args = [audio_state, enable_local_beep]) + controller_input_thd = threading.Thread(target = readControllerInput, args = [audio_state, enable_local_beep, use_builtin]) controller_input_thd.daemon = True controller_input_thd.start() @@ -443,6 +451,7 @@ if __name__ == "__main__": parser.add_argument("--cols", type=int, help="The number of columns on the board") parser.add_argument("--window_duration_s", type=int, help="The length in seconds of the audio recording handed to the transcription algorithm") parser.add_argument("--cpu", type=int, help="If set to 1, use CPU instead of GPU") + parser.add_argument("--use_builtin", type=int, help="If set to 1, use the text box built into the game.") args = parser.parse_args() if not args.mic: @@ -470,11 +479,16 @@ if __name__ == "__main__": else: args.cpu = False + if args.use_builtin == 1: + args.use_builtin = True + else: + args.use_builtin = False + generate_utils.config.BYTES_PER_CHAR = int(args.bytes_per_char) generate_utils.config.CHARS_PER_SYNC = int(args.chars_per_sync) generate_utils.config.BOARD_ROWS = int(args.rows) generate_utils.config.BOARD_COLS = int(args.cols) transcribeLoop(args.mic, args.language, args.model, args.enable_local_beep, - args.cpu) + args.cpu, args.use_builtin) |
