From ee150b692d23cc5a7d8dc89d9a3547e690d225fd Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:40:14 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20[Remove]=20main.py?= =?UTF-8?q?=E3=81=A8controller.py=E3=81=8C=E4=B8=8D=E8=A6=81=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=81=A3=E3=81=9F=E3=81=9F=E3=82=81=E3=80=81=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/controller.py | 1192 -------------------------------------- src-python/main.py | 33 -- 2 files changed, 1225 deletions(-) delete mode 100644 src-python/controller.py delete mode 100644 src-python/main.py diff --git a/src-python/controller.py b/src-python/controller.py deleted file mode 100644 index 36aa0c4b..00000000 --- a/src-python/controller.py +++ /dev/null @@ -1,1192 +0,0 @@ -from time import sleep -from subprocess import Popen -from threading import Thread -from config import config -from model import model -from view import view -from utils import getKeyByValue, isUniqueStrings, strPctToInt -import argparse - -# Common -def callbackUpdateSoftware(func=None): - setMainWindowGeometry() - model.updateSoftware(restart=True, func=func) - -def callbackRestartSoftware(): - setMainWindowGeometry() - model.reStartSoftware() - -def callbackFilepathLogs(): - print("callbackFilepathLogs", config.PATH_LOGS.replace('/', '\\')) - Popen(['explorer', config.PATH_LOGS.replace('/', '\\')], shell=True) - -def callbackFilepathConfigFile(): - print("callbackFilepathConfigFile", config.PATH_LOCAL.replace('/', '\\')) - Popen(['explorer', config.PATH_LOCAL.replace('/', '\\')], shell=True) - -def callbackQuitVrct(): - setMainWindowGeometry() - -def callbackEnableEasterEgg(): - 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 - -def messageFormatter(format_type:str, translation, message): - if format_type == "RECEIVED": - FORMAT_WITH_T = config.RECEIVED_MESSAGE_FORMAT_WITH_T - FORMAT = config.RECEIVED_MESSAGE_FORMAT - elif format_type == "SEND": - FORMAT_WITH_T = config.SEND_MESSAGE_FORMAT_WITH_T - FORMAT = config.SEND_MESSAGE_FORMAT - else: - raise ValueError("format_type is not found", format_type) - - if len(translation) > 0: - osc_message = FORMAT_WITH_T.replace("[message]", message) - osc_message = osc_message.replace("[translation]", translation) - else: - osc_message = FORMAT.replace("[message]", message) - return osc_message - -def changeToCTranslate2Process(): - if config.CHOICE_INPUT_TRANSLATOR != "CTranslate2" or config.CHOICE_OUTPUT_TRANSLATOR != "CTranslate2": - config.CHOICE_INPUT_TRANSLATOR = "CTranslate2" - config.CHOICE_OUTPUT_TRANSLATOR = "CTranslate2" - updateTranslationEngineAndEngineList() - view.printToTextbox_TranslationEngineLimitError() - -# func transcription send message -def sendMicMessage(message): - if len(message) > 0: - addSentMessageLog(message) - translation = "" - if model.checkKeywords(message): - view.printToTextbox_DetectedByWordFilter(detected_message=message) - return - elif model.detectRepeatSendMessage(message): - return - elif config.ENABLE_TRANSLATION is False: - pass - else: - translation, success = model.getInputTranslate(message) - if success is False: - changeToCTranslate2Process() - - if config.ENABLE_TRANSCRIPTION_SEND is True: - 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) - - - view.printToTextbox_SentMessage(message, translation) - if config.ENABLE_LOGGER_FEATURE 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) - -def startTranscriptionSendMessage(): - model.startMicTranscript(sendMicMessage, view.printToTextbox_TranscriptionSendNoDeviceError) - view.setMainWindowAllWidgetsStatusToNormal() - -def stopTranscriptionSendMessage(): - model.stopMicTranscript() - view.setMainWindowAllWidgetsStatusToNormal() - -def startThreadingTranscriptionSendMessage(): - view.printToTextbox_enableTranscriptionSend() - th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage) - th_startTranscriptionSendMessage.daemon = True - th_startTranscriptionSendMessage.start() - -def stopThreadingTranscriptionSendMessage(): - view.printToTextbox_disableTranscriptionSend() - th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessage) - th_stopTranscriptionSendMessage.daemon = True - th_stopTranscriptionSendMessage.start() - -def startTranscriptionSendMessageOnCloseConfigWindow(): - model.startMicTranscript(sendMicMessage, view.printToTextbox_TranscriptionSendNoDeviceError) - -def stopTranscriptionSendMessageOnOpenConfigWindow(): - model.stopMicTranscript() - -def startThreadingTranscriptionSendMessageOnCloseConfigWindow(): - th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessageOnCloseConfigWindow) - th_startTranscriptionSendMessage.daemon = True - th_startTranscriptionSendMessage.start() - -def stopThreadingTranscriptionSendMessageOnOpenConfigWindow(): - th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessageOnOpenConfigWindow) - th_stopTranscriptionSendMessage.daemon = True - th_stopTranscriptionSendMessage.start() - -# func transcription receive message -def receiveSpeakerMessage(message): - if len(message) > 0: - translation = "" - if model.detectRepeatReceiveMessage(message): - return - elif config.ENABLE_TRANSLATION is False: - pass - else: - translation, success = model.getOutputTranslate(message) - if success is False: - changeToCTranslate2Process() - - if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - if config.ENABLE_NOTICE_XSOVERLAY is True: - xsoverlay_message = messageFormatter("RECEIVED", translation, message) - model.notificationXSOverlay(xsoverlay_message) - - if config.ENABLE_OVERLAY_SMALL_LOG is True: - if model.overlay.initialized is True: - overlay_image = model.createOverlayImageShort(message, translation) - model.updateOverlay(overlay_image) - # overlay_image = model.createOverlayImageLong("receive", message, translation) - # model.updateOverlay(overlay_image) - - # ------------Speaker2Chatbox------------ - if config.ENABLE_SPEAKER2CHATBOX is True: - # send OSC message - if config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC is True: - osc_message = messageFormatter("RECEIVED", translation, message) - model.oscSendMessage(osc_message) - # ------------Speaker2Chatbox------------ - - # update textbox message log (Received) - view.printToTextbox_ReceivedMessage(message, translation) - if config.ENABLE_LOGGER_FEATURE is True: - if len(translation) > 0: - translation = f" ({translation})" - model.logger.info(f"[RECEIVED] {message}{translation}") - -def startTranscriptionReceiveMessage(): - model.startSpeakerTranscript(receiveSpeakerMessage, view.printToTextbox_TranscriptionReceiveNoDeviceError) - view.setMainWindowAllWidgetsStatusToNormal() - -def stopTranscriptionReceiveMessage(): - model.stopSpeakerTranscript() - view.setMainWindowAllWidgetsStatusToNormal() - -def startThreadingTranscriptionReceiveMessage(): - view.printToTextbox_enableTranscriptionReceive() - th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage) - th_startTranscriptionReceiveMessage.daemon = True - th_startTranscriptionReceiveMessage.start() - -def stopThreadingTranscriptionReceiveMessage(): - view.printToTextbox_disableTranscriptionReceive() - th_stopTranscriptionReceiveMessage = Thread(target=stopTranscriptionReceiveMessage) - th_stopTranscriptionReceiveMessage.daemon = True - th_stopTranscriptionReceiveMessage.start() - -def startTranscriptionReceiveMessageOnCloseConfigWindow(): - model.startSpeakerTranscript(receiveSpeakerMessage, view.printToTextbox_TranscriptionReceiveNoDeviceError) - - -def stopTranscriptionReceiveMessageOnOpenConfigWindow(): - model.stopSpeakerTranscript() - -def startThreadingTranscriptionReceiveMessageOnCloseConfigWindow(): - th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessageOnCloseConfigWindow) - th_startTranscriptionReceiveMessage.daemon = True - th_startTranscriptionReceiveMessage.start() - -def stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow(): - th_stopTranscriptionReceiveMessage = Thread(target=stopTranscriptionReceiveMessageOnOpenConfigWindow) - th_stopTranscriptionReceiveMessage.daemon = True - 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() - - # 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) - - # 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) - - # update textbox message log (Sent) - view.printToTextbox_SentMessage(message, translation) - if config.ENABLE_LOGGER_FEATURE is True: - if len(translation) > 0: - translation = f" ({translation})" - model.logger.info(f"[SENT] {message}{translation}") - - # delete message in entry message box - if config.ENABLE_AUTO_CLEAR_MESSAGE_BOX is True: - view.clearMessageBox() - -def messageBoxPressKeyEnter(): - model.oscStopSendTyping() - message = view.getTextFromMessageBox() - sendChatMessage(message) - -def messageBoxPressKeyAny(e): - if config.ENABLE_SEND_MESSAGE_TO_VRC is True: - model.oscStartSendTyping() - else: - model.oscStopSendTyping() - -def messageBoxFocusIn(e): - view.foregroundOffIfForegroundEnabled() - -def messageBoxFocusOut(e): - view.foregroundOnIfForegroundEnabled() - if config.ENABLE_SEND_MESSAGE_TO_VRC is True: - model.oscStopSendTyping() - -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 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 updateTranslationEngineAndEngineList(): - engine = config.CHOICE_INPUT_TRANSLATOR - engines = model.findTranslationEngines(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE) - if engine not in engines: - engine = engines[0] - config.CHOICE_INPUT_TRANSLATOR = engine - config.CHOICE_OUTPUT_TRANSLATOR = engine - view.updateSelectableTranslationEngineList(engines) - view.setGuiVariable_SelectedTranslationEngine(engine) - -def initSetTranslateEngine(): - engine = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES[config.SELECTED_TAB_NO] - config.CHOICE_INPUT_TRANSLATOR = engine - engine = config.SELECTED_TAB_TARGET_TRANSLATOR_ENGINES[config.SELECTED_TAB_NO] - config.CHOICE_OUTPUT_TRANSLATOR = engine - -def initSetLanguageAndCountry(): - select = config.SELECTED_TAB_YOUR_LANGUAGES[config.SELECTED_TAB_NO] - config.SOURCE_LANGUAGE = select["language"] - config.SOURCE_COUNTRY = select["country"] - select = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] - config.TARGET_LANGUAGE = select["language"] - config.TARGET_COUNTRY = select["country"] - -def setYourTranslateEngine(select): - engines = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES - engines[config.SELECTED_TAB_NO] = select - config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES = engines - config.CHOICE_INPUT_TRANSLATOR = select - -def setTargetTranslateEngine(select): - engines = config.SELECTED_TAB_TARGET_TRANSLATOR_ENGINES - engines[config.SELECTED_TAB_NO] = select - config.SELECTED_TAB_TARGET_TRANSLATOR_ENGINES = engines - config.CHOICE_OUTPUT_TRANSLATOR = select - -def setYourLanguageAndCountry(select): - 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() - view.printToTextbox_selectedYourLanguages(select) - -def setTargetLanguageAndCountry(select): - 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() - view.printToTextbox_selectedTargetLanguages(select) - -def swapYourLanguageAndTargetLanguage(): - 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) - # Update Selected Languages for UI - view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO) - - -def callbackSelectedLanguagePresetTab(selected_tab_no): - config.SELECTED_TAB_NO = selected_tab_no - view.updateGuiVariableByPresetTabNo(config.SELECTED_TAB_NO) - - engines = config.SELECTED_TAB_YOUR_TRANSLATOR_ENGINES - engine = engines[config.SELECTED_TAB_NO] - config.CHOICE_INPUT_TRANSLATOR = engine - - engines = config.SELECTED_TAB_TARGET_TRANSLATOR_ENGINES - engine = engines[config.SELECTED_TAB_NO] - config.CHOICE_OUTPUT_TRANSLATOR = engine - - languages = config.SELECTED_TAB_YOUR_LANGUAGES - select = languages[config.SELECTED_TAB_NO] - config.SOURCE_LANGUAGE = select["language"] - config.SOURCE_COUNTRY = select["country"] - - languages = config.SELECTED_TAB_TARGET_LANGUAGES - select = languages[config.SELECTED_TAB_NO] - config.TARGET_LANGUAGE = select["language"] - config.TARGET_COUNTRY = select["country"] - view.printToTextbox_changedLanguagePresetTab(config.SELECTED_TAB_NO) - updateTranslationEngineAndEngineList() - -def callbackSelectedTranslationEngine(selected_translation_engine): - print("callbackSelectedTranslationEngine", selected_translation_engine) - setYourTranslateEngine(selected_translation_engine) - setTargetTranslateEngine(selected_translation_engine) - view.setGuiVariable_SelectedTranslationEngine(config.CHOICE_OUTPUT_TRANSLATOR) - -# command func -def callbackToggleTranslation(is_turned_on): - config.ENABLE_TRANSLATION = is_turned_on - if config.ENABLE_TRANSLATION is True: - if model.isLoadedCTranslate2Model() is False: - model.changeTranslatorCTranslate2Model() - view.printToTextbox_enableTranslation() - else: - view.printToTextbox_disableTranslation() - -def callbackToggleTranscriptionSend(is_turned_on): - view.setMainWindowAllWidgetsStatusToDisabled() - config.ENABLE_TRANSCRIPTION_SEND = is_turned_on - if config.ENABLE_TRANSCRIPTION_SEND is True: - startThreadingTranscriptionSendMessage() - view.changeTranscriptionDisplayStatus("MIC_ON") - else: - stopThreadingTranscriptionSendMessage() - view.changeTranscriptionDisplayStatus("MIC_OFF") - -def callbackToggleTranscriptionReceive(is_turned_on): - view.setMainWindowAllWidgetsStatusToDisabled() - config.ENABLE_TRANSCRIPTION_RECEIVE = is_turned_on - if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - startThreadingTranscriptionReceiveMessage() - view.changeTranscriptionDisplayStatus("SPEAKER_ON") - else: - stopThreadingTranscriptionReceiveMessage() - view.changeTranscriptionDisplayStatus("SPEAKER_OFF") - - if config.ENABLE_TRANSCRIPTION_RECEIVE is True and config.ENABLE_OVERLAY_SMALL_LOG is True: - if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True: - model.startOverlay() - elif config.ENABLE_TRANSCRIPTION_RECEIVE is False: - pass - -def callbackToggleForeground(is_turned_on): - config.ENABLE_FOREGROUND = is_turned_on - if config.ENABLE_FOREGROUND is True: - view.printToTextbox_enableForeground() - view.foregroundOn() - else: - view.printToTextbox_disableForeground() - view.foregroundOff() - -def callbackEnableMainWindowSidebarCompactMode(): - config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True - view.enableMainWindowSidebarCompactMode() - -def callbackDisableMainWindowSidebarCompactMode(): - config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False - view.disableMainWindowSidebarCompactMode() - -# Config Window -def callbackOpenConfigWindow(): - view.setMainWindowAllWidgetsStatusToDisabled() - if config.ENABLE_TRANSCRIPTION_SEND is True: - stopThreadingTranscriptionSendMessageOnOpenConfigWindow() - if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow() - if config.ENABLE_FOREGROUND is True: - view.foregroundOff() - -def callbackCloseConfigWindow(): - model.stopCheckMicEnergy() - model.stopCheckSpeakerEnergy() - view.initMicThresholdCheckButton() - view.initSpeakerThresholdCheckButton() - - if config.ENABLE_TRANSCRIPTION_SEND is True: - startThreadingTranscriptionSendMessageOnCloseConfigWindow() - if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - sleep(2) - if config.ENABLE_TRANSCRIPTION_RECEIVE is True: - startThreadingTranscriptionReceiveMessageOnCloseConfigWindow() - if config.ENABLE_FOREGROUND is True: - view.foregroundOn() - view.setMainWindowAllWidgetsStatusToNormal() - -# Compact Mode Switch -def callbackEnableConfigWindowCompactMode(): - config.IS_CONFIG_WINDOW_COMPACT_MODE = True - model.stopCheckMicEnergy() - view.initMicThresholdCheckButton() - model.stopCheckSpeakerEnergy() - view.initSpeakerThresholdCheckButton() - - view.enableConfigWindowCompactMode() - -def callbackDisableConfigWindowCompactMode(): - config.IS_CONFIG_WINDOW_COMPACT_MODE = False - model.stopCheckMicEnergy() - view.initMicThresholdCheckButton() - model.stopCheckSpeakerEnergy() - view.initSpeakerThresholdCheckButton() - - view.disableConfigWindowCompactMode() - -# Appearance Tab -def callbackSetTransparency(value): - print("callbackSetTransparency", int(value)) - config.TRANSPARENCY = int(value) - view.setMainWindowTransparency(config.TRANSPARENCY/100) - -def callbackSetAppearance(value): - print("callbackSetAppearance", value) - config.APPEARANCE_THEME = value - view.showRestartButtonIfRequired() - -def callbackSetUiScaling(value): - print("callbackSetUiScaling", value) - config.UI_SCALING = value - new_scaling_float = strPctToInt(value) / 100 - print("callbackSetUiScaling_new_scaling_float", new_scaling_float) - view.showRestartButtonIfRequired() - -def callbackSetTextboxUiScaling(value): - print("callbackSetTextboxUiScaling", int(value)) - config.TEXTBOX_UI_SCALING = int(value) - view.setMainWindowTextboxUiSize(config.TEXTBOX_UI_SCALING/100) - -def callbackSetMessageBoxRatio(value): - print("callbackSetMessageBoxRatio", int(value)) - config.MESSAGE_BOX_RATIO = int(value) - view.setMainWindowMessageBoxRatio(config.MESSAGE_BOX_RATIO) - -def callbackSetFontFamily(value): - print("callbackSetFontFamily", value) - config.FONT_FAMILY = value - view.showRestartButtonIfRequired() - -def callbackSetUiLanguage(value): - print("callbackSetUiLanguage", value) - value = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, value) - print("callbackSetUiLanguage__after_getKeyByValue", value) - config.UI_LANGUAGE = value - view.showRestartButtonIfRequired(locale=config.UI_LANGUAGE) - -def callbackSetEnableRestoreMainWindowGeometry(value): - print("callbackSetEnableRestoreMainWindowGeometry", value) - config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value - -# Translation Tab -def callbackSetUseTranslationFeature(value): - print("callbackSetUseTranslationFeature", value) - config.USE_TRANSLATION_FEATURE = value - if config.USE_TRANSLATION_FEATURE is True: - view.useTranslationFeatureProcess("Normal") - 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 - view.useTranslationFeatureProcess("Restart") - else: - config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False - view.useTranslationFeatureProcess("Disable") - view.showRestartButtonIfRequired() - -def callbackSetCtranslate2WeightType(value): - print("callbackSetCtranslate2WeightType", value) - config.CTRANSLATE2_WEIGHT_TYPE = str(value) - view.updateSelectedCtranslate2WeightType(config.CTRANSLATE2_WEIGHT_TYPE) - view.setWidgetsStatus_changeWeightType_Pending() - if model.checkCTranslatorCTranslate2ModelWeight(): - config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False - def callback(): - model.changeTranslatorCTranslate2Model() - view.useTranslationFeatureProcess("Normal") - view.setWidgetsStatus_changeWeightType_Done() - th_callback = Thread(target=callback) - th_callback.daemon = True - th_callback.start() - else: - config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True - view.useTranslationFeatureProcess("Restart") - view.setWidgetsStatus_changeWeightType_Done() - view.showRestartButtonIfRequired() - -def callbackSetDeeplAuthKey(value): - print("callbackSetDeeplAuthKey", str(value)) - view.clearNotificationMessage() - if len(value) == 36 or len(value) == 39: - result = model.authenticationTranslatorDeepLAuthKey(auth_key=value) - if result is True: - key = value - view.printToTextbox_AuthenticationSuccess() - view.showSuccessMessage_DeeplAuthKey() - else: - key = None - view.printToTextbox_AuthenticationError() - view.showErrorMessage_DeeplAuthKey() - auth_keys = config.AUTH_KEYS - auth_keys["DeepL_API"] = key - config.AUTH_KEYS = auth_keys - elif len(value) == 0: - auth_keys = config.AUTH_KEYS - auth_keys["DeepL_API"] = None - config.AUTH_KEYS = auth_keys - updateTranslationEngineAndEngineList() - -# Transcription Tab -# Transcription (Mic) -def callbackSetMicHost(value): - print("callbackSetMicHost", value) - config.CHOICE_MIC_HOST = value - config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice() - - view.updateSelected_MicDevice(config.CHOICE_MIC_DEVICE) - view.updateList_MicDevice(model.getListInputDevice()) - - model.stopCheckMicEnergy() - view.replaceMicThresholdCheckButton_Passive() - -def callbackSetMicDevice(value): - print("callbackSetMicDevice", value) - config.CHOICE_MIC_DEVICE = value - - model.stopCheckMicEnergy() - view.replaceMicThresholdCheckButton_Passive() - -def callbackSetMicEnergyThreshold(value): - print("callbackSetMicEnergyThreshold", value) - if value == "": - return - try: - value = int(value) - if 0 <= value and value <= config.MAX_MIC_THRESHOLD: - view.clearNotificationMessage() - config.INPUT_MIC_THRESHOLD = value - view.setGuiVariable_MicEnergyThreshold(config.INPUT_MIC_THRESHOLD) - else: - raise ValueError() - except Exception: - view.showErrorMessage_MicEnergyThreshold() - -def callbackSetMicDynamicEnergyThreshold(value): - print("callbackSetMicDynamicEnergyThreshold", value) - config.INPUT_MIC_AUTOMATIC_THRESHOLD = value - if config.INPUT_MIC_AUTOMATIC_THRESHOLD is True: - view.closeMicEnergyThresholdWidget() - else: - view.openMicEnergyThresholdWidget() - -def setProgressBarMicEnergy(energy): - view.updateSetProgressBar_MicEnergy(energy) - -def callbackCheckMicThreshold(is_turned_on): - print("callbackCheckMicThreshold", is_turned_on) - if is_turned_on is True: - view.replaceMicThresholdCheckButton_Disabled() - model.startCheckMicEnergy(setProgressBarMicEnergy, view.initProgressBar_MicEnergy) - view.replaceMicThresholdCheckButton_Active() - else: - view.replaceMicThresholdCheckButton_Disabled() - model.stopCheckMicEnergy() - view.replaceMicThresholdCheckButton_Passive() - -def callbackSetMicRecordTimeout(value): - print("callbackSetMicRecordTimeout", value) - if value == "": - return - try: - value = int(value) - if 0 <= value and value <= config.INPUT_MIC_PHRASE_TIMEOUT: - view.clearNotificationMessage() - config.INPUT_MIC_RECORD_TIMEOUT = value - view.setGuiVariable_MicRecordTimeout(config.INPUT_MIC_RECORD_TIMEOUT) - else: - raise ValueError() - except Exception: - view.showErrorMessage_MicRecordTimeout() - -def callbackSetMicPhraseTimeout(value): - print("callbackSetMicPhraseTimeout", value) - if value == "": - return - try: - value = int(value) - if 0 <= value and value >= config.INPUT_MIC_RECORD_TIMEOUT: - view.clearNotificationMessage() - config.INPUT_MIC_PHRASE_TIMEOUT = value - view.setGuiVariable_MicPhraseTimeout(config.INPUT_MIC_PHRASE_TIMEOUT) - else: - raise ValueError() - except Exception: - view.showErrorMessage_MicPhraseTimeout() - -def callbackSetMicMaxPhrases(value): - print("callbackSetMicMaxPhrases", value) - if value == "": - return - try: - value = int(value) - if 0 <= value: - view.clearNotificationMessage() - config.INPUT_MIC_MAX_PHRASES = value - view.setGuiVariable_MicMaxPhrases(config.INPUT_MIC_MAX_PHRASES) - else: - raise ValueError() - except Exception: - view.showErrorMessage_MicMaxPhrases() - -def callbackSetMicWordFilter(values): - print("callbackSetMicWordFilter", values) - values = str(values) - values = [w.strip() for w in values.split(",") if len(w.strip()) > 0] - # Copy the list - new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER - new_added_value = [] - for value in values: - if value in new_input_mic_word_filter_list: - # If the value is already in the list, do nothing. - pass - else: - new_input_mic_word_filter_list.append(value) - new_added_value.append(value) - config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list - - view.addValueToList_WordFilter(new_added_value) - view.clearEntryBox_WordFilter() - view.setLatestConfigVariable("MicMicWordFilter") - - model.resetKeywordProcessor() - model.addKeywords() - -def callbackDeleteMicWordFilter(value): - print("callbackDeleteMicWordFilter", value) - try: - new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER - new_input_mic_word_filter_list.remove(str(value)) - config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list - view.setLatestConfigVariable("MicMicWordFilter") - model.resetKeywordProcessor() - model.addKeywords() - except Exception: - print("There was no the target word in config.INPUT_MIC_WORD_FILTER") - -# Transcription (Speaker) -def callbackSetSpeakerDevice(value): - print("callbackSetSpeakerDevice", value) - config.CHOICE_SPEAKER_DEVICE = value - - model.stopCheckSpeakerEnergy() - view.replaceSpeakerThresholdCheckButton_Passive() - -def callbackSetSpeakerEnergyThreshold(value): - print("callbackSetSpeakerEnergyThreshold", value) - if value == "": - return - try: - value = int(value) - if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD: - view.clearNotificationMessage() - config.INPUT_SPEAKER_ENERGY_THRESHOLD = value - view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD) - else: - raise ValueError() - except Exception: - view.showErrorMessage_SpeakerEnergyThreshold() - -def callbackSetSpeakerDynamicEnergyThreshold(value): - print("callbackSetSpeakerDynamicEnergyThreshold", value) - config.INPUT_SPEAKER_AUTOMATIC_THRESHOLD = value - if config.INPUT_SPEAKER_AUTOMATIC_THRESHOLD is True: - view.closeSpeakerEnergyThresholdWidget() - else: - view.openSpeakerEnergyThresholdWidget() - -def setProgressBarSpeakerEnergy(energy): - view.updateSetProgressBar_SpeakerEnergy(energy) - -def callbackCheckSpeakerThreshold(is_turned_on): - print("callbackCheckSpeakerThreshold", is_turned_on) - if is_turned_on is True: - view.replaceSpeakerThresholdCheckButton_Disabled() - model.startCheckSpeakerEnergy( - setProgressBarSpeakerEnergy, - view.initProgressBar_SpeakerEnergy, - view.showErrorMessage_CheckSpeakerThreshold_NoDevice - ) - - view.replaceSpeakerThresholdCheckButton_Active() - else: - view.replaceSpeakerThresholdCheckButton_Disabled() - model.stopCheckSpeakerEnergy() - view.replaceSpeakerThresholdCheckButton_Passive() - -def callbackSetSpeakerRecordTimeout(value): - print("callbackSetSpeakerRecordTimeout", value) - if value == "": - return - try: - value = int(value) - if 0 <= value and value <= config.INPUT_SPEAKER_PHRASE_TIMEOUT: - view.clearNotificationMessage() - config.INPUT_SPEAKER_RECORD_TIMEOUT = value - view.setGuiVariable_SpeakerRecordTimeout(config.INPUT_SPEAKER_RECORD_TIMEOUT) - else: - raise ValueError() - except Exception: - view.showErrorMessage_SpeakerRecordTimeout() - -def callbackSetSpeakerPhraseTimeout(value): - print("callbackSetSpeakerPhraseTimeout", value) - if value == "": - return - try: - value = int(value) - if 0 <= value and value >= config.INPUT_SPEAKER_RECORD_TIMEOUT: - view.clearNotificationMessage() - config.INPUT_SPEAKER_PHRASE_TIMEOUT = value - view.setGuiVariable_SpeakerPhraseTimeout(config.INPUT_SPEAKER_PHRASE_TIMEOUT) - else: - raise ValueError() - except Exception: - view.showErrorMessage_SpeakerPhraseTimeout() - -def callbackSetSpeakerMaxPhrases(value): - print("callbackSetSpeakerMaxPhrases", value) - if value == "": - return - try: - value = int(value) - if 0 <= value: - view.clearNotificationMessage() - config.INPUT_SPEAKER_MAX_PHRASES = value - view.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES) - else: - raise ValueError() - except Exception: - view.showErrorMessage_SpeakerMaxPhrases() - -# Transcription (Internal AI Model) -def callbackSetUserWhisperFeature(value): - print("callbackSetUserWhisperFeature", value) - config.USE_WHISPER_FEATURE = value - if config.USE_WHISPER_FEATURE is True: - view.openWhisperWeightTypeWidget() - 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: - view.closeWhisperWeightTypeWidget() - config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - view.showRestartButtonIfRequired() - -def callbackSetWhisperWeightType(value): - print("callbackSetWhisperWeightType", value) - config.WHISPER_WEIGHT_TYPE = str(value) - view.updateSelectedWhisperWeightType(config.WHISPER_WEIGHT_TYPE) - 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" - view.showRestartButtonIfRequired() - -# VR Tab -def callbackSetOverlaySettings(value, set_type:str): - print("callbackSetOverlaySettings", value, set_type) - pre_settings = config.OVERLAY_SETTINGS - pre_settings[set_type] = value - config.OVERLAY_SETTINGS = pre_settings - match (set_type): - case "opacity": - model.updateOverlayImageOpacity() - case "ui_scaling": - model.updateOverlayImageUiScaling() - -def callbackSetEnableOverlaySmallLog(value): - print("callbackSetEnableOverlaySmallLog", value) - config.ENABLE_OVERLAY_SMALL_LOG = value - - 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() - elif config.ENABLE_OVERLAY_SMALL_LOG is False: - model.clearOverlayImage() - model.shutdownOverlay() - - if config.ENABLE_OVERLAY_SMALL_LOG is True: - view.setStateOverlaySmallLog("enabled") - elif config.ENABLE_OVERLAY_SMALL_LOG is False: - view.setStateOverlaySmallLog("disabled") - -def callbackSetOverlaySmallLogSettings(value, set_type:str): - print("callbackSetOverlaySmallLogSettings", value, set_type) - pre_settings = config.OVERLAY_SMALL_LOG_SETTINGS - pre_settings[set_type] = value - config.OVERLAY_SMALL_LOG_SETTINGS = pre_settings - match (set_type): - case "x_pos" | "y_pos" | "z_pos" | "x_rotation" | "y_rotation" | "z_rotation": - model.updateOverlayPosition() - case "display_duration" | "fadeout_duration": - model.updateOverlayTimes() - -# Others Tab -def callbackSetEnableAutoClearMessageBox(value): - print("callbackSetEnableAutoClearMessageBox", value) - config.ENABLE_AUTO_CLEAR_MESSAGE_BOX = value - -def callbackSetEnableSendOnlyTranslatedMessages(value): - print("callbackSetEnableSendOnlyTranslatedMessages", value) - config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES = value - -def callbackSetSendMessageButtonType(value): - print("callbackSetSendMessageButtonType", value) - config.SEND_MESSAGE_BUTTON_TYPE = value - view.changeMainWindowSendMessageButton(config.SEND_MESSAGE_BUTTON_TYPE) - -def callbackSetEnableNoticeXsoverlay(value): - print("callbackSetEnableNoticeXsoverlay", value) - config.ENABLE_NOTICE_XSOVERLAY = value - -def callbackSetEnableAutoExportMessageLogs(value): - print("callbackSetEnableAutoExportMessageLogs", value) - config.ENABLE_LOGGER_FEATURE = value - - if config.ENABLE_LOGGER_FEATURE is True: - model.startLogger() - else: - model.stopLogger() - -def callbackSetEnableVrcMicMuteSync(value): - print("callbackSetEnableVrcMicMuteSync", value) - config.ENABLE_VRC_MIC_MUTE_SYNC = value - if config.ENABLE_VRC_MIC_MUTE_SYNC is True: - model.startCheckMuteSelfStatus() - view.setStateVrcMicMuteSync("enabled") - else: - model.stopCheckMuteSelfStatus() - view.setStateVrcMicMuteSync("disabled") - model.changeMicTranscriptStatus() - - -def callbackSetEnableSendMessageToVrc(value): - print("callbackSetEnableSendMessageToVrc", value) - config.ENABLE_SEND_MESSAGE_TO_VRC = value - -# Others (Message Formats(Send) -def callbackSetSendMessageFormat(value): - print("callbackSetSendMessageFormat", value) - if isUniqueStrings(["[message]"], value) is True: - config.SEND_MESSAGE_FORMAT = value - view.clearNotificationMessage() - view.setSendMessageFormat_EntryWidgets(config.SEND_MESSAGE_FORMAT) - else: - view.showErrorMessage_SendMessageFormat() - view.setSendMessageFormat_EntryWidgets(config.SEND_MESSAGE_FORMAT) - -def callbackSetSendMessageFormatWithT(value): - print("callbackSetSendMessageFormatWithT", value) - if len(value) > 0: - if isUniqueStrings(["[message]", "[translation]"], value) is True: - config.SEND_MESSAGE_FORMAT_WITH_T = value - view.clearNotificationMessage() - view.setSendMessageFormatWithT_EntryWidgets(config.SEND_MESSAGE_FORMAT_WITH_T) - else: - view.showErrorMessage_SendMessageFormatWithT() - view.setSendMessageFormatWithT_EntryWidgets(config.SEND_MESSAGE_FORMAT_WITH_T) - -# Others (Message Formats(Received) -def callbackSetReceivedMessageFormat(value): - print("callbackSetReceivedMessageFormat", value) - if isUniqueStrings(["[message]"], value) is True: - config.RECEIVED_MESSAGE_FORMAT = value - view.clearNotificationMessage() - view.setReceivedMessageFormat_EntryWidgets(config.RECEIVED_MESSAGE_FORMAT) - else: - view.showErrorMessage_ReceivedMessageFormat() - view.setReceivedMessageFormat_EntryWidgets(config.RECEIVED_MESSAGE_FORMAT) - -def callbackSetReceivedMessageFormatWithT(value): - print("callbackSetReceivedMessageFormatWithT", value) - if len(value) > 0: - if isUniqueStrings(["[message]", "[translation]"], value) is True: - config.RECEIVED_MESSAGE_FORMAT_WITH_T = value - view.clearNotificationMessage() - view.setReceivedMessageFormatWithT_EntryWidgets(config.RECEIVED_MESSAGE_FORMAT_WITH_T) - else: - view.showErrorMessage_ReceivedMessageFormatWithT() - view.setReceivedMessageFormatWithT_EntryWidgets(config.RECEIVED_MESSAGE_FORMAT_WITH_T) - -# ---------------------Speaker2Chatbox--------------------- -def callbackSetEnableSendReceivedMessageToVrc(value): - print("callbackSetEnableSendReceivedMessageToVrc", value) - config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC = value -# ---------------------Speaker2Chatbox--------------------- - -# Advanced Settings Tab -def callbackSetOscIpAddress(value): - if value == "": - return - print("callbackSetOscIpAddress", str(value)) - config.OSC_IP_ADDRESS = str(value) - -def callbackSetOscPort(value): - if value == "": - return - print("callbackSetOscPort", int(value)) - config.OSC_PORT = int(value) - - -def initSetConfigByExeArguments(): - parser = argparse.ArgumentParser() - parser.add_argument("--ip") - parser.add_argument("--port") - args = parser.parse_args() - if args.ip is not None: - config.OSC_IP_ADDRESS = str(args.ip) - view.setGuiVariable_OscIpAddress(config.OSC_IP_ADDRESS) - if args.port is not None: - config.OSC_PORT = int(args.port) - view.setGuiVariable_OscPort(config.OSC_PORT) - -def createMainWindow(splash): - splash.toProgress(1) - # create GUI - view.createGUI() - splash.toProgress(2) - - # init config - initSetConfigByExeArguments() - initSetTranslateEngine() - initSetLanguageAndCountry() - - 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 - auth_keys = config.AUTH_KEYS - auth_keys["DeepL_API"] = None - config.AUTH_KEYS = auth_keys - view.printToTextbox_AuthenticationError() - - # set Translation Engine - updateTranslationEngineAndEngineList() - - # set Transcription Engine - if config.USE_WHISPER_FEATURE is True: - config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" - else: - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - - # set word filter - model.addKeywords() - - # check Software Updated - if model.checkSoftwareUpdated() is True: - view.showUpdateAvailableButton() - - # init logger - if config.ENABLE_LOGGER_FEATURE is True: - model.startLogger() - - # init OSC receive - model.startReceiveOSC() - if config.ENABLE_VRC_MIC_MUTE_SYNC is True: - model.startCheckMuteSelfStatus() - - splash.toProgress(3) # Last one. - - # set UI and callback - view.register( - common_registers={ - "callback_enable_easter_egg": callbackEnableEasterEgg, - - "callback_update_software": callbackUpdateSoftware, - "callback_restart_software": callbackRestartSoftware, - "callback_filepath_logs": callbackFilepathLogs, - "callback_filepath_config_file": callbackFilepathConfigFile, - "callback_quit_vrct": callbackQuitVrct, - }, - - window_action_registers={ - "callback_open_config_window": callbackOpenConfigWindow, - "callback_close_config_window": callbackCloseConfigWindow, - }, - - main_window_registers={ - "callback_enable_main_window_sidebar_compact_mode": callbackEnableMainWindowSidebarCompactMode, - "callback_disable_main_window_sidebar_compact_mode": callbackDisableMainWindowSidebarCompactMode, - - "callback_toggle_translation": callbackToggleTranslation, - "callback_toggle_transcription_send": callbackToggleTranscriptionSend, - "callback_toggle_transcription_receive": callbackToggleTranscriptionReceive, - "callback_toggle_foreground": callbackToggleForeground, - - "callback_your_language": setYourLanguageAndCountry, - "callback_target_language": setTargetLanguageAndCountry, - "values": model.getListLanguageAndCountry(), - "callback_swap_languages": swapYourLanguageAndTargetLanguage, - - "callback_selected_language_preset_tab": callbackSelectedLanguagePresetTab, - - "callback_selected_translation_engine": callbackSelectedTranslationEngine, - - "message_box_bind_Return": messageBoxPressKeyEnter, - "message_box_bind_Any_KeyPress": messageBoxPressKeyAny, - "message_box_bind_FocusIn": messageBoxFocusIn, - "message_box_bind_FocusOut": messageBoxFocusOut, - "message_box_bind_Up_KeyPress": messageBoxUpKeyPress, - "message_box_bind_Down_KeyPress": messageBoxDownKeyPress, - }, - - config_window_registers={ - # Compact Mode Switch - "callback_disable_config_window_compact_mode": callbackEnableConfigWindowCompactMode, - "callback_enable_config_window_compact_mode": callbackDisableConfigWindowCompactMode, - - # Appearance Tab - "callback_set_transparency": callbackSetTransparency, - "callback_set_appearance": callbackSetAppearance, - "callback_set_ui_scaling": callbackSetUiScaling, - "callback_set_textbox_ui_scaling": callbackSetTextboxUiScaling, - "callback_set_message_box_ratio": callbackSetMessageBoxRatio, - "callback_set_font_family": callbackSetFontFamily, - "callback_set_ui_language": callbackSetUiLanguage, - "callback_set_enable_restore_main_window_geometry": callbackSetEnableRestoreMainWindowGeometry, - - # Translation Tab - "callback_set_use_translation_feature": callbackSetUseTranslationFeature, - "callback_set_ctranslate2_weight_type": callbackSetCtranslate2WeightType, - "callback_set_deepl_auth_key": callbackSetDeeplAuthKey, - - # Transcription Tab (Mic) - "callback_set_mic_host": callbackSetMicHost, - "list_mic_host": model.getListInputHost(), - "callback_set_mic_device": callbackSetMicDevice, - "list_mic_device": model.getListInputDevice(), - "callback_set_mic_energy_threshold": callbackSetMicEnergyThreshold, - "callback_set_mic_dynamic_energy_threshold": callbackSetMicDynamicEnergyThreshold, - "callback_check_mic_threshold": callbackCheckMicThreshold, - "callback_set_mic_record_timeout": callbackSetMicRecordTimeout, - "callback_set_mic_phrase_timeout": callbackSetMicPhraseTimeout, - "callback_set_mic_max_phrases": callbackSetMicMaxPhrases, - "callback_set_mic_word_filter": callbackSetMicWordFilter, - "callback_delete_mic_word_filter": callbackDeleteMicWordFilter, - - # Transcription Tab (Speaker) - "callback_set_speaker_device": callbackSetSpeakerDevice, - "list_speaker_device": model.getListOutputDevice(), - "callback_set_speaker_energy_threshold": callbackSetSpeakerEnergyThreshold, - "callback_set_speaker_dynamic_energy_threshold": callbackSetSpeakerDynamicEnergyThreshold, - "callback_check_speaker_threshold": callbackCheckSpeakerThreshold, - "callback_set_speaker_record_timeout": callbackSetSpeakerRecordTimeout, - "callback_set_speaker_phrase_timeout": callbackSetSpeakerPhraseTimeout, - "callback_set_speaker_max_phrases": callbackSetSpeakerMaxPhrases, - - # Transcription Tab (Internal AI Model) - "callback_set_use_whisper_feature": callbackSetUserWhisperFeature, - "callback_set_whisper_weight_type": callbackSetWhisperWeightType, - - # VR Tab - "callback_set_overlay_settings": callbackSetOverlaySettings, - "callback_set_enable_overlay_small_log": callbackSetEnableOverlaySmallLog, - "callback_set_overlay_small_log_settings": callbackSetOverlaySmallLogSettings, - - # Others Tab - "callback_set_enable_auto_clear_chatbox": callbackSetEnableAutoClearMessageBox, - "callback_set_send_only_translated_messages": callbackSetEnableSendOnlyTranslatedMessages, - "callback_set_send_message_button_type": callbackSetSendMessageButtonType, - "callback_set_enable_notice_xsoverlay": callbackSetEnableNoticeXsoverlay, - "callback_set_enable_auto_export_message_logs": callbackSetEnableAutoExportMessageLogs, - "callback_set_enable_vrc_mic_mute_sync": callbackSetEnableVrcMicMuteSync, - "callback_set_enable_send_message_to_vrc": callbackSetEnableSendMessageToVrc, - # Others(Message Formats(Send) - "callback_set_send_message_format": callbackSetSendMessageFormat, - "callback_set_send_message_format_with_t": callbackSetSendMessageFormatWithT, - # Others(Message Formats(Received) - "callback_set_received_message_format": callbackSetReceivedMessageFormat, - "callback_set_received_message_format_with_t": callbackSetReceivedMessageFormatWithT, - - # Speaker2Chatbox---------------- - "callback_set_enable_send_received_message_to_vrc": callbackSetEnableSendReceivedMessageToVrc, - # Speaker2Chatbox---------------- - - # Advanced Settings Tab - "callback_set_osc_ip_address": callbackSetOscIpAddress, - "callback_set_osc_port": callbackSetOscPort, - }, - ) - -def showMainWindow(): - view.startMainLoop() \ No newline at end of file diff --git a/src-python/main.py b/src-python/main.py deleted file mode 100644 index 257a3a63..00000000 --- a/src-python/main.py +++ /dev/null @@ -1,33 +0,0 @@ -if __name__ == "__main__": - try: - import ctypes - ctypes.windll.shcore.SetProcessDpiAwareness(0) - - from vrct_gui.splash_window import SplashWindow - splash = SplashWindow() - splash.showSplash() - - from config import config - # version 2.2.0からweightフォルダをweightsに変更する - from utils import renameWeightFolder - renameWeightFolder(config.PATH_LOCAL) - - from models.translation.translation_utils import downloadCTranslate2Weight - if config.USE_TRANSLATION_FEATURE is True: - downloadCTranslate2Weight(config.PATH_LOCAL, config.CTRANSLATE2_WEIGHT_TYPE, splash.updateDownloadProgress) - - from models.transcription.transcription_whisper import downloadWhisperWeight - if config.USE_WHISPER_FEATURE is True: - downloadWhisperWeight(config.PATH_LOCAL, config.WHISPER_WEIGHT_TYPE, splash.updateDownloadProgress) - - splash.toProgress(0) - - import controller - controller.createMainWindow(splash) - splash.destroySplash() - controller.showMainWindow() - - except Exception: - import traceback - with open('error.log', 'a') as f: - traceback.print_exc(file=f) \ No newline at end of file From 192507a605114dabd6b9cd9b171bbf115bd3c48b Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:48:28 +0900 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20[Remove]=20Config?= =?UTF-8?q?=20:=20IS=5FRESET=5FBUTTON=5FDISPLAYED=5FFOR=5F**=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 51 ---------------------------------- src-python/webui_controller.py | 36 ++---------------------- 2 files changed, 3 insertions(+), 84 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 9d5b3984..ee02eb05 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -177,51 +177,6 @@ class Config: if isinstance(value, bool): self._ENABLE_CHECK_ENERGY_RECEIVE = value - # @property - # def SENT_MESSAGES_LOG(self): - # return self._SENT_MESSAGES_LOG - - # @SENT_MESSAGES_LOG.setter - # def SENT_MESSAGES_LOG(self, value): - # if isinstance(value, list): - # self._SENT_MESSAGES_LOG = value - - # @property - # def CURRENT_SENT_MESSAGES_LOG_INDEX(self): - # return self._CURRENT_SENT_MESSAGES_LOG_INDEX - - # @CURRENT_SENT_MESSAGES_LOG_INDEX.setter - # def CURRENT_SENT_MESSAGES_LOG_INDEX(self, value): - # if isinstance(value, int): - # self._CURRENT_SENT_MESSAGES_LOG_INDEX = value - - @property - def IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION(self): - return self._IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION - - @IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION.setter - def IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION(self, value): - if isinstance(value, bool): - self._IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = value - - @property - def IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER(self): - return self._IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER - - @IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER.setter - def IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER(self, value): - if isinstance(value, bool): - self._IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = value - - # @property - # def IS_EASTER_EGG_ENABLED(self): - # return self._IS_EASTER_EGG_ENABLED - - # @IS_EASTER_EGG_ENABLED.setter - # def IS_EASTER_EGG_ENABLED(self, value): - # if isinstance(value, bool): - # self._IS_EASTER_EGG_ENABLED = value - # Save Json Data ## Main Window @property @@ -1008,12 +963,6 @@ class Config: self._ENABLE_CHECK_ENERGY_SEND = False self._ENABLE_CHECK_ENERGY_RECEIVE = False - # self._SENT_MESSAGES_LOG = [] - # self._CURRENT_SENT_MESSAGES_LOG_INDEX = 0 - self._IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False - self._IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER = False - # self._IS_EASTER_EGG_ENABLED = False - # Save Json Data ## Main Window self._SELECTED_TAB_NO = "1" diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index e8d89bf0..1832b42b 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -1080,31 +1080,17 @@ class Controller: def setEnableUseTranslationFeature(*args, **kwargs) -> dict: config.USE_TRANSLATION_FEATURE = 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 - return {"status":200, - "result":{ - "feature":config.USE_TRANSLATION_FEATURE, - "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, - }, - } + return {"status":200, "result":config.USE_TRANSLATION_FEATURE} @staticmethod def setDisableUseTranslationFeature(*args, **kwargs) -> dict: 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, - }, - } + return {"status":200, "result": config.USE_TRANSLATION_FEATURE} @staticmethod def getUseWhisperFeature(*args, **kwargs) -> dict: @@ -1114,29 +1100,24 @@ class Controller: def setEnableUseWhisperFeature(*args, **kwargs) -> dict: 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":200, "result":{ "feature":config.USE_WHISPER_FEATURE, "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, - "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, }, } @staticmethod def setDisableUseWhisperFeature(*args, **kwargs) -> dict: 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, }, } @@ -1148,20 +1129,12 @@ class Controller: def setCtranslate2WeightType(data, *args, **kwargs) -> dict: config.CTRANSLATE2_WEIGHT_TYPE = str(data) 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 - return {"status":200, - "result":{ - "feature":config.CTRANSLATE2_WEIGHT_TYPE, - "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION, - }, - } + return {"status":200, "result":config.CTRANSLATE2_WEIGHT_TYPE} @staticmethod def getWhisperWeightType(*args, **kwargs) -> dict: @@ -1171,16 +1144,13 @@ class Controller: def setWhisperWeightType(data, *args, **kwargs) -> dict: config.WHISPER_WEIGHT_TYPE = str(data) 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":200, "result":{ "weight_type":config.WHISPER_WEIGHT_TYPE, "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, - "reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_WHISPER, } } From 134ef373afe1327e81a08d7b12b9fef37cf25ecb Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:58:21 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20[Remove]=20Model=20?= =?UTF-8?q?:=20Whisper=E3=81=AE=E4=B8=8D=E8=A6=81=E3=81=AA=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 12 --------- src-python/webui_controller.py | 46 ++-------------------------------- src-python/webui_mainloop.py | 4 --- 3 files changed, 2 insertions(+), 60 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index ee02eb05..9045a690 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -677,17 +677,6 @@ class Config: self._USE_TRANSLATION_FEATURE = value self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property - @json_serializable('USE_WHISPER_FEATURE') - def USE_WHISPER_FEATURE(self): - return self._USE_WHISPER_FEATURE - - @USE_WHISPER_FEATURE.setter - def USE_WHISPER_FEATURE(self, value): - if isinstance(value, bool): - self._USE_WHISPER_FEATURE = value - self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property @json_serializable('SELECTED_TRANSLATION_COMPUTE_DEVICE') def SELECTED_TRANSLATION_COMPUTE_DEVICE(self): @@ -1083,7 +1072,6 @@ class Config: } self._USE_EXCLUDE_WORDS = True self._USE_TRANSLATION_FEATURE = True - self._USE_WHISPER_FEATURE = False self._SELECTED_TRANSLATION_COMPUTE_DEVICE = {"device": "cpu", "device_index": 0, "device_name":"cpu"} self._SELECTED_TRANSCRIPTION_COMPUTE_DEVICE = {"device": "cpu", "device_index": 0, "device_name":"cpu"} self._CTRANSLATE2_WEIGHT_TYPE = "Small" diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 1832b42b..d20790b2 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -1092,35 +1092,6 @@ class Controller: config.USE_TRANSLATION_FEATURE = False return {"status":200, "result": config.USE_TRANSLATION_FEATURE} - @staticmethod - def getUseWhisperFeature(*args, **kwargs) -> dict: - return {"status":200, "result":config.USE_WHISPER_FEATURE} - - @staticmethod - def setEnableUseWhisperFeature(*args, **kwargs) -> dict: - config.USE_WHISPER_FEATURE = True - if model.checkTranscriptionWhisperModelWeight() is True: - config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" - else: - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":200, - "result":{ - "feature":config.USE_WHISPER_FEATURE, - "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, - }, - } - - @staticmethod - def setDisableUseWhisperFeature(*args, **kwargs) -> dict: - config.USE_WHISPER_FEATURE = False - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":200, - "result":{ - "feature":config.USE_WHISPER_FEATURE, - "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, - }, - } - @staticmethod def getCtranslate2WeightType(*args, **kwargs) -> dict: return {"status":200, "result":config.CTRANSLATE2_WEIGHT_TYPE} @@ -1650,22 +1621,9 @@ class Controller: printLog("Set Translation Engine") self.updateTranslationEngineAndEngineList() - # check Downloaded CTranslate2 Model Weight - printLog("Check Downloaded CTranslate2 Model Weight") - if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False: - self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar) - # set Transcription Engine - printLog("Set Transcription Engine") - if config.USE_WHISPER_FEATURE is True: - config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" - else: - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - - # check Downloaded Whisper Model Weight - printLog("Check Downloaded Whisper Model Weight") - if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False: - self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar) + # printLog("Set Transcription Engine") + # self.updateTranscriptionEngineAndEngineList() # set word filter printLog("Set Word Filter") diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 68f6f3c1..54671c62 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -246,10 +246,6 @@ mapping = { "/get/data/whisper_weight_type": {"status": True, "variable":controller.getWhisperWeightType}, "/set/data/whisper_weight_type": {"status": True, "variable":controller.setWhisperWeightType}, - "/get/data/use_whisper_feature": {"status": True, "variable":controller.getUseWhisperFeature}, - "/set/enable/use_whisper_feature": {"status": True, "variable":controller.setEnableUseWhisperFeature}, - "/set/disable/use_whisper_feature": {"status": True, "variable":controller.setDisableUseWhisperFeature}, - "/run/download_whisper_weight": {"status": True, "variable":controller.downloadWhisperWeight}, # VR From 7fd3fad3ea31f90aa3d7bfeb2d4361300aefa17d Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 29 Oct 2024 22:58:18 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Model=20:?= =?UTF-8?q?=20AI=20=E3=83=A2=E3=83=87=E3=83=AB=E3=81=AE=E3=83=80=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=AD=E3=83=BC=E3=83=89=E6=96=B9=E6=B3=95=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AIモデルのダウンロード済み確認辞書を追加 - selectable_ctranslate2_weight_type_dict - selectable_whisper_weight_type_dict - AIモデルダウンロード処理完了のエンドポイントを追加 - /run/download_ctranslate2_weight - /run/downloaded_whisper_weight --- src-python/config.py | 55 +++--- src-python/model.py | 16 +- .../transcription/transcription_whisper.py | 35 ++-- .../models/translation/translation_utils.py | 40 ++-- src-python/webui_controller.py | 187 +++++++++++++----- src-python/webui_mainloop.py | 11 +- 6 files changed, 228 insertions(+), 116 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 9045a690..009749fb 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -98,14 +98,6 @@ class Config: def MESSAGE_BOX_RATIO_RANGE(self): return self._MESSAGE_BOX_RATIO_RANGE - @property - def SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST(self): - return self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST - - @property - def SELECTABLE_WHISPER_WEIGHT_TYPE_LIST(self): - return self._SELECTABLE_WHISPER_WEIGHT_TYPE_LIST - @property def MAX_MIC_THRESHOLD(self): return self._MAX_MIC_THRESHOLD @@ -177,6 +169,24 @@ class Config: if isinstance(value, bool): self._ENABLE_CHECK_ENERGY_RECEIVE = value + @property + def SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT(self): + return self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT + + @SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT.setter + def SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT(self, value): + if isinstance(value, dict): + self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = value + + @property + def SELECTABLE_WHISPER_WEIGHT_TYPE_DICT(self): + return self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT + + @SELECTABLE_WHISPER_WEIGHT_TYPE_DICT.setter + def SELECTABLE_WHISPER_WEIGHT_TYPE_DICT(self, value): + if isinstance(value, dict): + self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = value + # Save Json Data ## Main Window @property @@ -252,7 +262,7 @@ class Config: def SELECTED_TRANSCRIPTION_ENGINE(self, value): if isinstance(value, str): self._SELECTED_TRANSCRIPTION_ENGINE = value - # self.saveConfig(inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MULTI_LANGUAGE_TRANSLATION') @@ -706,7 +716,6 @@ class Config: @CTRANSLATE2_WEIGHT_TYPE.setter def CTRANSLATE2_WEIGHT_TYPE(self, value): - # if isinstance(value, str) and value in self.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST: if isinstance(value, str): self._CTRANSLATE2_WEIGHT_TYPE = value self.saveConfig(inspect.currentframe().f_code.co_name, value) @@ -924,20 +933,20 @@ class Config: self._UI_SCALING_RANGE = (40, 200) self._TEXTBOX_UI_SCALING_RANGE = (40, 200) self._MESSAGE_BOX_RATIO_RANGE = (1, 99) - self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST = [ - "Small", - "Large", - ] + self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = { + "Small": False, + "Large": False, + } - self._SELECTABLE_WHISPER_WEIGHT_TYPE_LIST = [ - "tiny", - "base", - "small", - "medium", - "large-v1", - "large-v2", - "large-v3", - ] + self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = { + "tiny": False, + "base": False, + "small": False, + "medium": False, + "large-v1": False, + "large-v2": False, + "large-v3": False, + } self._MAX_MIC_THRESHOLD = 2000 self._MAX_SPEAKER_THRESHOLD = 4000 diff --git a/src-python/model.py b/src-python/model.py index 589ec0fa..7408d4f2 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -101,8 +101,8 @@ class Model: self.kks = kakasi() self.watchdog = Watchdog(config.WATCHDOG_TIMEOUT, config.WATCHDOG_INTERVAL) - def checkCTranslatorCTranslate2ModelWeight(self): - return checkCTranslate2Weight(config.PATH_LOCAL, config.CTRANSLATE2_WEIGHT_TYPE) + def checkTranslatorCTranslate2ModelWeight(self, weight_type:str): + return checkCTranslate2Weight(config.PATH_LOCAL, weight_type) def changeTranslatorCTranslate2Model(self): self.translator.changeCTranslate2Model( @@ -111,17 +111,17 @@ class Model: config.SELECTED_TRANSLATION_COMPUTE_DEVICE["device"], config.SELECTED_TRANSLATION_COMPUTE_DEVICE["device_index"]) - def downloadCTranslate2ModelWeight(self, callbackFunc=None): - return downloadCTranslate2Weight(config.PATH_LOCAL, config.CTRANSLATE2_WEIGHT_TYPE, callbackFunc) + def downloadCTranslate2ModelWeight(self, weight_type, callback=None, end_callback=None): + return downloadCTranslate2Weight(config.PATH_LOCAL, weight_type, callback, end_callback) def isLoadedCTranslate2Model(self): return self.translator.isLoadedCTranslate2Model() - def checkTranscriptionWhisperModelWeight(self): - return checkWhisperWeight(config.PATH_LOCAL, config.WHISPER_WEIGHT_TYPE) + def checkTranscriptionWhisperModelWeight(self, weight_type:str): + return checkWhisperWeight(config.PATH_LOCAL, weight_type) - def downloadWhisperModelWeight(self, callbackFunc=None): - return downloadWhisperWeight(config.PATH_LOCAL, config.WHISPER_WEIGHT_TYPE, callbackFunc) + def downloadWhisperModelWeight(self, weight_type, callback=None, end_callback=None): + return downloadWhisperWeight(config.PATH_LOCAL, weight_type, callback, end_callback) def resetKeywordProcessor(self): del self.keyword_processor diff --git a/src-python/models/transcription/transcription_whisper.py b/src-python/models/transcription/transcription_whisper.py index 398a7524..d21df91a 100644 --- a/src-python/models/transcription/transcription_whisper.py +++ b/src-python/models/transcription/transcription_whisper.py @@ -63,17 +63,16 @@ def checkWhisperWeight(root, weight_type): pass return result -def downloadWhisperWeight(root, weight_type, callbackFunc): +def downloadWhisperWeight(root, weight_type, callback=None, end_callback=None): path = os_path.join(root, "weights", "whisper", weight_type) os_makedirs(path, exist_ok=True) - if checkWhisperWeight(root, weight_type) is True: - callbackFunc(1) - return - - for filename in _FILENAMES: - file_path = os_path.join(path, filename) - url = huggingface_hub.hf_hub_url(_MODELS[weight_type], filename) - downloadFile(url, file_path, func=callbackFunc) + if checkWhisperWeight(root, weight_type) is False: + for filename in _FILENAMES: + file_path = os_path.join(path, filename) + url = huggingface_hub.hf_hub_url(_MODELS[weight_type], filename) + downloadFile(url, file_path, func=callback) + if isinstance(end_callback, Callable): + end_callback() def getWhisperModel(root, weight_type, device="cpu", device_index=0): path = os_path.join(root, "weights", "whisper", weight_type) @@ -93,10 +92,14 @@ if __name__ == "__main__": print(value) pass - downloadWhisperWeight("./", "tiny", callback) - downloadWhisperWeight("./", "base", callback) - downloadWhisperWeight("./", "small", callback) - downloadWhisperWeight("./", "medium", callback) - downloadWhisperWeight("./", "large-v1", callback) - downloadWhisperWeight("./", "large-v2", callback) - downloadWhisperWeight("./", "large-v3", callback) \ No newline at end of file + def end_callback(): + print("end") + pass + + downloadWhisperWeight("./", "tiny", callback, end_callback) + downloadWhisperWeight("./", "base", callback, end_callback) + downloadWhisperWeight("./", "small", callback, end_callback) + downloadWhisperWeight("./", "medium", callback, end_callback) + downloadWhisperWeight("./", "large-v1", callback, end_callback) + downloadWhisperWeight("./", "large-v2", callback, end_callback) + downloadWhisperWeight("./", "large-v3", callback, end_callback) \ No newline at end of file diff --git a/src-python/models/translation/translation_utils.py b/src-python/models/translation/translation_utils.py index aa6437da..ca0eddc7 100644 --- a/src-python/models/translation/translation_utils.py +++ b/src-python/models/translation/translation_utils.py @@ -60,30 +60,30 @@ def checkCTranslate2Weight(path, weight_type="Small"): already_downloaded = True return already_downloaded -def downloadCTranslate2Weight(root, weight_type="Small", callbackFunc=None): +def downloadCTranslate2Weight(root, weight_type="Small", callback=None, end_callback=None): url = ctranslate2_weights[weight_type]["url"] filename = "weight.zip" path = os_path.join(root, "weights", "ctranslate2") os_makedirs(path, exist_ok=True) - if checkCTranslate2Weight(path, weight_type): - callbackFunc(1) - return + if checkCTranslate2Weight(path, weight_type) is False: + try: + with tempfile.TemporaryDirectory() as tmp_path: + res = requests_get(url, stream=True) + file_size = int(res.headers.get('content-length', 0)) + total_chunk = 0 + with open(os_path.join(tmp_path, filename), 'wb') as file: + for chunk in res.iter_content(chunk_size=1024*2000): + file.write(chunk) + if isinstance(callback, Callable): + total_chunk += len(chunk) + callback(total_chunk/file_size) + printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}") - try: - with tempfile.TemporaryDirectory() as tmp_path: - res = requests_get(url, stream=True) - file_size = int(res.headers.get('content-length', 0)) - total_chunk = 0 - with open(os_path.join(tmp_path, filename), 'wb') as file: - for chunk in res.iter_content(chunk_size=1024*2000): - file.write(chunk) - if isinstance(callbackFunc, Callable): - total_chunk += len(chunk) - callbackFunc(total_chunk/file_size) - printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}") + with ZipFile(os_path.join(tmp_path, filename)) as zf: + zf.extractall(path) + except Exception as e: + printLog("warning:downloadCTranslate2Weight()", e) - with ZipFile(os_path.join(tmp_path, filename)) as zf: - zf.extractall(path) - except Exception as e: - printLog("warning:downloadCTranslate2Weight()", e) \ No newline at end of file + if isinstance(end_callback, Callable): + end_callback() \ No newline at end of file diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index d20790b2..0cccba25 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -134,21 +134,55 @@ class Controller: energy, ) - def downloadCTranslate2ProgressBar(self, progress) -> None: - printLog("CTranslate2 Weight Download Progress", progress) - self.run( - 200, - self.run_mapping["download_ctranslate2"], - progress, - ) + class DownloadCTranslate2: + def __init__(self, run_mapping:dict, weight_type:str, run:Callable[[int, str, Any], None]) -> None: + self.run_mapping = run_mapping + self.weight_type = weight_type + self.run = run - def downloadWhisperProgressBar(self, progress) -> None: - printLog("Whisper Weight Download Progress", progress) - self.run( - 200, - self.run_mapping["download_whisper"], - progress, - ) + def progressBar(self, progress) -> None: + printLog("CTranslate2 Weight Download Progress", progress) + self.run( + 200, + self.run_mapping["download_ctranslate2_weight"], + {"weight_type": self.weight_type, "progress": progress}, + ) + + def downloaded(self) -> None: + weight_type_dict = config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT + weight_type_dict["self.weight_type"] = True + config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = weight_type_dict + + self.run( + 200, + self.run_mapping["downloaded_ctranslate2_weight"], + self.weight_type, + ) + + class DownloadWhisper: + def __init__(self, run_mapping:dict, weight_type:str, run:Callable[[int, str, Any], None]) -> None: + self.run_mapping = run_mapping + self.weight_type = weight_type + self.run = run + + def progressBar(self, progress) -> None: + printLog("Whisper Weight Download Progress", progress) + self.run( + 200, + self.run_mapping["download_whisper_weight"], + {"weight_type": self.weight_type, "progress": progress}, + ) + + def downloaded(self) -> None: + weight_type_dict = config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT + weight_type_dict[self.weight_type] = True + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = weight_type_dict + + self.run( + 200, + self.run_mapping["downloaded_whisper_weight"], + self.weight_type, + ) def micMessage(self, message: Union[str, bool]) -> None: if isinstance(message, bool) and message is False: @@ -397,8 +431,8 @@ class Controller: return {"status":200,"result":config.SELECTED_TRANSLATION_COMPUTE_DEVICE} @staticmethod - def getSelectableCtranslate2WeightTypeList(*args, **kwargs) -> dict: - return {"status":200, "result":config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST} + def getSelectableCtranslate2WeightTypeDict(*args, **kwargs) -> dict: + return {"status":200, "result":config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT} @staticmethod def getSelectedTranscriptionComputeDevice(*args, **kwargs) -> dict: @@ -411,8 +445,8 @@ class Controller: return {"status":200,"result":config.SELECTED_TRANSCRIPTION_COMPUTE_DEVICE} @staticmethod - def getSelectableWhisperWeightTypeList(*args, **kwargs) -> dict: - return {"status":200, "result":config.SELECTABLE_WHISPER_WEIGHT_TYPE_LIST} + def getSelectableWhisperWeightTypeDict(*args, **kwargs) -> dict: + return {"status":200, "result":config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT} @staticmethod def getMaxMicThreshold(*args, **kwargs) -> dict: @@ -511,6 +545,24 @@ class Controller: def getSelectedTranscriptionEngine(*args, **kwargs) -> dict: return {"status":200, "result":config.SELECTED_TRANSCRIPTION_ENGINE} + @staticmethod + def setSelectedTranscriptionEngine(data, *args, **kwargs) -> dict: + engine = data["engine"] + weight_type = data["weight_type"] + if engine == "Whisper" and config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] is False: + config.SELECTED_TRANSCRIPTION_ENGINE = "Google" + config.WHISPER_WEIGHT_TYPE = None + else: + config.SELECTED_TRANSCRIPTION_ENGINE = engine + config.WHISPER_WEIGHT_TYPE = weight_type + return { + "status":200, + "result":{ + "engine": config.SELECTED_TRANSCRIPTION_ENGINE, + "weight_type": config.WHISPER_WEIGHT_TYPE, + } + } + @staticmethod def getMultiLanguageTranslation(*args, **kwargs) -> dict: return {"status":200, "result":config.MULTI_LANGUAGE_TRANSLATION} @@ -1079,7 +1131,7 @@ class Controller: @staticmethod def setEnableUseTranslationFeature(*args, **kwargs) -> dict: config.USE_TRANSLATION_FEATURE = True - if model.checkCTranslatorCTranslate2ModelWeight(): + if model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE): def callback(): model.changeTranslatorCTranslate2Model() th_callback = Thread(target=callback) @@ -1099,7 +1151,7 @@ class Controller: @staticmethod def setCtranslate2WeightType(data, *args, **kwargs) -> dict: config.CTRANSLATE2_WEIGHT_TYPE = str(data) - if model.checkCTranslatorCTranslate2ModelWeight(): + if model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE): def callback(): model.changeTranslatorCTranslate2Model() th_callback = Thread(target=callback) @@ -1114,16 +1166,7 @@ class Controller: @staticmethod def setWhisperWeightType(data, *args, **kwargs) -> dict: config.WHISPER_WEIGHT_TYPE = str(data) - if model.checkTranscriptionWhisperModelWeight() is True: - config.SELECTED_TRANSCRIPTION_ENGINE = "Whisper" - else: - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - return {"status":200, - "result":{ - "weight_type":config.WHISPER_WEIGHT_TYPE, - "transcription_engine":config.SELECTED_TRANSCRIPTION_ENGINE, - } - } + return {"status":200, "result": config.WHISPER_WEIGHT_TYPE} @staticmethod def getAutoClearMessageBox(*args, **kwargs) -> dict: @@ -1410,12 +1453,33 @@ class Controller: th_start_update_software.start() return {"status":200, "result":True} - def downloadCtranslate2Weight(self, *args, **kwargs) -> dict: - self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar) + def downloadCtranslate2Weight(self, data:str, *args, **kwargs) -> dict: + weight_type = str(data) + download_ctranslate2 = self.DownloadCTranslate2( + self.run_mapping, + weight_type, + self.run + ) + + self.startThreadingDownloadCtranslate2Weight( + weight_type, + download_ctranslate2.progressBar, + download_ctranslate2.downloaded, + ) return {"status":200, "result":True} - def downloadWhisperWeight(self, *args, **kwargs) -> dict: - self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar) + def downloadWhisperWeight(self, data:str, *args, **kwargs) -> dict: + weight_type = str(data) + download_whisper = self.DownloadWhisper( + self.run_mapping, + weight_type, + self.run + ) + self.startThreadingDownloadWhisperWeight( + weight_type, + download_whisper.progressBar, + download_whisper.downloaded, + ) return {"status":200, "result":True} @staticmethod @@ -1524,14 +1588,35 @@ class Controller: cleaned_text = re.sub(pattern, r'\1', text) return cleaned_text + def updateDownloadedCTranslate2ModelWeight(self) -> None: + weight_type_dict = config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT + for weight_type in weight_type_dict.keys(): + weight_type_dict[weight_type] = model.checkTranslatorCTranslate2ModelWeight(weight_type) + config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = weight_type_dict + def updateTranslationEngineAndEngineList(self): - engine = config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] - engines = self.getTranslationEngines()["result"] - if engine not in engines: + engines = config.SELECTED_TRANSLATION_ENGINES + engine = engines[config.SELECTED_TAB_NO] + selectable_engines = self.getTranslationEngines()["result"] + if engine not in selectable_engines: engine = "CTranslate2" - config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = engine + engines[config.SELECTED_TAB_NO] = engine + config.SELECTED_TRANSLATION_ENGINES = engines + self.run(200, self.run_mapping["selected_translation_engines"], config.SELECTED_TRANSLATION_ENGINES) - self.run(200, self.run_mapping["translation_engines"], engines) + self.run(200, self.run_mapping["translation_engines"], selectable_engines) + + def updateDownloadedWhisperModelWeight(self) -> None: + weight_type_dict = config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT + for weight_type in weight_type_dict.keys(): + weight_type_dict[weight_type] = model.checkTranscriptionWhisperModelWeight(weight_type) + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = weight_type_dict + + def updateTranscriptionEngine(self): + weight_type_dict = config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT + weight_type = config.WHISPER_WEIGHT_TYPE + if config.SELECTED_TRANSCRIPTION_ENGINE == "Whisper" and weight_type_dict[weight_type] is False: + config.SELECTED_TRANSCRIPTION_ENGINE = "Google" def startCheckMicEnergy(self) -> None: while self.device_access_status is False: @@ -1576,14 +1661,14 @@ class Controller: th_stopCheckSpeakerEnergy.join() @staticmethod - def startThreadingDownloadCtranslate2Weight(callback:Callable[[float], None]) -> None: - th_download = Thread(target=model.downloadCTranslate2ModelWeight, args=(callback,)) + def startThreadingDownloadCtranslate2Weight(weight_type:str, callback:Callable[[float], None], end_callback:Callable[[float], None]) -> None: + th_download = Thread(target=model.downloadCTranslate2ModelWeight, args=(weight_type, callback, end_callback)) th_download.daemon = True th_download.start() @staticmethod - def startThreadingDownloadWhisperWeight(callback:Callable[[float], None]) -> None: - th_download = Thread(target=model.downloadWhisperModelWeight, args=(callback,)) + def startThreadingDownloadWhisperWeight(weight_type:str, callback:Callable[[float], None], end_callback:Callable[[float], None]) -> None: + th_download = Thread(target=model.downloadWhisperModelWeight, args=(weight_type, callback, end_callback)) th_download.daemon = True th_download.start() @@ -1619,11 +1704,23 @@ class Controller: # set Translation Engine printLog("Set Translation Engine") + self.updateDownloadedCTranslate2ModelWeight() self.updateTranslationEngineAndEngineList() + # download CTranslate2 Model Weight + printLog("Download CTranslate2 Model Weight") + if config.USE_TRANSLATION_FEATURE is True and model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE) is False: + self.downloadCtranslate2Weight(config.CTRANSLATE2_WEIGHT_TYPE) + # set Transcription Engine - # printLog("Set Transcription Engine") - # self.updateTranscriptionEngineAndEngineList() + printLog("Set Transcription Engine") + self.updateDownloadedWhisperModelWeight() + self.updateTranscriptionEngine() + + # download Whisper Model Weight + printLog("Download Whisper Model Weight") + if model.checkTranscriptionWhisperModelWeight(config.WHISPER_WEIGHT_TYPE) is False: + self.downloadWhisperWeight(config.WHISPER_WEIGHT_TYPE) # set word filter printLog("Set Word Filter") diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 54671c62..2f892dd8 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -20,8 +20,10 @@ run_mapping = { "error_translation_engine":"/run/error_translation_engine", "word_filter":"/run/word_filter", - "download_ctranslate2":"/run/download_ctranslate2_weight", - "download_whisper":"/run/download_whisper_weight", + "download_ctranslate2_weight":"/run/download_ctranslate2_weight", + "downloaded_ctranslate2_weight":"/run/download_ctranslate2_weight", + "download_whisper_weight":"/run/download_whisper_weight", + "downloaded_whisper_weight":"/run/downloaded_whisper_weight", "selected_mic_device":"/run/selected_mic_device", "selected_speaker_device":"/run/selected_speaker_device", @@ -79,6 +81,7 @@ mapping = { "/set/data/selected_target_languages": {"status": True, "variable":controller.setSelectedTargetLanguages}, "/get/data/selected_transcription_engine": {"status": False, "variable":controller.getSelectedTranscriptionEngine}, + "/set/data/selected_transcription_engine": {"status": False, "variable":controller.setSelectedTranscriptionEngine}, "/run/send_message_box": {"status": False, "variable":controller.sendMessageBox}, "/run/typing_message_box": {"status": False, "variable":controller.typingMessageBox}, @@ -136,7 +139,7 @@ mapping = { "/get/data/selected_translation_compute_device": {"status": True, "variable":controller.getSelectedTranslationComputeDevice}, "/set/data/selected_translation_compute_device": {"status": True, "variable":controller.setSelectedTranslationComputeDevice}, - "/get/data/selectable_ctranslate2_weight_type_list": {"status": True, "variable":controller.getSelectableCtranslate2WeightTypeList}, + "/get/data/selectable_ctranslate2_weight_type_dict": {"status": True, "variable":controller.getSelectableCtranslate2WeightTypeDict}, "/get/data/ctranslate2_weight_type": {"status": True, "variable":controller.getCtranslate2WeightType}, "/set/data/ctranslate2_weight_type": {"status": True, "variable":controller.setCtranslate2WeightType}, @@ -241,7 +244,7 @@ mapping = { "/get/data/selected_transcription_compute_device": {"status": True, "variable":controller.getSelectedTranscriptionComputeDevice}, "/set/data/selected_transcription_compute_device": {"status": True, "variable":controller.setSelectedTranscriptionComputeDevice}, - "/get/data/selectable_whisper_weight_type_list": {"status": True, "variable":controller.getSelectableWhisperWeightTypeList}, + "/get/data/selectable_whisper_weight_type_dict": {"status": True, "variable":controller.getSelectableWhisperWeightTypeDict}, "/get/data/whisper_weight_type": {"status": True, "variable":controller.getWhisperWeightType}, "/set/data/whisper_weight_type": {"status": True, "variable":controller.setWhisperWeightType}, From d77733911053e2f812349771c5a63970c03b4e23 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Wed, 30 Oct 2024 00:37:41 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Model=20:?= =?UTF-8?q?=20use=5Ftranslation=5Ffeature=E3=82=92=E5=89=8A=E9=99=A4/?= =?UTF-8?q?=E3=81=9D=E3=82=8C=E3=81=AB=E4=BC=B4=E3=81=84=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 14 +---- .../models/translation/translation_utils.py | 5 +- src-python/webui_controller.py | 55 ++++--------------- src-python/webui_mainloop.py | 6 +- 4 files changed, 16 insertions(+), 64 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 009749fb..a7a8e747 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -676,17 +676,6 @@ class Config: self._USE_EXCLUDE_WORDS = value self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property - @json_serializable('USE_TRANSLATION_FEATURE') - def USE_TRANSLATION_FEATURE(self): - return self._USE_TRANSLATION_FEATURE - - @USE_TRANSLATION_FEATURE.setter - def USE_TRANSLATION_FEATURE(self, value): - if isinstance(value, bool): - self._USE_TRANSLATION_FEATURE = value - self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property @json_serializable('SELECTED_TRANSLATION_COMPUTE_DEVICE') def SELECTED_TRANSLATION_COMPUTE_DEVICE(self): @@ -1033,7 +1022,7 @@ class Config: }, }, } - self._SELECTED_TRANSCRIPTION_ENGINE = "Google" + self._SELECTED_TRANSCRIPTION_ENGINE = "Whisper" self._MULTI_LANGUAGE_TRANSLATION = False self._CONVERT_MESSAGE_TO_ROMAJI = False self._CONVERT_MESSAGE_TO_HIRAGANA = False @@ -1080,7 +1069,6 @@ class Config: "DeepL_API": None, } self._USE_EXCLUDE_WORDS = True - self._USE_TRANSLATION_FEATURE = True self._SELECTED_TRANSLATION_COMPUTE_DEVICE = {"device": "cpu", "device_index": 0, "device_name":"cpu"} self._SELECTED_TRANSCRIPTION_COMPUTE_DEVICE = {"device": "cpu", "device_index": 0, "device_name":"cpu"} self._CTRANSLATE2_WEIGHT_TYPE = "Small" diff --git a/src-python/models/translation/translation_utils.py b/src-python/models/translation/translation_utils.py index ca0eddc7..dbe06e76 100644 --- a/src-python/models/translation/translation_utils.py +++ b/src-python/models/translation/translation_utils.py @@ -39,7 +39,7 @@ def calculate_file_hash(file_path, block_size=65536): return hash_object.hexdigest() -def checkCTranslate2Weight(path, weight_type="Small"): +def checkCTranslate2Weight(root, weight_type="Small"): weight_directory_name = ctranslate2_weights[weight_type]["directory_name"] hash_data = ctranslate2_weights[weight_type]["hash"] files = [ @@ -47,6 +47,7 @@ def checkCTranslate2Weight(path, weight_type="Small"): "sentencepiece.model", "shared_vocabulary.txt" ] + path = os_path.join(root, "weights", "ctranslate2") # check already downloaded already_downloaded = False @@ -66,7 +67,7 @@ def downloadCTranslate2Weight(root, weight_type="Small", callback=None, end_call path = os_path.join(root, "weights", "ctranslate2") os_makedirs(path, exist_ok=True) - if checkCTranslate2Weight(path, weight_type) is False: + if checkCTranslate2Weight(root, weight_type) is False: try: with tempfile.TemporaryDirectory() as tmp_path: res = requests_get(url, stream=True) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 0cccba25..371dda1b 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -547,21 +547,8 @@ class Controller: @staticmethod def setSelectedTranscriptionEngine(data, *args, **kwargs) -> dict: - engine = data["engine"] - weight_type = data["weight_type"] - if engine == "Whisper" and config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT[weight_type] is False: - config.SELECTED_TRANSCRIPTION_ENGINE = "Google" - config.WHISPER_WEIGHT_TYPE = None - else: - config.SELECTED_TRANSCRIPTION_ENGINE = engine - config.WHISPER_WEIGHT_TYPE = weight_type - return { - "status":200, - "result":{ - "engine": config.SELECTED_TRANSCRIPTION_ENGINE, - "weight_type": config.WHISPER_WEIGHT_TYPE, - } - } + config.SELECTED_TRANSCRIPTION_ENGINE = str(data) + return {"status":200, "result":config.SELECTED_TRANSCRIPTION_ENGINE} @staticmethod def getMultiLanguageTranslation(*args, **kwargs) -> dict: @@ -1124,26 +1111,6 @@ class Controller: self.updateTranslationEngineAndEngineList() return {"status":200, "result":config.AUTH_KEYS["DeepL_API"]} - @staticmethod - def getUseTranslationFeature(*args, **kwargs) -> dict: - return {"status":200, "result":config.USE_TRANSLATION_FEATURE} - - @staticmethod - def setEnableUseTranslationFeature(*args, **kwargs) -> dict: - config.USE_TRANSLATION_FEATURE = True - if model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE): - def callback(): - model.changeTranslatorCTranslate2Model() - th_callback = Thread(target=callback) - th_callback.daemon = True - th_callback.start() - return {"status":200, "result":config.USE_TRANSLATION_FEATURE} - - @staticmethod - def setDisableUseTranslationFeature(*args, **kwargs) -> dict: - config.USE_TRANSLATION_FEATURE = False - return {"status":200, "result": config.USE_TRANSLATION_FEATURE} - @staticmethod def getCtranslate2WeightType(*args, **kwargs) -> dict: return {"status":200, "result":config.CTRANSLATE2_WEIGHT_TYPE} @@ -1702,26 +1669,26 @@ class Controller: auth_keys["DeepL_API"] = None config.AUTH_KEYS = auth_keys + # download CTranslate2 Model Weight + printLog("Download CTranslate2 Model Weight") + if model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE) is False: + self.downloadCtranslate2Weight(config.CTRANSLATE2_WEIGHT_TYPE) + # set Translation Engine printLog("Set Translation Engine") self.updateDownloadedCTranslate2ModelWeight() self.updateTranslationEngineAndEngineList() - # download CTranslate2 Model Weight - printLog("Download CTranslate2 Model Weight") - if config.USE_TRANSLATION_FEATURE is True and model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE) is False: - self.downloadCtranslate2Weight(config.CTRANSLATE2_WEIGHT_TYPE) + # download Whisper Model Weight + printLog("Download Whisper Model Weight") + if model.checkTranscriptionWhisperModelWeight(config.WHISPER_WEIGHT_TYPE) is False: + self.downloadWhisperWeight(config.WHISPER_WEIGHT_TYPE) # set Transcription Engine printLog("Set Transcription Engine") self.updateDownloadedWhisperModelWeight() self.updateTranscriptionEngine() - # download Whisper Model Weight - printLog("Download Whisper Model Weight") - if model.checkTranscriptionWhisperModelWeight(config.WHISPER_WEIGHT_TYPE) is False: - self.downloadWhisperWeight(config.WHISPER_WEIGHT_TYPE) - # set word filter printLog("Set Word Filter") model.addKeywords() diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 2f892dd8..baddba4c 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -21,7 +21,7 @@ run_mapping = { "word_filter":"/run/word_filter", "download_ctranslate2_weight":"/run/download_ctranslate2_weight", - "downloaded_ctranslate2_weight":"/run/download_ctranslate2_weight", + "downloaded_ctranslate2_weight":"/run/downloaded_ctranslate2_weight", "download_whisper_weight":"/run/download_whisper_weight", "downloaded_whisper_weight":"/run/downloaded_whisper_weight", @@ -131,10 +131,6 @@ mapping = { "/set/data/main_window_geometry": {"status": True, "variable":controller.setMainWindowGeometry}, # Translation - "/get/data/use_translation_feature": {"status": True, "variable":controller.getUseTranslationFeature}, - "/set/enable/use_translation_feature": {"status": True, "variable":controller.setEnableUseTranslationFeature}, - "/set/disable/use_translation_feature": {"status": True, "variable":controller.setDisableUseTranslationFeature}, - "/get/data/translation_compute_device_list": {"status": True, "variable":controller.getComputeDeviceList}, "/get/data/selected_translation_compute_device": {"status": True, "variable":controller.getSelectedTranslationComputeDevice}, "/set/data/selected_translation_compute_device": {"status": True, "variable":controller.setSelectedTranslationComputeDevice}, From 1bc87e623a14d448a909cb3b9acd42f8d65b191a Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:15:40 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20Model=20:=20Speaker?= =?UTF-8?q?=20Transcription=E5=AE=9F=E8=A1=8C=E6=99=82=E3=81=AB=E7=BF=BB?= =?UTF-8?q?=E8=A8=B3=E3=81=8C=E6=A9=9F=E8=83=BD=E3=81=97=E3=81=AA=E3=81=84?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src-python/model.py b/src-python/model.py index 7408d4f2..9c32a158 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -252,7 +252,7 @@ class Model: target_country, message ) - return [translation], success_flag + return [translation], [success_flag] def addKeywords(self): for f in config.MIC_WORD_FILTER: From 2da19efb1944c86c606310d35695832cc99027ab Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:30:31 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Model=20:?= =?UTF-8?q?=20=E3=83=96=E3=83=AD=E3=82=B0=E3=83=AC=E3=82=B9=E3=81=AE?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=82=92model.bin=E3=81=AE=E3=83=80=E3=82=A6?= =?UTF-8?q?=E3=83=B3=E3=83=AD=E3=83=BC=E3=83=89=E3=81=AE=E3=81=BF=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4/wisper=E3=81=AEweight=E3=81=AE=E8=A1=A8?= =?UTF-8?q?=E8=A8=98=E3=81=AB=E5=90=88=E3=82=8F=E3=81=9B=E3=81=A6ctanslate?= =?UTF-8?q?2=E3=81=AEweight=E3=82=82=E5=B0=8F=E6=96=87=E5=AD=97=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 6 +++--- src-python/models/transcription/transcription_whisper.py | 2 +- src-python/models/translation/translation_utils.py | 8 ++++---- src-python/webui_mainloop.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index a7a8e747..52fa5f07 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -923,8 +923,8 @@ class Config: self._TEXTBOX_UI_SCALING_RANGE = (40, 200) self._MESSAGE_BOX_RATIO_RANGE = (1, 99) self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = { - "Small": False, - "Large": False, + "small": False, + "large": False, } self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = { @@ -1071,7 +1071,7 @@ class Config: self._USE_EXCLUDE_WORDS = True self._SELECTED_TRANSLATION_COMPUTE_DEVICE = {"device": "cpu", "device_index": 0, "device_name":"cpu"} self._SELECTED_TRANSCRIPTION_COMPUTE_DEVICE = {"device": "cpu", "device_index": 0, "device_name":"cpu"} - self._CTRANSLATE2_WEIGHT_TYPE = "Small" + self._CTRANSLATE2_WEIGHT_TYPE = "small" self._WHISPER_WEIGHT_TYPE = "base" self._SEND_MESSAGE_FORMAT = "[message]" self._SEND_MESSAGE_FORMAT_WITH_T = "[message]([translation])" diff --git a/src-python/models/transcription/transcription_whisper.py b/src-python/models/transcription/transcription_whisper.py index d21df91a..049af84a 100644 --- a/src-python/models/transcription/transcription_whisper.py +++ b/src-python/models/transcription/transcription_whisper.py @@ -70,7 +70,7 @@ def downloadWhisperWeight(root, weight_type, callback=None, end_callback=None): for filename in _FILENAMES: file_path = os_path.join(path, filename) url = huggingface_hub.hf_hub_url(_MODELS[weight_type], filename) - downloadFile(url, file_path, func=callback) + downloadFile(url, file_path, func=callback if filename == "model.bin" else None) if isinstance(end_callback, Callable): end_callback() diff --git a/src-python/models/translation/translation_utils.py b/src-python/models/translation/translation_utils.py index dbe06e76..f6312884 100644 --- a/src-python/models/translation/translation_utils.py +++ b/src-python/models/translation/translation_utils.py @@ -8,7 +8,7 @@ import hashlib from utils import printLog ctranslate2_weights = { - "Small": { # M2M-100 418M-parameter model + "small": { # M2M-100 418M-parameter model "url": "https://github.com/misyaguziya/VRCT-weights/releases/download/v1.0/m2m100_418m.zip", "directory_name": "m2m100_418m", "tokenizer": "facebook/m2m100_418M", @@ -18,7 +18,7 @@ ctranslate2_weights = { "shared_vocabulary.txt": "bd440aa21b8ca3453fc792a0018a1f3fe68b3464aadddd4d16a4b72f73c86d8c", } }, - "Large": { # M2M-100 1.2B-parameter model + "large": { # M2M-100 1.2B-parameter model "url": "https://github.com/misyaguziya/VRCT-weights/releases/download/v1.0/m2m100_12b.zip", "directory_name": "m2m100_12b", "tokenizer": "facebook/m2m100_1.2b", @@ -39,7 +39,7 @@ def calculate_file_hash(file_path, block_size=65536): return hash_object.hexdigest() -def checkCTranslate2Weight(root, weight_type="Small"): +def checkCTranslate2Weight(root, weight_type="small"): weight_directory_name = ctranslate2_weights[weight_type]["directory_name"] hash_data = ctranslate2_weights[weight_type]["hash"] files = [ @@ -61,7 +61,7 @@ def checkCTranslate2Weight(root, weight_type="Small"): already_downloaded = True return already_downloaded -def downloadCTranslate2Weight(root, weight_type="Small", callback=None, end_callback=None): +def downloadCTranslate2Weight(root, weight_type="small", callback=None, end_callback=None): url = ctranslate2_weights[weight_type]["url"] filename = "weight.zip" path = os_path.join(root, "weights", "ctranslate2") diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index baddba4c..a3deffcd 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -512,7 +512,7 @@ if __name__ == "__main__": case "/set/data/ui_language": data = "ja" case "/set/data/ctranslate2_weight_type": - data = "Small" + data = "small" case "/set/data/deepl_auth_key": data = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee:fx" case "/set/data/selected_mic_host":