From c1157d30cf751f22a40d9e5f221579fb4084b48f Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 17 Jun 2025 15:05:24 +0900 Subject: [PATCH 1/2] [Refactor] Move WebSocket message sending and logging to the correct position in the flow --- src-python/controller.py | 42 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src-python/controller.py b/src-python/controller.py index fb84126e..f0c3d55b 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -322,23 +322,6 @@ class Controller: "transliteration":transliteration }) - if model.checkWebSocketServerAlive() is True: - model.websocketSendMessage( - { - "type":"SENT", - "src_languages":config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO], - "dst_languages":config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO], - "message":message, - "translation":translation, - "transliteration":transliteration - } - ) - - if config.LOGGER_FEATURE is True: - if len(translation) > 0: - translation = " (" + "/".join(translation) + ")" - model.logger.info(f"[SENT] {message}{translation}") - if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True: if len(translation) > 0: @@ -360,6 +343,22 @@ class Controller: ) model.updateOverlayLargeLog(overlay_image) + if model.checkWebSocketServerAlive() is True: + model.websocketSendMessage( + { + "type":"SENT", + "src_languages":config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO], + "dst_languages":config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO], + "message":message, + "translation":translation, + "transliteration":transliteration + } + ) + + if config.LOGGER_FEATURE is True: + translation_text = f" ({'/'.join(translation)})" if translation else "" + model.logger.info(f"[SENT] {message}{translation_text}") + def speakerMessage(self, result:dict) -> None: message = result["text"] language = result["language"] @@ -497,9 +496,8 @@ class Controller: ) if config.LOGGER_FEATURE is True: - if len(translation) > 0: - translation = " (" + "/".join(translation) + ")" - model.logger.info(f"[RECEIVED] {message}{translation}") + translation_text = f" ({'/'.join(translation)})" if translation else "" + model.logger.info(f"[RECEIVED] {message}{translation_text}") def chatMessage(self, data) -> None: id = data["id"] @@ -615,10 +613,8 @@ class Controller: } ) - # update textbox message log (Chat) if config.LOGGER_FEATURE is True: - if len(translation) > 0: - translation_text = " (" + "/".join(translation) + ")" + translation_text = f" ({'/'.join(translation)})" if translation else "" model.logger.info(f"[CHAT] {message}{translation_text}") return {"status":200, From 5813ede67b917f56bcd6abd4f99b06dd6dd88f92 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 17 Jun 2025 15:06:30 +0900 Subject: [PATCH 2/2] [Refactor] Simplify conditional checks for transcript retrieval in Model class --- src-python/model.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src-python/model.py b/src-python/model.py index 9f905ec3..333f1394 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -452,9 +452,9 @@ class Model: config.MIC_AVG_LOGPROB, config.MIC_NO_SPEECH_PROB ) - if res: - result = self.mic_transcriber.getTranscript() - fnc(result) + if res: + result = self.mic_transcriber.getTranscript() + fnc(result) except Exception: errorLogging() @@ -635,9 +635,9 @@ class Model: config.SPEAKER_AVG_LOGPROB, config.SPEAKER_NO_SPEECH_PROB ) - if res: - result = self.speaker_transcriber.getTranscript() - fnc(result) + if res: + result = self.speaker_transcriber.getTranscript() + fnc(result) except Exception: errorLogging()