diff --git a/src-python/config.py b/src-python/config.py index eec377c3..64ba9166 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -963,7 +963,10 @@ class Config: self._VERSION = "2.2.5" self._ENABLE_SPEAKER2CHATBOX = False # Speaker2Chatbox self._ENABLE_SPEAKER2CHATBOX_PASS_CONFIRMATION = "VRCT=0YEN" - self._PATH_LOCAL = os_path.dirname(sys.executable) + if getattr(sys, 'frozen', False): + self._PATH_LOCAL = os_path.dirname(sys.executable) + else: + self._PATH_LOCAL = os_path.dirname(os_path.abspath(__file__)) self._PATH_CONFIG = os_path.join(self._PATH_LOCAL, "config.json") self._PATH_LOGS = os_path.join(self._PATH_LOCAL, "logs") os_makedirs(self._PATH_LOGS, exist_ok=True) diff --git a/src-python/model.py b/src-python/model.py index d2556f04..2272eb39 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -315,7 +315,7 @@ class Model: return update_flag @staticmethod - def updateSoftware(restart:bool=True, func=None): + def updateSoftware(restart:bool=True, download=None, update=None): def updateSoftwareTask(): filename = 'VRCT.zip' program_name = 'VRCT.exe' @@ -336,8 +336,8 @@ class Model: for chunk in res.iter_content(chunk_size=1024*5): file.write(chunk) total_chunk += len(chunk) - if isinstance(func, Callable): - func(progress=total_chunk/file_size, progress_type="downloading") + if isinstance(download, Callable): + download(total_chunk/file_size) print(f"downloaded {total_chunk}/{file_size}") with ZipFile(os_path.join(tmp_path, filename)) as zf: @@ -346,8 +346,8 @@ class Model: for file_info in zf.infolist(): extracted_files += 1 zf.extract(file_info, os_path.join(current_directory, tmp_directory_name)) - if isinstance(func, Callable): - func(progress=extracted_files/total_files, progress_type="extracting") + if isinstance(update, Callable): + update(extracted_files/total_files) print(f"extracted {extracted_files}/{total_files}") copyfile(os_path.join(current_directory, folder_name, "batch", batch_name), os_path.join(current_directory, batch_name)) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 63256a39..9f410382 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -10,47 +10,59 @@ from utils import getKeyByValue, isUniqueStrings, strPctToInt import argparse # Common -def callbackUpdateSoftware(func=None): - print(json.dumps({"log": "callbackUpdateSoftware"}), flush=True) - setMainWindowGeometry() - model.updateSoftware(restart=True, func=func) +class DownloadProgressBar: + def __init__(self, action): + self.action = action -def callbackRestartSoftware(): - print(json.dumps({"log": "callbackRestartSoftware"}), flush=True) - setMainWindowGeometry() + def set(self, progress) -> None: + print(json.dumps({"status":348, "log": "Software Download Progress", "data":progress}), flush=True) + self.action("download", { + "status":200, + "result":{ + "progress":progress + } + }) + +class UpdateProgressBar: + def __init__(self, action): + self.action = action + + def set(self, progress) -> None: + print(json.dumps({"status":348, "log": "Software Update Progress", "data":progress}), flush=True) + self.action("update", { + "status":200, + "result":{ + "progress":progress + } + }) + +def callbackUpdateSoftware(data, action, *args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackUpdateSoftware"}), flush=True) + download = DownloadProgressBar(action) + update = UpdateProgressBar(action) + model.updateSoftware(restart=True, download=download.set, update=update.set) + return {"status":200} + +def callbackRestartSoftware(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackRestartSoftware"}), flush=True) model.reStartSoftware() + return {"status":200} -def callbackFilepathLogs(): - print(json.dumps({"log": "callbackFilepathLogs"}), flush=True) +def callbackFilepathLogs(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackFilepathLogs"}), flush=True) Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True) - return "Success", 200 + return {"status":200} -def callbackFilepathConfigFile(): - print(json.dumps({"log": "callbackFilepathConfigFile"}), flush=True) +def callbackFilepathConfigFile(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackFilepathConfigFile"}), flush=True) Popen(['explorer', config.PATH_LOCAL.replace('/', '\\')], shell=True) - return "Success", 200 + return {"status":200} -def callbackQuitVrct(): - print(json.dumps({"log": "callbackQuitVrct"}), flush=True) - setMainWindowGeometry() - -def callbackEnableEasterEgg(): - print(json.dumps({"log": "callbackEnableEasterEgg"}), flush=True) - config.IS_EASTER_EGG_ENABLED = True - config.OVERLAY_UI_TYPE = "sakura" - # view.printToTextbox_enableEasterEgg() - -def setMainWindowGeometry(): - # PRE_SCALING_INT = strPctToInt(view.getPreUiScaling()) - # NEW_SCALING_INT = strPctToInt(config.UI_SCALING) - # MULTIPLY_FLOAT = (NEW_SCALING_INT / PRE_SCALING_INT) - # main_window_geometry = view.getMainWindowGeometry(return_int=True) - # main_window_geometry["width"] = str(int(main_window_geometry["width"] * MULTIPLY_FLOAT)) - # main_window_geometry["height"] = str(int(main_window_geometry["height"] * MULTIPLY_FLOAT)) - # main_window_geometry["x_pos"] = str(main_window_geometry["x_pos"]) - # main_window_geometry["y_pos"] = str(main_window_geometry["y_pos"]) - # config.MAIN_WINDOW_GEOMETRY = main_window_geometry - pass +# def callbackEnableEasterEgg(): +# print(json.dumps({"status":348, "log": "callbackEnableEasterEgg"}), flush=True) +# config.IS_EASTER_EGG_ENABLED = True +# config.OVERLAY_UI_TYPE = "sakura" +# return {"status":200, "result":config.IS_EASTER_EGG_ENABLED} def messageFormatter(format_type:str, translation, message): if format_type == "RECEIVED": @@ -74,7 +86,6 @@ def changeToCTranslate2Process(): config.CHOICE_INPUT_TRANSLATOR = "CTranslate2" config.CHOICE_OUTPUT_TRANSLATOR = "CTranslate2" updateTranslationEngineAndEngineList() - # view.printToTextbox_TranslationEngineLimitError() # func transcription send message class MicMessage: @@ -83,12 +94,22 @@ class MicMessage: def send(self, message: Union[str, bool]) -> None: if isinstance(message, bool) and message is False: - self.action({"status":"error", "message":"No mic device detected."}) + self.action("error_device", { + "status":400, + "result": { + "message":"No mic device detected." + } + }) elif isinstance(message, str) and len(message) > 0: addSentMessageLog(message) translation = "" if model.checkKeywords(message): - self.action("mic", {"status":"error", "message":f"Detected by word filter:{message}"}) + self.action("word_filter", { + "status":200, + "result": { + "message":f"Detected by word filter:{message}" + } + }) return elif model.detectRepeatSendMessage(message): return @@ -98,6 +119,12 @@ class MicMessage: translation, success = model.getInputTranslate(message) if success is False: changeToCTranslate2Process() + self.action("error_translation_engine", { + "status":400, + "result": { + "message":"translation engine limit error" + } + }) if config.ENABLE_TRANSCRIPTION_SEND is True: if config.ENABLE_SEND_MESSAGE_TO_VRC is True: @@ -110,7 +137,13 @@ class MicMessage: osc_message = messageFormatter("SEND", translation, message) model.oscSendMessage(osc_message) - self.action("mic", {"status":"success", "message":message, "translation":translation}) + self.action("mic", { + "status":200, + "result": { + "message":message, + "translation":translation + } + }) if config.ENABLE_LOGGER is True: if len(translation) > 0: translation = f" ({translation})" @@ -128,7 +161,12 @@ def startTranscriptionSendMessage(action:Callable[[dict], None]) -> None: def stopTranscriptionSendMessage(action:Callable[[dict], None]) -> None: model.stopMicTranscript() - action("mic", {"status":"success", "message":"Stopped sending messages"}) + action("mic", { + "status":200, + "result":{ + "message":"Stopped sending messages" + } + }) def startThreadingTranscriptionSendMessage(action:Callable[[dict], None]) -> None: th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage, args=(action,)) @@ -164,7 +202,12 @@ class SpeakerMessage: def receive(self, message): if isinstance(message, bool) and message is False: - self.action("speaker", {"status":"error", "message":"No mic device detected."}) + self.action("error_device",{ + "status":400, + "result": { + "message":"No mic device detected." + }, + }) elif isinstance(message, str) and len(message) > 0: translation = "" if model.detectRepeatReceiveMessage(message): @@ -175,6 +218,12 @@ class SpeakerMessage: translation, success = model.getOutputTranslate(message) if success is False: changeToCTranslate2Process() + self.action("error_translation_engine", { + "status":400, + "result": { + "message":"translation engine limit error" + } + }) if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_NOTICE_XSOVERLAY is True: @@ -197,7 +246,13 @@ class SpeakerMessage: # ------------Speaker2Chatbox------------ # update textbox message log (Received) - self.action("speaker",{"status":"success", "message":message, "translation":translation}) + self.action("speaker",{ + "status":200, + "result": { + "message":message, + "translation":translation + } + }) if config.ENABLE_LOGGER is True: if len(translation) > 0: translation = f" ({translation})" @@ -209,7 +264,12 @@ def startTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None: def stopTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None: model.stopSpeakerTranscript() - action({"status":"success", "message":"Stopped receiving messages"}) + action("speaker", { + "status":200, + "result": { + "message":"Stopped receiving messages" + } + }) def startThreadingTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None: th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage, args=(action,)) @@ -239,51 +299,62 @@ def stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow(): th_stopTranscriptionReceiveMessage.start() # func message box -def sendChatMessage(message): - if len(message) > 0: - addSentMessageLog(message) - translation = "" - if config.ENABLE_TRANSLATION is False: - pass - else: - translation, success = model.getInputTranslate(message) - if success is False: - changeToCTranslate2Process() +class ChatMessage: + def __init__(self, action:Callable[[dict], None]) -> None: + self.action = action - # send OSC message - if config.ENABLE_SEND_MESSAGE_TO_VRC is True: - if config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES is True: - if config.ENABLE_TRANSLATION is False: - osc_message = messageFormatter("SEND", "", message) - else: - osc_message = messageFormatter("SEND", "", translation) + def send(self, message): + if len(message) > 0: + addSentMessageLog(message) + translation = "" + if config.ENABLE_TRANSLATION is False: + pass else: - osc_message = messageFormatter("SEND", translation, message) - model.oscSendMessage(osc_message) + translation, success = model.getInputTranslate(message) + if success is False: + changeToCTranslate2Process() + self.action("error_translation_engine", { + "status":400, + "result":{ + "message":"translation engine limit error" + } + }) - # if config.ENABLE_OVERLAY_SMALL_LOG is True: - # overlay_image = model.createOverlayImageShort(message, translation) - # model.updateOverlay(overlay_image) - # overlay_image = model.createOverlayImageLong("send", message, translation) - # model.updateOverlay(overlay_image) + # send OSC message + if config.ENABLE_SEND_MESSAGE_TO_VRC is True: + if config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES is True: + if config.ENABLE_TRANSLATION is False: + osc_message = messageFormatter("SEND", "", message) + else: + osc_message = messageFormatter("SEND", "", translation) + else: + osc_message = messageFormatter("SEND", translation, message) + model.oscSendMessage(osc_message) - # update textbox message log (Sent) - # view.printToTextbox_SentMessage(message, translation) - if config.ENABLE_LOGGER is True: - if len(translation) > 0: - translation = f" ({translation})" - model.logger.info(f"[SENT] {message}{translation}") + # if config.ENABLE_OVERLAY_SMALL_LOG is True: + # overlay_image = model.createOverlayImageShort(message, translation) + # model.updateOverlay(overlay_image) + # overlay_image = model.createOverlayImageLong("send", message, translation) + # model.updateOverlay(overlay_image) - # delete message in entry message box - if config.ENABLE_AUTO_CLEAR_MESSAGE_BOX is True: - # view.clearMessageBox() - pass + # update textbox message log (Sent) + if config.ENABLE_LOGGER is True: + if len(translation) > 0: + translation = f" ({translation})" + model.logger.info(f"[SENT] {message}{translation}") -def messageBoxPressKeyEnter(): - # model.oscStopSendTyping() - # message = view.getTextFromMessageBox() - # sendChatMessage(message) - pass + return {"status":200, + "result":{ + "message":message, + "translation":translation, + "clear":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX + }, + } + +def callbackMessageBoxPressKeyEnter(data, action, *args, **kwargs) -> dict: + chat = ChatMessage(action) + response = chat.send(data) + return response def messageBoxPressKeyAny(e): if config.ENABLE_SEND_MESSAGE_TO_VRC is True: @@ -304,24 +375,24 @@ def addSentMessageLog(sent_message): config.SENT_MESSAGES_LOG.append(sent_message) config.CURRENT_SENT_MESSAGES_LOG_INDEX = len(config.SENT_MESSAGES_LOG) -def updateMessageBox(index_offset): - if len(config.SENT_MESSAGES_LOG) == 0: - return - try: - new_index = config.CURRENT_SENT_MESSAGES_LOG_INDEX + index_offset - target_message_text = config.SENT_MESSAGES_LOG[new_index] - # view.replaceMessageBox(target_message_text) - config.CURRENT_SENT_MESSAGES_LOG_INDEX = new_index - except IndexError: - pass +# def updateMessageBox(index_offset): +# if len(config.SENT_MESSAGES_LOG) == 0: +# return +# try: +# new_index = config.CURRENT_SENT_MESSAGES_LOG_INDEX + index_offset +# target_message_text = config.SENT_MESSAGES_LOG[new_index] +# # view.replaceMessageBox(target_message_text) +# config.CURRENT_SENT_MESSAGES_LOG_INDEX = new_index +# except IndexError: +# pass -def messageBoxUpKeyPress(): - if config.CURRENT_SENT_MESSAGES_LOG_INDEX > 0: - updateMessageBox(-1) +# def messageBoxUpKeyPress(): +# if config.CURRENT_SENT_MESSAGES_LOG_INDEX > 0: +# updateMessageBox(-1) -def messageBoxDownKeyPress(): - if config.CURRENT_SENT_MESSAGES_LOG_INDEX < len(config.SENT_MESSAGES_LOG) - 1: - updateMessageBox(1) +# def messageBoxDownKeyPress(): +# if config.CURRENT_SENT_MESSAGES_LOG_INDEX < len(config.SENT_MESSAGES_LOG) - 1: +# updateMessageBox(1) def updateTranslationEngineAndEngineList(): engine = config.CHOICE_INPUT_TRANSLATOR @@ -358,15 +429,15 @@ def setTargetTranslateEngine(select): config.CHOICE_OUTPUT_TRANSLATOR = select def setYourLanguageAndCountry(select:dict, *args, **kwargs) -> dict: - print(json.dumps({"log": "setYourLanguageAndCountry", "data":select}), flush=True) + print(json.dumps({"status":348, "log": "setYourLanguageAndCountry", "data":select}), flush=True) languages = config.SELECTED_TAB_YOUR_LANGUAGES languages[config.SELECTED_TAB_NO] = select config.SELECTED_TAB_YOUR_LANGUAGES = languages config.SOURCE_LANGUAGE = select["language"] config.SOURCE_COUNTRY = select["country"] updateTranslationEngineAndEngineList() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "your":{ "language":config.SOURCE_LANGUAGE, "country":config.SOURCE_COUNTRY @@ -375,15 +446,15 @@ def setYourLanguageAndCountry(select:dict, *args, **kwargs) -> dict: } def setTargetLanguageAndCountry(select:dict, *args, **kwargs) -> dict: - print(json.dumps({"log": "setTargetLanguageAndCountry", "data":select}), flush=True) + print(json.dumps({"status":348, "log": "setTargetLanguageAndCountry", "data":select}), flush=True) languages = config.SELECTED_TAB_TARGET_LANGUAGES languages[config.SELECTED_TAB_NO] = select config.SELECTED_TAB_TARGET_LANGUAGES = languages config.TARGET_LANGUAGE = select["language"] config.TARGET_COUNTRY = select["country"] updateTranslationEngineAndEngineList() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "target":{ "language":config.TARGET_LANGUAGE, "country":config.TARGET_COUNTRY @@ -392,13 +463,13 @@ def setTargetLanguageAndCountry(select:dict, *args, **kwargs) -> dict: } def swapYourLanguageAndTargetLanguage(*args, **kwargs) -> dict: - print(json.dumps({"log": "swapYourLanguageAndTargetLanguage"}), flush=True) + print(json.dumps({"status":348, "log": "swapYourLanguageAndTargetLanguage"}), flush=True) your_language = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO] target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] setYourLanguageAndCountry(target_language) setTargetLanguageAndCountry(your_language) - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "your":{"language":config.SOURCE_LANGUAGE, "country":config.SOURCE_COUNTRY, }, @@ -410,7 +481,7 @@ def swapYourLanguageAndTargetLanguage(*args, **kwargs) -> dict: } def callbackSelectedLanguagePresetTab(selected_tab_no:str, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSelectedLanguagePresetTab", "data":selected_tab_no}), flush=True) + print(json.dumps({"status":348, "log": "callbackSelectedLanguagePresetTab", "data":selected_tab_no}), flush=True) config.SELECTED_TAB_NO = selected_tab_no engines = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES @@ -431,86 +502,86 @@ def callbackSelectedLanguagePresetTab(selected_tab_no:str, *args, **kwargs) -> d config.TARGET_LANGUAGE = select["language"] config.TARGET_COUNTRY = select["country"] updateTranslationEngineAndEngineList() - return {"status":"success", "data":config.SELECTED_TAB_NO} + return {"status":200, "result":config.SELECTED_TAB_NO} def callbackSelectedTranslationEngine(selected_translation_engine:str, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSelectedTranslationEngine", "data":selected_translation_engine}), flush=True) + print(json.dumps({"status":348, "log": "callbackSelectedTranslationEngine", "data":selected_translation_engine}), flush=True) setYourTranslateEngine(selected_translation_engine) setTargetTranslateEngine(selected_translation_engine) - return {"status":"success", "data":selected_translation_engine} + return {"status":200, "result":selected_translation_engine} # command func def callbackEnableTranslation(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableTranslation"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableTranslation"}), flush=True) config.ENABLE_TRANSLATION = True if model.isLoadedCTranslate2Model() is False: model.changeTranslatorCTranslate2Model() - return {"status":"success", "data":config.ENABLE_TRANSLATION} + return {"status":200, "result":config.ENABLE_TRANSLATION} def callbackDisableTranslation(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableTranslation"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableTranslation"}), flush=True) config.ENABLE_TRANSLATION = False - return {"status":"success", "data":config.ENABLE_TRANSLATION} + return {"status":200, "result":config.ENABLE_TRANSLATION} def callbackEnableTranscriptionSend(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableTranscriptionSend"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableTranscriptionSend"}), flush=True) config.ENABLE_TRANSCRIPTION_SEND = True startThreadingTranscriptionSendMessage(action) - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_SEND} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} def callbackDisableTranscriptionSend(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableTranscriptionSend"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableTranscriptionSend"}), flush=True) config.ENABLE_TRANSCRIPTION_SEND = False stopThreadingTranscriptionSendMessage(action) - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_SEND} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_SEND} def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableTranscriptionReceive"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableTranscriptionReceive"}), flush=True) config.ENABLE_TRANSCRIPTION_RECEIVE = True startThreadingTranscriptionReceiveMessage(action) if config.ENABLE_OVERLAY_SMALL_LOG is True: if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: model.startOverlay() - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_RECEIVE} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} def callbackDisableTranscriptionReceive(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableTranscriptionReceive"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableTranscriptionReceive"}), flush=True) config.ENABLE_TRANSCRIPTION_RECEIVE = False stopThreadingTranscriptionReceiveMessage(action) - return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_RECEIVE} + return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} def callbackEnableForeground(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableForeground"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableForeground"}), flush=True) config.ENABLE_FOREGROUND = True - return {"status":"success", "data":config.ENABLE_FOREGROUND} + return {"status":200, "result":config.ENABLE_FOREGROUND} def callbackDisableForeground(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableForeground"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableForeground"}), flush=True) config.ENABLE_FOREGROUND = False - return {"status":"success", "data":config.ENABLE_FOREGROUND} + return {"status":200, "result":config.ENABLE_FOREGROUND} def callbackEnableMainWindowSidebarCompactMode(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableMainWindowSidebarCompactMode"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableMainWindowSidebarCompactMode"}), flush=True) config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True - return {"status":"success", "data":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} + return {"status":200, "result":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} def callbackDisableMainWindowSidebarCompactMode(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableMainWindowSidebarCompactMode"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableMainWindowSidebarCompactMode"}), flush=True) config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False - return {"status":"success", "data":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} + return {"status":200, "result":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE} # Config Window def callbackOpenConfigWindow(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackOpenConfigWindow"}), flush=True) + print(json.dumps({"status":348, "log": "callbackOpenConfigWindow"}), flush=True) if config.ENABLE_TRANSCRIPTION_SEND is True: stopThreadingTranscriptionSendMessageOnOpenConfigWindow() if config.ENABLE_TRANSCRIPTION_RECEIVE is True: stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow() - return {"status":"success"} + return {"status":200} def callbackCloseConfigWindow(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackCloseConfigWindow"}), flush=True) + print(json.dumps({"status":348, "log": "callbackCloseConfigWindow"}), flush=True) model.stopCheckMicEnergy() model.stopCheckSpeakerEnergy() @@ -520,90 +591,105 @@ def callbackCloseConfigWindow(data, action, *args, **kwargs) -> dict: sleep(2) if config.ENABLE_TRANSCRIPTION_RECEIVE is True: startThreadingTranscriptionReceiveMessageOnCloseConfigWindow(action) - return {"status":"success"} + return {"status":200} # Compact Mode Switch def callbackEnableConfigWindowCompactMode(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableConfigWindowCompactMode"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableConfigWindowCompactMode"}), flush=True) config.IS_CONFIG_WINDOW_COMPACT_MODE = True model.stopCheckMicEnergy() model.stopCheckSpeakerEnergy() - return {"status":"success", "data":config.IS_CONFIG_WINDOW_COMPACT_MODE} + return {"status":200, "result":config.IS_CONFIG_WINDOW_COMPACT_MODE} def callbackDisableConfigWindowCompactMode(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableConfigWindowCompactMode"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableConfigWindowCompactMode"}), flush=True) config.IS_CONFIG_WINDOW_COMPACT_MODE = False model.stopCheckMicEnergy() model.stopCheckSpeakerEnergy() - return {"status":"success", "data":config.IS_CONFIG_WINDOW_COMPACT_MODE} + return {"status":200, "result":config.IS_CONFIG_WINDOW_COMPACT_MODE} # Appearance Tab def callbackSetTransparency(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetTransparency", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetTransparency", "data":data}), flush=True) config.TRANSPARENCY = int(data) - return {"status":"success", "data":config.TRANSPARENCY} + return {"status":200, "result":config.TRANSPARENCY} def callbackSetAppearance(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetAppearance", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetAppearance", "data":data}), flush=True) config.APPEARANCE_THEME = data - return {"status":"success", "data":config.APPEARANCE_THEME} + return {"status":200, "result":config.APPEARANCE_THEME} def callbackSetUiScaling(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetUiScaling", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetUiScaling", "data":data}), flush=True) config.UI_SCALING = data - return {"status":"success", "data":config.UI_SCALING} + return {"status":200, "result":config.UI_SCALING} def callbackSetTextboxUiScaling(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetTextboxUiScaling", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetTextboxUiScaling", "data":data}), flush=True) config.TEXTBOX_UI_SCALING = int(data) - return {"status":"success", "data":config.TEXTBOX_UI_SCALING} + return {"status":200, "result":config.TEXTBOX_UI_SCALING} def callbackSetMessageBoxRatio(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMessageBoxRatio", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMessageBoxRatio", "data":data}), flush=True) config.MESSAGE_BOX_RATIO = int(data) - return {"status":"success", "data":config.MESSAGE_BOX_RATIO} + return {"status":200, "result":config.MESSAGE_BOX_RATIO} def callbackSetFontFamily(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetFontFamily", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetFontFamily", "data":data}), flush=True) config.FONT_FAMILY = data - return {"status":"success", "data":config.FONT_FAMILY} + return {"status":200, "result":config.FONT_FAMILY} def callbackSetUiLanguage(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetUiLanguage", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetUiLanguage", "data":data}), flush=True) data = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, data) config.UI_LANGUAGE = data - return {"status":"success", "data":config.UI_LANGUAGE} + return {"status":200, "result":config.UI_LANGUAGE} -def callbackSetEnableRestoreMainWindowGeometry(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetEnableRestoreMainWindowGeometry", "data":data}), flush=True) - config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = data - return {"status":"success", "data":config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY} +def callbackEnableRestoreMainWindowGeometry(data, *args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableRestoreMainWindowGeometry"}), flush=True) + config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = True + return {"status":200, "result":config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY} + +def callbackDisableRestoreMainWindowGeometry(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableRestoreMainWindowGeometry"}), flush=True) + config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = True + return {"status":200, "result":config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY} # Translation Tab -def callbackSetUseTranslationFeature(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetUseTranslationFeature", "data":data}), flush=True) - config.USE_TRANSLATION_FEATURE = data - if config.USE_TRANSLATION_FEATURE is True: - if model.checkCTranslatorCTranslate2ModelWeight(): - config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False - def callback(): - model.changeTranslatorCTranslate2Model() - th_callback = Thread(target=callback) - th_callback.daemon = True - th_callback.start() - else: - config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True - else: +def callbackEnableUseTranslationFeature(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableTranslationFeature"}), flush=True) + config.USE_TRANSLATION_FEATURE = True + + if model.checkCTranslatorCTranslate2ModelWeight(): config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False - return {"status":"success", - "data":{ + def callback(): + model.changeTranslatorCTranslate2Model() + th_callback = Thread(target=callback) + th_callback.daemon = True + th_callback.start() + else: + config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True + + return {"status":200, + "result":{ + "feature":config.USE_TRANSLATION_FEATURE, + "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, + }, + } + +def callbackDisableUseTranslationFeature(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableTranslationFeature"}), flush=True) + config.USE_TRANSLATION_FEATURE = False + config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False + return {"status":200, + "result":{ "feature":config.USE_TRANSLATION_FEATURE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, }, } def callbackSetCtranslate2WeightType(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetCtranslate2WeightType", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetCtranslate2WeightType", "data":data}), flush=True) config.CTRANSLATE2_WEIGHT_TYPE = str(data) if model.checkCTranslatorCTranslate2ModelWeight(): config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False @@ -614,95 +700,110 @@ def callbackSetCtranslate2WeightType(data, *args, **kwargs) -> dict: th_callback.start() else: config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "feature":config.CTRANSLATE2_WEIGHT_TYPE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, }, } def callbackSetDeeplAuthKey(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetDeeplAuthKey", "data":data}), flush=True) - status = "error" + print(json.dumps({"status":348, "log": "callbackSetDeeplAuthKey", "data":data}), flush=True) + status = 400 if len(data) == 36 or len(data) == 39: result = model.authenticationTranslatorDeepLAuthKey(auth_key=data) if result is True: key = data - status = "success" + status = 200 else: key = None auth_keys = config.AUTH_KEYS auth_keys["DeepL_API"] = key config.AUTH_KEYS = auth_keys updateTranslationEngineAndEngineList() - return {"status":status, "data":config.AUTH_KEYS["DeepL_API"]} + return {"status":status, "result":config.AUTH_KEYS["DeepL_API"]} def callbackClearDeeplAuthKey(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackClearDeeplAuthKey"}), flush=True) + print(json.dumps({"status":348, "log": "callbackClearDeeplAuthKey"}), flush=True) auth_keys = config.AUTH_KEYS auth_keys["DeepL_API"] = None config.AUTH_KEYS = auth_keys updateTranslationEngineAndEngineList() - return {"status":"success", "data":config.AUTH_KEYS["DeepL_API"]} + return {"status":200, "result":config.AUTH_KEYS["DeepL_API"]} # Transcription Tab # Transcription (Mic) def callbackSetMicHost(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicHost", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMicHost", "data":data}), flush=True) config.CHOICE_MIC_HOST = data config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice() model.stopCheckMicEnergy() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "host":config.CHOICE_MIC_HOST, "device":config.CHOICE_MIC_DEVICE, }, } def callbackSetMicDevice(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicDevice", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMicDevice", "data":data}), flush=True) config.CHOICE_MIC_DEVICE = data model.stopCheckMicEnergy() - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "host":config.CHOICE_MIC_HOST, }, } def callbackSetMicEnergyThreshold(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicEnergyThreshold", "data":data}), flush=True) - status = "error" + print(json.dumps({"status":348, "log": "callbackSetMicEnergyThreshold", "data":data}), flush=True) + status = 400 data = int(data) if 0 <= data <= config.MAX_MIC_ENERGY_THRESHOLD: config.INPUT_MIC_ENERGY_THRESHOLD = data - status = "success" - return {"status": status, "data": config.INPUT_MIC_ENERGY_THRESHOLD} + status = 200 + return {"status": status, "result": config.INPUT_MIC_ENERGY_THRESHOLD} -def callbackSetMicDynamicEnergyThreshold(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicDynamicEnergyThreshold", "data":data}), flush=True) - config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = data - return {"status":"success", "data":config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD} +def callbackEnableMicDynamicEnergyThreshold(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableMicDynamicEnergyThreshold"}), flush=True) + config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = True + return {"status":200, "result":config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD} -class ProgressBarEnergy: +def callbackDisableMicDynamicEnergyThreshold(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableMicDynamicEnergyThreshold"}), flush=True) + config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = False + return {"status":200, "result":config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD} + +class ProgressBarMicEnergy: def __init__(self, action): self.action = action def set(self, energy) -> None: - self.action("energy", {"status":"success", "energy":energy}) + self.action("mic", {"status":200, "result":energy}) + + def stopped(self) -> None: + self.action("stopped", {"status":200}) + + def error(self) -> None: + self.action("error_device", {"status":400,"result": {"message":"No mic device detected."}}) def callbackEnableCheckMicThreshold(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableCheckMicThreshold"}), flush=True) - progressbar_mic_energy = ProgressBarEnergy(action) - model.startCheckMicEnergy(progressbar_mic_energy.set) - return {"status":"success"} + print(json.dumps({"status":348, "log": "callbackEnableCheckMicThreshold"}), flush=True) + progressbar_mic_energy = ProgressBarMicEnergy(action) + model.startCheckMicEnergy( + progressbar_mic_energy.set, + progressbar_mic_energy.stopped, + progressbar_mic_energy.error + ) + return {"status":200} def callbackDisableCheckMicThreshold(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableCheckMicThreshold"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableCheckMicThreshold"}), flush=True) model.stopCheckMicEnergy() - return {"status":"success"} + return {"status":200} def callbackSetMicRecordTimeout(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicRecordTimeout", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMicRecordTimeout", "data":data}), flush=True) try: data = int(data) if 0 <= data <= config.INPUT_MIC_PHRASE_TIMEOUT: @@ -710,13 +811,13 @@ def callbackSetMicRecordTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Mic Record Timeout"} + response = {"status":400, "result":{"message":"Error Mic Record Timeout"}} else: - response = {"status":"success", "data":config.INPUT_MIC_RECORD_TIMEOUT} + response = {"status":200, "result":config.INPUT_MIC_RECORD_TIMEOUT} return response def callbackSetMicPhraseTimeout(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicPhraseTimeout", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMicPhraseTimeout", "data":data}), flush=True) try: data = int(data) if data >= config.INPUT_MIC_RECORD_TIMEOUT: @@ -724,13 +825,13 @@ def callbackSetMicPhraseTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Mic Phrase Timeout"} + response = {"status":400, "result":{"message":"Error Mic Phrase Timeout"}} else: - response = {"status":"success", "data":config.INPUT_MIC_PHRASE_TIMEOUT} + response = {"status":200, "result":config.INPUT_MIC_PHRASE_TIMEOUT} return response def callbackSetMicMaxPhrases(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicMaxPhrases", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMicMaxPhrases", "data":data}), flush=True) try: data = int(data) if 0 <= data: @@ -738,13 +839,13 @@ def callbackSetMicMaxPhrases(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Mic Max Phrases"} + response = {"status":400, "result":{"message":"Error Mic Max Phrases"}} else: - response = {"status":"success", "data":config.INPUT_MIC_MAX_PHRASES} + response = {"status":200, "result":config.INPUT_MIC_MAX_PHRASES} return response def callbackSetMicWordFilter(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetMicWordFilter", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetMicWordFilter", "data":data}), flush=True) data = str(data) data = [w.strip() for w in data.split(",") if len(w.strip()) > 0] # Copy the list @@ -761,10 +862,10 @@ def callbackSetMicWordFilter(data, *args, **kwargs) -> dict: model.resetKeywordProcessor() model.addKeywords() - return {"status":"success", "data":config.INPUT_MIC_WORD_FILTER} + return {"status":200, "result":config.INPUT_MIC_WORD_FILTER} def callbackDeleteMicWordFilter(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDeleteMicWordFilter", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackDeleteMicWordFilter", "data":data}), flush=True) try: new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER new_input_mic_word_filter_list.remove(str(data)) @@ -773,49 +874,69 @@ def callbackDeleteMicWordFilter(data, *args, **kwargs) -> dict: model.addKeywords() except Exception: print("There was no the target word in config.INPUT_MIC_WORD_FILTER") - return {"status":"success", "data":config.INPUT_MIC_WORD_FILTER} + return {"status":200, "result":config.INPUT_MIC_WORD_FILTER} # Transcription (Speaker) def callbackSetSpeakerDevice(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSpeakerDevice", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSpeakerDevice", "data":data}), flush=True) config.CHOICE_SPEAKER_DEVICE = data model.stopCheckSpeakerEnergy() - return {"status":"success", "data":config.CHOICE_SPEAKER_DEVICE} + return {"status":200, "result":config.CHOICE_SPEAKER_DEVICE} def callbackSetSpeakerEnergyThreshold(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSpeakerEnergyThreshold", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSpeakerEnergyThreshold", "data":data}), flush=True) try: data = int(data) if 0 <= data <= config.MAX_SPEAKER_ENERGY_THRESHOLD: - # view.clearNotificationMessage() config.INPUT_SPEAKER_ENERGY_THRESHOLD = data - # view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD) else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Set Speaker Energy Threshold"} + response = {"status":400, "result":{"message":"Error Set Speaker Energy Threshold"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_ENERGY_THRESHOLD} + response = {"status":200, "result":config.INPUT_SPEAKER_ENERGY_THRESHOLD} return response -def callbackSetSpeakerDynamicEnergyThreshold(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSpeakerDynamicEnergyThreshold", "data":data}), flush=True) - config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = data - return {"status":"success", "data":config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD} +def callbackEnableSpeakerDynamicEnergyThreshold(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableSpeakerDynamicEnergyThreshold"}), flush=True) + config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = True + return {"status":200, "result":config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD} + +def callbackDisableSpeakerDynamicEnergyThreshold(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableSpeakerDynamicEnergyThreshold"}), flush=True) + config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = False + return {"status":200, "result":config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD} + +class ProgressBarSpeakerEnergy: + def __init__(self, action): + self.action = action + + def set(self, energy) -> None: + self.action("speaker", {"status":200, "result":energy}) + + def stopped(self) -> None: + self.action("stopped", {"status":200}) + + def error(self) -> None: + self.action("error_device", {"status":400,"result": {"message":"No mic device detected."}}) def callbackEnableCheckSpeakerThreshold(data, action, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableCheckSpeakerThreshold"}), flush=True) - progressbar_speaker_energy = ProgressBarEnergy(action) - model.startCheckSpeakerEnergy(progressbar_speaker_energy.set) - return {"status":"success"} + print(json.dumps({"status":348, "log": "callbackEnableCheckSpeakerThreshold"}), flush=True) + progressbar_speaker_energy = ProgressBarSpeakerEnergy(action) + model.startCheckSpeakerEnergy( + progressbar_speaker_energy.set, + progressbar_speaker_energy.stopped, + progressbar_speaker_energy.error + ) + return {"status":200} def callbackDisableCheckSpeakerThreshold(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableCheckSpeakerThreshold"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableCheckSpeakerThreshold"}), flush=True) model.stopCheckSpeakerEnergy() - return {"status":"success"} + return {"status":200} def callbackSetSpeakerRecordTimeout(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSpeakerRecordTimeout", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSpeakerRecordTimeout", "data":data}), flush=True) try: data = int(data) if 0 <= data <= config.INPUT_SPEAKER_PHRASE_TIMEOUT: @@ -823,13 +944,13 @@ def callbackSetSpeakerRecordTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Speaker Record Timeout"} + response = {"status":400, "result":{"message":"Error Speaker Record Timeout"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_RECORD_TIMEOUT} + response = {"status":200, "result":config.INPUT_SPEAKER_RECORD_TIMEOUT} return response def callbackSetSpeakerPhraseTimeout(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSpeakerPhraseTimeout", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSpeakerPhraseTimeout", "data":data}), flush=True) try: data = int(data) if 0 <= data and data >= config.INPUT_SPEAKER_RECORD_TIMEOUT: @@ -837,13 +958,13 @@ def callbackSetSpeakerPhraseTimeout(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Speaker Phrase Timeout"} + response = {"status":400, "result":{"message":"Error Speaker Phrase Timeout"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_PHRASE_TIMEOUT} + response = {"status":200, "result":config.INPUT_SPEAKER_PHRASE_TIMEOUT} return response def callbackSetSpeakerMaxPhrases(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSpeakerMaxPhrases", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSpeakerMaxPhrases", "data":data}), flush=True) try: data = int(data) if 0 <= data: @@ -851,27 +972,36 @@ def callbackSetSpeakerMaxPhrases(data, *args, **kwargs) -> dict: else: raise ValueError() except Exception: - response = {"status":"error", "message":"Error Speaker Max Phrases"} + response = {"status":400, "result":{"message":"Error Speaker Max Phrases"}} else: - response = {"status":"success", "data":config.INPUT_SPEAKER_MAX_PHRASES} + response = {"status":200, "result":config.INPUT_SPEAKER_MAX_PHRASES} return response # Transcription (Internal AI Model) -def callbackSetUserWhisperFeature(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetUserWhisperFeature", "data":data}), flush=True) - config.USE_WHISPER_FEATURE = data - if config.USE_WHISPER_FEATURE is True: - if model.checkTranscriptionWhisperModelWeight() is True: - config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False - config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" - else: - config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = True - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - else: +def callbackEnableUseWhisperFeature(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableUserWhisperFeature"}), flush=True) + config.USE_WHISPER_FEATURE = True + if model.checkTranscriptionWhisperModelWeight() is True: config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False + config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" + else: + config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = True config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":"success", - "data":{ + return {"status":200, + "result":{ + "feature":config.USE_WHISPER_FEATURE, + "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, + "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, + }, + } + +def callbackDisableUseWhisperFeature(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableUserWhisperFeature"}), flush=True) + config.USE_WHISPER_FEATURE = False + config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False + config.SELECTED_TRANSCRIPTION_ENGINE = "Google" + return {"status":200, + "result":{ "feature":config.USE_WHISPER_FEATURE, "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, @@ -879,7 +1009,7 @@ def callbackSetUserWhisperFeature(data, *args, **kwargs) -> dict: } def callbackSetWhisperWeightType(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetWhisperWeightType", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetWhisperWeightType", "data":data}), flush=True) config.WHISPER_WEIGHT_TYPE = str(data) if model.checkTranscriptionWhisperModelWeight() is True: config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False @@ -887,8 +1017,8 @@ def callbackSetWhisperWeightType(data, *args, **kwargs) -> dict: else: config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = True config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":"success", - "data":{ + return {"status":200, + "result":{ "weight_type":config.WHISPER_WEIGHT_TYPE, "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, @@ -897,215 +1027,241 @@ def callbackSetWhisperWeightType(data, *args, **kwargs) -> dict: # VR Tab def callbackSetOverlaySettingsOpacity(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySettingsOpacity", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySettingsOpacity", "data":data}), flush=True) pre_settings = config.OVERLAY_SETTINGS pre_settings["opacity"] = data config.OVERLAY_SETTINGS = pre_settings model.updateOverlayImageOpacity() - return {"status":"success", "data":config.OVERLAY_SETTINGS["opacity"]} + return {"status":200, "result":config.OVERLAY_SETTINGS["opacity"]} def callbackSetOverlaySettingsUiScaling(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySettingsUiScaling", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySettingsUiScaling", "data":data}), flush=True) pre_settings = config.OVERLAY_SETTINGS pre_settings["ui_scaling"] = data config.OVERLAY_SETTINGS = pre_settings model.updateOverlayImageUiScaling() - return {"status":"success", "data":config.OVERLAY_SETTINGS["ui_scaling"]} + return {"status":200, "result":config.OVERLAY_SETTINGS["ui_scaling"]} def callbackEnableOverlaySmallLog(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableOverlaySmallLog"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableOverlaySmallLog"}), flush=True) config.ENABLE_OVERLAY_SMALL_LOG = True if config.ENABLE_OVERLAY_SMALL_LOG is True and config.ENABLE_TRANSCRIPTION_RECEIVE is True: if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: model.startOverlay() - return {"status":"success", "data":config.ENABLE_OVERLAY_SMALL_LOG} + return {"status":200, "result":config.ENABLE_OVERLAY_SMALL_LOG} def callbackDisableOverlaySmallLog(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableOverlaySmallLog"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableOverlaySmallLog"}), flush=True) config.ENABLE_OVERLAY_SMALL_LOG = False if config.ENABLE_OVERLAY_SMALL_LOG is False: model.clearOverlayImage() model.shutdownOverlay() - return {"status":"success", "data":config.ENABLE_OVERLAY_SMALL_LOG} + return {"status":200, "result":config.ENABLE_OVERLAY_SMALL_LOG} def callbackSetOverlaySmallLogSettingsXPos(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsXPos", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySmallLogSettingsXPos", "data":data}), flush=True) pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS pre_settings["x_pos"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["x_pos"]} def callbackSetOverlaySmallLogSettingsYPos(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsYPos", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySmallLogSettingsYPos", "data":data}), flush=True) pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS pre_settings["y_pos"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["y_pos"]} def callbackSetOverlaySmallLogSettingsZPos(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsZPos", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySmallLogSettingsZPos", "data":data}), flush=True) pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS pre_settings["z_pos"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["z_pos"]} def callbackSetOverlaySmallLogSettingsXRotation(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsXRotation", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySmallLogSettingsXRotation", "data":data}), flush=True) pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS pre_settings["x_rotation"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["x_rotation"]} def callbackSetOverlaySmallLogSettingsYRotation(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsYRotation", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySmallLogSettingsYRotation", "data":data}), flush=True) pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS pre_settings["y_rotation"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["y_rotation"]} def callbackSetOverlaySmallLogSettingsZRotation(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOverlaySmallLogSettingsZRotation", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOverlaySmallLogSettingsZRotation", "data":data}), flush=True) pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS pre_settings["z_rotation"] = data config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings model.updateOverlayPosition() - return {"status":"success", "data":config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"]} + return {"status":200, "result":config.OVERLAY_SMALL_LOG_SETTINGS["z_rotation"]} # Others Tab -def callbackSetEnableAutoClearMessageBox(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetEnableAutoClearMessageBox", "data":data}), flush=True) - config.ENABLE_AUTO_CLEAR_MESSAGE_BOX = data - return {"status":"success", "data":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX} +def callbackEnableAutoClearMessageBox(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableAutoClearMessageBox"}), flush=True) + config.ENABLE_AUTO_CLEAR_MESSAGE_BOX = True + return {"status":200, "result":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX} -def callbackSetEnableSendOnlyTranslatedMessages(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetEnableSendOnlyTranslatedMessages", "data":data}), flush=True) - config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES = data - return {"status":"success", "data":config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES} +def callbackDisableAutoClearMessageBox(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableAutoClearMessageBox"}), flush=True) + config.ENABLE_AUTO_CLEAR_MESSAGE_BOX = False + return {"status":200, "result":config.ENABLE_AUTO_CLEAR_MESSAGE_BOX} + +def callbackEnableSendOnlyTranslatedMessages(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableSendOnlyTranslatedMessages"}), flush=True) + config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES = True + return {"status":200, "result":config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES} + +def callbackDisableSendOnlyTranslatedMessages(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableSendOnlyTranslatedMessages"}), flush=True) + config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES = False + return {"status":200, "result":config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES} def callbackSetSendMessageButtonType(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSendMessageButtonType", "data":data}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSendMessageButtonType", "data":data}), flush=True) config.SEND_MESSAGE_BUTTON_TYPE = data - return {"status":"success", "data":config.SEND_MESSAGE_BUTTON_TYPE} + return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} def callbackEnableNoticeXsoverlay(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableNoticeXsoverlay"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableNoticeXsoverlay"}), flush=True) config.ENABLE_NOTICE_XSOVERLAY = True - return {"status":"success", "data":config.ENABLE_NOTICE_XSOVERLAY} + return {"status":200, "result":config.ENABLE_NOTICE_XSOVERLAY} def callbackDisableNoticeXsoverlay(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableNoticeXsoverlay"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableNoticeXsoverlay"}), flush=True) config.ENABLE_NOTICE_XSOVERLAY = False - return {"status":"success", "data":config.ENABLE_NOTICE_XSOVERLAY} + return {"status":200, "result":config.ENABLE_NOTICE_XSOVERLAY} def callbackEnableAutoExportMessageLogs(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableAutoExportMessageLogs"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableAutoExportMessageLogs"}), flush=True) config.ENABLE_LOGGER = True model.startLogger() + return {"status":200, "result":config.ENABLE_LOGGER} def callbackDisableAutoExportMessageLogs(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableAutoExportMessageLogs"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableAutoExportMessageLogs"}), flush=True) config.ENABLE_LOGGER = False model.stopLogger() + return {"status":200, "result":config.ENABLE_LOGGER} def callbackEnableVrcMicMuteSync(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableVrcMicMuteSync"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableVrcMicMuteSync"}), flush=True) config.ENABLE_VRC_MIC_MUTE_SYNC = True model.startCheckMuteSelfStatus() model.changeMicTranscriptStatus() + return {"status":200, "result":config.ENABLE_VRC_MIC_MUTE_SYNC} def callbackDisableVrcMicMuteSync(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableVrcMicMuteSync"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableVrcMicMuteSync"}), flush=True) config.ENABLE_VRC_MIC_MUTE_SYNC = False model.stopCheckMuteSelfStatus() model.changeMicTranscriptStatus() + return {"status":200, "result":config.ENABLE_VRC_MIC_MUTE_SYNC} def callbackEnableSendMessageToVrc(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableSendMessageToVrc"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableSendMessageToVrc"}), flush=True) config.ENABLE_SEND_MESSAGE_TO_VRC = True - return {"status":"success", "data":config.ENABLE_SEND_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_MESSAGE_TO_VRC} def callbackDisableSendMessageToVrc(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetEnableSendMessageToVrc"}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetEnableSendMessageToVrc"}), flush=True) config.ENABLE_SEND_MESSAGE_TO_VRC = False - return {"status":"success", "data":config.ENABLE_SEND_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_MESSAGE_TO_VRC} # Others (Message Formats(Send) def callbackSetSendMessageFormat(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetSendMessageFormat", "data": str(data)}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetSendMessageFormat", "data": str(data)}), flush=True) if isUniqueStrings(["[message]"], data) is True: config.SEND_MESSAGE_FORMAT = data - return {"status":"success", "data":config.SEND_MESSAGE_FORMAT} + return {"status":200, "result":config.SEND_MESSAGE_FORMAT} def callbackSetSendMessageFormatWithT(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetReceivedMessageFormat", "data": str(data)}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetReceivedMessageFormat", "data": str(data)}), flush=True) if len(data) > 0: if isUniqueStrings(["[message]", "[translation]"], data) is True: config.SEND_MESSAGE_FORMAT_WITH_T = data - return {"status":"success", "data":config.SEND_MESSAGE_FORMAT_WITH_T} + return {"status":200, "result":config.SEND_MESSAGE_FORMAT_WITH_T} # Others (Message Formats(Received) def callbackSetReceivedMessageFormat(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetReceivedMessageFormat", "data": str(data)}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetReceivedMessageFormat", "data": str(data)}), flush=True) if isUniqueStrings(["[message]"], data) is True: config.RECEIVED_MESSAGE_FORMAT = data - return {"status":"success", "data":config.RECEIVED_MESSAGE_FORMAT} + return {"status":200, "result":config.RECEIVED_MESSAGE_FORMAT} def callbackSetReceivedMessageFormatWithT(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetReceivedMessageFormatWithT", "data": str(data)}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetReceivedMessageFormatWithT", "data": str(data)}), flush=True) if len(data) > 0: if isUniqueStrings(["[message]", "[translation]"], data) is True: config.RECEIVED_MESSAGE_FORMAT_WITH_T = data - return {"status":"success", "data":config.RECEIVED_MESSAGE_FORMAT_WITH_T} + return {"status":200, "result":config.RECEIVED_MESSAGE_FORMAT_WITH_T} # ---------------------Speaker2Chatbox--------------------- def callbackEnableSendReceivedMessageToVrc(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackEnableSendReceivedMessageToVrc"}), flush=True) + print(json.dumps({"status":348, "log": "callbackEnableSendReceivedMessageToVrc"}), flush=True) config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = True - return {"status":"success", "data":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} def callbackDisableSendReceivedMessageToVrc(*args, **kwargs) -> dict: - print(json.dumps({"log": "callbackDisableSendReceivedMessageToVrc"}), flush=True) + print(json.dumps({"status":348, "log": "callbackDisableSendReceivedMessageToVrc"}), flush=True) config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = False - return {"status":"success", "data":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} + return {"status":200, "result":config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC} # ---------------------Speaker2Chatbox--------------------- +def callbackEnableLogger(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackEnableLogger"}), flush=True) + config.ENABLE_LOGGER = True + model.startLogger() + return {"status":200, "result":config.ENABLE_LOGGER} + +def callbackDisableLogger(*args, **kwargs) -> dict: + print(json.dumps({"status":348, "log": "callbackDisableLogger"}), flush=True) + config.ENABLE_LOGGER = False + model.stopLogger() + return {"status":200, "result":config.ENABLE_LOGGER} + # Advanced Settings Tab def callbackSetOscIpAddress(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOscIpAddress", "data": str(data)}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOscIpAddress", "data": str(data)}), flush=True) config.OSC_IP_ADDRESS = str(data) - return {"status":"success", "data":config.OSC_IP_ADDRESS} + return {"status":200, "result":config.OSC_IP_ADDRESS} def callbackSetOscPort(data, *args, **kwargs) -> dict: - print(json.dumps({"log": "callbackSetOscPort", "data": int(data)}), flush=True) + print(json.dumps({"status":348, "log": "callbackSetOscPort", "data": int(data)}), flush=True) config.OSC_PORT = int(data) - return {"status":"success", "data":config.OSC_PORT} + return {"status":200, "result":config.OSC_PORT} -def getListLanguageAndCountry(): - return model.getListLanguageAndCountry() +def getListLanguageAndCountry(*args, **kwargs) -> dict: + return {"status":200, "result": model.getListLanguageAndCountry()} -def getListInputHost(): - return model.getListInputHost() +def getListInputHost(*args, **kwargs) -> dict: + return {"status":200, "result": model.getListInputHost()} -def getListInputDevice(): - return model.getListInputDevice() +def getListInputDevice(*args, **kwargs) -> dict: + return {"status":200, "result": model.getListInputDevice()} -def getListOutputDevice(): - return model.getListOutputDevice() +def getListOutputDevice(*args, **kwargs) -> dict: + return {"status":200, "result": model.getListOutputDevice()} def init(): - print(json.dumps({"log": "Start Initialization"}), flush=True) - print(json.dumps({"log": "Start InitSetTranslateEngine"}), flush=True) + print(json.dumps({"status":348, "log": "Start Initialization"}), flush=True) + print(json.dumps({"status":348, "log": "Start InitSetTranslateEngine"}), flush=True) initSetTranslateEngine() - print(json.dumps({"log": "Start Init LanguageAndCountry"}), flush=True) + print(json.dumps({"status":348, "log": "Start Init LanguageAndCountry"}), flush=True) initSetLanguageAndCountry() - print(json.dumps({"log": "Start check DeepL API Key"}), flush=True) + print(json.dumps({"status":348, "log": "Start check DeepL API Key"}), flush=True) if config.AUTH_KEYS["DeepL_API"] is not None: if model.authenticationTranslatorDeepLAuthKey(auth_key=config.AUTH_KEYS["DeepL_API"]) is False: # error update Auth key @@ -1114,32 +1270,32 @@ def init(): config.AUTH_KEYS = auth_keys # set Translation Engine - print(json.dumps({"log": "Set Translation Engine"}), flush=True) + print(json.dumps({"status":348, "log": "Set Translation Engine"}), flush=True) updateTranslationEngineAndEngineList() # set Transcription Engine - print(json.dumps({"log": "Set Transcription Engine"}), flush=True) + print(json.dumps({"status":348, "log": "Set Transcription Engine"}), flush=True) if config.USE_WHISPER_FEATURE is True: config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" else: config.SELECTED_TRANSCRIPTION_ENGINE = "Google" # set word filter - print(json.dumps({"log": "Set Word Filter"}), flush=True) + print(json.dumps({"status":348, "log": "Set Word Filter"}), flush=True) model.addKeywords() # check Software Updated - print(json.dumps({"log": "Check Software Updated"}), flush=True) + print(json.dumps({"status":348, "log": "Check Software Updated"}), flush=True) if model.checkSoftwareUpdated() is True: pass # init logger - print(json.dumps({"log": "Init Logger"}), flush=True) + print(json.dumps({"status":348, "log": "Init Logger"}), flush=True) if config.ENABLE_LOGGER is True: model.startLogger() # init OSC receive - print(json.dumps({"log": "Init OSC Receive"}), flush=True) + print(json.dumps({"status":348, "log": "Init OSC Receive"}), flush=True) model.startReceiveOSC() if config.ENABLE_VRC_MIC_MUTE_SYNC is True: model.startCheckMuteSelfStatus() \ No newline at end of file diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index e3000c72..e083304e 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -101,6 +101,7 @@ controller_mapping = { # "/controller/callback_restart_software": controller.callbackRestartSoftware, "/controller/callback_filepath_logs": controller.callbackFilepathLogs, "/controller/callback_filepath_config_file": controller.callbackFilepathConfigFile, + # "/controller/callback_enable_easter_egg": controller.callbackEnableEasterEgg, "/controller/callback_open_config_window": controller.callbackOpenConfigWindow, "/controller/callback_close_config_window": controller.callbackCloseConfigWindow, "/controller/callback_enable_main_window_sidebar_compact_mode": controller.callbackEnableMainWindowSidebarCompactMode, @@ -111,6 +112,7 @@ controller_mapping = { "/controller/callback_disable_transcription_send": controller.callbackDisableTranscriptionSend, "/controller/callback_enable_transcription_receive": controller.callbackEnableTranscriptionReceive, "/controller/callback_disable_transcription_receive": controller.callbackDisableTranscriptionReceive, + "/controller/callback_messagebox_press_key_enter": controller.callbackMessageBoxPressKeyEnter, "/controller/callback_enable_foreground": controller.callbackEnableForeground, "/controller/callback_disable_foreground": controller.callbackDisableForeground, "/controller/set_your_language_and_country": controller.setYourLanguageAndCountry, @@ -127,15 +129,18 @@ controller_mapping = { "/controller/callback_set_message_box_ratio": controller.callbackSetMessageBoxRatio, "/controller/callback_set_font_family": controller.callbackSetFontFamily, "/controller/callback_set_ui_language": controller.callbackSetUiLanguage, - "/controller/callback_set_enable_restore_main_window_geometry": controller.callbackSetEnableRestoreMainWindowGeometry, - "/controller/callback_set_use_translation_feature": controller.callbackSetUseTranslationFeature, + "/controller/callback_enable_restore_main_window_geometry": controller.callbackEnableRestoreMainWindowGeometry, + "/controller/callback_disable_restore_main_window_geometry": controller.callbackDisableRestoreMainWindowGeometry, + "/controller/callback_enable_use_translation_feature": controller.callbackEnableUseTranslationFeature, + "/controller/callback_disable_use_translation_feature": controller.callbackDisableUseTranslationFeature, "/controller/callback_set_ctranslate2_weight_type": controller.callbackSetCtranslate2WeightType, "/controller/callback_set_deepl_auth_key": controller.callbackSetDeeplAuthKey, "/controller/callback_clear_deepl_auth_key": controller.callbackClearDeeplAuthKey, "/controller/callback_set_mic_host": controller.callbackSetMicHost, "/controller/callback_set_mic_device": controller.callbackSetMicDevice, "/controller/callback_set_mic_energy_threshold": controller.callbackSetMicEnergyThreshold, - "/controller/callback_set_mic_dynamic_energy_threshold": controller.callbackSetMicDynamicEnergyThreshold, + "/controller/callback_enable_mic_dynamic_energy_threshold": controller.callbackEnableMicDynamicEnergyThreshold, + "/controller/callback_disable_mic_dynamic_energy_threshold": controller.callbackDisableMicDynamicEnergyThreshold, "/controller/callback_enable_check_mic_threshold": controller.callbackEnableCheckMicThreshold, "/controller/callback_disable_check_mic_threshold": controller.callbackDisableCheckMicThreshold, "/controller/callback_set_mic_record_timeout": controller.callbackSetMicRecordTimeout, @@ -145,13 +150,15 @@ controller_mapping = { "/controller/callback_delete_mic_word_filter": controller.callbackDeleteMicWordFilter, "/controller/callback_set_speaker_device": controller.callbackSetSpeakerDevice, "/controller/callback_set_speaker_energy_threshold": controller.callbackSetSpeakerEnergyThreshold, - "/controller/callback_set_speaker_dynamic_energy_threshold": controller.callbackSetSpeakerDynamicEnergyThreshold, + "/controller/callback_enable_speaker_dynamic_energy_threshold": controller.callbackEnableSpeakerDynamicEnergyThreshold, + "/controller/callback_disable_speaker_dynamic_energy_threshold": controller.callbackDisableSpeakerDynamicEnergyThreshold, "/controller/callback_enable_check_speaker_threshold": controller.callbackEnableCheckSpeakerThreshold, "/controller/callback_disable_check_speaker_threshold": controller.callbackDisableCheckSpeakerThreshold, "/controller/callback_set_speaker_record_timeout": controller.callbackSetSpeakerRecordTimeout, "/controller/callback_set_speaker_phrase_timeout": controller.callbackSetSpeakerPhraseTimeout, "/controller/callback_set_speaker_max_phrases": controller.callbackSetSpeakerMaxPhrases, - "/controller/callback_set_use_whisper_feature": controller.callbackSetUserWhisperFeature, + "/controller/callback_enable_use_whisper_feature": controller.callbackEnableUseWhisperFeature, + "/controller/callback_disable_use_whisper_feature": controller.callbackDisableUseWhisperFeature, "/controller/callback_set_whisper_weight_type": controller.callbackSetWhisperWeightType, "/controller/callback_set_overlay_settings_opacity": controller.callbackSetOverlaySettingsOpacity, "/controller/callback_set_overlay_settings_ui_scaling": controller.callbackSetOverlaySettingsUiScaling, @@ -163,8 +170,10 @@ controller_mapping = { "/controller/callback_set_overlay_small_log_settings_x_rotation": controller.callbackSetOverlaySmallLogSettingsXRotation, "/controller/callback_set_overlay_small_log_settings_y_rotation": controller.callbackSetOverlaySmallLogSettingsYRotation, "/controller/callback_set_overlay_small_log_settings_z_rotation": controller.callbackSetOverlaySmallLogSettingsZRotation, - "/controller/callback_set_enable_auto_clear_chatbox": controller.callbackSetEnableAutoClearMessageBox, - "/controller/callback_set_send_only_translated_messages": controller.callbackSetEnableSendOnlyTranslatedMessages, + "/controller/callback_enable_auto_clear_chatbox": controller.callbackEnableAutoClearMessageBox, + "/controller/callback_disable_auto_clear_chatbox": controller.callbackDisableAutoClearMessageBox, + "/controller/callback_enable_send_only_translated_messages": controller.callbackEnableSendOnlyTranslatedMessages, + "/controller/callback_disable_send_only_translated_messages": controller.callbackDisableSendOnlyTranslatedMessages, "/controller/callback_set_send_message_button_type": controller.callbackSetSendMessageButtonType, "/controller/callback_enable_notice_xsoverlay": controller.callbackEnableNoticeXsoverlay, "/controller/callback_disable_notice_xsoverlay": controller.callbackDisableNoticeXsoverlay, @@ -180,17 +189,54 @@ controller_mapping = { "/controller/callback_set_received_message_format_with_t": controller.callbackSetReceivedMessageFormatWithT, "/controller/callback_enable_send_received_message_to_vrc": controller.callbackEnableSendReceivedMessageToVrc, "/controller/callback_disable_send_received_message_to_vrc": controller.callbackDisableSendReceivedMessageToVrc, + "/controller/callback_enable_logger": controller.callbackEnableLogger, + "/controller/callback_disable_logger": controller.callbackDisableLogger, "/controller/callback_set_osc_ip_address": controller.callbackSetOscIpAddress, "/controller/callback_set_osc_port": controller.callbackSetOscPort, } action_mapping = { - "/controller/callback_close_config_window": {"mic":"/action/transcription_send_message", "speaker":"/action/transcription_receive_message"}, - "/controller/callback_enable_transcription_send": {"mic":"/action/transcription_send_message"}, - "/controller/callback_disable_transcription_send": {"mic":"/action/transcription_send_stopped"}, - "/controller/callback_enable_transcription_receive": {"speaker":"/action/transcription_receive_message"}, - "/controller/callback_disable_transcription_receive": {"speaker":"/action/transcription_receive_stopped"}, - "/controller/callback_enable_check_mic_threshold": {"mic":"/action/check_mic_threshold_energy"}, + "/controller/callback_update_software": { + "download":"/action/download_software", + "update":"/action/update_software" + }, + "/controller/callback_close_config_window": { + "mic":"/action/transcription_send_mic_message", + "speaker":"/action/transcription_receive_speaker_message", + "error_device":"/action/error_device", + "error_translation_engine":"/action/error_translation_engine", + "word_filter":"/action/word_filter", + }, + "/controller/callback_enable_transcription_send": { + "mic":"/action/transcription_send_mic_message", + "error_device":"/action/error_device", + "error_translation_engine":"/action/error_translation_engine", + "word_filter":"/action/word_filter", + }, + "/controller/callback_disable_transcription_send": { + "mic":"/action/transcription_send_mic_message_stopped" + }, + "/controller/callback_enable_transcription_receive": { + "speaker":"/action/transcription_receive_speaker_message", + "error_device":"/action/error_device", + "error_translation_engine":"/action/error_translation_engine", + }, + "/controller/callback_disable_transcription_receive": { + "speaker":"/action/transcription_receive_speaker_message_stopped" + }, + "/controller/callback_enable_check_mic_threshold": { + "mic":"/action/check_mic_threshold_energy", + "stopped":"/action/check_mic_threshold_energy_stopped", + "error_device":"/action/error_device", + }, + "/controller/callback_enable_check_speaker_threshold": { + "speaker":"/action/check_speaker_threshold_energy", + "stopped":"/action/check_speaker_threshold_energy_stopped", + "error_device":"/action/error_device", + }, + "/controller/callback_messagebox_press_key_enter": { + "error_translation_engine":"/action/error_translation_engine" + }, } def handleConfigRequest(endpoint): @@ -214,18 +260,21 @@ def handleControllerRequest(endpoint, data=None): response = handler(data, Action(action_endpoint).transmit) else: response = handler(data) - status = 200 - return response, status + status = response.get("status", None) + result = response.get("result", None) + return result, status class Action: def __init__(self, endpoints:dict) -> None: self.endpoints = endpoints def transmit(self, key:str, data:dict) -> None: + status = data.get("status", None) + result = data.get("result", None) response = { "endpoint": self.endpoints[key], - "status": 200, - "data": data, + "status": status, + "result": result, } response = json.dumps(response) print(response, flush=True) @@ -238,15 +287,6 @@ def main(): f.write(f"received_data: {received_data}\n") if received_data: - # response_data = { - # "status": 200, - # "id": received_data["id"], - # "data": received_data["data"], - # } - # response = json.dumps(response_data) - # time.sleep(2) - # print(response, flush=True) - endpoint = received_data.get("endpoint", None) data = received_data.get("data", None) @@ -278,23 +318,127 @@ def main(): print(response, flush=True) if __name__ == "__main__": - # endpoint = "/controller/list_mic_host" - # data = None - # response_data, status = handleControllerRequest(endpoint, data) - # response = { - # "status": status, - # "endpoint": endpoint, - # "data": response_data, - # } - # response = json.dumps(response) - # print(response, flush=True) - - try: + response_test = False + if response_test: + import time controller.init() - print(json.dumps({"init_key_from_py": "Initialization from Python."}), flush=True) - while True: - main() - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) \ No newline at end of file + + for endpoint, value in config_mapping.items(): + response_data, status = handleConfigRequest(endpoint) + response = { + "status": status, + "endpoint": endpoint, + "result": response_data, + } + response = json.dumps(response) + print(response, flush=True) + time.sleep(0.1) + + for endpoint, value in controller_mapping.items(): + print("endpoint: ", endpoint) + + match endpoint: + case "/controller/callback_messagebox_press_key_enter": + data = "テスト" + case "/controller/set_your_language_and_country": + data = {"language": "English", "country": "Hong Kong"} + case "/controller/set_target_language_and_country": + data = {"language": "Japanese", "country": "Japan"} + case "/controller/callback_set_transparency": + data = 0.5 + case "/controller/callback_set_appearance": + data = "Dark" + case "/controller/callback_set_ui_scaling": + data = 1.5 + case "/controller/callback_set_textbox_ui_scaling": + data = 1.5 + case "/controller/callback_set_message_box_ratio": + data = 0.5 + case "/controller/callback_set_font_family": + data = "Yu Gothic UI" + case "/controller/callback_set_ui_language": + data = "ja" + case "/controller/callback_set_ctranslate2_weight_type": + data = "Small" + case "/controller/callback_set_deepl_auth_key": + data = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee:fx" + case "/controller/callback_set_mic_host": + data = "MME" + case "/controller/callback_set_mic_device": + data = "マイク (Realtek High Definition Audio)" + case "/controller/callback_set_mic_energy_threshold": + data = 0.5 + case "/controller/callback_set_mic_record_timeout": + data = 5 + case "/controller/callback_set_mic_phrase_timeout": + data = 5 + case "/controller/callback_set_mic_max_phrases": + data = 5 + case "/controller/callback_set_mic_word_filter": + data = "test0, test1, test2" + case "/controller/callback_delete_mic_word_filter": + data = "test1" + case "/controller/callback_set_speaker_device": + data = "スピーカー (Realtek High Definition Audio)" + case "/controller/callback_set_speaker_energy_threshold": + data = 0.5 + case "/controller/callback_set_speaker_record_timeout": + data = 5 + case "/controller/callback_set_speaker_phrase_timeout": + data = 5 + case "/controller/callback_set_speaker_max_phrases": + data = 5 + case "/controller/callback_set_whisper_weight_type": + data = "base" + case "/controller/callback_set_overlay_settings_opacity": + data = 0.5 + case "/controller/callback_set_overlay_settings_ui_scaling": + data = 1.5 + case "/controller/callback_set_overlay_small_log_settings_x_pos": + data = 0 + case "/controller/callback_set_overlay_small_log_settings_y_pos": + data = 0 + case "/controller/callback_set_overlay_small_log_settings_z_pos": + data = 0 + case "/controller/callback_set_overlay_small_log_settings_x_rotation": + data = 0 + case "/controller/callback_set_overlay_small_log_settings_y_rotation": + data = 0 + case "/controller/callback_set_overlay_small_log_settings_z_rotation": + data = 0 + case "/controller/callback_set_send_message_button_type": + data = "show" + case "/controller/callback_set_send_message_format": + data = "[message]" + case "/controller/callback_set_send_message_format_with_t": + data = "[message]([translation])" + case "/controller/callback_set_received_message_format": + data = "[message]" + case "/controller/callback_set_received_message_format_with_t": + data = "[message]([translation])" + case "/controller/callback_set_osc_ip_address": + data = "127.0.0.1" + case "/controller/callback_set_osc_port": + data = 8000 + case _: + data = None + + response_data, status = handleControllerRequest(endpoint, data) + response = { + "status": status, + "endpoint": endpoint, + "result": response_data, + } + response = json.dumps(response) + print(response, flush=True) + time.sleep(0.5) + else: + try: + controller.init() + print(json.dumps({"status":348, "log": "Initialization from Python."}), flush=True) + while True: + main() + except Exception: + import traceback + with open('error.log', 'a') as f: + traceback.print_exc(file=f) \ No newline at end of file