From ae9ac5ba5942447f47d8d996d2d340381e730c33 Mon Sep 17 00:00:00 2001 From: yum Date: Wed, 23 Nov 2022 12:24:07 -0800 Subject: Tweak speech indicator Use a single indicator with 3 states: 1. green: actively speaking 2. orange: waiting for paging 3. red: up-to-date Use slightly nicer colors. --- TaSTT.shader | 52 ++++++++++++++++++++++++++++++++++------------------ osc_ctrl.py | 26 ++++++++++++-------------- transcribe.py | 6 +++++- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/TaSTT.shader b/TaSTT.shader index 272f08b..79a1bfc 100644 --- a/TaSTT.shader +++ b/TaSTT.shader @@ -408,12 +408,34 @@ Texture2D _Font_0xA000_0xBFFF; Texture2D _Font_0xC000_0xDFFF; + float3 HUEtoRGB(in float H) + { + float R = abs(H * 6 - 3) - 1; + float G = 2 - abs(H * 6 - 2); + float B = 2 - abs(H * 6 - 4); + return saturate(float3(R, G, B)); + } + + float3 HSVtoRGB(in float3 HSV) + { + float3 RGB = HUEtoRGB(HSV.x); + return ((RGB - 1) * HSV.y + 1) * HSV.z; + } + float TaSTT_Indicator_0; - static const fixed4 TaSTT_Indicator_0_Off_Color = fixed4(0.0, 1.0, 0.0, 2) * 0.7; - static const fixed4 TaSTT_Indicator_0_On_Color = fixed4(0.8, 0.2, 0.0, 2) * 0.9; float TaSTT_Indicator_1; - static const fixed4 TaSTT_Indicator_1_Off_Color = fixed4(0.0, 1.0, 0.0, 2) * 0.7; - static const fixed4 TaSTT_Indicator_1_On_Color = fixed4(0.8, 0.2, 0.0, 2) * 0.9; + static const float3 TaSTT_Indicator_Color_0 = HSVtoRGB(float3(0.00, 0.7, 1.0)); + static const float3 TaSTT_Indicator_Color_1 = HSVtoRGB(float3(0.07, 0.7, 1.0)); + static const float3 TaSTT_Indicator_Color_2 = HSVtoRGB(float3(0.30, 0.7, 1.0)); + + fixed4 float3tofixed4(in float3 f3, in float alpha) + { + return fixed4( + f3.r, + f3.g, + f3.b, + alpha); + } Texture2D TaSTT_Backplate; @@ -1284,21 +1306,15 @@ indicator_center.y = 1.0 - indicator_center.y; if (InRadius2(uv, indicator_center, radius * radius)) { - if (floor(TaSTT_Indicator_0) == 0.0) { - return TaSTT_Indicator_0_Off_Color; - } else { - return TaSTT_Indicator_0_On_Color; - } - } - - // Next, draw the second indicator. Same size as before, just shifted - // over a little. - indicator_center.x += radius * 2.5; - if (InRadius2(uv, indicator_center, radius * radius)) { - if (floor(TaSTT_Indicator_1) == 0.0) { - return TaSTT_Indicator_1_Off_Color; + if (floor(TaSTT_Indicator_0) == 1.0) { + // Actively speaking + return float3tofixed4(TaSTT_Indicator_Color_2, 1.0); + } else if (floor(TaSTT_Indicator_1) == 1.0) { + // Done speaking, waiting for paging. + return float3tofixed4(TaSTT_Indicator_Color_1, 1.0); } else { - return TaSTT_Indicator_1_On_Color; + // Neither speaking nor paging. + return float3tofixed4(TaSTT_Indicator_Color_0, 1.0); } } diff --git a/osc_ctrl.py b/osc_ctrl.py index c72aed6..46c7997 100644 --- a/osc_ctrl.py +++ b/osc_ctrl.py @@ -221,7 +221,14 @@ def resizeBoard(num_lines, tx_state, shrink_only): # Send a message to the board, but only overwrite cells that we know need to # change. -# This may take multiple calls to complete. Returns True once it's done. +# This may take multiple calls to complete. +# Returns 3 possible values: +# 0: Done sending. +# 1: Exhausted empty cell budget. +# 2: Exhausted nonempty cell budget. +SEND_MSG_LAZY_DONE = 0 +SEND_MSG_LAZY_SENT_EMPTY = 1 +SEND_MSG_LAZY_SENT_NON_EMPTY = 2 def sendMessageLazy(client, msg, tx_state): lines = splitMessage(msg) msg_encoded = encodeMessage(lines) @@ -243,22 +250,13 @@ def sendMessageLazy(client, msg, tx_state): if cell_msg == last_cell_msg: continue - # Skip cells on previous pages. This mitigates a bug where updating the - # earlier part of a transcription causes that text to overwrite text - # from a later part of the transcription. - page = floor(cell / (2 ** generate_utils.INDEX_BITS)) - last_cell = (len(tx_state.last_msg_encoded) / NUM_LAYERS) - 1 - last_page = floor(last_cell / (2 ** generate_utils.INDEX_BITS)) - if page < last_page: - pass - if cell_msg == [state.encoding[' ']] * NUM_LAYERS: if empty_cells_sent >= tx_state.empty_cells_to_send_per_call: - return False + return SEND_MSG_LAZY_SENT_EMPTY empty_cells_sent += 1 else: if nonempty_cells_sent >= tx_state.nonempty_cells_to_send_per_call: - return False + return SEND_MSG_LAZY_SENT_NON_EMPTY nonempty_cells_sent += 1 sendMessageCellDiscrete(client, cell_msg, cell) @@ -268,7 +266,7 @@ def sendMessageLazy(client, msg, tx_state): tx_state.last_msg_encoded[cell_begin:cell_end] = cell_msg #resizeBoard(len(lines), tx_state, shrink_only=True) - return True + return SEND_MSG_LAZY_DONE def sendRawMessage(client, msg): n_cells = ceil(len(msg) / NUM_LAYERS) @@ -317,7 +315,7 @@ if __name__ == "__main__": tx_state = OscTxState() for line in fileinput.input(): - while not sendMessageLazy(client, line, tx_state): + while sendMessageLazy(client, line, tx_state) != SEND_MSG_LAZY_DONE: continue clear(client, tx_state) diff --git a/transcribe.py b/transcribe.py index b316014..48a97ba 100644 --- a/transcribe.py +++ b/transcribe.py @@ -288,8 +288,9 @@ def sendAudio(audio_state): audio_state.transcribe_lock.acquire() text = audio_state.committed_text + " " + audio_state.text - is_paging = not osc_ctrl.sendMessageLazy(audio_state.osc_client, text, + ret = osc_ctrl.sendMessageLazy(audio_state.osc_client, text, audio_state.tx_state) + is_paging = (ret == osc_ctrl.SEND_MSG_LAZY_SENT_NON_EMPTY) osc_ctrl.indicatePaging(audio_state.osc_client, is_paging) audio_state.transcribe_lock.release() @@ -301,12 +302,15 @@ def readControllerInput(audio_state): RECORD_STATE = 0 PAUSE_STATE = 1 state = PAUSE_STATE + osc_ctrl.indicateSpeech(audio_state.osc_client, False) + osc_ctrl.indicatePaging(audio_state.osc_client, False) while audio_state.run_app == True: time.sleep(0.05) event = steamvr.pollButtonPress(session) if event == steamvr.EVENT_RISING_EDGE: + print("event get") if state == RECORD_STATE: state = PAUSE_STATE osc_ctrl.indicateSpeech(audio_state.osc_client, False) -- cgit v1.2.3