diff --git a/config.py b/config.py index be98a68f..669c2e64 100644 --- a/config.py +++ b/config.py @@ -94,6 +94,10 @@ class Config: def SELECTABLE_UI_LANGUAGES_DICT(self): return self._SELECTABLE_UI_LANGUAGES_DICT + @property + def SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT(self): + return self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT + @property def MAX_MIC_ENERGY_THRESHOLD(self): return self._MAX_MIC_ENERGY_THRESHOLD @@ -544,6 +548,17 @@ class Config: self._AUTH_KEYS[key] = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS) + @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 + saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + @property @json_serializable('WEIGHT_TYPE') def WEIGHT_TYPE(self): @@ -551,6 +566,7 @@ class Config: @WEIGHT_TYPE.setter def WEIGHT_TYPE(self, value): + # if isinstance(value, str) and value in self.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT: if isinstance(value, str): self._WEIGHT_TYPE = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) @@ -726,6 +742,11 @@ class Config: "ko": "한국어" # If you want to add a new language and key, please append it here. } + self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = { + # {Save json str}: {i18n_placeholder} pairs + "Small": "Small", + "Large": "Large", + } self._MAX_MIC_ENERGY_THRESHOLD = 2000 self._MAX_SPEAKER_ENERGY_THRESHOLD = 4000 @@ -799,6 +820,7 @@ class Config: self._AUTH_KEYS = { "DeepL_API": None, } + self._USE_TRANSLATION_FEATURE = True self._WEIGHT_TYPE = "m2m100_418m" self._SEND_MESSAGE_FORMAT = "[message]" self._SEND_MESSAGE_FORMAT_WITH_T = "[message]([translation])" diff --git a/controller.py b/controller.py index 73d98cae..0c6d368f 100644 --- a/controller.py +++ b/controller.py @@ -483,6 +483,20 @@ def 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.setLatestCTranslate2WeightType() + view.openCtranslate2WeightTypeWidget() + else: + view.closeCtranslate2WeightTypeWidget() + +def callbackSetCtranslate2WeightType(value): + print("callbackSetCtranslate2WeightType", value) + config.WEIGHT_TYPE = str(value) + view.updateSelectedCtranslate2WeightType(config.WEIGHT_TYPE) + def callbackSetDeeplAuthkey(value): print("callbackSetDeeplAuthkey", str(value)) if len(value) == 39: @@ -923,6 +937,8 @@ def createMainWindow(): "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_authkey": callbackSetDeeplAuthkey, # Transcription Tab (Mic) diff --git a/locales/en.yml b/locales/en.yml index 3c4febc2..31406a23 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -119,6 +119,16 @@ config_window: label: Remember The Main Window Position desc: Restore the position and size of the previous window upon startup. + use_translation_feature: + label: Use Translation Feature + desc: You can't use the translation feature while this is turned off. Instead, the VRCT startup becomes a little faster. This is for users who don't need the translation feature and only use VRCT as a chatbox and transcription tool. + + ctranslate2_weight_type: + label: Select Internal Translation Model + desc: You can choose the translation model to use for the internal translation engine. + small: "Basic model (%{capacity})" + large: "High accuracy model (%{capacity})" + deepl_auth_key: label: DeepL Auth Key diff --git a/locales/ja.yml b/locales/ja.yml index 13b0f847..2b3eb2a8 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -116,6 +116,16 @@ config_window: label: メイン画面の位置を記憶する desc: 起動時、前回の画面の位置とサイズを復元します。 + use_translation_feature: + label: 翻訳機能を使用する + desc: "オフにしている間は、翻訳機能を使わない代わり、VRCTの起動が少し速くなります。\n翻訳機能を必要とせず、VRCTをチャット送信と文字起こしツールとしてのみ使用するユーザー用です。" + + ctranslate2_weight_type: + label: オフライン翻訳のタイプ + desc: 翻訳エンジン(オフライン翻訳)で翻訳する際に、使用する翻訳モデルを選択できます。 + small: "通常モデル (%{capacity})" + large: "高精度モデル (%{capacity})" + deepl_auth_key: label: DeepL 認証キー diff --git a/view.py b/view.py index e006a056..a3c7c166 100644 --- a/view.py +++ b/view.py @@ -269,6 +269,18 @@ class View(): VAR_ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY=BooleanVar(value=config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY), # Translation Tab + VAR_LABEL_USE_TRANSLATION_FEATURE=StringVar(value=i18n.t("config_window.use_translation_feature.label")), + VAR_DESC_USE_TRANSLATION_FEATURE=StringVar(value=i18n.t("config_window.use_translation_feature.desc")), + CALLBACK_SET_USE_TRANSLATION_FEATURE=None, + VAR_USE_TRANSLATION_FEATURE=BooleanVar(value=config.USE_TRANSLATION_FEATURE), + + VAR_LABEL_CTRANSLATE2_WEIGHT_TYPE=StringVar(value=i18n.t("config_window.ctranslate2_weight_type.label")), + VAR_DESC_CTRANSLATE2_WEIGHT_TYPE=StringVar(value=i18n.t("config_window.ctranslate2_weight_type.desc")), + DICT_CTRANSLATE2_WEIGHT_TYPE=self.getSelectableCtranslate2WeightTypeDict(), + CALLBACK_SET_CTRANSLATE2_WEIGHT_TYPE=None, + VAR_CTRANSLATE2_WEIGHT_TYPE=StringVar(value=self.getSelectableCtranslate2WeightTypeDict()["Small"]), + # VAR_CTRANSLATE2_WEIGHT_TYPE=StringVar(value=self.getSelectableCtranslate2WeightTypeDict()[config.WEIGHT_TYPE]), + VAR_LABEL_DEEPL_AUTH_KEY=StringVar(value=i18n.t("config_window.deepl_auth_key.label")), VAR_DESC_DEEPL_AUTH_KEY=None, CALLBACK_SET_DEEPL_AUTH_KEY=None, @@ -578,6 +590,8 @@ class View(): # Translation Tab + self.view_variable.CALLBACK_SET_USE_TRANSLATION_FEATURE = config_window_registers.get("callback_set_use_translation_feature", None) + self.view_variable.CALLBACK_SET_CTRANSLATE2_WEIGHT_TYPE = config_window_registers.get("callback_set_ctranslate2_weight_type", None) self.view_variable.CALLBACK_SET_DEEPL_AUTHKEY = config_window_registers.get("callback_set_deepl_authkey", None) # Transcription Tab (Mic) @@ -635,6 +649,11 @@ class View(): self.setMainWindowMessageBoxRatio(config.MESSAGE_BOX_RATIO) + if config.USE_TRANSLATION_FEATURE is True: + self.openCtranslate2WeightTypeWidget() + else: + self.closeCtranslate2WeightTypeWidget() + if config.CHOICE_MIC_HOST == "NoHost": self.view_variable.VAR_MIC_HOST.set("No Mic Host Detected") @@ -852,6 +871,13 @@ class View(): def getPreUiScaling(self): return self.restart_required_configs_pre_data.ui_scaling + @staticmethod + def getSelectableCtranslate2WeightTypeDict(): + return { + config._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT["Small"]: i18n.t("config_window.ctranslate2_weight_type.small", capacity="418MB"), + config._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT["Large"]: i18n.t("config_window.ctranslate2_weight_type.large", capacity="1.2GB"), + } + # Open Webpage Functions def openWebPage_Booth(self): self.openWebPage(config.BOOTH_URL) @@ -966,6 +992,22 @@ class View(): vrct_gui.config_window.setting_box_compact_mode_switch_box.configure(state="normal") + def updateSelectedCtranslate2WeightType(self, selected_weight_type:str): + self.view_variable.VAR_CTRANSLATE2_WEIGHT_TYPE.set(self.getSelectableCtranslate2WeightTypeDict()[selected_weight_type]) + + def setLatestCTranslate2WeightType(self): + selected_weight_type = self.getSelectableCtranslate2WeightTypeDict()[config.WEIGHT_TYPE] + self.view_variable.VAR_CTRANSLATE2_WEIGHT_TYPE.set(selected_weight_type) + + + def openCtranslate2WeightTypeWidget(self): + vrct_gui.config_window.sb__use_translation_feature.grid(pady=0) + vrct_gui.config_window.sb__ctranslate2_weight_type.grid() + + def closeCtranslate2WeightTypeWidget(self): + vrct_gui.config_window.sb__use_translation_feature.grid(pady=(0,1)) + vrct_gui.config_window.sb__ctranslate2_weight_type.grid_remove() + def openMicEnergyThresholdWidget(self): self.view_variable.VAR_LABEL_MIC_DYNAMIC_ENERGY_THRESHOLD.set(i18n.t("config_window.mic_dynamic_energy_threshold.label_for_manual")) diff --git a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_translation/createSettingBox_Translation.py b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_translation/createSettingBox_Translation.py index d2975d0d..574856fe 100644 --- a/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_translation/createSettingBox_Translation.py +++ b/vrct_gui/config_window/widgets/createSideMenuAndSettingsBoxContainers/setting_box_containers/setting_box_translation/createSettingBox_Translation.py @@ -4,14 +4,43 @@ from .._SettingBoxGenerator import _SettingBoxGenerator def createSettingBox_Translation(setting_box_wrapper, config_window, settings, view_variable): sbg = _SettingBoxGenerator(setting_box_wrapper, config_window, settings, view_variable) + createSettingBoxSwitch = sbg.createSettingBoxSwitch + createSettingBoxDropdownMenu = sbg.createSettingBoxDropdownMenu createSettingBoxEntry = sbg.createSettingBoxEntry + def switch_use_translation_feature_callback(switch_widget): + callFunctionIfCallable(view_variable.CALLBACK_SET_USE_TRANSLATION_FEATURE, switch_widget.get()) + + def optionmenu_ctranslate2_weight_type_callback(value): + callFunctionIfCallable(view_variable.CALLBACK_SET_CTRANSLATE2_WEIGHT_TYPE, value) def deepl_authkey_callback(value): callFunctionIfCallable(view_variable.CALLBACK_SET_DEEPL_AUTHKEY, value) row=0 + config_window.sb__use_translation_feature = createSettingBoxSwitch( + for_var_label_text=view_variable.VAR_LABEL_USE_TRANSLATION_FEATURE, + for_var_desc_text=view_variable.VAR_DESC_USE_TRANSLATION_FEATURE, + switch_attr_name="sb__switch_use_translation_feature", + command=lambda: switch_use_translation_feature_callback(config_window.sb__switch_use_translation_feature), + variable=view_variable.VAR_USE_TRANSLATION_FEATURE + ) + config_window.sb__use_translation_feature.grid(row=row, pady=0) + row+=1 + + config_window.sb__ctranslate2_weight_type = createSettingBoxDropdownMenu( + for_var_label_text=view_variable.VAR_LABEL_CTRANSLATE2_WEIGHT_TYPE, + for_var_desc_text=view_variable.VAR_DESC_CTRANSLATE2_WEIGHT_TYPE, + optionmenu_attr_name="sb__optionmenu_ctranslate2_weight_type", + dropdown_menu_values=view_variable.DICT_CTRANSLATE2_WEIGHT_TYPE, + command=lambda value: optionmenu_ctranslate2_weight_type_callback(value), + variable=view_variable.VAR_CTRANSLATE2_WEIGHT_TYPE, + ) + config_window.sb__ctranslate2_weight_type.grid(row=row) + row+=1 + + config_window.sb__deepl_authkey = createSettingBoxEntry( for_var_label_text=view_variable.VAR_LABEL_DEEPL_AUTH_KEY, for_var_desc_text=view_variable.VAR_DESC_DEEPL_AUTH_KEY,