From 401bc7f504705937b15082a14039c14946da2173 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 6 Jul 2023 07:05:43 +0900 Subject: [PATCH 01/54] add word filter --- VRCT.py | 18 ++++++++++++++++++ window_config.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/VRCT.py b/VRCT.py index 13d9840e..0563b5ca 100644 --- a/VRCT.py +++ b/VRCT.py @@ -4,6 +4,7 @@ import queue import tkinter as tk import customtkinter from PIL import Image +from flashtext import KeywordProcessor import utils import osc_tools @@ -21,9 +22,11 @@ class App(customtkinter.CTk): # init instance self.translator = translation.Translator() + self.keyword_processor = KeywordProcessor() # init config self.PATH_CONFIG = "./config.json" + ## main window self.ENABLE_TRANSLATION = False self.ENABLE_TRANSCRIPTION_SEND = False @@ -48,6 +51,7 @@ class App(customtkinter.CTk): self.INPUT_MIC_RECORD_TIMEOUT = 3 self.INPUT_MIC_PHRASE_TIMEOUT = 3 self.INPUT_MIC_MAX_PHRASES = 10 + self.INPUT_MIC_WORD_FILTER = [] ## Transcription Receive self.CHOICE_SPEAKER_DEVICE = audio_utils.get_default_output_device()["name"] self.INPUT_SPEAKER_VOICE_LANGUAGE = list(languages.transcription_lang.keys())[1] @@ -139,6 +143,9 @@ class App(customtkinter.CTk): if "INPUT_MIC_MAX_PHRASES" in config.keys(): if type(config["INPUT_MIC_MAX_PHRASES"]) is int: self.INPUT_MIC_MAX_PHRASES = config["INPUT_MIC_MAX_PHRASES"] + if "INPUT_MIC_WORD_FILTER" in config.keys(): + if type(config["INPUT_MIC_WORD_FILTER"]) is list: + self.INPUT_MIC_WORD_FILTER = config["INPUT_MIC_WORD_FILTER"] if "CHOICE_SPEAKER_DEVICE" in config.keys(): if config["CHOICE_SPEAKER_DEVICE"] in [device["name"] for device in audio_utils.get_output_device_list()]: @@ -201,6 +208,7 @@ class App(customtkinter.CTk): "INPUT_MIC_RECORD_TIMEOUT": self.INPUT_MIC_RECORD_TIMEOUT, "INPUT_MIC_PHRASE_TIMEOUT": self.INPUT_MIC_PHRASE_TIMEOUT, "INPUT_MIC_MAX_PHRASES": self.INPUT_MIC_MAX_PHRASES, + "INPUT_MIC_WORD_FILTER": self.INPUT_MIC_WORD_FILTER, "CHOICE_SPEAKER_DEVICE": self.CHOICE_SPEAKER_DEVICE, "INPUT_SPEAKER_VOICE_LANGUAGE": self.INPUT_SPEAKER_VOICE_LANGUAGE, "INPUT_SPEAKER_ENERGY_THRESHOLD": self.INPUT_SPEAKER_ENERGY_THRESHOLD, @@ -392,6 +400,10 @@ class App(customtkinter.CTk): else: self.checkbox_foreground.deselect() + ## set word filter + for f in self.INPUT_MIC_WORD_FILTER: + self.keyword_processor.add_keyword(f) + ## set bind entry message box self.entry_message_box.bind("", self.entry_message_box_press_key_enter) self.entry_message_box.bind("", self.entry_message_box_press_key_any) @@ -459,6 +471,12 @@ class App(customtkinter.CTk): self.mic_transcriber.transcribe_audio_queue(self.mic_audio_queue) message = self.mic_transcriber.get_transcript() if len(message) > 0: + # word filter + if len(self.keyword_processor.extract_keywords(message)) != 0: + utils.print_textbox(self.textbox_message_log, f"Detect WordFilter :{message}", "INFO") + utils.print_textbox(self.textbox_message_system_log, f"Detect WordFilter :{message}", "INFO") + return + # translate if self.checkbox_translation.get() is False: voice_message = f"{message}" diff --git a/window_config.py b/window_config.py index adbe90b9..2919b18c 100644 --- a/window_config.py +++ b/window_config.py @@ -1,6 +1,8 @@ import os import tkinter as tk import customtkinter +from flashtext import KeywordProcessor + import utils import audio_utils import languages @@ -346,6 +348,23 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_max_phrases.bind("", self.entry_input_mic_max_phrases_callback) + ## entry input mic word filter + row +=1 + self.label_input_mic_word_filter = customtkinter.CTkLabel( + self.tabview_config.tab("Transcription"), + text="Input Mic Word Filter:", + fg_color="transparent", + font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_word_filter.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_mic_word_filter = customtkinter.CTkEntry( + self.tabview_config.tab("Transcription"), + textvariable=customtkinter.StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), + font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_word_filter.bind("", self.entry_input_mic_word_filters_callback) + ## optionmenu input speaker device row +=1 self.label_input_speaker_device = customtkinter.CTkLabel( @@ -613,6 +632,8 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.entry_input_mic_phrase_timeout.configure(font=customtkinter.CTkFont(family=choice)) self.label_input_mic_max_phrases.configure(font=customtkinter.CTkFont(family=choice)) self.entry_input_mic_max_phrases.configure(font=customtkinter.CTkFont(family=choice)) + self.label_input_mic_word_filter.configure(font=customtkinter.CTkFont(family=choice)) + self.entry_input_mic_word_filter.configure(font=customtkinter.CTkFont(family=choice)) self.label_input_speaker_device.configure(font=customtkinter.CTkFont(family=choice)) self.optionmenu_input_speaker_device.configure(font=customtkinter.CTkFont(family=choice)) self.optionmenu_input_speaker_device._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) @@ -734,6 +755,13 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.parent.INPUT_MIC_MAX_PHRASES = int(self.entry_input_mic_max_phrases.get()) utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_MAX_PHRASES", self.parent.INPUT_MIC_MAX_PHRASES) + def entry_input_mic_word_filters_callback(self, event): + self.parent.INPUT_MIC_WORD_FILTER = self.entry_input_mic_word_filter.get().split(",") + self.parent.keyword_processor = KeywordProcessor() + for f in self.parent.INPUT_MIC_WORD_FILTER: + self.parent.keyword_processor.add_keyword(f) + utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_WORD_FILTER", self.parent.INPUT_MIC_WORD_FILTER) + def optionmenu_input_speaker_device_callback(self, choice): self.parent.CHOICE_SPEAKER_DEVICE = choice utils.save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) From a5c509033547c0e8a9bc7a9f850a2c513e968a71 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 6 Jul 2023 09:20:10 +0900 Subject: [PATCH 02/54] optimization same code --- VRCT.py | 240 ++++++++--------- audio_recorder.py | 14 +- audio_transcriber.py | 21 +- audio_utils.py | 18 +- translation.py | 22 +- utils.py | 16 +- window_config.py | 586 +++++++++++++++++++++--------------------- window_information.py | 8 +- 8 files changed, 464 insertions(+), 461 deletions(-) diff --git a/VRCT.py b/VRCT.py index 0563b5ca..ae101678 100644 --- a/VRCT.py +++ b/VRCT.py @@ -1,27 +1,29 @@ -import os -import json -import queue +from os import path as os_path +from json import load as json_load +from json import dump as json_dump +from queue import Queue import tkinter as tk import customtkinter -from PIL import Image +from customtkinter import CTk, CTkFrame, CTkCheckBox, CTkFont, CTkButton, CTkImage, CTkTabview, CTkTextbox, CTkEntry +from PIL.Image import open as Image_open from flashtext import KeywordProcessor -import utils -import osc_tools -import window_config -import window_information -import languages -import audio_utils -import audio_recorder -import audio_transcriber -import translation +from utils import save_json, print_textbox, thread_fnc +from osc_tools import send_typing, send_message +from window_config import ToplevelWindowConfig +from window_information import ToplevelWindowInformation +from languages import transcription_lang, translators, translation_lang +from audio_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device +from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder +from audio_transcriber import AudioTranscriber +from translation import Translator -class App(customtkinter.CTk): +class App(CTk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # init instance - self.translator = translation.Translator() + self.translator = Translator() self.keyword_processor = KeywordProcessor() # init config @@ -38,14 +40,14 @@ class App(customtkinter.CTk): self.UI_SCALING = "100%" self.FONT_FAMILY = "Yu Gothic UI" ## Translation - self.CHOICE_TRANSLATOR = languages.translators[0] - self.INPUT_SOURCE_LANG = list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys())[0] - self.INPUT_TARGET_LANG = list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys())[1] - self.OUTPUT_SOURCE_LANG = list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys())[1] - self.OUTPUT_TARGET_LANG = list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys())[0] + self.CHOICE_TRANSLATOR = translators[0] + self.INPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[0] + self.INPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[1] + self.OUTPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[1] + self.OUTPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[0] ## Transcription Send - self.CHOICE_MIC_DEVICE = audio_utils.get_default_input_device()["name"] - self.INPUT_MIC_VOICE_LANGUAGE = list(languages.transcription_lang.keys())[0] + self.CHOICE_MIC_DEVICE = get_default_input_device()["name"] + self.INPUT_MIC_VOICE_LANGUAGE = list(transcription_lang.keys())[0] self.INPUT_MIC_ENERGY_THRESHOLD = 300 self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = True self.INPUT_MIC_RECORD_TIMEOUT = 3 @@ -53,8 +55,8 @@ class App(customtkinter.CTk): self.INPUT_MIC_MAX_PHRASES = 10 self.INPUT_MIC_WORD_FILTER = [] ## Transcription Receive - self.CHOICE_SPEAKER_DEVICE = audio_utils.get_default_output_device()["name"] - self.INPUT_SPEAKER_VOICE_LANGUAGE = list(languages.transcription_lang.keys())[1] + self.CHOICE_SPEAKER_DEVICE = get_default_output_device()["name"] + self.INPUT_SPEAKER_VOICE_LANGUAGE = list(transcription_lang.keys())[1] self.INPUT_SPEAKER_ENERGY_THRESHOLD = 300 self.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = True self.INPUT_SPEAKER_RECORD_TIMEOUT = 3 @@ -72,9 +74,9 @@ class App(customtkinter.CTk): self.MESSAGE_FORMAT = "[message]([translation])" # load config - if os.path.isfile(self.PATH_CONFIG) is not False: + if os_path.isfile(self.PATH_CONFIG) is not False: with open(self.PATH_CONFIG, 'r') as fp: - config = json.load(fp) + config = json_load(fp) # main window if "ENABLE_TRANSLATION" in config.keys(): if type(config["ENABLE_TRANSLATION"]) is bool: @@ -109,24 +111,24 @@ class App(customtkinter.CTk): if config["CHOICE_TRANSLATOR"] in list(self.translator.translator_status.keys()): self.CHOICE_TRANSLATOR = config["CHOICE_TRANSLATOR"] if "INPUT_SOURCE_LANG" in config.keys(): - if config["INPUT_SOURCE_LANG"] in list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys()): + if config["INPUT_SOURCE_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR].keys()): self.INPUT_SOURCE_LANG = config["INPUT_SOURCE_LANG"] if "INPUT_TARGET_LANG" in config.keys(): - if config["INPUT_SOURCE_LANG"] in list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys()): + if config["INPUT_SOURCE_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR].keys()): self.INPUT_TARGET_LANG = config["INPUT_TARGET_LANG"] if "OUTPUT_SOURCE_LANG" in config.keys(): - if config["INPUT_SOURCE_LANG"] in list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys()): + if config["INPUT_SOURCE_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR].keys()): self.OUTPUT_SOURCE_LANG = config["OUTPUT_SOURCE_LANG"] if "OUTPUT_TARGET_LANG" in config.keys(): - if config["INPUT_SOURCE_LANG"] in list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys()): + if config["INPUT_SOURCE_LANG"] in list(translation_lang[self.CHOICE_TRANSLATOR].keys()): self.OUTPUT_TARGET_LANG = config["OUTPUT_TARGET_LANG"] # Transcription if "CHOICE_MIC_DEVICE" in config.keys(): - if config["CHOICE_MIC_DEVICE"] in [device["name"] for device in audio_utils.get_input_device_list()]: + if config["CHOICE_MIC_DEVICE"] in [device["name"] for device in get_input_device_list()]: self.CHOICE_MIC_DEVICE = config["CHOICE_MIC_DEVICE"] if "INPUT_MIC_VOICE_LANGUAGE" in config.keys(): - if config["INPUT_MIC_VOICE_LANGUAGE"] in list(languages.transcription_lang.keys()): + if config["INPUT_MIC_VOICE_LANGUAGE"] in list(transcription_lang.keys()): self.INPUT_MIC_VOICE_LANGUAGE = config["INPUT_MIC_VOICE_LANGUAGE"] if "INPUT_MIC_ENERGY_THRESHOLD" in config.keys(): if type(config["INPUT_MIC_ENERGY_THRESHOLD"]) is int: @@ -148,10 +150,10 @@ class App(customtkinter.CTk): self.INPUT_MIC_WORD_FILTER = config["INPUT_MIC_WORD_FILTER"] if "CHOICE_SPEAKER_DEVICE" in config.keys(): - if config["CHOICE_SPEAKER_DEVICE"] in [device["name"] for device in audio_utils.get_output_device_list()]: + if config["CHOICE_SPEAKER_DEVICE"] in [device["name"] for device in get_output_device_list()]: self.CHOICE_SPEAKER_DEVICE = config["CHOICE_SPEAKER_DEVICE"] if "INPUT_SPEAKER_VOICE_LANGUAGE" in config.keys(): - if config["INPUT_SPEAKER_VOICE_LANGUAGE"] in list(languages.transcription_lang.keys()): + if config["INPUT_SPEAKER_VOICE_LANGUAGE"] in list(transcription_lang.keys()): self.INPUT_SPEAKER_VOICE_LANGUAGE = config["INPUT_SPEAKER_VOICE_LANGUAGE"] if "INPUT_SPEAKER_ENERGY_THRESHOLD" in config.keys(): if type(config["INPUT_SPEAKER_ENERGY_THRESHOLD"]) is int: @@ -221,14 +223,14 @@ class App(customtkinter.CTk): "AUTH_KEYS": self.AUTH_KEYS, "MESSAGE_FORMAT": self.MESSAGE_FORMAT, } - json.dump(config, fp, indent=4) + json_dump(config, fp, indent=4) ## set UI theme customtkinter.set_appearance_mode(self.APPEARANCE_THEME) customtkinter.set_default_color_theme("blue") # init main window - self.iconbitmap(os.path.join(os.path.dirname(__file__), "img", "app.ico")) + self.iconbitmap(os_path.join(os_path.dirname(__file__), "img", "app.ico")) self.title("VRCT") self.geometry(f"{400}x{175}") self.minsize(400, 175) @@ -236,84 +238,84 @@ class App(customtkinter.CTk): self.grid_rowconfigure(0, weight=1) # add sidebar left - self.sidebar_frame = customtkinter.CTkFrame(self, corner_radius=0) + self.sidebar_frame = CTkFrame(self, corner_radius=0) self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsw") self.sidebar_frame.grid_rowconfigure(5, weight=1) # add checkbox translation - self.checkbox_translation = customtkinter.CTkCheckBox( + self.checkbox_translation = CTkCheckBox( self.sidebar_frame, text="translation", onvalue=True, offvalue=False, command=self.checkbox_translation_callback, - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.checkbox_translation.grid(row=0, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") # add checkbox transcription send - self.checkbox_transcription_send = customtkinter.CTkCheckBox( + self.checkbox_transcription_send = CTkCheckBox( self.sidebar_frame, text="voice2chatbox", onvalue=True, offvalue=False, command=self.checkbox_transcription_send_callback, - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.checkbox_transcription_send.grid(row=1, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") # add checkbox transcription receive - self.checkbox_transcription_receive = customtkinter.CTkCheckBox( + self.checkbox_transcription_receive = CTkCheckBox( self.sidebar_frame, text="speaker2log", onvalue=True, offvalue=False, command=self.checkbox_transcription_receive_callback, - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.checkbox_transcription_receive.grid(row=2, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") # add checkbox foreground - self.checkbox_foreground = customtkinter.CTkCheckBox( + self.checkbox_foreground = CTkCheckBox( self.sidebar_frame, text="foreground", onvalue=True, offvalue=False, command=self.checkbox_foreground_callback, - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.checkbox_foreground.grid(row=3, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") # add button information - self.button_information = customtkinter.CTkButton( + self.button_information = CTkButton( self.sidebar_frame, text="", width=25, command=self.button_information_callback, - image=customtkinter.CTkImage(Image.open(os.path.join(os.path.dirname(__file__), "img", "info-icon-white.png"))) + image=CTkImage(Image_open(os_path.join(os_path.dirname(__file__), "img", "info-icon-white.png"))) ) self.button_information.grid(row=5, column=0, padx=(10, 5), pady=(5, 5), sticky="wse") self.information_window = None # add button config - self.button_config = customtkinter.CTkButton( + self.button_config = CTkButton( self.sidebar_frame, text="", width=25, command=self.button_config_callback, - image=customtkinter.CTkImage(Image.open(os.path.join(os.path.dirname(__file__), "img", "config-icon-white.png"))) + image=CTkImage(Image_open(os_path.join(os_path.dirname(__file__), "img", "config-icon-white.png"))) ) self.button_config.grid(row=5, column=1, padx=(5, 10), pady=(5, 5), sticky="wse") self.config_window = None # add tabview textbox - self.tabview_logs = customtkinter.CTkTabview(master=self) + self.tabview_logs = CTkTabview(master=self) self.tabview_logs.add("log") self.tabview_logs.add("send") self.tabview_logs.add("receive") self.tabview_logs.add("system") self.tabview_logs.grid(row=0, column=1, padx=0, pady=0, sticky="nsew") - self.tabview_logs._segmented_button.configure(font=customtkinter.CTkFont(family=self.FONT_FAMILY)) + self.tabview_logs._segmented_button.configure(font=CTkFont(family=self.FONT_FAMILY)) self.tabview_logs._segmented_button.grid(sticky="W") self.tabview_logs.tab("log").grid_rowconfigure(0, weight=1) self.tabview_logs.tab("log").grid_columnconfigure(0, weight=1) @@ -326,42 +328,42 @@ class App(customtkinter.CTk): self.tabview_logs.configure(fg_color="transparent") # add textbox message log - self.textbox_message_log = customtkinter.CTkTextbox( + self.textbox_message_log = CTkTextbox( self.tabview_logs.tab("log"), - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.textbox_message_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_log.configure(state='disabled') # add textbox message send log - self.textbox_message_send_log = customtkinter.CTkTextbox( + self.textbox_message_send_log = CTkTextbox( self.tabview_logs.tab("send"), - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.textbox_message_send_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_send_log.configure(state='disabled') # add textbox message receive log - self.textbox_message_receive_log = customtkinter.CTkTextbox( + self.textbox_message_receive_log = CTkTextbox( self.tabview_logs.tab("receive"), - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.textbox_message_receive_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_receive_log.configure(state='disabled') # add textbox message system log - self.textbox_message_system_log = customtkinter.CTkTextbox( + self.textbox_message_system_log = CTkTextbox( self.tabview_logs.tab("system"), - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.textbox_message_system_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") self.textbox_message_system_log.configure(state='disabled') # add entry message box - self.entry_message_box = customtkinter.CTkEntry( + self.entry_message_box = CTkEntry( self, placeholder_text="message", - font=customtkinter.CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY) ) self.entry_message_box.grid(row=1, column=1, columnspan=2, padx=5, pady=(5, 10), sticky="nsew") @@ -369,8 +371,8 @@ class App(customtkinter.CTk): ## set translator if self.translator.authentication(self.CHOICE_TRANSLATOR, self.AUTH_KEYS[self.CHOICE_TRANSLATOR]) is False: # error update Auth key - utils.print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") - utils.print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") ## set checkbox enable translation if self.ENABLE_TRANSLATION: @@ -421,7 +423,7 @@ class App(customtkinter.CTk): def button_config_callback(self): if self.config_window is None or not self.config_window.winfo_exists(): - self.config_window = window_config.ToplevelWindowConfig(self) + self.config_window = ToplevelWindowConfig(self) self.checkbox_translation.configure(state="disabled") self.checkbox_transcription_send.configure(state="disabled") self.checkbox_transcription_receive.configure(state="disabled") @@ -429,41 +431,41 @@ class App(customtkinter.CTk): def button_information_callback(self): if self.information_window is None or not self.information_window.winfo_exists(): - self.information_window = window_information.ToplevelWindowInformation(self) + self.information_window = ToplevelWindowInformation(self) self.information_window.focus() def checkbox_translation_callback(self): self.ENABLE_TRANSLATION = self.checkbox_translation.get() if self.ENABLE_TRANSLATION: self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - utils.print_textbox(self.textbox_message_log, "Start translation", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Start translation", "INFO") + print_textbox(self.textbox_message_log, "Start translation", "INFO") + print_textbox(self.textbox_message_system_log, "Start translation", "INFO") else: if ((self.checkbox_translation.get() is False) and (self.checkbox_transcription_send.get() is False) and (self.checkbox_transcription_receive.get() is False)): self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) - utils.print_textbox(self.textbox_message_log, "Stop translation", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Stop translation", "INFO") - utils.save_json(self.PATH_CONFIG, "ENABLE_TRANSLATION", self.ENABLE_TRANSLATION) + print_textbox(self.textbox_message_log, "Stop translation", "INFO") + print_textbox(self.textbox_message_system_log, "Stop translation", "INFO") + save_json(self.PATH_CONFIG, "ENABLE_TRANSLATION", self.ENABLE_TRANSLATION) def checkbox_transcription_send_callback(self): self.ENABLE_TRANSCRIPTION_SEND = self.checkbox_transcription_send.get() if self.ENABLE_TRANSCRIPTION_SEND is True: self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.mic_audio_queue = queue.Queue() - mic_device = [device for device in audio_utils.get_input_device_list() if device["name"] == self.CHOICE_MIC_DEVICE][0] - self.mic_audio_recorder = audio_recorder.SelectedMicRecorder( + self.mic_audio_queue = Queue() + mic_device = [device for device in get_input_device_list() if device["name"] == self.CHOICE_MIC_DEVICE][0] + self.mic_audio_recorder = SelectedMicRecorder( mic_device, self.INPUT_MIC_ENERGY_THRESHOLD, self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, self.INPUT_MIC_RECORD_TIMEOUT, ) self.mic_audio_recorder.record_into_queue(self.mic_audio_queue) - self.mic_transcriber = audio_transcriber.AudioTranscriber( + self.mic_transcriber = AudioTranscriber( speaker=False, source=self.mic_audio_recorder.source, - language=languages.transcription_lang[self.INPUT_MIC_VOICE_LANGUAGE], + language=transcription_lang[self.INPUT_MIC_VOICE_LANGUAGE], phrase_timeout=self.INPUT_MIC_PHRASE_TIMEOUT, max_phrases=self.INPUT_MIC_MAX_PHRASES, ) @@ -473,16 +475,16 @@ class App(customtkinter.CTk): if len(message) > 0: # word filter if len(self.keyword_processor.extract_keywords(message)) != 0: - utils.print_textbox(self.textbox_message_log, f"Detect WordFilter :{message}", "INFO") - utils.print_textbox(self.textbox_message_system_log, f"Detect WordFilter :{message}", "INFO") + print_textbox(self.textbox_message_log, f"Detect WordFilter :{message}", "INFO") + print_textbox(self.textbox_message_system_log, f"Detect WordFilter :{message}", "INFO") return # translate if self.checkbox_translation.get() is False: voice_message = f"{message}" elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: - utils.print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") - utils.print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") voice_message = f"{message}" else: result = self.translator.translate( @@ -495,49 +497,49 @@ class App(customtkinter.CTk): if self.checkbox_transcription_send.get() is True: # send OSC message - osc_tools.send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) # update textbox message log - utils.print_textbox(self.textbox_message_log, f"{voice_message}", "SEND") - utils.print_textbox(self.textbox_message_send_log, f"{voice_message}", "SEND") + print_textbox(self.textbox_message_log, f"{voice_message}", "SEND") + print_textbox(self.textbox_message_send_log, f"{voice_message}", "SEND") - self.mic_print_transcript = utils.thread_fnc(mic_transcript_to_chatbox) + self.mic_print_transcript = thread_fnc(mic_transcript_to_chatbox) self.mic_print_transcript.daemon = True self.mic_print_transcript.start() - utils.print_textbox(self.textbox_message_log, "Start voice2chatbox", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Start voice2chatbox", "INFO") + print_textbox(self.textbox_message_log, "Start voice2chatbox", "INFO") + print_textbox(self.textbox_message_system_log, "Start voice2chatbox", "INFO") else: if ((self.checkbox_translation.get() is False) and (self.checkbox_transcription_send.get() is False) and (self.checkbox_transcription_receive.get() is False)): self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) - if isinstance(self.mic_print_transcript, utils.thread_fnc): + if isinstance(self.mic_print_transcript, thread_fnc): self.mic_print_transcript.stop() if self.mic_audio_recorder.stop != None: self.mic_audio_recorder.stop() self.mic_audio_recorder.stop = None - utils.print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO") - utils.save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_SEND", self.ENABLE_TRANSCRIPTION_SEND) + print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO") + print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO") + save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_SEND", self.ENABLE_TRANSCRIPTION_SEND) def checkbox_transcription_receive_callback(self): self.ENABLE_TRANSCRIPTION_RECEIVE = self.checkbox_transcription_receive.get() if self.ENABLE_TRANSCRIPTION_RECEIVE is True: self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.spk_audio_queue = queue.Queue() - spk_device = [device for device in audio_utils.get_output_device_list() if device["name"] == self.CHOICE_SPEAKER_DEVICE][0] - self.spk_audio_recorder = audio_recorder.SelectedSpeakerRecorder( + self.spk_audio_queue = Queue() + spk_device = [device for device in get_output_device_list() if device["name"] == self.CHOICE_SPEAKER_DEVICE][0] + self.spk_audio_recorder = SelectedSpeakerRecorder( spk_device, self.INPUT_SPEAKER_ENERGY_THRESHOLD, self.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD, self.INPUT_SPEAKER_RECORD_TIMEOUT, ) self.spk_audio_recorder.record_into_queue(self.spk_audio_queue) - self.spk_transcriber = audio_transcriber.AudioTranscriber( + self.spk_transcriber = AudioTranscriber( speaker=True, source=self.spk_audio_recorder.source, - language=languages.transcription_lang[self.INPUT_SPEAKER_VOICE_LANGUAGE], + language=transcription_lang[self.INPUT_SPEAKER_VOICE_LANGUAGE], phrase_timeout=self.INPUT_SPEAKER_PHRASE_TIMEOUT, max_phrases=self.INPUT_SPEAKER_MAX_PHRASES, ) @@ -550,8 +552,8 @@ class App(customtkinter.CTk): if self.checkbox_translation.get() is False: voice_message = f"{message}" elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: - utils.print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") - utils.print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") voice_message = f"{message}" else: result = self.translator.translate( @@ -562,47 +564,47 @@ class App(customtkinter.CTk): ) voice_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) # send OSC message - # osc_tools.send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + # send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) if self.checkbox_transcription_receive.get() is True: # update textbox message receive log - utils.print_textbox(self.textbox_message_log, f"{voice_message}", "RECEIVE") - utils.print_textbox(self.textbox_message_receive_log, f"{voice_message}", "RECEIVE") + print_textbox(self.textbox_message_log, f"{voice_message}", "RECEIVE") + print_textbox(self.textbox_message_receive_log, f"{voice_message}", "RECEIVE") - self.spk_print_transcript = utils.thread_fnc(spk_transcript_to_textbox) + self.spk_print_transcript = thread_fnc(spk_transcript_to_textbox) self.spk_print_transcript.daemon = True self.spk_print_transcript.start() - utils.print_textbox(self.textbox_message_log, "Start speaker2log", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Start speaker2log", "INFO") + print_textbox(self.textbox_message_log, "Start speaker2log", "INFO") + print_textbox(self.textbox_message_system_log, "Start speaker2log", "INFO") else: if ((self.checkbox_translation.get() is False) and (self.checkbox_transcription_send.get() is False) and (self.checkbox_transcription_receive.get() is False)): self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) - if isinstance(self.spk_print_transcript, utils.thread_fnc): + if isinstance(self.spk_print_transcript, thread_fnc): self.spk_print_transcript.stop() if self.spk_audio_recorder.stop != None: self.spk_audio_recorder.stop() self.spk_audio_recorder.stop = None - utils.print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO") - utils.save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_RECEIVE", self.ENABLE_TRANSCRIPTION_RECEIVE) + print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO") + print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO") + save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_RECEIVE", self.ENABLE_TRANSCRIPTION_RECEIVE) def checkbox_foreground_callback(self): self.ENABLE_FOREGROUND = self.checkbox_foreground.get() if self.ENABLE_FOREGROUND: self.attributes("-topmost", True) - utils.print_textbox(self.textbox_message_log, "Start foreground", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Start foreground", "INFO") + print_textbox(self.textbox_message_log, "Start foreground", "INFO") + print_textbox(self.textbox_message_system_log, "Start foreground", "INFO") else: self.attributes("-topmost", False) - utils.print_textbox(self.textbox_message_log, "Stop foreground", "INFO") - utils.print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO") - utils.save_json(self.PATH_CONFIG, "ENABLE_FOREGROUND", self.ENABLE_FOREGROUND) + print_textbox(self.textbox_message_log, "Stop foreground", "INFO") + print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO") + save_json(self.PATH_CONFIG, "ENABLE_FOREGROUND", self.ENABLE_FOREGROUND) def entry_message_box_press_key_enter(self, event): # send OSC typing - osc_tools.send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) if self.ENABLE_FOREGROUND: self.attributes("-topmost", True) @@ -613,8 +615,8 @@ class App(customtkinter.CTk): if self.checkbox_translation.get() is False: chat_message = f"{message}" elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: - utils.print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") - utils.print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") chat_message = f"{message}" else: result = self.translator.translate( @@ -626,24 +628,24 @@ class App(customtkinter.CTk): chat_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) # send OSC message - osc_tools.send_message(chat_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_message(chat_message, self.OSC_IP_ADDRESS, self.OSC_PORT) # update textbox message log - utils.print_textbox(self.textbox_message_log, f"{chat_message}", "SEND") - utils.print_textbox(self.textbox_message_send_log, f"{chat_message}", "SEND") + print_textbox(self.textbox_message_log, f"{chat_message}", "SEND") + print_textbox(self.textbox_message_send_log, f"{chat_message}", "SEND") # delete message in entry message box # self.entry_message_box.delete(0, customtkinter.END) def entry_message_box_press_key_any(self, event): # send OSC typing - osc_tools.send_typing(True, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_typing(True, self.OSC_IP_ADDRESS, self.OSC_PORT) if self.ENABLE_FOREGROUND: self.attributes("-topmost", False) def entry_message_box_leave(self, event): # send OSC typing - osc_tools.send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) + send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) if self.ENABLE_FOREGROUND: self.attributes("-topmost", True) diff --git a/audio_recorder.py b/audio_recorder.py index 34f990e5..0b146677 100644 --- a/audio_recorder.py +++ b/audio_recorder.py @@ -1,10 +1,10 @@ -import speech_recognition as sr -import pyaudiowpatch as pyaudio +from speech_recognition import Recognizer, Microphone +from pyaudiowpatch import get_sample_size, paInt16 from datetime import datetime class BaseRecorder: def __init__(self, source, energy_threshold, dynamic_energy_threshold, record_timeout): - self.recorder = sr.Recognizer() + self.recorder = Recognizer() self.recorder.energy_threshold = energy_threshold self.recorder.dynamic_energy_threshold = dynamic_energy_threshold self.record_timeout = record_timeout @@ -20,14 +20,14 @@ class BaseRecorder: self.recorder.adjust_for_ambient_noise(self.source) def record_into_queue(self, audio_queue): - def record_callback(_, audio:sr.AudioData) -> None: + def record_callback(_, audio): audio_queue.put((audio.get_raw_data(), datetime.now())) self.stop = self.recorder.listen_in_background(self.source, record_callback, phrase_time_limit=self.record_timeout) class SelectedMicRecorder(BaseRecorder): def __init__(self, device, energy_threshold, dynamic_energy_threshold, record_timeout): - source=sr.Microphone( + source=Microphone( device_index=device['index'], sample_rate=int(device["defaultSampleRate"]), ) @@ -37,10 +37,10 @@ class SelectedMicRecorder(BaseRecorder): class SelectedSpeakerRecorder(BaseRecorder): def __init__(self, device, energy_threshold, dynamic_energy_threshold, record_timeout): - source = sr.Microphone(speaker=True, + source = Microphone(speaker=True, device_index= device["index"], sample_rate=int(device["defaultSampleRate"]), - chunk_size=pyaudio.get_sample_size(pyaudio.paInt16), + chunk_size=get_sample_size(paInt16), channels=device["maxInputChannels"] ) super().__init__(source=source, energy_threshold=energy_threshold, dynamic_energy_threshold=dynamic_energy_threshold, record_timeout=record_timeout) diff --git a/audio_transcriber.py b/audio_transcriber.py index 695ee55f..aadd6adf 100644 --- a/audio_transcriber.py +++ b/audio_transcriber.py @@ -1,9 +1,9 @@ -import io -import threading +from io import BytesIO +from threading import Event import wave -import speech_recognition as sr +from speech_recognition import Recognizer, AudioData, AudioFile from datetime import timedelta -import pyaudiowpatch as pyaudio +from pyaudiowpatch import get_sample_size, paInt16 PHRASE_TIMEOUT = 3 MAX_PHRASES = 10 @@ -15,8 +15,8 @@ class AudioTranscriber: self.phrase_timeout = phrase_timeout self.max_phrases = max_phrases self.transcript_data = [] - self.transcript_changed_event = threading.Event() - self.audio_recognizer = sr.Recognizer() + self.transcript_changed_event = Event() + self.audio_recognizer = Recognizer() self.audio_sources = { "sample_rate": source.SAMPLE_RATE, "sample_width": source.SAMPLE_WIDTH, @@ -59,19 +59,18 @@ class AudioTranscriber: source_info["last_spoken"] = time_spoken def process_mic_data(self): - audio_data = sr.AudioData(self.audio_sources["last_sample"], self.audio_sources["sample_rate"], self.audio_sources["sample_width"]) + audio_data = AudioData(self.audio_sources["last_sample"], self.audio_sources["sample_rate"], self.audio_sources["sample_width"]) return audio_data def process_speaker_data(self): - temp_file = io.BytesIO() + temp_file = BytesIO() with wave.open(temp_file, 'wb') as wf: wf.setnchannels(self.audio_sources["channels"]) - p = pyaudio.PyAudio() - wf.setsampwidth(p.get_sample_size(pyaudio.paInt16)) + wf.setsampwidth(get_sample_size(paInt16)) wf.setframerate(self.audio_sources["sample_rate"]) wf.writeframes(self.audio_sources["last_sample"]) temp_file.seek(0) - with sr.AudioFile(temp_file) as source: + with AudioFile(temp_file) as source: audio = self.audio_recognizer.record(source) return audio diff --git a/audio_utils.py b/audio_utils.py index fd56ae5c..b6d0d6e0 100644 --- a/audio_utils.py +++ b/audio_utils.py @@ -1,9 +1,9 @@ -import pyaudiowpatch as pyaudio +from pyaudiowpatch import PyAudio, paWASAPI def get_input_device_list(): devices = [] - with pyaudio.PyAudio() as p: - wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI) + with PyAudio() as p: + wasapi_info = p.get_host_api_info_by_type(paWASAPI) for host_index in range(0, p.get_host_api_count()): for device_index in range(0, p. get_host_api_info_by_index(host_index)['deviceCount']): device = p.get_device_info_by_host_api_device_index(host_index, device_index) @@ -13,16 +13,16 @@ def get_input_device_list(): def get_output_device_list(): devices =[] - with pyaudio.PyAudio() as p: - wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI) + with PyAudio() as p: + wasapi_info = p.get_host_api_info_by_type(paWASAPI) for device in p.get_loopback_device_info_generator(): if device["hostApi"] == wasapi_info["index"] and device["isLoopbackDevice"] is True: devices.append(device) return devices def get_default_input_device(): - with pyaudio.PyAudio() as p: - wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI) + with PyAudio() as p: + wasapi_info = p.get_host_api_info_by_type(paWASAPI) defaultInputDevice = wasapi_info["defaultInputDevice"] for host_index in range(0, p.get_host_api_count()): @@ -33,8 +33,8 @@ def get_default_input_device(): return default_device def get_default_output_device(): - with pyaudio.PyAudio() as p: - wasapi_info = p.get_host_api_info_by_type(pyaudio.paWASAPI) + with PyAudio() as p: + wasapi_info = p.get_host_api_info_by_type(paWASAPI) defaultOutputDevice = wasapi_info["defaultOutputDevice"] for host_index in range(0, p.get_host_api_count()): diff --git a/translation.py b/translation.py index 50eda54e..8eacf8a6 100644 --- a/translation.py +++ b/translation.py @@ -1,13 +1,13 @@ -import deepl -import deepl_translate -import translators as ts -import languages +from deepl import Translator as deepl_Translator +from deepl_translate import translate as deepl_web_Translator +from translators import translate_text as other_web_Translator +from languages import translators, translation_lang # Translator class Translator(): def __init__(self): self.translator_status = {} - for translator in languages.translators: + for translator in translators: self.translator_status[translator] = False self.deepl_client = None @@ -18,7 +18,7 @@ class Translator(): self.translator_status["DeepL(web)"] = True result = True elif translator_name == "DeepL(auth)": - self.deepl_client = deepl.Translator(authkey) + self.deepl_client = deepl_Translator(authkey) self.deepl_client.translate_text(" ", target_lang="EN-US") self.translator_status["DeepL(auth)"] = True result = True @@ -35,10 +35,10 @@ class Translator(): def translate(self, translator_name, source_language, target_language, message): result = "" try: - source_language=languages.translation_lang[translator_name][source_language] - target_language=languages.translation_lang[translator_name][target_language] + source_language=translation_lang[translator_name][source_language] + target_language=translation_lang[translator_name][target_language] if translator_name == "DeepL(web)": - result = deepl_translate.translate( + result = deepl_web_Translator( source_language=source_language, target_language=target_language, text=message @@ -50,14 +50,14 @@ class Translator(): target_lang=target_language, ).text elif translator_name == "Google(web)": - result = ts.translate_text( + result = other_web_Translator( query_text=message, translator="google", from_language=source_language, to_language=target_language, ) elif translator_name == "Bing(web)": - result = ts.translate_text( + result = other_web_Translator( query_text=message, translator="bing", from_language=source_language, diff --git a/utils.py b/utils.py index 473487fc..013b16c6 100644 --- a/utils.py +++ b/utils.py @@ -1,16 +1,16 @@ -import json -import datetime -import threading +from json import load, dump +from datetime import datetime +from threading import Thread, Event def save_json(path, key, value): with open(path, "r") as fp: - json_data = json.load(fp) + json_data = load(fp) json_data[key] = value with open(path, "w") as fp: - json.dump(json_data, fp, indent=4) + dump(json_data, fp, indent=4) def print_textbox(textbox, message, tags=None): - now = datetime.datetime.now() + now = datetime.now() now = now.strftime('%H:%M:%S') textbox.tag_config("ERROR", foreground="#FF0000") @@ -25,11 +25,11 @@ def print_textbox(textbox, message, tags=None): textbox.configure(state='disabled') textbox.see("end") -class thread_fnc(threading.Thread): +class thread_fnc(Thread): def __init__(self, fnc, daemon=True, *args, **kwargs): super(thread_fnc, self).__init__(daemon=daemon, *args, **kwargs) self.fnc = fnc - self._stop = threading.Event() + self._stop = Event() def stop(self): self._stop.set() def stopped(self): diff --git a/window_config.py b/window_config.py index 2919b18c..475a59bc 100644 --- a/window_config.py +++ b/window_config.py @@ -1,13 +1,15 @@ -import os -import tkinter as tk +from os import path as os_path +from tkinter import DoubleVar +from tkinter import font as tk_font import customtkinter +from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox from flashtext import KeywordProcessor -import utils -import audio_utils -import languages +from utils import save_json, print_textbox +from audio_utils import get_input_device_list, get_output_device_list +from languages import translation_lang, transcription_lang -class ToplevelWindowConfig(customtkinter.CTkToplevel): +class ToplevelWindowConfig(CTkToplevel): def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.parent = parent @@ -16,11 +18,11 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) - self.after(200, lambda: self.iconbitmap(os.path.join(os.path.dirname(__file__), "img", "app.ico"))) + self.after(200, lambda: self.iconbitmap(os_path.join(os_path.dirname(__file__), "img", "app.ico"))) self.title("Config") # tabwiew config - self.tabview_config = customtkinter.CTkTabview(self) + self.tabview_config = CTkTabview(self) self.tabview_config.grid(row=0, column=0, padx=5, pady=5, sticky="nsew") self.tabview_config.add("UI") self.tabview_config.add("Translation") @@ -30,7 +32,7 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.tabview_config.tab("Translation").grid_columnconfigure([1,2,3], weight=1) self.tabview_config.tab("Transcription").grid_columnconfigure(1, weight=1) self.tabview_config.tab("Parameter").grid_columnconfigure(1, weight=1) - self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.tabview_config._segmented_button.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) self.tabview_config._segmented_button.grid(sticky="W") # tab UI @@ -38,258 +40,258 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): row = 0 padx = 5 pady = 1 - self.label_transparency = customtkinter.CTkLabel( + self.label_transparency = CTkLabel( self.tabview_config.tab("UI"), text="Transparency:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_transparency.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.slider_transparency = customtkinter.CTkSlider( + self.slider_transparency = CTkSlider( self.tabview_config.tab("UI"), from_=50, to=100, command=self.slider_transparency_callback, - variable=tk.DoubleVar(value=self.parent.TRANSPARENCY), + variable=DoubleVar(value=self.parent.TRANSPARENCY), ) self.slider_transparency.grid(row=row, column=1, columnspan=1, padx=padx, pady=10, sticky="nsew") ## optionmenu theme row += 1 - self.label_appearance_theme = customtkinter.CTkLabel( + self.label_appearance_theme = CTkLabel( self.tabview_config.tab("UI"), text="Appearance Theme:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_appearance_theme.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_appearance_theme = customtkinter.CTkOptionMenu( + self.optionmenu_appearance_theme = CTkOptionMenu( self.tabview_config.tab("UI"), values=["Light", "Dark", "System"], command=self.optionmenu_theme_callback, - variable=customtkinter.StringVar(value=self.parent.APPEARANCE_THEME), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.APPEARANCE_THEME), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_appearance_theme.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_appearance_theme._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_appearance_theme._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu UI scaling row += 1 - self.label_ui_scaling = customtkinter.CTkLabel( + self.label_ui_scaling = CTkLabel( self.tabview_config.tab("UI"), text="UI Scaling:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_ui_scaling.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_ui_scaling = customtkinter.CTkOptionMenu( + self.optionmenu_ui_scaling = CTkOptionMenu( self.tabview_config.tab("UI"), values=["80%", "90%", "100%", "110%", "120%"], command=self.optionmenu_ui_scaling_callback, - variable=customtkinter.StringVar(value=self.parent.UI_SCALING), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.UI_SCALING), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_ui_scaling.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_ui_scaling._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_ui_scaling._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu font family row += 1 - self.label_font_family = customtkinter.CTkLabel( + self.label_font_family = CTkLabel( self.tabview_config.tab("UI"), text="Font Family:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_font_family.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - font_families = list(tk.font.families()) - self.optionmenu_font_family = customtkinter.CTkOptionMenu( + font_families = list(tk_font.families()) + self.optionmenu_font_family = CTkOptionMenu( self.tabview_config.tab("UI"), values=font_families, command=self.optionmenu_font_family_callback, - variable=customtkinter.StringVar(value=self.parent.FONT_FAMILY), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.FONT_FAMILY), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_font_family._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) # tab Translation ## optionmenu translation translator row = 0 padx = 5 pady = 1 - self.label_translation_translator = customtkinter.CTkLabel( + self.label_translation_translator = CTkLabel( self.tabview_config.tab("Translation"), text="Select Translator:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.label_translation_translator.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_translation_translator = customtkinter.CTkOptionMenu( + self.optionmenu_translation_translator = CTkOptionMenu( self.tabview_config.tab("Translation"), values=list(self.parent.translator.translator_status.keys()), command=self.optionmenu_translation_translator_callback, - variable=customtkinter.StringVar(value=self.parent.CHOICE_TRANSLATOR), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.CHOICE_TRANSLATOR), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3 ,padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_translator._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu translation input language row +=1 - self.label_translation_input_language = customtkinter.CTkLabel( + self.label_translation_input_language = CTkLabel( self.tabview_config.tab("Translation"), text="Send Language:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_translation_input_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") ## select translation input source language - self.optionmenu_translation_input_source_language = customtkinter.CTkOptionMenu( + self.optionmenu_translation_input_source_language = CTkOptionMenu( self.tabview_config.tab("Translation"), command=self.optionmenu_translation_input_source_language_callback, - values=list(languages.translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=customtkinter.StringVar(value=self.parent.INPUT_SOURCE_LANG), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.INPUT_SOURCE_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_input_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## label translation input arrow - self.label_translation_input_arrow = customtkinter.CTkLabel( + self.label_translation_input_arrow = CTkLabel( self.tabview_config.tab("Translation"), text="-->", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_translation_input_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") ## select translation input target language - self.optionmenu_translation_input_target_language = customtkinter.CTkOptionMenu( + self.optionmenu_translation_input_target_language = CTkOptionMenu( self.tabview_config.tab("Translation"), command=self.optionmenu_translation_input_target_language_callback, - values=list(languages.translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=customtkinter.StringVar(value=self.parent.INPUT_TARGET_LANG), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.INPUT_TARGET_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_input_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu translation output language row +=1 - self.label_translation_output_language = customtkinter.CTkLabel( + self.label_translation_output_language = CTkLabel( self.tabview_config.tab("Translation"), text="Receive Language:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_translation_output_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") ## select translation output source language - self.optionmenu_translation_output_source_language = customtkinter.CTkOptionMenu( + self.optionmenu_translation_output_source_language = CTkOptionMenu( self.tabview_config.tab("Translation"), command=self.optionmenu_translation_output_source_language_callback, - values=list(languages.translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=customtkinter.StringVar(value=self.parent.OUTPUT_SOURCE_LANG), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.OUTPUT_SOURCE_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_output_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## label translation output arrow - self.label_translation_output_arrow = customtkinter.CTkLabel( + self.label_translation_output_arrow = CTkLabel( self.tabview_config.tab("Translation"), text="-->", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_translation_output_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") ## select translation output target language - self.optionmenu_translation_output_target_language = customtkinter.CTkOptionMenu( + self.optionmenu_translation_output_target_language = CTkOptionMenu( self.tabview_config.tab("Translation"), command=self.optionmenu_translation_output_target_language_callback, - values=list(languages.translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=customtkinter.StringVar(value=self.parent.OUTPUT_TARGET_LANG), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.OUTPUT_TARGET_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_output_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) # tab Transcription ## optionmenu input mic device row = 0 padx = 5 pady = 1 - self.label_input_mic_device = customtkinter.CTkLabel( + self.label_input_mic_device = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Device:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_mic_device = customtkinter.CTkOptionMenu( + self.optionmenu_input_mic_device = CTkOptionMenu( self.tabview_config.tab("Transcription"), - values=[device["name"] for device in audio_utils.get_input_device_list()], + values=[device["name"] for device in get_input_device_list()], command=self.optionmenu_input_mic_device_callback, - variable=customtkinter.StringVar(value=self.parent.CHOICE_MIC_DEVICE), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_device._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu input mic voice language row +=1 - self.label_input_mic_voice_language = customtkinter.CTkLabel( + self.label_input_mic_voice_language = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Voice Language:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_mic_voice_language = customtkinter.CTkOptionMenu( + self.optionmenu_input_mic_voice_language = CTkOptionMenu( self.tabview_config.tab("Transcription"), - values=list(languages.transcription_lang.keys()), + values=list(transcription_lang.keys()), command=self.optionmenu_input_mic_voice_language_callback, - variable=customtkinter.StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## entry input mic energy threshold row +=1 - self.label_input_mic_energy_threshold = customtkinter.CTkLabel( + self.label_input_mic_energy_threshold = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Energy Threshold:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_energy_threshold = customtkinter.CTkEntry( + self.entry_input_mic_energy_threshold = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_energy_threshold.bind("", self.entry_input_mic_energy_threshold_callback) ## checkbox input mic dynamic energy threshold row +=1 - self.label_input_mic_dynamic_energy_threshold = customtkinter.CTkLabel( + self.label_input_mic_dynamic_energy_threshold = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Dynamic Energy Threshold:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.checkbox_input_mic_dynamic_energy_threshold = customtkinter.CTkCheckBox( + self.checkbox_input_mic_dynamic_energy_threshold = CTkCheckBox( self.tabview_config.tab("Transcription"), text="", onvalue=True, offvalue=False, command=self.checkbox_input_mic_dynamic_energy_threshold_callback, - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.checkbox_input_mic_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") if self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD is True: @@ -299,143 +301,143 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): ## entry input mic record timeout row +=1 - self.label_input_mic_record_timeout = customtkinter.CTkLabel( + self.label_input_mic_record_timeout = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Record Timeout:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_record_timeout = customtkinter.CTkEntry( + self.entry_input_mic_record_timeout = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_MIC_RECORD_TIMEOUT), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_MIC_RECORD_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_mic_record_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_record_timeout.bind("", self.entry_input_mic_record_timeout_callback) ## entry input mic phrase timeout row +=1 - self.label_input_mic_phrase_timeout = customtkinter.CTkLabel( + self.label_input_mic_phrase_timeout = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Phrase Timeout:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_phrase_timeout = customtkinter.CTkEntry( + self.entry_input_mic_phrase_timeout = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_MIC_PHRASE_TIMEOUT), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_MIC_PHRASE_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_mic_phrase_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_phrase_timeout.bind("", self.entry_input_mic_phrase_timeout_callback) ## entry input mic max phrases row +=1 - self.label_input_mic_max_phrases = customtkinter.CTkLabel( + self.label_input_mic_max_phrases = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Max Phrases:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_max_phrases = customtkinter.CTkEntry( + self.entry_input_mic_max_phrases = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_MIC_MAX_PHRASES), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_MIC_MAX_PHRASES), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_max_phrases.bind("", self.entry_input_mic_max_phrases_callback) ## entry input mic word filter row +=1 - self.label_input_mic_word_filter = customtkinter.CTkLabel( + self.label_input_mic_word_filter = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Word Filter:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_word_filter.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_word_filter = customtkinter.CTkEntry( + self.entry_input_mic_word_filter = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_word_filter.bind("", self.entry_input_mic_word_filters_callback) ## optionmenu input speaker device row +=1 - self.label_input_speaker_device = customtkinter.CTkLabel( + self.label_input_speaker_device = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Device:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_speaker_device = customtkinter.CTkOptionMenu( + self.optionmenu_input_speaker_device = CTkOptionMenu( self.tabview_config.tab("Transcription"), - values=[device["name"] for device in audio_utils.get_output_device_list()], + values=[device["name"] for device in get_output_device_list()], command=self.optionmenu_input_speaker_device_callback, - variable=customtkinter.StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_speaker_device._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu input speaker voice language row +=1 - self.label_input_speaker_voice_language = customtkinter.CTkLabel( + self.label_input_speaker_voice_language = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Voice Language:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_speaker_voice_language = customtkinter.CTkOptionMenu( + self.optionmenu_input_speaker_voice_language = CTkOptionMenu( self.tabview_config.tab("Transcription"), - values=list(languages.transcription_lang.keys()), + values=list(transcription_lang.keys()), command=self.optionmenu_input_speaker_voice_language_callback, - variable=customtkinter.StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY), + variable=StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), + font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) + self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## entry input speaker energy threshold row +=1 - self.label_input_speaker_energy_threshold = customtkinter.CTkLabel( + self.label_input_speaker_energy_threshold = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Energy Threshold:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_energy_threshold = customtkinter.CTkEntry( + self.entry_input_speaker_energy_threshold = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_energy_threshold.bind("", self.entry_input_speaker_energy_threshold_callback) ## checkbox input speaker dynamic energy threshold row +=1 - self.label_input_speaker_dynamic_energy_threshold = customtkinter.CTkLabel( + self.label_input_speaker_dynamic_energy_threshold = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Dynamic Energy Threshold:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.checkbox_input_speaker_dynamic_energy_threshold = customtkinter.CTkCheckBox( + self.checkbox_input_speaker_dynamic_energy_threshold = CTkCheckBox( self.tabview_config.tab("Transcription"), text="", onvalue=True, offvalue=False, command=self.checkbox_input_speaker_dynamic_energy_threshold_callback, - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.checkbox_input_speaker_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") if self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: @@ -445,51 +447,51 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): ## entry input speaker record timeout row +=1 - self.label_input_speaker_record_timeout = customtkinter.CTkLabel( + self.label_input_speaker_record_timeout = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Record Timeout:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_record_timeout = customtkinter.CTkEntry( + self.entry_input_speaker_record_timeout = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_SPEAKER_RECORD_TIMEOUT), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_RECORD_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_speaker_record_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_record_timeout.bind("", self.entry_input_speaker_record_timeout_callback) ## entry input speaker phrase timeout row +=1 - self.label_input_speaker_phrase_timeout = customtkinter.CTkLabel( + self.label_input_speaker_phrase_timeout = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Phrase Timeout:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_phrase_timeout = customtkinter.CTkEntry( + self.entry_input_speaker_phrase_timeout = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_speaker_phrase_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_phrase_timeout.bind("", self.entry_input_speaker_phrase_timeout_callback) ## entry input speaker max phrases row +=1 - self.label_input_speaker_max_phrases = customtkinter.CTkLabel( + self.label_input_speaker_max_phrases = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Speaker Max Phrases:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_speaker_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_max_phrases = customtkinter.CTkEntry( + self.entry_input_speaker_max_phrases = CTkEntry( self.tabview_config.tab("Transcription"), - textvariable=customtkinter.StringVar(value=self.parent.INPUT_SPEAKER_MAX_PHRASES), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_MAX_PHRASES), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_speaker_max_phrases.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_max_phrases.bind("", self.entry_input_speaker_max_phrases_callback) @@ -499,68 +501,68 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): row = 0 padx = 5 pady = 1 - self.label_ip_address = customtkinter.CTkLabel( + self.label_ip_address = CTkLabel( self.tabview_config.tab("Parameter"), text="OSC IP address:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_ip_address.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_ip_address = customtkinter.CTkEntry( + self.entry_ip_address = CTkEntry( self.tabview_config.tab("Parameter"), - textvariable=customtkinter.StringVar(value=self.parent.OSC_IP_ADDRESS), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.OSC_IP_ADDRESS), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_ip_address.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_ip_address.bind("", self.entry_ip_address_callback) ## entry port row +=1 - self.label_port = customtkinter.CTkLabel( + self.label_port = CTkLabel( self.tabview_config.tab("Parameter"), text="OSC Port:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_port.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_port = customtkinter.CTkEntry( + self.entry_port = CTkEntry( self.tabview_config.tab("Parameter"), - textvariable=customtkinter.StringVar(value=self.parent.OSC_PORT), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.OSC_PORT), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_port.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_port.bind("", self.entry_port_callback) ## entry authkey row +=1 - self.label_authkey = customtkinter.CTkLabel( + self.label_authkey = CTkLabel( self.tabview_config.tab("Parameter"), text="DeepL Auth Key:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_authkey.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_authkey = customtkinter.CTkEntry( + self.entry_authkey = CTkEntry( self.tabview_config.tab("Parameter"), - textvariable=customtkinter.StringVar(value=self.parent.AUTH_KEYS["DeepL(auth)"]), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.AUTH_KEYS["DeepL(auth)"]), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_authkey.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_authkey.bind("", self.entry_authkey_callback) ## entry message format row +=1 - self.label_message_format = customtkinter.CTkLabel( + self.label_message_format = CTkLabel( self.tabview_config.tab("Parameter"), text="Message Format:", fg_color="transparent", - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_message_format.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_message_format = customtkinter.CTkEntry( + self.entry_message_format = CTkEntry( self.tabview_config.tab("Parameter"), - textvariable=customtkinter.StringVar(value=self.parent.MESSAGE_FORMAT), - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + textvariable=StringVar(value=self.parent.MESSAGE_FORMAT), + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_message_format.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_message_format.bind("", self.entry_message_format_callback) @@ -570,243 +572,243 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): def slider_transparency_callback(self, value): self.parent.wm_attributes("-alpha", value/100) self.parent.TRANSPARENCY = value - utils.save_json(self.parent.PATH_CONFIG, "TRANSPARENCY", self.parent.TRANSPARENCY) + save_json(self.parent.PATH_CONFIG, "TRANSPARENCY", self.parent.TRANSPARENCY) def optionmenu_theme_callback(self, choice): customtkinter.set_appearance_mode(choice) self.parent.APPEARANCE_THEME = choice - utils.save_json(self.parent.PATH_CONFIG, "APPEARANCE_THEME", self.parent.APPEARANCE_THEME) + save_json(self.parent.PATH_CONFIG, "APPEARANCE_THEME", self.parent.APPEARANCE_THEME) def optionmenu_ui_scaling_callback(self, choice): new_scaling_float = int(choice.replace("%", "")) / 100 customtkinter.set_widget_scaling(new_scaling_float) self.parent.UI_SCALING = choice - utils.save_json(self.parent.PATH_CONFIG, "UI_SCALING", self.parent.UI_SCALING) + save_json(self.parent.PATH_CONFIG, "UI_SCALING", self.parent.UI_SCALING) def optionmenu_font_family_callback(self, choice): # tab menu - self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=choice)) + self.tabview_config._segmented_button.configure(font=CTkFont(family=choice)) # tab UI - self.label_transparency.configure(font=customtkinter.CTkFont(family=choice)) - self.label_appearance_theme.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_appearance_theme.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_appearance_theme._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_ui_scaling.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_ui_scaling.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_ui_scaling._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_font_family.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_font_family.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_font_family._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) + self.label_transparency.configure(font=CTkFont(family=choice)) + self.label_appearance_theme.configure(font=CTkFont(family=choice)) + self.optionmenu_appearance_theme.configure(font=CTkFont(family=choice)) + self.optionmenu_appearance_theme._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_ui_scaling.configure(font=CTkFont(family=choice)) + self.optionmenu_ui_scaling.configure(font=CTkFont(family=choice)) + self.optionmenu_ui_scaling._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_font_family.configure(font=CTkFont(family=choice)) + self.optionmenu_font_family.configure(font=CTkFont(family=choice)) + self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=choice)) # tab Translation - self.label_translation_translator.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_translator.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_translator._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_translation_input_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_input_source_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_translation_input_arrow.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_input_target_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_translation_output_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_output_source_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_translation_output_arrow.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_output_target_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) + self.label_translation_translator.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_translator.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_translation_input_language.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_input_source_language.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_translation_input_arrow.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_input_target_language.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_translation_output_language.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_output_source_language.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_translation_output_arrow.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_output_target_language.configure(font=CTkFont(family=choice)) + self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=choice)) # tab Transcription - self.label_input_mic_device.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_mic_device.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_mic_device._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_voice_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_mic_voice_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_energy_threshold.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_mic_energy_threshold.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_dynamic_energy_threshold.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_record_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_mic_record_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_phrase_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_mic_phrase_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_max_phrases.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_mic_max_phrases.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_mic_word_filter.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_mic_word_filter.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_device.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_speaker_device.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_speaker_device._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_voice_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_speaker_voice_language.configure(font=customtkinter.CTkFont(family=choice)) - self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_energy_threshold.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_speaker_energy_threshold.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_dynamic_energy_threshold.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_record_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_speaker_record_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_phrase_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_speaker_phrase_timeout.configure(font=customtkinter.CTkFont(family=choice)) - self.label_input_speaker_max_phrases.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_input_speaker_max_phrases.configure(font=customtkinter.CTkFont(family=choice)) + self.label_input_mic_device.configure(font=CTkFont(family=choice)) + self.optionmenu_input_mic_device.configure(font=CTkFont(family=choice)) + self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_input_mic_voice_language.configure(font=CTkFont(family=choice)) + self.optionmenu_input_mic_voice_language.configure(font=CTkFont(family=choice)) + self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_input_mic_energy_threshold.configure(font=CTkFont(family=choice)) + self.entry_input_mic_energy_threshold.configure(font=CTkFont(family=choice)) + self.label_input_mic_dynamic_energy_threshold.configure(font=CTkFont(family=choice)) + self.label_input_mic_record_timeout.configure(font=CTkFont(family=choice)) + self.entry_input_mic_record_timeout.configure(font=CTkFont(family=choice)) + self.label_input_mic_phrase_timeout.configure(font=CTkFont(family=choice)) + self.entry_input_mic_phrase_timeout.configure(font=CTkFont(family=choice)) + self.label_input_mic_max_phrases.configure(font=CTkFont(family=choice)) + self.entry_input_mic_max_phrases.configure(font=CTkFont(family=choice)) + self.label_input_mic_word_filter.configure(font=CTkFont(family=choice)) + self.entry_input_mic_word_filter.configure(font=CTkFont(family=choice)) + self.label_input_speaker_device.configure(font=CTkFont(family=choice)) + self.optionmenu_input_speaker_device.configure(font=CTkFont(family=choice)) + self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_input_speaker_voice_language.configure(font=CTkFont(family=choice)) + self.optionmenu_input_speaker_voice_language.configure(font=CTkFont(family=choice)) + self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_input_speaker_energy_threshold.configure(font=CTkFont(family=choice)) + self.entry_input_speaker_energy_threshold.configure(font=CTkFont(family=choice)) + self.label_input_speaker_dynamic_energy_threshold.configure(font=CTkFont(family=choice)) + self.label_input_speaker_record_timeout.configure(font=CTkFont(family=choice)) + self.entry_input_speaker_record_timeout.configure(font=CTkFont(family=choice)) + self.label_input_speaker_phrase_timeout.configure(font=CTkFont(family=choice)) + self.entry_input_speaker_phrase_timeout.configure(font=CTkFont(family=choice)) + self.label_input_speaker_max_phrases.configure(font=CTkFont(family=choice)) + self.entry_input_speaker_max_phrases.configure(font=CTkFont(family=choice)) # tab Parameter - self.label_ip_address.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_ip_address.configure(font=customtkinter.CTkFont(family=choice)) - self.label_port.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_port.configure(font=customtkinter.CTkFont(family=choice)) - self.label_authkey.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_authkey.configure(font=customtkinter.CTkFont(family=choice)) - self.label_message_format.configure(font=customtkinter.CTkFont(family=choice)) - self.entry_message_format.configure(font=customtkinter.CTkFont(family=choice)) + self.label_ip_address.configure(font=CTkFont(family=choice)) + self.entry_ip_address.configure(font=CTkFont(family=choice)) + self.label_port.configure(font=CTkFont(family=choice)) + self.entry_port.configure(font=CTkFont(family=choice)) + self.label_authkey.configure(font=CTkFont(family=choice)) + self.entry_authkey.configure(font=CTkFont(family=choice)) + self.label_message_format.configure(font=CTkFont(family=choice)) + self.entry_message_format.configure(font=CTkFont(family=choice)) # main window - self.parent.checkbox_translation.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.checkbox_transcription_send.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.checkbox_transcription_receive.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.checkbox_foreground.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.textbox_message_log.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.textbox_message_send_log.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.textbox_message_receive_log.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.textbox_message_system_log.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.entry_message_box.configure(font=customtkinter.CTkFont(family=choice)) - self.parent.tabview_logs._segmented_button.configure(font=customtkinter.CTkFont(family=choice)) + self.parent.checkbox_translation.configure(font=CTkFont(family=choice)) + self.parent.checkbox_transcription_send.configure(font=CTkFont(family=choice)) + self.parent.checkbox_transcription_receive.configure(font=CTkFont(family=choice)) + self.parent.checkbox_foreground.configure(font=CTkFont(family=choice)) + self.parent.textbox_message_log.configure(font=CTkFont(family=choice)) + self.parent.textbox_message_send_log.configure(font=CTkFont(family=choice)) + self.parent.textbox_message_receive_log.configure(font=CTkFont(family=choice)) + self.parent.textbox_message_system_log.configure(font=CTkFont(family=choice)) + self.parent.entry_message_box.configure(font=CTkFont(family=choice)) + self.parent.tabview_logs._segmented_button.configure(font=CTkFont(family=choice)) # window information try: - self.parent.information_window.textbox_information.configure(font=customtkinter.CTkFont(family=choice)) + self.parent.information_window.textbox_information.configure(font=CTkFont(family=choice)) except: pass self.parent.FONT_FAMILY = choice - utils.save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) + save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) def optionmenu_translation_translator_callback(self, choice): if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: - utils.print_textbox(self.parent.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") - utils.print_textbox(self.parent.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.parent.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.parent.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") else: self.optionmenu_translation_input_source_language.configure( - values=list(languages.translation_lang[choice].keys()), - variable=customtkinter.StringVar(value=list(languages.translation_lang[choice].keys())[0])) + values=list(translation_lang[choice].keys()), + variable=StringVar(value=list(translation_lang[choice].keys())[0])) self.optionmenu_translation_input_target_language.configure( - values=list(languages.translation_lang[choice].keys()), - variable=customtkinter.StringVar(value=list(languages.translation_lang[choice].keys())[1])) + values=list(translation_lang[choice].keys()), + variable=StringVar(value=list(translation_lang[choice].keys())[1])) self.optionmenu_translation_output_source_language.configure( - values=list(languages.translation_lang[choice].keys()), - variable=customtkinter.StringVar(value=list(languages.translation_lang[choice].keys())[1])) + values=list(translation_lang[choice].keys()), + variable=StringVar(value=list(translation_lang[choice].keys())[1])) self.optionmenu_translation_output_target_language.configure( - values=list(languages.translation_lang[choice].keys()), - variable=customtkinter.StringVar(value=list(languages.translation_lang[choice].keys())[0])) + values=list(translation_lang[choice].keys()), + variable=StringVar(value=list(translation_lang[choice].keys())[0])) self.parent.CHOICE_TRANSLATOR = choice - self.parent.INPUT_SOURCE_LANG = list(languages.translation_lang[choice].keys())[0] - self.parent.INPUT_TARGET_LANG = list(languages.translation_lang[choice].keys())[1] - self.parent.OUTPUT_SOURCE_LANG = list(languages.translation_lang[choice].keys())[1] - self.parent.OUTPUT_TARGET_LANG = list(languages.translation_lang[choice].keys())[0] - utils.save_json(self.parent.PATH_CONFIG, "CHOICE_TRANSLATOR", self.parent.CHOICE_TRANSLATOR) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) - utils.save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) - utils.save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) + self.parent.INPUT_SOURCE_LANG = list(translation_lang[choice].keys())[0] + self.parent.INPUT_TARGET_LANG = list(translation_lang[choice].keys())[1] + self.parent.OUTPUT_SOURCE_LANG = list(translation_lang[choice].keys())[1] + self.parent.OUTPUT_TARGET_LANG = list(translation_lang[choice].keys())[0] + save_json(self.parent.PATH_CONFIG, "CHOICE_TRANSLATOR", self.parent.CHOICE_TRANSLATOR) + save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) + save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) + save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) + save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) def optionmenu_translation_input_source_language_callback(self, choice): self.parent.INPUT_SOURCE_LANG = choice - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) + save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) def optionmenu_translation_input_target_language_callback(self, choice): self.parent.INPUT_TARGET_LANG = choice - utils.save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) + save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) def optionmenu_translation_output_source_language_callback(self, choice): self.parent.OUTPUT_SOURCE_LANG = choice - utils.save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) + save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) def optionmenu_translation_output_target_language_callback(self, choice): self.parent.OUTPUT_TARGET_LANG = choice - utils.save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) + save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) def optionmenu_input_mic_device_callback(self, choice): self.parent.CHOICE_MIC_DEVICE = choice - utils.save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) + save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) def optionmenu_input_mic_voice_language_callback(self, choice): self.parent.INPUT_MIC_VOICE_LANGUAGE = choice - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) def entry_input_mic_energy_threshold_callback(self, event): self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(self.entry_input_mic_energy_threshold.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_ENERGY_THRESHOLD) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_ENERGY_THRESHOLD) def checkbox_input_mic_dynamic_energy_threshold_callback(self): value = self.checkbox_input_mic_dynamic_energy_threshold.get() self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD) def entry_input_mic_record_timeout_callback(self, event): self.parent.INPUT_MIC_RECORD_TIMEOUT = int(self.entry_input_mic_record_timeout.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_RECORD_TIMEOUT", self.parent.INPUT_MIC_RECORD_TIMEOUT) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_RECORD_TIMEOUT", self.parent.INPUT_MIC_RECORD_TIMEOUT) def entry_input_mic_phrase_timeout_callback(self, event): self.parent.INPUT_MIC_PHRASE_TIMEOUT = int(self.entry_input_mic_phrase_timeout.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_PHRASE_TIMEOUT", self.parent.INPUT_MIC_PHRASE_TIMEOUT) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_PHRASE_TIMEOUT", self.parent.INPUT_MIC_PHRASE_TIMEOUT) def entry_input_mic_max_phrases_callback(self, event): self.parent.INPUT_MIC_MAX_PHRASES = int(self.entry_input_mic_max_phrases.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_MAX_PHRASES", self.parent.INPUT_MIC_MAX_PHRASES) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_MAX_PHRASES", self.parent.INPUT_MIC_MAX_PHRASES) def entry_input_mic_word_filters_callback(self, event): self.parent.INPUT_MIC_WORD_FILTER = self.entry_input_mic_word_filter.get().split(",") self.parent.keyword_processor = KeywordProcessor() for f in self.parent.INPUT_MIC_WORD_FILTER: self.parent.keyword_processor.add_keyword(f) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_MIC_WORD_FILTER", self.parent.INPUT_MIC_WORD_FILTER) + save_json(self.parent.PATH_CONFIG, "INPUT_MIC_WORD_FILTER", self.parent.INPUT_MIC_WORD_FILTER) def optionmenu_input_speaker_device_callback(self, choice): self.parent.CHOICE_SPEAKER_DEVICE = choice - utils.save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) + save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) def optionmenu_input_speaker_voice_language_callback(self, choice): self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) + save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) def entry_input_speaker_energy_threshold_callback(self, event): self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(self.entry_input_speaker_energy_threshold.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD) + save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD) def checkbox_input_speaker_dynamic_energy_threshold_callback(self): value = self.checkbox_input_speaker_dynamic_energy_threshold.get() self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD) + save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD) def entry_input_speaker_record_timeout_callback(self, event): self.parent.INPUT_SPEAKER_RECORD_TIMEOUT = int(self.entry_input_speaker_record_timeout.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_RECORD_TIMEOUT", self.parent.INPUT_SPEAKER_RECORD_TIMEOUT) + save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_RECORD_TIMEOUT", self.parent.INPUT_SPEAKER_RECORD_TIMEOUT) def entry_input_speaker_phrase_timeout_callback(self, event): self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT = int(self.entry_input_speaker_phrase_timeout.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_PHRASE_TIMEOUT", self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT) + save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_PHRASE_TIMEOUT", self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT) def entry_input_speaker_max_phrases_callback(self, event): self.parent.INPUT_SPEAKER_MAX_PHRASES = int(self.entry_input_speaker_max_phrases.get()) - utils.save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_MAX_PHRASES", self.parent.INPUT_SPEAKER_MAX_PHRASES) + save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_MAX_PHRASES", self.parent.INPUT_SPEAKER_MAX_PHRASES) def entry_ip_address_callback(self, event): self.parent.OSC_IP_ADDRESS = self.entry_ip_address.get() - utils.save_json(self.parent.PATH_CONFIG, "OSC_IP_ADDRESS", self.parent.OSC_IP_ADDRESS) + save_json(self.parent.PATH_CONFIG, "OSC_IP_ADDRESS", self.parent.OSC_IP_ADDRESS) def entry_port_callback(self, event): self.parent.OSC_PORT = self.entry_port.get() - utils.save_json(self.parent.PATH_CONFIG, "OSC_PORT", self.parent.OSC_PORT) + save_json(self.parent.PATH_CONFIG, "OSC_PORT", self.parent.OSC_PORT) def entry_authkey_callback(self, event): value = self.entry_authkey.get() if len(value) > 0: if self.parent.translator.authentication("DeepL(auth)", value) is True: self.parent.AUTH_KEYS["DeepL(auth)"] = value - utils.save_json(self.parent.PATH_CONFIG, "AUTH_KEYS", self.parent.AUTH_KEYS) - utils.print_textbox(self.parent.textbox_message_log, "Auth key update completed", "INFO") - utils.print_textbox(self.parent.textbox_message_system_log, "Auth key update completed", "INFO") + save_json(self.parent.PATH_CONFIG, "AUTH_KEYS", self.parent.AUTH_KEYS) + print_textbox(self.parent.textbox_message_log, "Auth key update completed", "INFO") + print_textbox(self.parent.textbox_message_system_log, "Auth key update completed", "INFO") else: pass @@ -820,4 +822,4 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): value = self.entry_message_format.get() if len(value) > 0: self.parent.MESSAGE_FORMAT = value - utils.save_json(self.parent.PATH_CONFIG, "MESSAGE_FORMAT", self.parent.MESSAGE_FORMAT) \ No newline at end of file + save_json(self.parent.PATH_CONFIG, "MESSAGE_FORMAT", self.parent.MESSAGE_FORMAT) \ No newline at end of file diff --git a/window_information.py b/window_information.py index f3039589..39f9d713 100644 --- a/window_information.py +++ b/window_information.py @@ -1,7 +1,7 @@ import os -import customtkinter +from customtkinter import CTkToplevel, CTkTextbox, CTkFont -class ToplevelWindowInformation(customtkinter.CTkToplevel): +class ToplevelWindowInformation(CTkToplevel): def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.parent = parent @@ -13,9 +13,9 @@ class ToplevelWindowInformation(customtkinter.CTkToplevel): self.after(200, lambda: self.iconbitmap(os.path.join(os.path.dirname(__file__), "img", "app.ico"))) self.title("Information") # create textbox information - self.textbox_information = customtkinter.CTkTextbox( + self.textbox_information = CTkTextbox( self, - font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + font=CTkFont(family=self.parent.FONT_FAMILY) ) self.textbox_information.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew") textbox_information_message = """VRCT(v1.2) From 3c6d51f8354b931412c92f9ae665ceb37518111a Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 7 Jul 2023 18:05:22 +0900 Subject: [PATCH 03/54] [update] Config Transcription Tab change energy threshold UI. Entry to Slider --- window_config.py | 66 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 20 deletions(-) diff --git a/window_config.py b/window_config.py index 475a59bc..0a80b333 100644 --- a/window_config.py +++ b/window_config.py @@ -1,8 +1,8 @@ from os import path as os_path -from tkinter import DoubleVar +from tkinter import DoubleVar, IntVar from tkinter import font as tk_font import customtkinter -from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox +from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox, CTkProgressBar from flashtext import KeywordProcessor from utils import save_json, print_textbox @@ -10,6 +10,9 @@ from audio_utils import get_input_device_list, get_output_device_list from languages import translation_lang, transcription_lang class ToplevelWindowConfig(CTkToplevel): + MAX_MIC_ENERGY_THRESHOLD = 2000 + MAX_SPEAKER_ENERGY_THRESHOLD = 2000 + def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.parent = parent @@ -267,14 +270,26 @@ class ToplevelWindowConfig(CTkToplevel): fg_color="transparent", font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_energy_threshold = CTkEntry( + self.label_input_mic_energy_threshold.grid(row=row, column=0, rowspan=2, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.progressBar_input_mic_energy_threshold = CTkProgressBar( self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), - font=CTkFont(family=self.parent.FONT_FAMILY) + corner_radius=0 ) - self.entry_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") - self.entry_input_mic_energy_threshold.bind("", self.entry_input_mic_energy_threshold_callback) + self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") + + row +=1 + self.slider_input_mic_energy_threshold = customtkinter.CTkSlider( + self.tabview_config.tab("Transcription"), + from_=0, + to=self.MAX_MIC_ENERGY_THRESHOLD, + border_width=5, + button_length=0, + button_corner_radius=3, + number_of_steps=self.MAX_MIC_ENERGY_THRESHOLD, + command=self.slider_input_mic_energy_threshold_callback, + variable=IntVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), + ) + self.slider_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=0, sticky="nsew") ## checkbox input mic dynamic energy threshold row +=1 @@ -413,14 +428,27 @@ class ToplevelWindowConfig(CTkToplevel): fg_color="transparent", font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_energy_threshold = CTkEntry( + self.label_input_speaker_energy_threshold.grid(row=row, column=0, rowspan=2, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + self.progressBar_input_speaker_energy_threshold = CTkProgressBar( self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), - font=CTkFont(family=self.parent.FONT_FAMILY) + corner_radius=0 ) - self.entry_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") - self.entry_input_speaker_energy_threshold.bind("", self.entry_input_speaker_energy_threshold_callback) + self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") + + row +=1 + self.slider_input_speaker_energy_threshold = customtkinter.CTkSlider( + self.tabview_config.tab("Transcription"), + from_=0, + to=self.MAX_SPEAKER_ENERGY_THRESHOLD, + border_width=5, + button_length=0, + button_corner_radius=3, + number_of_steps=self.MAX_SPEAKER_ENERGY_THRESHOLD, + command=self.slider_input_speaker_energy_threshold_callback, + variable=IntVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), + ) + self.slider_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=0, sticky="nsew") ## checkbox input speaker dynamic energy threshold row +=1 @@ -626,7 +654,6 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_mic_voice_language.configure(font=CTkFont(family=choice)) self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=choice)) self.label_input_mic_energy_threshold.configure(font=CTkFont(family=choice)) - self.entry_input_mic_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_mic_dynamic_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_mic_record_timeout.configure(font=CTkFont(family=choice)) self.entry_input_mic_record_timeout.configure(font=CTkFont(family=choice)) @@ -643,7 +670,6 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_speaker_voice_language.configure(font=CTkFont(family=choice)) self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=choice)) self.label_input_speaker_energy_threshold.configure(font=CTkFont(family=choice)) - self.entry_input_speaker_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_speaker_dynamic_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_speaker_record_timeout.configure(font=CTkFont(family=choice)) self.entry_input_speaker_record_timeout.configure(font=CTkFont(family=choice)) @@ -736,8 +762,8 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.INPUT_MIC_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) - def entry_input_mic_energy_threshold_callback(self, event): - self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(self.entry_input_mic_energy_threshold.get()) + def slider_input_mic_energy_threshold_callback(self, value): + self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) save_json(self.parent.PATH_CONFIG, "INPUT_MIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_ENERGY_THRESHOLD) def checkbox_input_mic_dynamic_energy_threshold_callback(self): @@ -772,8 +798,8 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) - def entry_input_speaker_energy_threshold_callback(self, event): - self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(self.entry_input_speaker_energy_threshold.get()) + def slider_input_speaker_energy_threshold_callback(self, value): + self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD) def checkbox_input_speaker_dynamic_energy_threshold_callback(self): From 0a8c7dd0d07bd15d5c0f32079508ab819a63a1de Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sun, 9 Jul 2023 02:03:45 +0900 Subject: [PATCH 04/54] Check Point MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit このままだと動かない --- window_config.py | 50 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/window_config.py b/window_config.py index 0a80b333..66d7a840 100644 --- a/window_config.py +++ b/window_config.py @@ -1,4 +1,6 @@ +from time import sleep from os import path as os_path +from threading import Thread from tkinter import DoubleVar, IntVar from tkinter import font as tk_font import customtkinter @@ -7,11 +9,11 @@ from flashtext import KeywordProcessor from utils import save_json, print_textbox from audio_utils import get_input_device_list, get_output_device_list +from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder from languages import translation_lang, transcription_lang class ToplevelWindowConfig(CTkToplevel): - MAX_MIC_ENERGY_THRESHOLD = 2000 - MAX_SPEAKER_ENERGY_THRESHOLD = 2000 + def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) @@ -24,6 +26,12 @@ class ToplevelWindowConfig(CTkToplevel): self.after(200, lambda: self.iconbitmap(os_path.join(os_path.dirname(__file__), "img", "app.ico"))) self.title("Config") + # init parameter + self.MAX_MIC_ENERGY_THRESHOLD = 2000 + self.MAX_SPEAKER_ENERGY_THRESHOLD = 4000 + self.FLAG_LOOP_MIC = True + self.FLAG_LOOP_SPEAKER = True + # tabwiew config self.tabview_config = CTkTabview(self) self.tabview_config.grid(row=0, column=0, padx=5, pady=5, sticky="nsew") @@ -276,6 +284,9 @@ class ToplevelWindowConfig(CTkToplevel): corner_radius=0 ) self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") + self.th_progressBar_input_mic_energy_threshold_recorder = Thread(target=self.progressBar_input_mic_energy_threshold_recorder, daemon=True) + self.th_progressBar_input_mic_energy_threshold_recorder.start() + sleep(2) row +=1 self.slider_input_mic_energy_threshold = customtkinter.CTkSlider( @@ -435,7 +446,9 @@ class ToplevelWindowConfig(CTkToplevel): corner_radius=0 ) self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - + self.th_progressBar_input_speaker_energy_threshold_recorder = Thread(target=self.progressBar_input_speaker_energy_threshold_recorder, daemon=True) + self.th_progressBar_input_speaker_energy_threshold_recorder.start() + row +=1 self.slider_input_speaker_energy_threshold = customtkinter.CTkSlider( self.tabview_config.tab("Transcription"), @@ -762,6 +775,19 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.INPUT_MIC_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) + def progressBar_input_mic_energy_threshold_recorder(self): + while self.FLAG_LOOP_MIC: + mic_device_name = self.parent.CHOICE_MIC_DEVICE + mic_device = [device for device in get_input_device_list() if device["name"] == mic_device_name][0] + re = SelectedMicRecorder(mic_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) + while self.FLAG_LOOP_MIC: + if mic_device_name != self.parent.CHOICE_MIC_DEVICE: + break + with re.source as source: + energy = re.recorder.listen_energy(source) + self.progressBar_input_mic_energy_threshold.set(energy/self.MAX_MIC_ENERGY_THRESHOLD) + sleep(2) + def slider_input_mic_energy_threshold_callback(self, value): self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) save_json(self.parent.PATH_CONFIG, "INPUT_MIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_ENERGY_THRESHOLD) @@ -798,6 +824,19 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) + def progressBar_input_speaker_energy_threshold_recorder(self): + while self.FLAG_LOOP_SPEAKER: + speaker_device_name = self.parent.CHOICE_SPEAKER_DEVICE + speaker_device = [device for device in get_output_device_list() if device["name"] == speaker_device_name][0] + re = SelectedSpeakerRecorder(speaker_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) + while self.FLAG_LOOP_SPEAKER: + if speaker_device_name != self.parent.CHOICE_SPEAKER_DEVICE: + break + with re.source as source: + energy = re.recorder.listen_energy(source) + self.progressBar_input_speaker_energy_threshold.set(energy/self.MAX_SPEAKER_ENERGY_THRESHOLD) + sleep(2) + def slider_input_speaker_energy_threshold_callback(self, value): self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD) @@ -839,6 +878,11 @@ class ToplevelWindowConfig(CTkToplevel): pass def delete_window(self): + self.FLAG_LOOP_MIC = False + self.FLAG_LOOP_SPEAKER = False + self.th_progressBar_input_mic_energy_threshold_recorder.join() + self.th_progressBar_input_speaker_energy_threshold_recorder.join() + sleep(1) self.parent.checkbox_translation.configure(state="normal") self.parent.checkbox_transcription_send.configure(state="normal") self.parent.checkbox_transcription_receive.configure(state="normal") From 41df105bab84196a42bfa588faab44c3b1dd8ac9 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sun, 9 Jul 2023 03:51:55 +0900 Subject: [PATCH 05/54] Corrected process But unstable --- window_config.py | 61 ++++++++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 25 deletions(-) diff --git a/window_config.py b/window_config.py index 66d7a840..acb834b9 100644 --- a/window_config.py +++ b/window_config.py @@ -1,13 +1,12 @@ from time import sleep from os import path as os_path -from threading import Thread from tkinter import DoubleVar, IntVar from tkinter import font as tk_font import customtkinter from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox, CTkProgressBar from flashtext import KeywordProcessor -from utils import save_json, print_textbox +from utils import save_json, print_textbox, thread_fnc from audio_utils import get_input_device_list, get_output_device_list from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder from languages import translation_lang, transcription_lang @@ -29,8 +28,8 @@ class ToplevelWindowConfig(CTkToplevel): # init parameter self.MAX_MIC_ENERGY_THRESHOLD = 2000 self.MAX_SPEAKER_ENERGY_THRESHOLD = 4000 - self.FLAG_LOOP_MIC = True - self.FLAG_LOOP_SPEAKER = True + self.last_mic_device_name = None + self.last_speaker_device_name = None # tabwiew config self.tabview_config = CTkTabview(self) @@ -284,7 +283,8 @@ class ToplevelWindowConfig(CTkToplevel): corner_radius=0 ) self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - self.th_progressBar_input_mic_energy_threshold_recorder = Thread(target=self.progressBar_input_mic_energy_threshold_recorder, daemon=True) + self.th_progressBar_input_mic_energy_threshold_recorder = thread_fnc(fnc=self.progressBar_input_mic_energy_threshold_recorder) + self.th_progressBar_input_mic_energy_threshold_recorder.daemon = True self.th_progressBar_input_mic_energy_threshold_recorder.start() sleep(2) @@ -446,7 +446,8 @@ class ToplevelWindowConfig(CTkToplevel): corner_radius=0 ) self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - self.th_progressBar_input_speaker_energy_threshold_recorder = Thread(target=self.progressBar_input_speaker_energy_threshold_recorder, daemon=True) + self.th_progressBar_input_speaker_energy_threshold_recorder = thread_fnc(fnc=self.progressBar_input_speaker_energy_threshold_recorder) + self.th_progressBar_input_speaker_energy_threshold_recorder.daemon=True self.th_progressBar_input_speaker_energy_threshold_recorder.start() row +=1 @@ -776,17 +777,20 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) def progressBar_input_mic_energy_threshold_recorder(self): - while self.FLAG_LOOP_MIC: - mic_device_name = self.parent.CHOICE_MIC_DEVICE - mic_device = [device for device in get_input_device_list() if device["name"] == mic_device_name][0] - re = SelectedMicRecorder(mic_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) - while self.FLAG_LOOP_MIC: - if mic_device_name != self.parent.CHOICE_MIC_DEVICE: + self.last_mic_device_name = self.parent.CHOICE_MIC_DEVICE + mic_device = [device for device in get_input_device_list() if device["name"] == self.last_mic_device_name][0] + re = SelectedMicRecorder(mic_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) + try: + while True: + if self.last_mic_device_name != self.parent.CHOICE_MIC_DEVICE: break with re.source as source: energy = re.recorder.listen_energy(source) self.progressBar_input_mic_energy_threshold.set(energy/self.MAX_MIC_ENERGY_THRESHOLD) - sleep(2) + sleep(0.05) + except: + pass + sleep(5) def slider_input_mic_energy_threshold_callback(self, value): self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) @@ -825,17 +829,20 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) def progressBar_input_speaker_energy_threshold_recorder(self): - while self.FLAG_LOOP_SPEAKER: - speaker_device_name = self.parent.CHOICE_SPEAKER_DEVICE - speaker_device = [device for device in get_output_device_list() if device["name"] == speaker_device_name][0] - re = SelectedSpeakerRecorder(speaker_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) - while self.FLAG_LOOP_SPEAKER: - if speaker_device_name != self.parent.CHOICE_SPEAKER_DEVICE: + self.last_speaker_device_name = self.parent.CHOICE_SPEAKER_DEVICE + speaker_device = [device for device in get_output_device_list() if device["name"] == self.last_speaker_device_name][0] + re = SelectedSpeakerRecorder(speaker_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) + try: + while True: + if self.last_speaker_device_name != self.parent.CHOICE_SPEAKER_DEVICE: break with re.source as source: energy = re.recorder.listen_energy(source) self.progressBar_input_speaker_energy_threshold.set(energy/self.MAX_SPEAKER_ENERGY_THRESHOLD) - sleep(2) + sleep(0.05) + except: + pass + sleep(5) def slider_input_speaker_energy_threshold_callback(self, value): self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) @@ -878,11 +885,15 @@ class ToplevelWindowConfig(CTkToplevel): pass def delete_window(self): - self.FLAG_LOOP_MIC = False - self.FLAG_LOOP_SPEAKER = False - self.th_progressBar_input_mic_energy_threshold_recorder.join() - self.th_progressBar_input_speaker_energy_threshold_recorder.join() - sleep(1) + + if isinstance(self.th_progressBar_input_mic_energy_threshold_recorder, thread_fnc): + self.th_progressBar_input_mic_energy_threshold_recorder.stop() + self.last_mic_device_name = None + + if isinstance(self.th_progressBar_input_speaker_energy_threshold_recorder, thread_fnc): + self.th_progressBar_input_speaker_energy_threshold_recorder.stop() + self.last_speaker_device_name = None + self.parent.checkbox_translation.configure(state="normal") self.parent.checkbox_transcription_send.configure(state="normal") self.parent.checkbox_transcription_receive.configure(state="normal") From 14d3a4a33e14e2c0211744fc8ffe3ede71acd026 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 00:40:39 +0900 Subject: [PATCH 06/54] add SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder --- audio_recorder.py | 46 ++++++++++++++++++- window_config.py | 110 ++++++++++++++++++++++++++-------------------- 2 files changed, 108 insertions(+), 48 deletions(-) diff --git a/audio_recorder.py b/audio_recorder.py index 0b146677..9d63001e 100644 --- a/audio_recorder.py +++ b/audio_recorder.py @@ -21,7 +21,7 @@ class BaseRecorder: def record_into_queue(self, audio_queue): def record_callback(_, audio): - audio_queue.put((audio.get_raw_data(), datetime.now())) + audio_queue.put((audio[0].get_raw_data(), audio[1], datetime.now())) self.stop = self.recorder.listen_in_background(self.source, record_callback, phrase_time_limit=self.record_timeout) @@ -44,4 +44,48 @@ class SelectedSpeakerRecorder(BaseRecorder): channels=device["maxInputChannels"] ) super().__init__(source=source, energy_threshold=energy_threshold, dynamic_energy_threshold=dynamic_energy_threshold, record_timeout=record_timeout) + self.adjust_for_noise() + +class BaseEnergyRecorder: + def __init__(self, source): + self.recorder = Recognizer() + self.recorder.energy_threshold = 0 + self.recorder.dynamic_energy_threshold = False + self.record_timeout = 0 + self.stop = None + + if source is None: + raise ValueError("audio source can't be None") + + self.source = source + + def adjust_for_noise(self): + with self.source: + self.recorder.adjust_for_ambient_noise(self.source) + + def record_into_queue(self, energy_queue): + def record_callback(_, energy): + energy_queue.put(energy) + + self.stop = self.recorder.listen_energy_in_background(self.source, record_callback) + +class SelectedMicEnergyRecorder(BaseEnergyRecorder): + def __init__(self, device): + source=Microphone( + device_index=device['index'], + sample_rate=int(device["defaultSampleRate"]), + ) + super().__init__(source=source) + self.adjust_for_noise() + +class SelectedSpeakeEnergyRecorder(BaseEnergyRecorder): + def __init__(self, device): + + source = Microphone(speaker=True, + device_index= device["index"], + sample_rate=int(device["defaultSampleRate"]), + chunk_size=get_sample_size(paInt16), + channels=device["maxInputChannels"] + ) + super().__init__(source=source) self.adjust_for_noise() \ No newline at end of file diff --git a/window_config.py b/window_config.py index acb834b9..0462e261 100644 --- a/window_config.py +++ b/window_config.py @@ -1,4 +1,5 @@ from time import sleep +from queue import Queue from os import path as os_path from tkinter import DoubleVar, IntVar from tkinter import font as tk_font @@ -8,12 +9,11 @@ from flashtext import KeywordProcessor from utils import save_json, print_textbox, thread_fnc from audio_utils import get_input_device_list, get_output_device_list -from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder +from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder from languages import translation_lang, transcription_lang class ToplevelWindowConfig(CTkToplevel): - def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.parent = parent @@ -27,7 +27,7 @@ class ToplevelWindowConfig(CTkToplevel): # init parameter self.MAX_MIC_ENERGY_THRESHOLD = 2000 - self.MAX_SPEAKER_ENERGY_THRESHOLD = 4000 + self.MAX_SPEAKER_ENERGY_THRESHOLD = 2000 self.last_mic_device_name = None self.last_speaker_device_name = None @@ -283,11 +283,21 @@ class ToplevelWindowConfig(CTkToplevel): corner_radius=0 ) self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - self.th_progressBar_input_mic_energy_threshold_recorder = thread_fnc(fnc=self.progressBar_input_mic_energy_threshold_recorder) - self.th_progressBar_input_mic_energy_threshold_recorder.daemon = True - self.th_progressBar_input_mic_energy_threshold_recorder.start() + + self.mic_energy_queue = Queue() + mic_device = [device for device in get_input_device_list() if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] + + try: + self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) + self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) + except Exception as e: + print(e) sleep(2) + self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) + self.mic_energy_plot_progressbar.daemon = True + self.mic_energy_plot_progressbar.start() + row +=1 self.slider_input_mic_energy_threshold = customtkinter.CTkSlider( self.tabview_config.tab("Transcription"), @@ -446,9 +456,19 @@ class ToplevelWindowConfig(CTkToplevel): corner_radius=0 ) self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - self.th_progressBar_input_speaker_energy_threshold_recorder = thread_fnc(fnc=self.progressBar_input_speaker_energy_threshold_recorder) - self.th_progressBar_input_speaker_energy_threshold_recorder.daemon=True - self.th_progressBar_input_speaker_energy_threshold_recorder.start() + + self.speaker_energy_queue = Queue() + speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] + try: + self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) + self.speaker_energy_recorder.record_into_queue(self.speaker_energy_queue) + except Exception as e: + print(e) + sleep(2) + + self.speaker_energy_plot_progressbar = thread_fnc(self.progressBar_input_speaker_energy_plot) + self.speaker_energy_plot_progressbar.daemon = True + self.speaker_energy_plot_progressbar.start() row +=1 self.slider_input_speaker_energy_threshold = customtkinter.CTkSlider( @@ -772,25 +792,25 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.CHOICE_MIC_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) + self.mic_energy_recorder.stop() + self.mic_energy_recorder.stop = None + sleep(2) + try: + mic_device = [device for device in get_input_device_list() if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] + self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) + self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) + except Exception as e: + print(e) + def optionmenu_input_mic_voice_language_callback(self, choice): self.parent.INPUT_MIC_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) - def progressBar_input_mic_energy_threshold_recorder(self): - self.last_mic_device_name = self.parent.CHOICE_MIC_DEVICE - mic_device = [device for device in get_input_device_list() if device["name"] == self.last_mic_device_name][0] - re = SelectedMicRecorder(mic_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) - try: - while True: - if self.last_mic_device_name != self.parent.CHOICE_MIC_DEVICE: - break - with re.source as source: - energy = re.recorder.listen_energy(source) - self.progressBar_input_mic_energy_threshold.set(energy/self.MAX_MIC_ENERGY_THRESHOLD) - sleep(0.05) - except: - pass - sleep(5) + def progressBar_input_mic_energy_plot(self): + if self.mic_energy_queue.empty() is False: + energy = self.mic_energy_queue.get() + self.progressBar_input_mic_energy_threshold.set(energy/self.MAX_MIC_ENERGY_THRESHOLD) + sleep(0.01) def slider_input_mic_energy_threshold_callback(self, value): self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) @@ -824,25 +844,25 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.CHOICE_SPEAKER_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) + self.speaker_energy_recorder.stop() + self.speaker_energy_recorder.stop = None + sleep(2) + try: + speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] + self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) + self.speaker_energy_recorder.record_into_queue(self.speaker_energy_queue) + except Exception as e: + print(e) + def optionmenu_input_speaker_voice_language_callback(self, choice): self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) - def progressBar_input_speaker_energy_threshold_recorder(self): - self.last_speaker_device_name = self.parent.CHOICE_SPEAKER_DEVICE - speaker_device = [device for device in get_output_device_list() if device["name"] == self.last_speaker_device_name][0] - re = SelectedSpeakerRecorder(speaker_device, energy_threshold=0, dynamic_energy_threshold=False, record_timeout=0) - try: - while True: - if self.last_speaker_device_name != self.parent.CHOICE_SPEAKER_DEVICE: - break - with re.source as source: - energy = re.recorder.listen_energy(source) - self.progressBar_input_speaker_energy_threshold.set(energy/self.MAX_SPEAKER_ENERGY_THRESHOLD) - sleep(0.05) - except: - pass - sleep(5) + def progressBar_input_speaker_energy_plot(self): + if self.speaker_energy_queue.empty() is False: + energy = self.speaker_energy_queue.get() + self.progressBar_input_speaker_energy_threshold.set(energy/self.MAX_SPEAKER_ENERGY_THRESHOLD) + sleep(0.01) def slider_input_speaker_energy_threshold_callback(self, value): self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) @@ -885,15 +905,11 @@ class ToplevelWindowConfig(CTkToplevel): pass def delete_window(self): - - if isinstance(self.th_progressBar_input_mic_energy_threshold_recorder, thread_fnc): - self.th_progressBar_input_mic_energy_threshold_recorder.stop() - self.last_mic_device_name = None + self.mic_energy_recorder.stop() + self.mic_energy_plot_progressbar.stop() + self.speaker_energy_recorder.stop() + self.speaker_energy_plot_progressbar.stop() - if isinstance(self.th_progressBar_input_speaker_energy_threshold_recorder, thread_fnc): - self.th_progressBar_input_speaker_energy_threshold_recorder.stop() - self.last_speaker_device_name = None - self.parent.checkbox_translation.configure(state="normal") self.parent.checkbox_transcription_send.configure(state="normal") self.parent.checkbox_transcription_receive.configure(state="normal") From 574133034ded716dc2443e7505457502fe21f366 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 01:20:50 +0900 Subject: [PATCH 07/54] fix typo --- audio_recorder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/audio_recorder.py b/audio_recorder.py index 9d63001e..ab03d78b 100644 --- a/audio_recorder.py +++ b/audio_recorder.py @@ -21,7 +21,7 @@ class BaseRecorder: def record_into_queue(self, audio_queue): def record_callback(_, audio): - audio_queue.put((audio[0].get_raw_data(), audio[1], datetime.now())) + audio_queue.put((audio.get_raw_data(), datetime.now())) self.stop = self.recorder.listen_in_background(self.source, record_callback, phrase_time_limit=self.record_timeout) From 4cfc4d0d2e066a7261ab55fbf69ee43d8ba5fd5f Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 11 Jul 2023 07:11:58 +0900 Subject: [PATCH 08/54] =?UTF-8?q?=E3=83=81=E3=83=A3=E3=83=83=E3=83=88?= =?UTF-8?q?=E9=80=81=E4=BF=A1=E5=BE=8C=E3=80=81=E8=87=AA=E5=8B=95=E7=9A=84?= =?UTF-8?q?=E3=81=AB=E3=83=81=E3=83=A3=E3=83=83=E3=83=88=E3=83=9C=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=B9=E3=82=92=E7=A9=BA=E3=81=AB=E3=81=99=E3=82=8B?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E5=BE=A9=E6=B4=BB=E3=80=82Config?= =?UTF-8?q?=E3=81=A7=E3=82=AA=E3=83=B3=E3=82=AA=E3=83=95=E5=88=87=E6=9B=BF?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=80=82=E3=81=BE=E3=81=9F=E3=80=81Config?= =?UTF-8?q?=E7=94=BB=E9=9D=A2=E3=81=AE=E3=82=BF=E3=83=96=E3=81=ABOthers?= =?UTF-8?q?=E3=82=BF=E3=83=96=E3=82=92=E8=BF=BD=E5=8A=A0=E3=80=82=EF=BC=88?= =?UTF-8?q?=E4=BB=8A=E5=9B=9E=E3=81=AE=E6=A9=9F=E8=83=BD=E3=81=AF=E6=97=A2?= =?UTF-8?q?=E5=AD=98=E3=81=AE=E3=81=A9=E3=81=AE=E3=82=BF=E3=83=96=E3=81=AB?= =?UTF-8?q?=E3=82=82=E5=BD=93=E3=81=A6=E3=81=AF=E3=81=BE=E3=82=89=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=81=A8=E5=88=A4=E6=96=AD=EF=BC=89=20=E3=81=9D?= =?UTF-8?q?=E3=82=8C=E3=81=AB=E4=BC=B4=E3=81=84README=E3=81=AE=E9=A0=85?= =?UTF-8?q?=E7=9B=AE=E3=82=82=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ README.txt | 2 ++ VRCT.py | 8 +++++++- window_config.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c880a05..7534c30d 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,8 @@ ptyhon VRCT.py - [message]がメッセージボックスに記入したメッセージに置換される - [translation]が翻訳されたメッセージに置換される - 初期フォーマット:`[message]([translation])` +- Others tab + - Auto clear chat box: チャット送信時にチャットボックスを空にする ## Author みしゃ(misyaguzi) diff --git a/README.txt b/README.txt index 97085db2..5a28b468 100644 --- a/README.txt +++ b/README.txt @@ -63,6 +63,8 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ      - [message]がメッセージボックスに記入したメッセージに置換される      - [translation]が翻訳されたメッセージに置換される      - 初期フォーマット:"[message]([translation])" +  - Othersタブ +    - Auto clear chat box: チャット送信時にチャットボックスを空にする  設定の初期化   - config.jsonを削除 diff --git a/VRCT.py b/VRCT.py index 13d9840e..2bd467ed 100644 --- a/VRCT.py +++ b/VRCT.py @@ -34,6 +34,7 @@ class App(customtkinter.CTk): self.APPEARANCE_THEME = "System" self.UI_SCALING = "100%" self.FONT_FAMILY = "Yu Gothic UI" + self.ENABLE_AUTO_CLEAR_CHATBOX = False ## Translation self.CHOICE_TRANSLATOR = languages.translators[0] self.INPUT_SOURCE_LANG = list(languages.translation_lang[self.CHOICE_TRANSLATOR].keys())[0] @@ -99,6 +100,9 @@ class App(customtkinter.CTk): if "FONT_FAMILY" in config.keys(): if config["FONT_FAMILY"] in list(tk.font.families()): self.FONT_FAMILY = config["FONT_FAMILY"] + if "ENABLE_AUTO_CLEAR_CHATBOX" in config.keys(): + if type(config["ENABLE_AUTO_CLEAR_CHATBOX"]) is bool: + self.ENABLE_AUTO_CLEAR_CHATBOX = config["ENABLE_AUTO_CLEAR_CHATBOX"] # translation if "CHOICE_TRANSLATOR" in config.keys(): @@ -189,6 +193,7 @@ class App(customtkinter.CTk): "APPEARANCE_THEME": self.APPEARANCE_THEME, "UI_SCALING": self.UI_SCALING, "FONT_FAMILY": self.FONT_FAMILY, + "ENABLE_AUTO_CLEAR_CHATBOX": self.ENABLE_AUTO_CLEAR_CHATBOX, "CHOICE_TRANSLATOR": self.CHOICE_TRANSLATOR, "INPUT_SOURCE_LANG": self.INPUT_SOURCE_LANG, "INPUT_TARGET_LANG": self.INPUT_TARGET_LANG, @@ -615,7 +620,8 @@ class App(customtkinter.CTk): utils.print_textbox(self.textbox_message_send_log, f"{chat_message}", "SEND") # delete message in entry message box - # self.entry_message_box.delete(0, customtkinter.END) + if self.ENABLE_AUTO_CLEAR_CHATBOX == True: + self.entry_message_box.delete(0, customtkinter.END) def entry_message_box_press_key_any(self, event): # send OSC typing diff --git a/window_config.py b/window_config.py index adbe90b9..c16cde0d 100644 --- a/window_config.py +++ b/window_config.py @@ -24,10 +24,12 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.tabview_config.add("Translation") self.tabview_config.add("Transcription") self.tabview_config.add("Parameter") + self.tabview_config.add("Others") self.tabview_config.tab("UI").grid_columnconfigure(1, weight=1) self.tabview_config.tab("Translation").grid_columnconfigure([1,2,3], weight=1) self.tabview_config.tab("Transcription").grid_columnconfigure(1, weight=1) self.tabview_config.tab("Parameter").grid_columnconfigure(1, weight=1) + self.tabview_config.tab("Others").grid_columnconfigure(1, weight=1) self.tabview_config._segmented_button.configure(font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY)) self.tabview_config._segmented_button.grid(sticky="W") @@ -546,6 +548,30 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.entry_message_format.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_message_format.bind("", self.entry_message_format_callback) + # tab Others + # checkbox auto clear chat box + row += 1 + self.label_checkbox_auto_clear_chatbox = customtkinter.CTkLabel( + self.tabview_config.tab("Others"), + text="Auto clear chat box", + fg_color="transparent", + font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_checkbox_auto_clear_chatbox.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.checkbox_auto_clear_chatbox = customtkinter.CTkCheckBox( + self.tabview_config.tab("Others"), + text="", + onvalue=True, + offvalue=False, + command=self.checkbox_auto_clear_chatbox_callback, + font=customtkinter.CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_auto_clear_chatbox.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + if self.parent.ENABLE_AUTO_CLEAR_CHATBOX is True: + self.checkbox_auto_clear_chatbox.select() + else: + self.checkbox_auto_clear_chatbox.deselect() + self.protocol("WM_DELETE_WINDOW", self.delete_window) def slider_transparency_callback(self, value): @@ -659,6 +685,11 @@ class ToplevelWindowConfig(customtkinter.CTkToplevel): self.parent.FONT_FAMILY = choice utils.save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) + + def checkbox_auto_clear_chatbox_callback(self): + value = self.checkbox_auto_clear_chatbox.get() + self.parent.ENABLE_AUTO_CLEAR_CHATBOX = value + utils.save_json(self.parent.PATH_CONFIG, "ENABLE_AUTO_CLEAR_CHATBOX", self.parent.ENABLE_AUTO_CLEAR_CHATBOX) def optionmenu_translation_translator_callback(self, choice): if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: From 9d7401392f0e3ca69110cd0b7d1f354073dae6b4 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 11 Jul 2023 08:35:32 +0900 Subject: [PATCH 09/54] =?UTF-8?q?fixed=20README.md=20install=E3=81=AE?= =?UTF-8?q?=E9=A0=85=E7=9B=AE=E3=82=92=E7=B7=A8=E9=9B=86=E3=80=82install?= =?UTF-8?q?=E6=99=82=E3=81=AB=E3=82=AB=E3=83=AC=E3=83=B3=E3=83=88=E3=83=87?= =?UTF-8?q?=E3=82=A3=E3=83=AC=E3=82=AF=E3=83=88=E3=83=AA=E3=81=AE=E7=A7=BB?= =?UTF-8?q?=E5=8B=95=E3=81=8C=E5=BF=85=E8=A6=81=E3=81=A0=E3=81=A3=E3=81=9F?= =?UTF-8?q?=E3=81=AE=E3=81=A7=E3=80=81=E3=81=9D=E3=81=AE=E7=A7=BB=E5=8B=95?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=82=82=E5=90=AB=E3=82=81=E3=81=A6=E3=82=B3?= =?UTF-8?q?=E3=83=9E=E3=83=B3=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7534c30d..b3891b50 100644 --- a/README.md +++ b/README.md @@ -24,11 +24,17 @@ pip install -r requirements.txt ```bash git clone https://github.com/misyaguziya/translators.git -python ./translators/setup.py install +cd translators +python ./setup.py install +cd ../ git clone https://github.com/misyaguziya/deepl-translate.git -python ./deepl_translate/setup.py install +cd deepl-translate +python ./setup.py install +cd ../ git clone https://github.com/misyaguziya/custom_speech_recognition.git -python ./custom_speech_recognition/setup.py install +cd custom_speech_recognition +python ./setup.py install +cd ../ ``` ## Usage From d6e950f66256fc7ceb0b0aa3bdfbac1fc8b1bfbc Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 10:03:57 +0900 Subject: [PATCH 10/54] update progressBar energy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit マイクとスピーカーのthresholdの閾値を可視化 --- window_config.py | 185 +++++++++++++++++++++++++++-------------------- 1 file changed, 107 insertions(+), 78 deletions(-) diff --git a/window_config.py b/window_config.py index 0462e261..1be950e5 100644 --- a/window_config.py +++ b/window_config.py @@ -1,5 +1,6 @@ from time import sleep from queue import Queue +from threading import Thread from os import path as os_path from tkinter import DoubleVar, IntVar from tkinter import font as tk_font @@ -8,7 +9,7 @@ from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, from flashtext import KeywordProcessor from utils import save_json, print_textbox, thread_fnc -from audio_utils import get_input_device_list, get_output_device_list +from audio_utils import get_input_device_list, get_output_device_list, get_default_output_device from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder from languages import translation_lang, transcription_lang @@ -27,9 +28,11 @@ class ToplevelWindowConfig(CTkToplevel): # init parameter self.MAX_MIC_ENERGY_THRESHOLD = 2000 - self.MAX_SPEAKER_ENERGY_THRESHOLD = 2000 - self.last_mic_device_name = None - self.last_speaker_device_name = None + self.MAX_SPEAKER_ENERGY_THRESHOLD = 4000 + self.mic_energy_recorder = None + self.mic_energy_plot_progressbar = None + self.speaker_energy_recorder = None + self.speaker_energy_plot_progressbar = None # tabwiew config self.tabview_config = CTkTabview(self) @@ -269,7 +272,7 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - ## entry input mic energy threshold + ## slider input mic energy threshold row +=1 self.label_input_mic_energy_threshold = CTkLabel( self.tabview_config.tab("Transcription"), @@ -277,40 +280,39 @@ class ToplevelWindowConfig(CTkToplevel): fg_color="transparent", font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.label_input_mic_energy_threshold.grid(row=row, column=0, rowspan=2, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.progressBar_input_mic_energy_threshold = CTkProgressBar( - self.tabview_config.tab("Transcription"), - corner_radius=0 - ) - self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - - self.mic_energy_queue = Queue() - mic_device = [device for device in get_input_device_list() if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] - - try: - self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) - self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) - except Exception as e: - print(e) - sleep(2) + self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) - self.mic_energy_plot_progressbar.daemon = True - self.mic_energy_plot_progressbar.start() - - row +=1 self.slider_input_mic_energy_threshold = customtkinter.CTkSlider( self.tabview_config.tab("Transcription"), from_=0, to=self.MAX_MIC_ENERGY_THRESHOLD, - border_width=5, + border_width=7, button_length=0, button_corner_radius=3, number_of_steps=self.MAX_MIC_ENERGY_THRESHOLD, command=self.slider_input_mic_energy_threshold_callback, variable=IntVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), ) - self.slider_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=0, sticky="nsew") + self.slider_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") + + ## progressBar input mic energy threshold + row +=1 + self.checkbox_input_mic_threshold_check = CTkCheckBox( + self.tabview_config.tab("Transcription"), + text="check threshold point", + onvalue=True, + offvalue=False, + command=self.checkbox_input_mic_threshold_check_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_input_mic_threshold_check.grid(row=row, column=0, columnspan=1 ,padx=padx, pady=pady, sticky="nsw") + + self.progressBar_input_mic_energy_threshold = CTkProgressBar( + self.tabview_config.tab("Transcription"), + corner_radius=0 + ) + self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=5, sticky="nsew") + self.progressBar_input_mic_energy_threshold.set(0) ## checkbox input mic dynamic energy threshold row +=1 @@ -449,40 +451,40 @@ class ToplevelWindowConfig(CTkToplevel): fg_color="transparent", font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.label_input_speaker_energy_threshold.grid(row=row, column=0, rowspan=2, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.progressBar_input_speaker_energy_threshold = CTkProgressBar( - self.tabview_config.tab("Transcription"), - corner_radius=0 - ) - self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=5, pady=(5,0), sticky="nsew") - - self.speaker_energy_queue = Queue() - speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] - try: - self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) - self.speaker_energy_recorder.record_into_queue(self.speaker_energy_queue) - except Exception as e: - print(e) - sleep(2) - - self.speaker_energy_plot_progressbar = thread_fnc(self.progressBar_input_speaker_energy_plot) - self.speaker_energy_plot_progressbar.daemon = True - self.speaker_energy_plot_progressbar.start() - - row +=1 + ## progressBar input speaker energy threshold self.slider_input_speaker_energy_threshold = customtkinter.CTkSlider( self.tabview_config.tab("Transcription"), from_=0, to=self.MAX_SPEAKER_ENERGY_THRESHOLD, - border_width=5, + border_width=7, button_length=0, button_corner_radius=3, number_of_steps=self.MAX_SPEAKER_ENERGY_THRESHOLD, command=self.slider_input_speaker_energy_threshold_callback, variable=IntVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), ) - self.slider_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=0, sticky="nsew") + self.slider_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") + + ## progressBar input speaker energy threshold + row +=1 + self.checkbox_input_speaker_threshold_check = CTkCheckBox( + self.tabview_config.tab("Transcription"), + text="check threshold point", + onvalue=True, + offvalue=False, + command=self.checkbox_input_speaker_threshold_check_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_input_speaker_threshold_check.grid(row=row, column=0, columnspan=1 ,padx=padx, pady=pady, sticky="nsw") + + self.progressBar_input_speaker_energy_threshold = CTkProgressBar( + self.tabview_config.tab("Transcription"), + corner_radius=0 + ) + self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=5, sticky="nsew") + self.progressBar_input_speaker_energy_threshold.set(0) ## checkbox input speaker dynamic energy threshold row +=1 @@ -791,16 +793,8 @@ class ToplevelWindowConfig(CTkToplevel): def optionmenu_input_mic_device_callback(self, choice): self.parent.CHOICE_MIC_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) - - self.mic_energy_recorder.stop() - self.mic_energy_recorder.stop = None - sleep(2) - try: - mic_device = [device for device in get_input_device_list() if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] - self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) - self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) - except Exception as e: - print(e) + self.checkbox_input_mic_threshold_check.deselect() + self.checkbox_input_mic_threshold_check_callback() def optionmenu_input_mic_voice_language_callback(self, choice): self.parent.INPUT_MIC_VOICE_LANGUAGE = choice @@ -809,9 +803,28 @@ class ToplevelWindowConfig(CTkToplevel): def progressBar_input_mic_energy_plot(self): if self.mic_energy_queue.empty() is False: energy = self.mic_energy_queue.get() - self.progressBar_input_mic_energy_threshold.set(energy/self.MAX_MIC_ENERGY_THRESHOLD) + try: + self.progressBar_input_mic_energy_threshold.set(energy/self.MAX_MIC_ENERGY_THRESHOLD) + except: + pass sleep(0.01) + def checkbox_input_mic_threshold_check_callback(self): + if self.checkbox_input_mic_threshold_check.get(): + self.mic_energy_queue = Queue() + mic_device = [device for device in get_input_device_list() if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] + self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) + self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) + self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) + self.mic_energy_plot_progressbar.daemon = True + self.mic_energy_plot_progressbar.start() + else: + if self.mic_energy_recorder != None: + self.mic_energy_recorder.stop() + if self.mic_energy_plot_progressbar != None: + self.mic_energy_plot_progressbar.stop() + self.progressBar_input_mic_energy_threshold.set(0) + def slider_input_mic_energy_threshold_callback(self, value): self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) save_json(self.parent.PATH_CONFIG, "INPUT_MIC_ENERGY_THRESHOLD", self.parent.INPUT_MIC_ENERGY_THRESHOLD) @@ -843,16 +856,8 @@ class ToplevelWindowConfig(CTkToplevel): def optionmenu_input_speaker_device_callback(self, choice): self.parent.CHOICE_SPEAKER_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) - - self.speaker_energy_recorder.stop() - self.speaker_energy_recorder.stop = None - sleep(2) - try: - speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] - self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) - self.speaker_energy_recorder.record_into_queue(self.speaker_energy_queue) - except Exception as e: - print(e) + self.checkbox_input_speaker_threshold_check.deselect() + self.checkbox_input_speaker_threshold_check_callback() def optionmenu_input_speaker_voice_language_callback(self, choice): self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice @@ -861,9 +866,33 @@ class ToplevelWindowConfig(CTkToplevel): def progressBar_input_speaker_energy_plot(self): if self.speaker_energy_queue.empty() is False: energy = self.speaker_energy_queue.get() - self.progressBar_input_speaker_energy_threshold.set(energy/self.MAX_SPEAKER_ENERGY_THRESHOLD) + try: + self.progressBar_input_speaker_energy_threshold.set(energy/self.MAX_SPEAKER_ENERGY_THRESHOLD) + except: + pass sleep(0.01) + def checkbox_input_speaker_threshold_check_callback(self): + if self.checkbox_input_speaker_threshold_check.get(): + self.speaker_energy_queue = Queue() + speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] + + if get_default_output_device()["index"] == speaker_device["index"]: + self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) + self.speaker_energy_recorder.record_into_queue(self.speaker_energy_queue) + self.speaker_energy_plot_progressbar = thread_fnc(self.progressBar_input_speaker_energy_plot) + self.speaker_energy_plot_progressbar.daemon = True + self.speaker_energy_plot_progressbar.start() + else: + print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") + self.checkbox_input_speaker_threshold_check.deselect() + else: + if self.speaker_energy_recorder != None: + self.speaker_energy_recorder.stop() + if self.speaker_energy_plot_progressbar != None: + self.speaker_energy_plot_progressbar.stop() + self.progressBar_input_speaker_energy_threshold.set(0) + def slider_input_speaker_energy_threshold_callback(self, value): self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_ENERGY_THRESHOLD", self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD) @@ -905,11 +934,11 @@ class ToplevelWindowConfig(CTkToplevel): pass def delete_window(self): - self.mic_energy_recorder.stop() - self.mic_energy_plot_progressbar.stop() - self.speaker_energy_recorder.stop() - self.speaker_energy_plot_progressbar.stop() - + self.checkbox_input_mic_threshold_check.deselect() + self.checkbox_input_speaker_threshold_check.deselect() + self.checkbox_input_mic_threshold_check_callback() + self.checkbox_input_speaker_threshold_check_callback() + self.parent.checkbox_translation.configure(state="normal") self.parent.checkbox_transcription_send.configure(state="normal") self.parent.checkbox_transcription_receive.configure(state="normal") From 44b3b7de33411f58249c14b4ea259160121d243b Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 10:52:20 +0900 Subject: [PATCH 11/54] =?UTF-8?q?=E3=82=B9=E3=83=94=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=83=BC=E3=81=AE=E5=87=BA=E5=8A=9B=E3=81=A0=E3=81=91=E7=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=8F=96=E5=BE=97=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_config.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/window_config.py b/window_config.py index 1be950e5..2b3c5c89 100644 --- a/window_config.py +++ b/window_config.py @@ -32,6 +32,7 @@ class ToplevelWindowConfig(CTkToplevel): self.mic_energy_recorder = None self.mic_energy_plot_progressbar = None self.speaker_energy_recorder = None + self.speaker_energy_get_progressbar = None self.speaker_energy_plot_progressbar = None # tabwiew config @@ -872,6 +873,11 @@ class ToplevelWindowConfig(CTkToplevel): pass sleep(0.01) + def progressBar_input_speaker_energy_get(self): + with self.speaker_energy_recorder.source as source: + energy = self.speaker_energy_recorder.recorder.listen_energy(source) + self.speaker_energy_queue.put(energy) + def checkbox_input_speaker_threshold_check_callback(self): if self.checkbox_input_speaker_threshold_check.get(): self.speaker_energy_queue = Queue() @@ -879,7 +885,9 @@ class ToplevelWindowConfig(CTkToplevel): if get_default_output_device()["index"] == speaker_device["index"]: self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) - self.speaker_energy_recorder.record_into_queue(self.speaker_energy_queue) + self.speaker_energy_get_progressbar = thread_fnc(self.progressBar_input_speaker_energy_get) + self.speaker_energy_get_progressbar.daemon = True + self.speaker_energy_get_progressbar.start() self.speaker_energy_plot_progressbar = thread_fnc(self.progressBar_input_speaker_energy_plot) self.speaker_energy_plot_progressbar.daemon = True self.speaker_energy_plot_progressbar.start() @@ -887,8 +895,10 @@ class ToplevelWindowConfig(CTkToplevel): print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") self.checkbox_input_speaker_threshold_check.deselect() else: - if self.speaker_energy_recorder != None: - self.speaker_energy_recorder.stop() + if self.speaker_energy_get_progressbar != None: + self.speaker_energy_get_progressbar.stop() + # if self.speaker_energy_recorder != None: + # self.speaker_energy_recorder.stop() if self.speaker_energy_plot_progressbar != None: self.speaker_energy_plot_progressbar.stop() self.progressBar_input_speaker_energy_threshold.set(0) From f4099e5e76c00cb740b4db301d95adff139183de Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 11:16:43 +0900 Subject: [PATCH 12/54] remove comment out --- window_config.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/window_config.py b/window_config.py index 2b3c5c89..516a4371 100644 --- a/window_config.py +++ b/window_config.py @@ -897,8 +897,6 @@ class ToplevelWindowConfig(CTkToplevel): else: if self.speaker_energy_get_progressbar != None: self.speaker_energy_get_progressbar.stop() - # if self.speaker_energy_recorder != None: - # self.speaker_energy_recorder.stop() if self.speaker_energy_plot_progressbar != None: self.speaker_energy_plot_progressbar.stop() self.progressBar_input_speaker_energy_threshold.set(0) From 1987128b0ec8c117264380094d7870df3e961c9a Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 11:27:20 +0900 Subject: [PATCH 13/54] fix typo --- window_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index 1cc8a7f9..0c6b6147 100644 --- a/window_config.py +++ b/window_config.py @@ -712,7 +712,7 @@ class ToplevelWindowConfig(CTkToplevel): def checkbox_auto_clear_chatbox_callback(self): value = self.checkbox_auto_clear_chatbox.get() self.parent.ENABLE_AUTO_CLEAR_CHATBOX = value - utils.save_json(self.parent.PATH_CONFIG, "ENABLE_AUTO_CLEAR_CHATBOX", self.parent.ENABLE_AUTO_CLEAR_CHATBOX) + save_json(self.parent.PATH_CONFIG, "ENABLE_AUTO_CLEAR_CHATBOX", self.parent.ENABLE_AUTO_CLEAR_CHATBOX) def optionmenu_translation_translator_callback(self, choice): if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: From e0d3e321e909422d105b29169579720ff74160c7 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 11:31:26 +0900 Subject: [PATCH 14/54] add package flashtext --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1e4b81c7..aef8b222 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ pillow PyAudioWPatch python-osc customtkinter -deepl \ No newline at end of file +deepl +flashtext \ No newline at end of file From 81f2c9e44ec76378b1db97629c2c4b0003f856bf Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 11:47:57 +0900 Subject: [PATCH 15/54] remove customtkinter --- window_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index 367765a6..5a0c43f4 100644 --- a/window_config.py +++ b/window_config.py @@ -285,7 +285,7 @@ class ToplevelWindowConfig(CTkToplevel): ) self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.slider_input_mic_energy_threshold = customtkinter.CTkSlider( + self.slider_input_mic_energy_threshold = CTkSlider( self.tabview_config.tab("Transcription"), from_=0, to=self.MAX_MIC_ENERGY_THRESHOLD, From 0d4ed64590c54307536fd014328189eec22f9a0f Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 12:00:22 +0900 Subject: [PATCH 16/54] remove customtkinter --- window_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index 5a0c43f4..cce2a4f5 100644 --- a/window_config.py +++ b/window_config.py @@ -457,7 +457,7 @@ class ToplevelWindowConfig(CTkToplevel): self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") ## progressBar input speaker energy threshold - self.slider_input_speaker_energy_threshold = customtkinter.CTkSlider( + self.slider_input_speaker_energy_threshold = CTkSlider( self.tabview_config.tab("Transcription"), from_=0, to=self.MAX_SPEAKER_ENERGY_THRESHOLD, From 0b0ec88b8e9ddaa7b6763eb9534a8c481644ea6e Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 11 Jul 2023 22:35:42 +0900 Subject: [PATCH 17/54] [bugfix] Add Mic Host API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WASAPI以外のHostAPIでもマイクとして使用できるように変更 --- VRCT.py | 11 ++++++++--- audio_utils.py | 21 ++++++++++++--------- window_config.py | 31 ++++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 15 deletions(-) diff --git a/VRCT.py b/VRCT.py index cc028db9..b58812d6 100644 --- a/VRCT.py +++ b/VRCT.py @@ -47,7 +47,8 @@ class App(CTk): self.OUTPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[1] self.OUTPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[0] ## Transcription Send - self.CHOICE_MIC_DEVICE = get_default_input_device()["name"] + self.CHOICE_MIC_HOST = get_default_input_device()["host"]["name"] + self.CHOICE_MIC_DEVICE = get_default_input_device()["device"]["name"] self.INPUT_MIC_VOICE_LANGUAGE = list(transcription_lang.keys())[0] self.INPUT_MIC_ENERGY_THRESHOLD = 300 self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = True @@ -128,8 +129,11 @@ class App(CTk): self.OUTPUT_TARGET_LANG = config["OUTPUT_TARGET_LANG"] # Transcription + if "CHOICE_MIC_HOST" in config.keys(): + if config["CHOICE_MIC_HOST"] in [host for host in get_input_device_list().keys()]: + self.CHOICE_MIC_HOST = config["CHOICE_MIC_HOST"] if "CHOICE_MIC_DEVICE" in config.keys(): - if config["CHOICE_MIC_DEVICE"] in [device["name"] for device in get_input_device_list()]: + if config["CHOICE_MIC_DEVICE"] in [device["name"] for device in get_input_device_list()[self.CHOICE_MIC_HOST]]: self.CHOICE_MIC_DEVICE = config["CHOICE_MIC_DEVICE"] if "INPUT_MIC_VOICE_LANGUAGE" in config.keys(): if config["INPUT_MIC_VOICE_LANGUAGE"] in list(transcription_lang.keys()): @@ -208,6 +212,7 @@ class App(CTk): "INPUT_TARGET_LANG": self.INPUT_TARGET_LANG, "OUTPUT_SOURCE_LANG": self.OUTPUT_SOURCE_LANG, "OUTPUT_TARGET_LANG": self.OUTPUT_TARGET_LANG, + "CHOICE_MIC_HOST": self.CHOICE_MIC_HOST, "CHOICE_MIC_DEVICE": self.CHOICE_MIC_DEVICE, "INPUT_MIC_VOICE_LANGUAGE": self.INPUT_MIC_VOICE_LANGUAGE, "INPUT_MIC_ENERGY_THRESHOLD": self.INPUT_MIC_ENERGY_THRESHOLD, @@ -459,7 +464,7 @@ class App(CTk): if self.ENABLE_TRANSCRIPTION_SEND is True: self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) self.mic_audio_queue = Queue() - mic_device = [device for device in get_input_device_list() if device["name"] == self.CHOICE_MIC_DEVICE][0] + mic_device = [device for device in get_input_device_list()[self.CHOICE_MIC_HOST] if device["name"] == self.CHOICE_MIC_DEVICE][0] self.mic_audio_recorder = SelectedMicRecorder( mic_device, self.INPUT_MIC_ENERGY_THRESHOLD, diff --git a/audio_utils.py b/audio_utils.py index b6d0d6e0..b66172c2 100644 --- a/audio_utils.py +++ b/audio_utils.py @@ -1,14 +1,17 @@ from pyaudiowpatch import PyAudio, paWASAPI def get_input_device_list(): - devices = [] + devices = {} with PyAudio() as p: - wasapi_info = p.get_host_api_info_by_type(paWASAPI) for host_index in range(0, p.get_host_api_count()): - for device_index in range(0, p. get_host_api_info_by_index(host_index)['deviceCount']): + host = p.get_host_api_info_by_index(host_index) + for device_index in range(0, p.get_host_api_info_by_index(host_index)['deviceCount']): device = p.get_device_info_by_host_api_device_index(host_index, device_index) - if device["hostApi"] == wasapi_info["index"] and device["maxInputChannels"] > 0 and device["isLoopbackDevice"] is False: - devices.append(device) + if device["maxInputChannels"] > 0 and device["isLoopbackDevice"] is False: + if host["name"] in devices.keys(): + devices[host["name"]].append(device) + else: + devices[host["name"]] = [device] return devices def get_output_device_list(): @@ -22,15 +25,15 @@ def get_output_device_list(): def get_default_input_device(): with PyAudio() as p: - wasapi_info = p.get_host_api_info_by_type(paWASAPI) - defaultInputDevice = wasapi_info["defaultInputDevice"] + api_info = p.get_default_host_api_info() + defaultInputDevice = api_info["defaultInputDevice"] for host_index in range(0, p.get_host_api_count()): + host = p.get_host_api_info_by_index(host_index) for device_index in range(0, p. get_host_api_info_by_index(host_index)['deviceCount']): device = p.get_device_info_by_host_api_device_index(host_index, device_index) if device["index"] == defaultInputDevice: - default_device = device - return default_device + return {"host":host, "device": device} def get_default_output_device(): with PyAudio() as p: diff --git a/window_config.py b/window_config.py index cce2a4f5..1587cc62 100644 --- a/window_config.py +++ b/window_config.py @@ -1,6 +1,5 @@ from time import sleep from queue import Queue -from threading import Thread from os import path as os_path from tkinter import DoubleVar, IntVar from tkinter import font as tk_font @@ -239,6 +238,24 @@ class ToplevelWindowConfig(CTkToplevel): row = 0 padx = 5 pady = 1 + self.label_input_mic_host = CTkLabel( + self.tabview_config.tab("Transcription"), + text="Input Mic Host:", + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_host.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_input_mic_host = CTkOptionMenu( + self.tabview_config.tab("Transcription"), + values=[host for host in get_input_device_list().keys()], + command=self.optionmenu_input_mic_host_callback, + variable=StringVar(value=self.parent.CHOICE_MIC_HOST), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + row += 1 self.label_input_mic_device = CTkLabel( self.tabview_config.tab("Transcription"), text="Input Mic Device:", @@ -248,7 +265,7 @@ class ToplevelWindowConfig(CTkToplevel): self.label_input_mic_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.optionmenu_input_mic_device = CTkOptionMenu( self.tabview_config.tab("Transcription"), - values=[device["name"] for device in get_input_device_list()], + values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]], command=self.optionmenu_input_mic_device_callback, variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), font=CTkFont(family=self.parent.FONT_FAMILY), @@ -710,6 +727,9 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=choice)) # tab Transcription + self.label_input_mic_host.configure(font=CTkFont(family=choice)) + self.optionmenu_input_mic_host.configure(font=CTkFont(family=choice)) + self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=choice)) self.label_input_mic_device.configure(font=CTkFont(family=choice)) self.optionmenu_input_mic_device.configure(font=CTkFont(family=choice)) self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=choice)) @@ -822,6 +842,11 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.OUTPUT_TARGET_LANG = choice save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) + def optionmenu_input_mic_host_callback(self, choice): + self.parent.CHOICE_MIC_HOST = choice + save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_HOST", self.parent.CHOICE_MIC_HOST) + self.optionmenu_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]]) + def optionmenu_input_mic_device_callback(self, choice): self.parent.CHOICE_MIC_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) @@ -844,7 +869,7 @@ class ToplevelWindowConfig(CTkToplevel): def checkbox_input_mic_threshold_check_callback(self): if self.checkbox_input_mic_threshold_check.get(): self.mic_energy_queue = Queue() - mic_device = [device for device in get_input_device_list() if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] + mic_device = [device for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST] if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) From 4025e0ae70a0a20020e0412ee1482883b3dc2239 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Wed, 12 Jul 2023 01:26:05 +0900 Subject: [PATCH 18/54] [bugfix] Add change font items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit フォント変更時の記載漏れ --- window_config.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index 1587cc62..f6a97b4b 100644 --- a/window_config.py +++ b/window_config.py @@ -656,7 +656,7 @@ class ToplevelWindowConfig(CTkToplevel): row += 1 self.label_checkbox_auto_clear_chatbox = CTkLabel( self.tabview_config.tab("Others"), - text="Auto clear chat box", + text="Auto clear chat box:", fg_color="transparent", font=CTkFont(family=self.parent.FONT_FAMILY) ) @@ -736,6 +736,7 @@ class ToplevelWindowConfig(CTkToplevel): self.label_input_mic_voice_language.configure(font=CTkFont(family=choice)) self.optionmenu_input_mic_voice_language.configure(font=CTkFont(family=choice)) self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.checkbox_input_mic_threshold_check.configure(font=CTkFont(family=choice)) self.label_input_mic_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_mic_dynamic_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_mic_record_timeout.configure(font=CTkFont(family=choice)) @@ -752,6 +753,7 @@ class ToplevelWindowConfig(CTkToplevel): self.label_input_speaker_voice_language.configure(font=CTkFont(family=choice)) self.optionmenu_input_speaker_voice_language.configure(font=CTkFont(family=choice)) self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=choice)) + self.checkbox_input_speaker_threshold_check.configure(font=CTkFont(family=choice)) self.label_input_speaker_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_speaker_dynamic_energy_threshold.configure(font=CTkFont(family=choice)) self.label_input_speaker_record_timeout.configure(font=CTkFont(family=choice)) @@ -771,6 +773,9 @@ class ToplevelWindowConfig(CTkToplevel): self.label_message_format.configure(font=CTkFont(family=choice)) self.entry_message_format.configure(font=CTkFont(family=choice)) + # tab Others + self.label_checkbox_auto_clear_chatbox.configure(font=CTkFont(family=choice)) + # main window self.parent.checkbox_translation.configure(font=CTkFont(family=choice)) self.parent.checkbox_transcription_send.configure(font=CTkFont(family=choice)) From 8ffe90e387a026900e58aefcc6d733c3e597c54f Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:58:25 +0900 Subject: [PATCH 19/54] Chore: move code to a different location --- VRCT.py | 13 ++++++++----- window_config.py | 12 ++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/VRCT.py b/VRCT.py index b58812d6..ded551d5 100644 --- a/VRCT.py +++ b/VRCT.py @@ -39,7 +39,6 @@ class App(CTk): self.APPEARANCE_THEME = "System" self.UI_SCALING = "100%" self.FONT_FAMILY = "Yu Gothic UI" - self.ENABLE_AUTO_CLEAR_CHATBOX = False ## Translation self.CHOICE_TRANSLATOR = translators[0] self.INPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[0] @@ -74,6 +73,8 @@ class App(CTk): "Google(web)": None, } self.MESSAGE_FORMAT = "[message]([translation])" + # Others + self.ENABLE_AUTO_CLEAR_CHATBOX = False # load config if os_path.isfile(self.PATH_CONFIG) is not False: @@ -107,9 +108,6 @@ class App(CTk): if "FONT_FAMILY" in config.keys(): if config["FONT_FAMILY"] in list(tk.font.families()): self.FONT_FAMILY = config["FONT_FAMILY"] - if "ENABLE_AUTO_CLEAR_CHATBOX" in config.keys(): - if type(config["ENABLE_AUTO_CLEAR_CHATBOX"]) is bool: - self.ENABLE_AUTO_CLEAR_CHATBOX = config["ENABLE_AUTO_CLEAR_CHATBOX"] # translation if "CHOICE_TRANSLATOR" in config.keys(): @@ -196,6 +194,11 @@ class App(CTk): if type(config["MESSAGE_FORMAT"]) is str: self.MESSAGE_FORMAT = config["MESSAGE_FORMAT"] + # Others + if "ENABLE_AUTO_CLEAR_CHATBOX" in config.keys(): + if type(config["ENABLE_AUTO_CLEAR_CHATBOX"]) is bool: + self.ENABLE_AUTO_CLEAR_CHATBOX = config["ENABLE_AUTO_CLEAR_CHATBOX"] + with open(self.PATH_CONFIG, 'w') as fp: config = { "ENABLE_TRANSLATION": self.ENABLE_TRANSLATION, @@ -206,7 +209,6 @@ class App(CTk): "APPEARANCE_THEME": self.APPEARANCE_THEME, "UI_SCALING": self.UI_SCALING, "FONT_FAMILY": self.FONT_FAMILY, - "ENABLE_AUTO_CLEAR_CHATBOX": self.ENABLE_AUTO_CLEAR_CHATBOX, "CHOICE_TRANSLATOR": self.CHOICE_TRANSLATOR, "INPUT_SOURCE_LANG": self.INPUT_SOURCE_LANG, "INPUT_TARGET_LANG": self.INPUT_TARGET_LANG, @@ -232,6 +234,7 @@ class App(CTk): "OSC_PORT": self.OSC_PORT, "AUTH_KEYS": self.AUTH_KEYS, "MESSAGE_FORMAT": self.MESSAGE_FORMAT, + "ENABLE_AUTO_CLEAR_CHATBOX": self.ENABLE_AUTO_CLEAR_CHATBOX, } json_dump(config, fp, indent=4) diff --git a/window_config.py b/window_config.py index f6a97b4b..f9d8f137 100644 --- a/window_config.py +++ b/window_config.py @@ -652,7 +652,7 @@ class ToplevelWindowConfig(CTkToplevel): self.entry_message_format.bind("", self.entry_message_format_callback) # tab Others - # checkbox auto clear chat box + ## checkbox auto clear chat box row += 1 self.label_checkbox_auto_clear_chatbox = CTkLabel( self.tabview_config.tab("Others"), @@ -796,11 +796,6 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.FONT_FAMILY = choice save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) - - def checkbox_auto_clear_chatbox_callback(self): - value = self.checkbox_auto_clear_chatbox.get() - self.parent.ENABLE_AUTO_CLEAR_CHATBOX = value - save_json(self.parent.PATH_CONFIG, "ENABLE_AUTO_CLEAR_CHATBOX", self.parent.ENABLE_AUTO_CLEAR_CHATBOX) def optionmenu_translation_translator_callback(self, choice): if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: @@ -1002,6 +997,11 @@ class ToplevelWindowConfig(CTkToplevel): else: pass + def checkbox_auto_clear_chatbox_callback(self): + value = self.checkbox_auto_clear_chatbox.get() + self.parent.ENABLE_AUTO_CLEAR_CHATBOX = value + save_json(self.parent.PATH_CONFIG, "ENABLE_AUTO_CLEAR_CHATBOX", self.parent.ENABLE_AUTO_CLEAR_CHATBOX) + def delete_window(self): self.checkbox_input_mic_threshold_check.deselect() self.checkbox_input_speaker_threshold_check.deselect() From ffbcc4d9401e9822a4adad341547985c357bdf4b Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Wed, 12 Jul 2023 05:10:40 +0900 Subject: [PATCH 20/54] Chore: just move comma --- VRCT.py | 8 ++++---- window_config.py | 34 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/VRCT.py b/VRCT.py index ded551d5..1c294404 100644 --- a/VRCT.py +++ b/VRCT.py @@ -264,7 +264,7 @@ class App(CTk): command=self.checkbox_translation_callback, font=CTkFont(family=self.FONT_FAMILY) ) - self.checkbox_translation.grid(row=0, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") + self.checkbox_translation.grid(row=0, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") # add checkbox transcription send self.checkbox_transcription_send = CTkCheckBox( @@ -275,7 +275,7 @@ class App(CTk): command=self.checkbox_transcription_send_callback, font=CTkFont(family=self.FONT_FAMILY) ) - self.checkbox_transcription_send.grid(row=1, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") + self.checkbox_transcription_send.grid(row=1, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") # add checkbox transcription receive self.checkbox_transcription_receive = CTkCheckBox( @@ -286,7 +286,7 @@ class App(CTk): command=self.checkbox_transcription_receive_callback, font=CTkFont(family=self.FONT_FAMILY) ) - self.checkbox_transcription_receive.grid(row=2, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") + self.checkbox_transcription_receive.grid(row=2, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") # add checkbox foreground self.checkbox_foreground = CTkCheckBox( @@ -297,7 +297,7 @@ class App(CTk): command=self.checkbox_foreground_callback, font=CTkFont(family=self.FONT_FAMILY) ) - self.checkbox_foreground.grid(row=3, column=0, columnspan=2 ,padx=10, pady=(5, 5), sticky="we") + self.checkbox_foreground.grid(row=3, column=0, columnspan=2, padx=10, pady=(5, 5), sticky="we") # add button information self.button_information = CTkButton( diff --git a/window_config.py b/window_config.py index f9d8f137..637af7f5 100644 --- a/window_config.py +++ b/window_config.py @@ -148,7 +148,7 @@ class ToplevelWindowConfig(CTkToplevel): variable=StringVar(value=self.parent.CHOICE_TRANSLATOR), font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3, padx=padx, pady=pady, sticky="nsew") self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu translation input language @@ -252,7 +252,7 @@ class ToplevelWindowConfig(CTkToplevel): variable=StringVar(value=self.parent.CHOICE_MIC_HOST), font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) row += 1 @@ -270,7 +270,7 @@ class ToplevelWindowConfig(CTkToplevel): variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu input mic voice language @@ -289,7 +289,7 @@ class ToplevelWindowConfig(CTkToplevel): variable=StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## slider input mic energy threshold @@ -325,7 +325,7 @@ class ToplevelWindowConfig(CTkToplevel): command=self.checkbox_input_mic_threshold_check_callback, font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.checkbox_input_mic_threshold_check.grid(row=row, column=0, columnspan=1 ,padx=padx, pady=pady, sticky="nsw") + self.checkbox_input_mic_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.progressBar_input_mic_energy_threshold = CTkProgressBar( self.tabview_config.tab("Transcription"), @@ -351,7 +351,7 @@ class ToplevelWindowConfig(CTkToplevel): command=self.checkbox_input_mic_dynamic_energy_threshold_callback, font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.checkbox_input_mic_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.checkbox_input_mic_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") if self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD is True: self.checkbox_input_mic_dynamic_energy_threshold.select() else: @@ -371,7 +371,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=self.parent.INPUT_MIC_RECORD_TIMEOUT), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_mic_record_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_record_timeout.bind("", self.entry_input_mic_record_timeout_callback) ## entry input mic phrase timeout @@ -388,7 +388,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=self.parent.INPUT_MIC_PHRASE_TIMEOUT), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_mic_phrase_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_phrase_timeout.bind("", self.entry_input_mic_phrase_timeout_callback) ## entry input mic max phrases @@ -405,7 +405,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=self.parent.INPUT_MIC_MAX_PHRASES), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_max_phrases.bind("", self.entry_input_mic_max_phrases_callback) ## entry input mic word filter @@ -422,7 +422,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_mic_word_filter.bind("", self.entry_input_mic_word_filters_callback) ## optionmenu input speaker device @@ -441,7 +441,7 @@ class ToplevelWindowConfig(CTkToplevel): variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## optionmenu input speaker voice language @@ -460,7 +460,7 @@ class ToplevelWindowConfig(CTkToplevel): variable=StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## entry input speaker energy threshold @@ -497,7 +497,7 @@ class ToplevelWindowConfig(CTkToplevel): command=self.checkbox_input_speaker_threshold_check_callback, font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.checkbox_input_speaker_threshold_check.grid(row=row, column=0, columnspan=1 ,padx=padx, pady=pady, sticky="nsw") + self.checkbox_input_speaker_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") self.progressBar_input_speaker_energy_threshold = CTkProgressBar( self.tabview_config.tab("Transcription"), @@ -523,7 +523,7 @@ class ToplevelWindowConfig(CTkToplevel): command=self.checkbox_input_speaker_dynamic_energy_threshold_callback, font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.checkbox_input_speaker_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.checkbox_input_speaker_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") if self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: self.checkbox_input_speaker_dynamic_energy_threshold.select() else: @@ -543,7 +543,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=self.parent.INPUT_SPEAKER_RECORD_TIMEOUT), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_speaker_record_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_speaker_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_record_timeout.bind("", self.entry_input_speaker_record_timeout_callback) ## entry input speaker phrase timeout @@ -560,7 +560,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_speaker_phrase_timeout.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_speaker_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_phrase_timeout.bind("", self.entry_input_speaker_phrase_timeout_callback) ## entry input speaker max phrases @@ -577,7 +577,7 @@ class ToplevelWindowConfig(CTkToplevel): textvariable=StringVar(value=self.parent.INPUT_SPEAKER_MAX_PHRASES), font=CTkFont(family=self.parent.FONT_FAMILY) ) - self.entry_input_speaker_max_phrases.grid(row=row, column=1, columnspan=1 ,padx=padx, pady=pady, sticky="nsew") + self.entry_input_speaker_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.entry_input_speaker_max_phrases.bind("", self.entry_input_speaker_max_phrases_callback) # tab Parameter From 829e1de2b37e303c12ae991106e14b6f3d72f310 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Wed, 12 Jul 2023 10:32:37 +0900 Subject: [PATCH 21/54] =?UTF-8?q?UI=E3=81=AE=E5=A4=9A=E8=A8=80=E8=AA=9E?= =?UTF-8?q?=E5=8C=96=EF=BC=88=E6=97=A5=E6=9C=AC=E8=AA=9E=E3=81=A8=E8=8B=B1?= =?UTF-8?q?=E8=AA=9E=EF=BC=89=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=80=81Config?= =?UTF-8?q?=E3=81=A7=E8=A8=80=E8=AA=9E=E3=82=92=E5=A4=89=E6=9B=B4=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E3=80=82=E3=81=9D?= =?UTF-8?q?=E3=82=8C=E3=81=AB=E4=BC=B4=E3=81=84UI=E3=82=92=E5=86=8D?= =?UTF-8?q?=E7=94=9F=E6=88=90=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B=E3=81=9F?= =?UTF-8?q?=E3=82=81=E3=80=81=E3=81=9D=E3=81=AE=E9=83=A8=E5=88=86=E3=82=92?= =?UTF-8?q?=E9=96=A2=E6=95=B0=E5=8C=96=E3=81=97=E3=81=A6=E5=88=87=E3=82=8A?= =?UTF-8?q?=E5=87=BA=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 136 +++-- languages.py | 6 + locales.yml | 125 +++++ utils.py | 91 +++- window_config.py | 1356 ++++++++++++++++++++++++---------------------- 5 files changed, 1015 insertions(+), 699 deletions(-) create mode 100644 locales.yml diff --git a/VRCT.py b/VRCT.py index 1c294404..3270081f 100644 --- a/VRCT.py +++ b/VRCT.py @@ -8,11 +8,11 @@ from customtkinter import CTk, CTkFrame, CTkCheckBox, CTkFont, CTkButton, CTkIma from PIL.Image import open as Image_open from flashtext import KeywordProcessor -from utils import save_json, print_textbox, thread_fnc +from utils import save_json, print_textbox, thread_fnc, get_localized_text, widget_main_window_label_setter from osc_tools import send_typing, send_message from window_config import ToplevelWindowConfig from window_information import ToplevelWindowInformation -from languages import transcription_lang, translators, translation_lang +from languages import transcription_lang, translators, translation_lang, selectable_languages from audio_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder from audio_transcriber import AudioTranscriber @@ -39,6 +39,7 @@ class App(CTk): self.APPEARANCE_THEME = "System" self.UI_SCALING = "100%" self.FONT_FAMILY = "Yu Gothic UI" + self.UI_LANGUAGE = "en" ## Translation self.CHOICE_TRANSLATOR = translators[0] self.INPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR].keys())[0] @@ -108,6 +109,9 @@ class App(CTk): if "FONT_FAMILY" in config.keys(): if config["FONT_FAMILY"] in list(tk.font.families()): self.FONT_FAMILY = config["FONT_FAMILY"] + if "UI_LANGUAGE" in config.keys(): + if config["UI_LANGUAGE"] in list(selectable_languages.keys()): + self.UI_LANGUAGE = config["UI_LANGUAGE"] # translation if "CHOICE_TRANSLATOR" in config.keys(): @@ -208,6 +212,7 @@ class App(CTk): "TRANSPARENCY": self.TRANSPARENCY, "APPEARANCE_THEME": self.APPEARANCE_THEME, "UI_SCALING": self.UI_SCALING, + "UI_LANGUAGE": self.UI_LANGUAGE, "FONT_FAMILY": self.FONT_FAMILY, "CHOICE_TRANSLATOR": self.CHOICE_TRANSLATOR, "INPUT_SOURCE_LANG": self.INPUT_SOURCE_LANG, @@ -255,10 +260,12 @@ class App(CTk): self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsw") self.sidebar_frame.grid_rowconfigure(5, weight=1) + init_lang_text = "Loading..." + # add checkbox translation self.checkbox_translation = CTkCheckBox( self.sidebar_frame, - text="translation", + text=init_lang_text, onvalue=True, offvalue=False, command=self.checkbox_translation_callback, @@ -269,7 +276,7 @@ class App(CTk): # add checkbox transcription send self.checkbox_transcription_send = CTkCheckBox( self.sidebar_frame, - text="voice2chatbox", + text=init_lang_text, onvalue=True, offvalue=False, command=self.checkbox_transcription_send_callback, @@ -280,7 +287,7 @@ class App(CTk): # add checkbox transcription receive self.checkbox_transcription_receive = CTkCheckBox( self.sidebar_frame, - text="speaker2log", + text=init_lang_text, onvalue=True, offvalue=False, command=self.checkbox_transcription_receive_callback, @@ -291,7 +298,7 @@ class App(CTk): # add checkbox foreground self.checkbox_foreground = CTkCheckBox( self.sidebar_frame, - text="foreground", + text=init_lang_text, onvalue=True, offvalue=False, command=self.checkbox_foreground_callback, @@ -321,56 +328,10 @@ class App(CTk): self.button_config.grid(row=5, column=1, padx=(5, 10), pady=(5, 5), sticky="wse") self.config_window = None + # load ui language data + language_yaml_data = get_localized_text(f"{self.UI_LANGUAGE}") # add tabview textbox - self.tabview_logs = CTkTabview(master=self) - self.tabview_logs.add("log") - self.tabview_logs.add("send") - self.tabview_logs.add("receive") - self.tabview_logs.add("system") - self.tabview_logs.grid(row=0, column=1, padx=0, pady=0, sticky="nsew") - self.tabview_logs._segmented_button.configure(font=CTkFont(family=self.FONT_FAMILY)) - self.tabview_logs._segmented_button.grid(sticky="W") - self.tabview_logs.tab("log").grid_rowconfigure(0, weight=1) - self.tabview_logs.tab("log").grid_columnconfigure(0, weight=1) - self.tabview_logs.tab("send").grid_rowconfigure(0, weight=1) - self.tabview_logs.tab("send").grid_columnconfigure(0, weight=1) - self.tabview_logs.tab("receive").grid_rowconfigure(0, weight=1) - self.tabview_logs.tab("receive").grid_columnconfigure(0, weight=1) - self.tabview_logs.tab("system").grid_rowconfigure(0, weight=1) - self.tabview_logs.tab("system").grid_columnconfigure(0, weight=1) - self.tabview_logs.configure(fg_color="transparent") - - # add textbox message log - self.textbox_message_log = CTkTextbox( - self.tabview_logs.tab("log"), - font=CTkFont(family=self.FONT_FAMILY) - ) - self.textbox_message_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") - self.textbox_message_log.configure(state='disabled') - - # add textbox message send log - self.textbox_message_send_log = CTkTextbox( - self.tabview_logs.tab("send"), - font=CTkFont(family=self.FONT_FAMILY) - ) - self.textbox_message_send_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") - self.textbox_message_send_log.configure(state='disabled') - - # add textbox message receive log - self.textbox_message_receive_log = CTkTextbox( - self.tabview_logs.tab("receive"), - font=CTkFont(family=self.FONT_FAMILY) - ) - self.textbox_message_receive_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") - self.textbox_message_receive_log.configure(state='disabled') - - # add textbox message system log - self.textbox_message_system_log = CTkTextbox( - self.tabview_logs.tab("system"), - font=CTkFont(family=self.FONT_FAMILY) - ) - self.textbox_message_system_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") - self.textbox_message_system_log.configure(state='disabled') + self.add_tabview_logs(language_yaml_data) # add entry message box self.entry_message_box = CTkEntry( @@ -667,6 +628,71 @@ class App(CTk): self.quit() self.destroy() + def delete_tabview_logs(self, pre_language_yaml_data): + self.tabview_logs.delete(pre_language_yaml_data["main_tab_title_log"]) + self.tabview_logs.delete(pre_language_yaml_data["main_tab_title_send"]) + self.tabview_logs.delete(pre_language_yaml_data["main_tab_title_receive"]) + self.tabview_logs.delete(pre_language_yaml_data["main_tab_title_system"]) + + def add_tabview_logs(self, language_yaml_data): + main_tab_title_log = language_yaml_data["main_tab_title_log"] + main_tab_title_send = language_yaml_data["main_tab_title_send"] + main_tab_title_receive = language_yaml_data["main_tab_title_receive"] + main_tab_title_system = language_yaml_data["main_tab_title_system"] + + # add tabview textbox + self.tabview_logs = CTkTabview(master=self) + self.tabview_logs.add(main_tab_title_log) + self.tabview_logs.add(main_tab_title_send) + self.tabview_logs.add(main_tab_title_receive) + self.tabview_logs.add(main_tab_title_system) + self.tabview_logs.grid(row=0, column=1, padx=0, pady=0, sticky="nsew") + self.tabview_logs._segmented_button.configure(font=CTkFont(family=self.FONT_FAMILY)) + self.tabview_logs._segmented_button.grid(sticky="W") + self.tabview_logs.tab(main_tab_title_log).grid_rowconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_log).grid_columnconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_send).grid_rowconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_send).grid_columnconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_receive).grid_rowconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_receive).grid_columnconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_system).grid_rowconfigure(0, weight=1) + self.tabview_logs.tab(main_tab_title_system).grid_columnconfigure(0, weight=1) + self.tabview_logs.configure(fg_color="transparent") + + # add textbox message log + self.textbox_message_log = CTkTextbox( + self.tabview_logs.tab(main_tab_title_log), + font=CTkFont(family=self.FONT_FAMILY) + ) + self.textbox_message_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") + self.textbox_message_log.configure(state='disabled') + + # add textbox message send log + self.textbox_message_send_log = CTkTextbox( + self.tabview_logs.tab(main_tab_title_send), + font=CTkFont(family=self.FONT_FAMILY) + ) + self.textbox_message_send_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") + self.textbox_message_send_log.configure(state='disabled') + + # add textbox message receive log + self.textbox_message_receive_log = CTkTextbox( + self.tabview_logs.tab(main_tab_title_receive), + font=CTkFont(family=self.FONT_FAMILY) + ) + self.textbox_message_receive_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") + self.textbox_message_receive_log.configure(state='disabled') + + # add textbox message system log + self.textbox_message_system_log = CTkTextbox( + self.tabview_logs.tab(main_tab_title_system), + font=CTkFont(family=self.FONT_FAMILY) + ) + self.textbox_message_system_log.grid(row=0, column=0, padx=0, pady=0, sticky="nsew") + self.textbox_message_system_log.configure(state='disabled') + + widget_main_window_label_setter(self, language_yaml_data) + if __name__ == "__main__": try: app = App() diff --git a/languages.py b/languages.py index 40b546f5..186fd747 100644 --- a/languages.py +++ b/languages.py @@ -278,4 +278,10 @@ translation_lang["Bing(web)"] = { "telugu":"te", "punjabi":"pa", "irish":"ga" +} + +selectable_languages = { + "en": "English", + "ja": "日本語", + # 新しい言語とキーを追加する場合はここに追記してください } \ No newline at end of file diff --git a/locales.yml b/locales.yml new file mode 100644 index 00000000..38dbe6e4 --- /dev/null +++ b/locales.yml @@ -0,0 +1,125 @@ +en: + # main window + checkbox_translation: "Translation" + checkbox_transcription_send: "Voice2chatbox" + checkbox_transcription_receive: "Speaker2log" + checkbox_foreground: "Foreground" + + # main tabview + main_tab_title_log: "Log" + main_tab_title_send: "Send" + main_tab_title_receive: "Receive" + main_tab_title_system: "System" + + + # configure window + # config tabview + config_tab_title_ui: "UI" + config_tab_title_translation: "Translation" + config_tab_title_transcription: "Transcription" + config_tab_title_parameter: "Parameter" + config_tab_title_others: "Others" + # tab UI + label_transparency: "Transparency" + label_appearance_theme: "Appearance Theme" + label_ui_scaling: "UI Scaling" + label_font_family: "Font Family" + label_ui_language: "UI Language" + + # tab Translation + label_translation_translator: "Select Translator" + label_translation_input_language: "Send Language" + label_translation_output_language: "Receive Language" + + # tab Transcription + label_input_mic_host: "Input Mic Host" + label_input_mic_device: "Input Mic Device" + label_input_mic_voice_language: "Input Mic Voice Language" + label_input_mic_energy_threshold: "Input Mic Energy Threshold" + checkbox_input_mic_threshold_check: "Check threshold point" + label_input_mic_dynamic_energy_threshold: "Input Mic Dynamic Energy Threshold" + label_input_mic_record_timeout: "Input Mic Record Timeout" + label_input_mic_phrase_timeout: "Input Mic Phrase Timeout" + label_input_mic_max_phrases: "Input Mic Max Phrases" + label_input_mic_word_filter: "Input Mic Word Filter" + + label_input_speaker_device: "Input Speaker Device" + label_input_speaker_voice_language: "Input Speaker Voice Language" + label_input_speaker_energy_threshold: "Input Speaker Energy Threshold" + checkbox_input_speaker_threshold_check: "Check threshold point" + label_input_speaker_dynamic_energy_threshold: "Input Speaker Dynamic Energy Threshold" + label_input_speaker_record_timeout: "Input Speaker Record Timeout" + label_input_speaker_phrase_timeout: "Input Speaker Phrase Timeout" + label_input_speaker_max_phrases: "Input Speaker Max Phrases" + + # tab Parameter + label_ip_address: "OSC IP address" + label_port: "OSC Port" + label_authkey: "DeepL Auth Key" + label_message_format: "Message Format" + + # tab Others + label_checkbox_auto_clear_chatbox: "Auto clear chat box" + + +ja: + # main window + checkbox_translation: "翻訳" + checkbox_transcription_send: "マイク->チャットボックス" + checkbox_transcription_receive: "スピーカー->ログ" + checkbox_foreground: "最前面表示" + + # main tabview + main_tab_title_log: "ログ" + main_tab_title_send: "送信" + main_tab_title_receive: "受信" + main_tab_title_system: "システム" + + + # configure window + # config tabview + config_tab_title_ui: "UI" + config_tab_title_translation: "翻訳方法" + config_tab_title_transcription: "音声認識" + config_tab_title_parameter: "パラメーター" + config_tab_title_others: "その他" + + # tab UI + label_transparency: "透過度" + label_appearance_theme: "外観テーマを選択" + label_ui_scaling: "UIの拡大縮小" + label_font_family: "使用フォントの変更" + label_ui_language: "UI 言語" + + # tab Translation + label_translation_translator: "翻訳エンジンの選択" + label_translation_input_language: "送信言語-->翻訳言語" + label_translation_output_language: "受信言語-->翻訳言語" + + # tab Transcription + label_input_mic_host: "マイク入力ホスト" + label_input_mic_device: "マイク入力デバイス" + label_input_mic_voice_language: "マイクで話す言語" + label_input_mic_energy_threshold: "音声取得のしきい値" + label_input_mic_dynamic_energy_threshold: "音声取得のしきい値の自動調整" + label_input_mic_record_timeout: "マイク音声の区切りの無音時間" + # label_input_mic_phrase_timeout: "" + label_input_mic_max_phrases: "保留する単語の上限(マイク)" + + label_input_speaker_device: "スピーカー(聞き取りたいデバイス)" + label_input_speaker_voice_language: "聞き取る音声の言語" + label_input_speaker_energy_threshold: "音声取得のしきい値" + label_input_speaker_dynamic_energy_threshold: "音声取得のしきい値の自動調整" + label_input_speaker_record_timeout: "スピーカー音声の区切りの無音時間" + # label_input_speaker_phrase_timeout: "" + label_input_speaker_max_phrases: "保留する単語の上限(スピーカー)" + + # tab Parameter + # label_ip_address: "" + # label_port: "" + # label_authkey: "" + label_message_format: "送信するメッセージのフォーマット" + + # tab Others + label_checkbox_auto_clear_chatbox: "送信後はチャットボックスを空にする" + diff --git a/utils.py b/utils.py index 013b16c6..0e63f179 100644 --- a/utils.py +++ b/utils.py @@ -1,4 +1,6 @@ from json import load, dump +from os import path as os_path +import yaml from datetime import datetime from threading import Thread, Event @@ -38,4 +40,91 @@ class thread_fnc(Thread): while True: if self.stopped(): return - self.fnc(*self._args, **self._kwargs) \ No newline at end of file + self.fnc(*self._args, **self._kwargs) + +def get_localized_text(language): + file_path = os_path.join(os_path.dirname(__file__), "locales.yml") + + with open(file_path, encoding="utf-8") as file: + languages_yaml_data = yaml.safe_load(file) + default_language = "en" + if language in languages_yaml_data: + localized_text = languages_yaml_data[language] + if default_language in languages_yaml_data: + default_text = languages_yaml_data[default_language] + merged_text = {**default_text, **localized_text} + return merged_text + else: + return localized_text + else: + return None + +def get_key_by_value(dictionary, value): + for key, val in dictionary.items(): + if val == value: + return key + return None + +def widget_config_window_label_setter(self, language_yaml_data): + widget_names = [ + # tab UI + "label_transparency", + "label_appearance_theme", + "label_ui_scaling", + "label_font_family", + "label_ui_language", + + # tab Translation + "label_translation_translator", + "label_translation_input_language", + "label_translation_output_language", + + # tab Transcription + "label_input_mic_host", + "label_input_mic_device", + "label_input_mic_voice_language", + "label_input_mic_energy_threshold", + "checkbox_input_mic_threshold_check", + "label_input_mic_dynamic_energy_threshold", + "label_input_mic_record_timeout", + "label_input_mic_phrase_timeout", + "label_input_mic_max_phrases", + "label_input_mic_word_filter", + + "label_input_speaker_device", + "label_input_speaker_voice_language", + "label_input_speaker_energy_threshold", + "checkbox_input_speaker_threshold_check", + "label_input_speaker_dynamic_energy_threshold", + "label_input_speaker_record_timeout", + "label_input_speaker_phrase_timeout", + "label_input_speaker_max_phrases", + + + # tab Parameter + "label_ip_address", + "label_port", + "label_authkey", + "label_message_format", + + # tab Others + "label_checkbox_auto_clear_chatbox" + ] + for name in widget_names: + widget = getattr(self, name) + text_value = language_yaml_data.get(name) + if widget is not None and text_value is not None: + widget.configure(text=text_value + ":") + +def widget_main_window_label_setter(self, language_yaml_data): + widget_names = [ + "checkbox_translation", + "checkbox_transcription_send", + "checkbox_transcription_receive", + "checkbox_foreground", + ] + for name in widget_names: + widget = getattr(self, name) + text_value = language_yaml_data.get(name) + if widget is not None and text_value is not None: + widget.configure(text=text_value) \ No newline at end of file diff --git a/window_config.py b/window_config.py index 637af7f5..747f21f8 100644 --- a/window_config.py +++ b/window_config.py @@ -7,10 +7,10 @@ import customtkinter from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox, CTkProgressBar from flashtext import KeywordProcessor -from utils import save_json, print_textbox, thread_fnc +from utils import save_json, print_textbox, thread_fnc, get_localized_text, get_key_by_value, widget_config_window_label_setter from audio_utils import get_input_device_list, get_output_device_list, get_default_output_device from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder -from languages import translation_lang, transcription_lang +from languages import translation_lang, transcription_lang, selectable_languages class ToplevelWindowConfig(CTkToplevel): @@ -34,646 +34,12 @@ class ToplevelWindowConfig(CTkToplevel): self.speaker_energy_get_progressbar = None self.speaker_energy_plot_progressbar = None - # tabwiew config - self.tabview_config = CTkTabview(self) - self.tabview_config.grid(row=0, column=0, padx=5, pady=5, sticky="nsew") - self.tabview_config.add("UI") - self.tabview_config.add("Translation") - self.tabview_config.add("Transcription") - self.tabview_config.add("Parameter") - self.tabview_config.add("Others") - self.tabview_config.tab("UI").grid_columnconfigure(1, weight=1) - self.tabview_config.tab("Translation").grid_columnconfigure([1,2,3], weight=1) - self.tabview_config.tab("Transcription").grid_columnconfigure(1, weight=1) - self.tabview_config.tab("Parameter").grid_columnconfigure(1, weight=1) - self.tabview_config.tab("Others").grid_columnconfigure(1, weight=1) - self.tabview_config._segmented_button.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - self.tabview_config._segmented_button.grid(sticky="W") - - # tab UI - ## slider transparency - row = 0 - padx = 5 - pady = 1 - self.label_transparency = CTkLabel( - self.tabview_config.tab("UI"), - text="Transparency:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_transparency.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.slider_transparency = CTkSlider( - self.tabview_config.tab("UI"), - from_=50, - to=100, - command=self.slider_transparency_callback, - variable=DoubleVar(value=self.parent.TRANSPARENCY), - ) - self.slider_transparency.grid(row=row, column=1, columnspan=1, padx=padx, pady=10, sticky="nsew") - - ## optionmenu theme - row += 1 - self.label_appearance_theme = CTkLabel( - self.tabview_config.tab("UI"), - text="Appearance Theme:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_appearance_theme.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_appearance_theme = CTkOptionMenu( - self.tabview_config.tab("UI"), - values=["Light", "Dark", "System"], - command=self.optionmenu_theme_callback, - variable=StringVar(value=self.parent.APPEARANCE_THEME), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_appearance_theme.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_appearance_theme._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## optionmenu UI scaling - row += 1 - self.label_ui_scaling = CTkLabel( - self.tabview_config.tab("UI"), - text="UI Scaling:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_ui_scaling.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_ui_scaling = CTkOptionMenu( - self.tabview_config.tab("UI"), - values=["80%", "90%", "100%", "110%", "120%"], - command=self.optionmenu_ui_scaling_callback, - variable=StringVar(value=self.parent.UI_SCALING), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_ui_scaling.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_ui_scaling._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## optionmenu font family - row += 1 - self.label_font_family = CTkLabel( - self.tabview_config.tab("UI"), - text="Font Family:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_font_family.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - font_families = list(tk_font.families()) - self.optionmenu_font_family = CTkOptionMenu( - self.tabview_config.tab("UI"), - values=font_families, - command=self.optionmenu_font_family_callback, - variable=StringVar(value=self.parent.FONT_FAMILY), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - # tab Translation - ## optionmenu translation translator - row = 0 - padx = 5 - pady = 1 - self.label_translation_translator = CTkLabel( - self.tabview_config.tab("Translation"), - text="Select Translator:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.label_translation_translator.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_translation_translator = CTkOptionMenu( - self.tabview_config.tab("Translation"), - values=list(self.parent.translator.translator_status.keys()), - command=self.optionmenu_translation_translator_callback, - variable=StringVar(value=self.parent.CHOICE_TRANSLATOR), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## optionmenu translation input language - row +=1 - self.label_translation_input_language = CTkLabel( - self.tabview_config.tab("Translation"), - text="Send Language:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_translation_input_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - - ## select translation input source language - self.optionmenu_translation_input_source_language = CTkOptionMenu( - self.tabview_config.tab("Translation"), - command=self.optionmenu_translation_input_source_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=StringVar(value=self.parent.INPUT_SOURCE_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_translation_input_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## label translation input arrow - self.label_translation_input_arrow = CTkLabel( - self.tabview_config.tab("Translation"), - text="-->", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_translation_input_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") - - ## select translation input target language - self.optionmenu_translation_input_target_language = CTkOptionMenu( - self.tabview_config.tab("Translation"), - command=self.optionmenu_translation_input_target_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=StringVar(value=self.parent.INPUT_TARGET_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_translation_input_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## optionmenu translation output language - row +=1 - self.label_translation_output_language = CTkLabel( - self.tabview_config.tab("Translation"), - text="Receive Language:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_translation_output_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - - ## select translation output source language - self.optionmenu_translation_output_source_language = CTkOptionMenu( - self.tabview_config.tab("Translation"), - command=self.optionmenu_translation_output_source_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=StringVar(value=self.parent.OUTPUT_SOURCE_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_translation_output_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## label translation output arrow - self.label_translation_output_arrow = CTkLabel( - self.tabview_config.tab("Translation"), - text="-->", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_translation_output_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") - - ## select translation output target language - self.optionmenu_translation_output_target_language = CTkOptionMenu( - self.tabview_config.tab("Translation"), - command=self.optionmenu_translation_output_target_language_callback, - values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), - variable=StringVar(value=self.parent.OUTPUT_TARGET_LANG), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_translation_output_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - # tab Transcription - ## optionmenu input mic device - row = 0 - padx = 5 - pady = 1 - self.label_input_mic_host = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Host:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_host.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_mic_host = CTkOptionMenu( - self.tabview_config.tab("Transcription"), - values=[host for host in get_input_device_list().keys()], - command=self.optionmenu_input_mic_host_callback, - variable=StringVar(value=self.parent.CHOICE_MIC_HOST), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - row += 1 - self.label_input_mic_device = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Device:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_mic_device = CTkOptionMenu( - self.tabview_config.tab("Transcription"), - values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]], - command=self.optionmenu_input_mic_device_callback, - variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## optionmenu input mic voice language - row +=1 - self.label_input_mic_voice_language = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Voice Language:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_mic_voice_language = CTkOptionMenu( - self.tabview_config.tab("Transcription"), - values=list(transcription_lang.keys()), - command=self.optionmenu_input_mic_voice_language_callback, - variable=StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## slider input mic energy threshold - row +=1 - self.label_input_mic_energy_threshold = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Energy Threshold:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - - self.slider_input_mic_energy_threshold = CTkSlider( - self.tabview_config.tab("Transcription"), - from_=0, - to=self.MAX_MIC_ENERGY_THRESHOLD, - border_width=7, - button_length=0, - button_corner_radius=3, - number_of_steps=self.MAX_MIC_ENERGY_THRESHOLD, - command=self.slider_input_mic_energy_threshold_callback, - variable=IntVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), - ) - self.slider_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") - - ## progressBar input mic energy threshold - row +=1 - self.checkbox_input_mic_threshold_check = CTkCheckBox( - self.tabview_config.tab("Transcription"), - text="check threshold point", - onvalue=True, - offvalue=False, - command=self.checkbox_input_mic_threshold_check_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.checkbox_input_mic_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - - self.progressBar_input_mic_energy_threshold = CTkProgressBar( - self.tabview_config.tab("Transcription"), - corner_radius=0 - ) - self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=5, sticky="nsew") - self.progressBar_input_mic_energy_threshold.set(0) - - ## checkbox input mic dynamic energy threshold - row +=1 - self.label_input_mic_dynamic_energy_threshold = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Dynamic Energy Threshold:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.checkbox_input_mic_dynamic_energy_threshold = CTkCheckBox( - self.tabview_config.tab("Transcription"), - text="", - onvalue=True, - offvalue=False, - command=self.checkbox_input_mic_dynamic_energy_threshold_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.checkbox_input_mic_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD is True: - self.checkbox_input_mic_dynamic_energy_threshold.select() - else: - self.checkbox_input_mic_dynamic_energy_threshold.deselect() - - ## entry input mic record timeout - row +=1 - self.label_input_mic_record_timeout = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Record Timeout:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_record_timeout = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_MIC_RECORD_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_mic_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_mic_record_timeout.bind("", self.entry_input_mic_record_timeout_callback) - - ## entry input mic phrase timeout - row +=1 - self.label_input_mic_phrase_timeout = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Phrase Timeout:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_phrase_timeout = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_MIC_PHRASE_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_mic_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_mic_phrase_timeout.bind("", self.entry_input_mic_phrase_timeout_callback) - - ## entry input mic max phrases - row +=1 - self.label_input_mic_max_phrases = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Max Phrases:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_max_phrases = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_MIC_MAX_PHRASES), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_mic_max_phrases.bind("", self.entry_input_mic_max_phrases_callback) - - ## entry input mic word filter - row +=1 - self.label_input_mic_word_filter = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Mic Word Filter:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_mic_word_filter.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_mic_word_filter = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_mic_word_filter.bind("", self.entry_input_mic_word_filters_callback) - - ## optionmenu input speaker device - row +=1 - self.label_input_speaker_device = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Device:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_speaker_device = CTkOptionMenu( - self.tabview_config.tab("Transcription"), - values=[device["name"] for device in get_output_device_list()], - command=self.optionmenu_input_speaker_device_callback, - variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## optionmenu input speaker voice language - row +=1 - self.label_input_speaker_voice_language = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Voice Language:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.optionmenu_input_speaker_voice_language = CTkOptionMenu( - self.tabview_config.tab("Transcription"), - values=list(transcription_lang.keys()), - command=self.optionmenu_input_speaker_voice_language_callback, - variable=StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) - - ## entry input speaker energy threshold - row +=1 - self.label_input_speaker_energy_threshold = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Energy Threshold:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - - ## progressBar input speaker energy threshold - self.slider_input_speaker_energy_threshold = CTkSlider( - self.tabview_config.tab("Transcription"), - from_=0, - to=self.MAX_SPEAKER_ENERGY_THRESHOLD, - border_width=7, - button_length=0, - button_corner_radius=3, - number_of_steps=self.MAX_SPEAKER_ENERGY_THRESHOLD, - command=self.slider_input_speaker_energy_threshold_callback, - variable=IntVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), - ) - self.slider_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") - - ## progressBar input speaker energy threshold - row +=1 - self.checkbox_input_speaker_threshold_check = CTkCheckBox( - self.tabview_config.tab("Transcription"), - text="check threshold point", - onvalue=True, - offvalue=False, - command=self.checkbox_input_speaker_threshold_check_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.checkbox_input_speaker_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - - self.progressBar_input_speaker_energy_threshold = CTkProgressBar( - self.tabview_config.tab("Transcription"), - corner_radius=0 - ) - self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=5, sticky="nsew") - self.progressBar_input_speaker_energy_threshold.set(0) - - ## checkbox input speaker dynamic energy threshold - row +=1 - self.label_input_speaker_dynamic_energy_threshold = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Dynamic Energy Threshold:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.checkbox_input_speaker_dynamic_energy_threshold = CTkCheckBox( - self.tabview_config.tab("Transcription"), - text="", - onvalue=True, - offvalue=False, - command=self.checkbox_input_speaker_dynamic_energy_threshold_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.checkbox_input_speaker_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: - self.checkbox_input_speaker_dynamic_energy_threshold.select() - else: - self.checkbox_input_speaker_dynamic_energy_threshold.deselect() - - ## entry input speaker record timeout - row +=1 - self.label_input_speaker_record_timeout = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Record Timeout:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_record_timeout = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_RECORD_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_speaker_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_speaker_record_timeout.bind("", self.entry_input_speaker_record_timeout_callback) - - ## entry input speaker phrase timeout - row +=1 - self.label_input_speaker_phrase_timeout = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Phrase Timeout:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_phrase_timeout = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_speaker_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_speaker_phrase_timeout.bind("", self.entry_input_speaker_phrase_timeout_callback) - - ## entry input speaker max phrases - row +=1 - self.label_input_speaker_max_phrases = CTkLabel( - self.tabview_config.tab("Transcription"), - text="Input Speaker Max Phrases:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_input_speaker_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_input_speaker_max_phrases = CTkEntry( - self.tabview_config.tab("Transcription"), - textvariable=StringVar(value=self.parent.INPUT_SPEAKER_MAX_PHRASES), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_input_speaker_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_input_speaker_max_phrases.bind("", self.entry_input_speaker_max_phrases_callback) - - # tab Parameter - ## entry ip address - row = 0 - padx = 5 - pady = 1 - self.label_ip_address = CTkLabel( - self.tabview_config.tab("Parameter"), - text="OSC IP address:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_ip_address.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_ip_address = CTkEntry( - self.tabview_config.tab("Parameter"), - textvariable=StringVar(value=self.parent.OSC_IP_ADDRESS), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_ip_address.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_ip_address.bind("", self.entry_ip_address_callback) - - ## entry port - row +=1 - self.label_port = CTkLabel( - self.tabview_config.tab("Parameter"), - text="OSC Port:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_port.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_port = CTkEntry( - self.tabview_config.tab("Parameter"), - textvariable=StringVar(value=self.parent.OSC_PORT), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_port.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_port.bind("", self.entry_port_callback) - - ## entry authkey - row +=1 - self.label_authkey = CTkLabel( - self.tabview_config.tab("Parameter"), - text="DeepL Auth Key:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_authkey.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_authkey = CTkEntry( - self.tabview_config.tab("Parameter"), - textvariable=StringVar(value=self.parent.AUTH_KEYS["DeepL(auth)"]), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_authkey.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_authkey.bind("", self.entry_authkey_callback) - - ## entry message format - row +=1 - self.label_message_format = CTkLabel( - self.tabview_config.tab("Parameter"), - text="Message Format:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_message_format.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.entry_message_format = CTkEntry( - self.tabview_config.tab("Parameter"), - textvariable=StringVar(value=self.parent.MESSAGE_FORMAT), - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.entry_message_format.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.entry_message_format.bind("", self.entry_message_format_callback) - - # tab Others - ## checkbox auto clear chat box - row += 1 - self.label_checkbox_auto_clear_chatbox = CTkLabel( - self.tabview_config.tab("Others"), - text="Auto clear chat box:", - fg_color="transparent", - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.label_checkbox_auto_clear_chatbox.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") - self.checkbox_auto_clear_chatbox = CTkCheckBox( - self.tabview_config.tab("Others"), - text="", - onvalue=True, - offvalue=False, - command=self.checkbox_auto_clear_chatbox_callback, - font=CTkFont(family=self.parent.FONT_FAMILY) - ) - self.checkbox_auto_clear_chatbox.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - if self.parent.ENABLE_AUTO_CLEAR_CHATBOX is True: - self.checkbox_auto_clear_chatbox.select() - else: - self.checkbox_auto_clear_chatbox.deselect() + # load ui language data + language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") + # add tabview config + self.add_tabview_config(language_yaml_data, selectable_languages) + # set all config window labels + widget_config_window_label_setter(self, language_yaml_data) self.protocol("WM_DELETE_WINDOW", self.delete_window) @@ -708,6 +74,9 @@ class ToplevelWindowConfig(CTkToplevel): self.label_font_family.configure(font=CTkFont(family=choice)) self.optionmenu_font_family.configure(font=CTkFont(family=choice)) self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=choice)) + self.label_ui_language.configure(font=CTkFont(family=choice)) + self.optionmenu_ui_language.configure(font=CTkFont(family=choice)) + self.optionmenu_ui_language._dropdown_menu.configure(font=CTkFont(family=choice)) # tab Translation self.label_translation_translator.configure(font=CTkFont(family=choice)) @@ -797,6 +166,27 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.FONT_FAMILY = choice save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) + def optionmenu_ui_language_callback(self, choice): + pre_language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") + self.parent.UI_LANGUAGE = get_key_by_value(selectable_languages, choice) + language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") + save_json(self.parent.PATH_CONFIG, "UI_LANGUAGE", self.parent.UI_LANGUAGE) + + + # delete + self.parent.delete_tabview_logs(pre_language_yaml_data) + self.delete_tabview_config(pre_language_yaml_data) + # add tabview textbox + self.parent.add_tabview_logs(language_yaml_data) + self.add_tabview_config(language_yaml_data, selectable_languages) + + # 翻訳予定 + # window information + # try: + # self.parent.information_window.textbox_information.configure(font=customtkinter.CTkFont(family=choice)) + # except: + # pass + def optionmenu_translation_translator_callback(self, choice): if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: print_textbox(self.parent.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") @@ -1017,4 +407,684 @@ class ToplevelWindowConfig(CTkToplevel): value = self.entry_message_format.get() if len(value) > 0: self.parent.MESSAGE_FORMAT = value - save_json(self.parent.PATH_CONFIG, "MESSAGE_FORMAT", self.parent.MESSAGE_FORMAT) \ No newline at end of file + save_json(self.parent.PATH_CONFIG, "MESSAGE_FORMAT", self.parent.MESSAGE_FORMAT) + + def delete_tabview_config(self, pre_language_yaml_data): + self.tabview_config.delete(pre_language_yaml_data["config_tab_title_ui"]) + self.tabview_config.delete(pre_language_yaml_data["config_tab_title_translation"]) + self.tabview_config.delete(pre_language_yaml_data["config_tab_title_transcription"]) + self.tabview_config.delete(pre_language_yaml_data["config_tab_title_parameter"]) + self.tabview_config.delete(pre_language_yaml_data["config_tab_title_others"]) + + def add_tabview_config(self, language_yaml_data, selectable_languages): + config_tab_title_ui = language_yaml_data["config_tab_title_ui"] + config_tab_title_translation = language_yaml_data["config_tab_title_translation"] + config_tab_title_transcription = language_yaml_data["config_tab_title_transcription"] + config_tab_title_parameter = language_yaml_data["config_tab_title_parameter"] + config_tab_title_others = language_yaml_data["config_tab_title_others"] + + init_lang_text = "Loading..." + + # tabwiew config + self.tabview_config = CTkTabview(self) + self.tabview_config.grid(row=0, column=0, padx=5, pady=5, sticky="nsew") + self.tabview_config.add(config_tab_title_ui) + self.tabview_config.add(config_tab_title_translation) + self.tabview_config.add(config_tab_title_transcription) + self.tabview_config.add(config_tab_title_parameter) + self.tabview_config.add(config_tab_title_others) + self.tabview_config.tab(config_tab_title_ui).grid_columnconfigure(1, weight=1) + self.tabview_config.tab(config_tab_title_translation).grid_columnconfigure([1,2,3], weight=1) + self.tabview_config.tab(config_tab_title_transcription).grid_columnconfigure(1, weight=1) + self.tabview_config.tab(config_tab_title_parameter).grid_columnconfigure(1, weight=1) + self.tabview_config.tab(config_tab_title_others).grid_columnconfigure(1, weight=1) + self.tabview_config._segmented_button.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + self.tabview_config._segmented_button.grid(sticky="W") + + # tab UI + ## slider transparency + row = 0 + padx = 5 + pady = 1 + self.label_transparency = CTkLabel( + self.tabview_config.tab(config_tab_title_ui), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_transparency.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.slider_transparency = CTkSlider( + self.tabview_config.tab(config_tab_title_ui), + from_=50, + to=100, + command=self.slider_transparency_callback, + variable=DoubleVar(value=self.parent.TRANSPARENCY), + ) + self.slider_transparency.grid(row=row, column=1, columnspan=1, padx=padx, pady=10, sticky="nsew") + + ## optionmenu theme + row += 1 + self.label_appearance_theme = CTkLabel( + self.tabview_config.tab(config_tab_title_ui), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_appearance_theme.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_appearance_theme = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_ui), + values=["Light", "Dark", "System"], + command=self.optionmenu_theme_callback, + variable=StringVar(value=self.parent.APPEARANCE_THEME), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_appearance_theme.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_appearance_theme._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu UI scaling + row += 1 + self.label_ui_scaling = CTkLabel( + self.tabview_config.tab(config_tab_title_ui), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_ui_scaling.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_ui_scaling = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_ui), + values=["80%", "90%", "100%", "110%", "120%"], + command=self.optionmenu_ui_scaling_callback, + variable=StringVar(value=self.parent.UI_SCALING), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_ui_scaling.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_ui_scaling._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu font family + row += 1 + self.label_font_family = CTkLabel( + self.tabview_config.tab(config_tab_title_ui), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_font_family.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + font_families = list(tk_font.families()) + self.optionmenu_font_family = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_ui), + values=font_families, + command=self.optionmenu_font_family_callback, + variable=StringVar(value=self.parent.FONT_FAMILY), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu ui language + row += 1 + self.label_ui_language = CTkLabel( + self.tabview_config.tab(config_tab_title_ui), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_ui_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + selectable_languages_values = list(selectable_languages.values()) + self.optionmenu_ui_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_ui), + values=selectable_languages_values, + command=self.optionmenu_ui_language_callback, + variable=StringVar(value=selectable_languages[self.parent.UI_LANGUAGE]), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_ui_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_ui_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + # tab Translation + ## optionmenu translation translator + row = 0 + padx = 5 + pady = 1 + self.label_translation_translator = CTkLabel( + self.tabview_config.tab(config_tab_title_translation), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.label_translation_translator.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_translation_translator = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_translation), + values=list(self.parent.translator.translator_status.keys()), + command=self.optionmenu_translation_translator_callback, + variable=StringVar(value=self.parent.CHOICE_TRANSLATOR), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu translation input language + row +=1 + self.label_translation_input_language = CTkLabel( + self.tabview_config.tab(config_tab_title_translation), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_translation_input_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + ## select translation input source language + self.optionmenu_translation_input_source_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_translation), + command=self.optionmenu_translation_input_source_language_callback, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.INPUT_SOURCE_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_translation_input_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## label translation input arrow + self.label_translation_input_arrow = CTkLabel( + self.tabview_config.tab(config_tab_title_translation), + text="-->", + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_translation_input_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") + + ## select translation input target language + self.optionmenu_translation_input_target_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_translation), + command=self.optionmenu_translation_input_target_language_callback, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.INPUT_TARGET_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_translation_input_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu translation output language + row +=1 + self.label_translation_output_language = CTkLabel( + self.tabview_config.tab(config_tab_title_translation), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_translation_output_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + ## select translation output source language + self.optionmenu_translation_output_source_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_translation), + command=self.optionmenu_translation_output_source_language_callback, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.OUTPUT_SOURCE_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_translation_output_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## label translation output arrow + self.label_translation_output_arrow = CTkLabel( + self.tabview_config.tab(config_tab_title_translation), + text="-->", + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_translation_output_arrow.grid(row=row, column=2, columnspan=1, padx=padx, pady=pady, sticky="nsew") + + ## select translation output target language + self.optionmenu_translation_output_target_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_translation), + command=self.optionmenu_translation_output_target_language_callback, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + variable=StringVar(value=self.parent.OUTPUT_TARGET_LANG), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_translation_output_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + # tab Transcription + ## optionmenu input mic device's host + row = 0 + padx = 5 + pady = 1 + self.label_input_mic_host = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_host.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_input_mic_host = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_transcription), + values=[host for host in get_input_device_list().keys()], + command=self.optionmenu_input_mic_host_callback, + variable=StringVar(value=self.parent.CHOICE_MIC_HOST), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu input mic device + row += 1 + self.label_input_mic_device = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_input_mic_device = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_transcription), + values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]], + command=self.optionmenu_input_mic_device_callback, + variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu input mic voice language + row +=1 + self.label_input_mic_voice_language = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_input_mic_voice_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_transcription), + values=list(transcription_lang.keys()), + command=self.optionmenu_input_mic_voice_language_callback, + variable=StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## slider input mic energy threshold + row +=1 + self.label_input_mic_energy_threshold = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + self.slider_input_mic_energy_threshold = CTkSlider( + self.tabview_config.tab(config_tab_title_transcription), + from_=0, + to=self.MAX_MIC_ENERGY_THRESHOLD, + border_width=7, + button_length=0, + button_corner_radius=3, + number_of_steps=self.MAX_MIC_ENERGY_THRESHOLD, + command=self.slider_input_mic_energy_threshold_callback, + variable=IntVar(value=self.parent.INPUT_MIC_ENERGY_THRESHOLD), + ) + self.slider_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") + + ## progressBar input mic energy threshold + row +=1 + self.checkbox_input_mic_threshold_check = CTkCheckBox( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + onvalue=True, + offvalue=False, + command=self.checkbox_input_mic_threshold_check_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_input_mic_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + self.progressBar_input_mic_energy_threshold = CTkProgressBar( + self.tabview_config.tab(config_tab_title_transcription), + corner_radius=0 + ) + self.progressBar_input_mic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=5, sticky="nsew") + self.progressBar_input_mic_energy_threshold.set(0) + + ## checkbox input mic dynamic energy threshold + row +=1 + self.label_input_mic_dynamic_energy_threshold = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.checkbox_input_mic_dynamic_energy_threshold = CTkCheckBox( + self.tabview_config.tab(config_tab_title_transcription), + text="", + onvalue=True, + offvalue=False, + command=self.checkbox_input_mic_dynamic_energy_threshold_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_input_mic_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + if self.parent.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD is True: + self.checkbox_input_mic_dynamic_energy_threshold.select() + else: + self.checkbox_input_mic_dynamic_energy_threshold.deselect() + + ## entry input mic record timeout + row +=1 + self.label_input_mic_record_timeout = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_mic_record_timeout = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=self.parent.INPUT_MIC_RECORD_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_mic_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_record_timeout.bind("", self.entry_input_mic_record_timeout_callback) + + ## entry input mic phrase timeout + row +=1 + self.label_input_mic_phrase_timeout = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_mic_phrase_timeout = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=self.parent.INPUT_MIC_PHRASE_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_mic_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_phrase_timeout.bind("", self.entry_input_mic_phrase_timeout_callback) + + ## entry input mic max phrases + row +=1 + self.label_input_mic_max_phrases = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_mic_max_phrases = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=self.parent.INPUT_MIC_MAX_PHRASES), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_mic_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_max_phrases.bind("", self.entry_input_mic_max_phrases_callback) + + ## entry input mic word filter + row +=1 + self.label_input_mic_word_filter = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_mic_word_filter.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_mic_word_filter = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_mic_word_filter.bind("", self.entry_input_mic_word_filters_callback) + + ## optionmenu input speaker device + row +=1 + self.label_input_speaker_device = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_device.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_input_speaker_device = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_transcription), + values=[device["name"] for device in get_output_device_list()], + command=self.optionmenu_input_speaker_device_callback, + variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## optionmenu input speaker voice language + row +=1 + self.label_input_speaker_voice_language = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_voice_language.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.optionmenu_input_speaker_voice_language = CTkOptionMenu( + self.tabview_config.tab(config_tab_title_transcription), + values=list(transcription_lang.keys()), + command=self.optionmenu_input_speaker_voice_language_callback, + variable=StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## entry input speaker energy threshold + row +=1 + self.label_input_speaker_energy_threshold = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + ## progressBar input speaker energy threshold + self.slider_input_speaker_energy_threshold = CTkSlider( + self.tabview_config.tab(config_tab_title_transcription), + from_=0, + to=self.MAX_SPEAKER_ENERGY_THRESHOLD, + border_width=7, + button_length=0, + button_corner_radius=3, + number_of_steps=self.MAX_SPEAKER_ENERGY_THRESHOLD, + command=self.slider_input_speaker_energy_threshold_callback, + variable=IntVar(value=self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD), + ) + self.slider_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=0, pady=5, sticky="nsew") + + ## progressBar input speaker energy threshold + row +=1 + self.checkbox_input_speaker_threshold_check = CTkCheckBox( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + onvalue=True, + offvalue=False, + command=self.checkbox_input_speaker_threshold_check_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_input_speaker_threshold_check.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + + self.progressBar_input_speaker_energy_threshold = CTkProgressBar( + self.tabview_config.tab(config_tab_title_transcription), + corner_radius=0 + ) + self.progressBar_input_speaker_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=5, sticky="nsew") + self.progressBar_input_speaker_energy_threshold.set(0) + + ## checkbox input speaker dynamic energy threshold + row +=1 + self.label_input_speaker_dynamic_energy_threshold = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_dynamic_energy_threshold.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.checkbox_input_speaker_dynamic_energy_threshold = CTkCheckBox( + self.tabview_config.tab(config_tab_title_transcription), + text="", + onvalue=True, + offvalue=False, + command=self.checkbox_input_speaker_dynamic_energy_threshold_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_input_speaker_dynamic_energy_threshold.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + if self.parent.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: + self.checkbox_input_speaker_dynamic_energy_threshold.select() + else: + self.checkbox_input_speaker_dynamic_energy_threshold.deselect() + + ## entry input speaker record timeout + row +=1 + self.label_input_speaker_record_timeout = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_record_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_speaker_record_timeout = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_RECORD_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_speaker_record_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_speaker_record_timeout.bind("", self.entry_input_speaker_record_timeout_callback) + + ## entry input speaker phrase timeout + row +=1 + self.label_input_speaker_phrase_timeout = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_phrase_timeout.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_speaker_phrase_timeout = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_PHRASE_TIMEOUT), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_speaker_phrase_timeout.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_speaker_phrase_timeout.bind("", self.entry_input_speaker_phrase_timeout_callback) + + ## entry input speaker max phrases + row +=1 + self.label_input_speaker_max_phrases = CTkLabel( + self.tabview_config.tab(config_tab_title_transcription), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_input_speaker_max_phrases.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_input_speaker_max_phrases = CTkEntry( + self.tabview_config.tab(config_tab_title_transcription), + textvariable=StringVar(value=self.parent.INPUT_SPEAKER_MAX_PHRASES), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_input_speaker_max_phrases.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_input_speaker_max_phrases.bind("", self.entry_input_speaker_max_phrases_callback) + + # tab Parameter + ## entry ip address + row = 0 + padx = 5 + pady = 1 + self.label_ip_address = CTkLabel( + self.tabview_config.tab(config_tab_title_parameter), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_ip_address.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_ip_address = CTkEntry( + self.tabview_config.tab(config_tab_title_parameter), + textvariable=StringVar(value=self.parent.OSC_IP_ADDRESS), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_ip_address.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_ip_address.bind("", self.entry_ip_address_callback) + + ## entry port + row +=1 + self.label_port = CTkLabel( + self.tabview_config.tab(config_tab_title_parameter), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_port.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_port = CTkEntry( + self.tabview_config.tab(config_tab_title_parameter), + textvariable=StringVar(value=self.parent.OSC_PORT), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_port.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_port.bind("", self.entry_port_callback) + + ## entry authkey + row +=1 + self.label_authkey = CTkLabel( + self.tabview_config.tab(config_tab_title_parameter), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_authkey.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_authkey = CTkEntry( + self.tabview_config.tab(config_tab_title_parameter), + textvariable=StringVar(value=self.parent.AUTH_KEYS["DeepL(auth)"]), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_authkey.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_authkey.bind("", self.entry_authkey_callback) + + ## entry message format + row +=1 + self.label_message_format = CTkLabel( + self.tabview_config.tab(config_tab_title_parameter), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_message_format.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.entry_message_format = CTkEntry( + self.tabview_config.tab(config_tab_title_parameter), + textvariable=StringVar(value=self.parent.MESSAGE_FORMAT), + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.entry_message_format.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.entry_message_format.bind("", self.entry_message_format_callback) + + # tab Others + ## checkbox auto clear chat box + row += 1 + self.label_checkbox_auto_clear_chatbox = CTkLabel( + self.tabview_config.tab(config_tab_title_others), + text=init_lang_text, + fg_color="transparent", + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.label_checkbox_auto_clear_chatbox.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + self.checkbox_auto_clear_chatbox = CTkCheckBox( + self.tabview_config.tab(config_tab_title_others), + text="", + onvalue=True, + offvalue=False, + command=self.checkbox_auto_clear_chatbox_callback, + font=CTkFont(family=self.parent.FONT_FAMILY) + ) + self.checkbox_auto_clear_chatbox.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + if self.parent.ENABLE_AUTO_CLEAR_CHATBOX is True: + self.checkbox_auto_clear_chatbox.select() + else: + self.checkbox_auto_clear_chatbox.deselect() + + widget_config_window_label_setter(self, language_yaml_data) \ No newline at end of file From 7ea247ced2c1e36e3049c364c799736158379372 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Thu, 13 Jul 2023 09:14:38 +0900 Subject: [PATCH 22/54] add pyyaml into requiremnts.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index aef8b222..0b8705f5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,5 @@ PyAudioWPatch python-osc customtkinter deepl -flashtext \ No newline at end of file +flashtext +pyyaml \ No newline at end of file From 0755b41cf08c6fecea5fe9b3d3d9f5a537e592b0 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 13 Jul 2023 10:45:15 +0900 Subject: [PATCH 23/54] =?UTF-8?q?=E3=82=B9=E3=83=94=E3=83=BC=E3=82=AB?= =?UTF-8?q?=E3=83=BC=E3=81=AB=E3=81=A4=E3=81=84=E3=81=A6=E6=97=A2=E5=AE=9A?= =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E4=BB=A5=E5=A4=96=E3=82=92?= =?UTF-8?q?=E9=81=B8=E6=8A=9E=E3=81=97=E3=81=9F=E6=99=82=E3=81=ABERROR?= =?UTF-8?q?=E3=81=8C=E5=87=BA=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 4 +++- window_config.py | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/VRCT.py b/VRCT.py index 3270081f..9915b82c 100644 --- a/VRCT.py +++ b/VRCT.py @@ -161,7 +161,9 @@ class App(CTk): if "CHOICE_SPEAKER_DEVICE" in config.keys(): if config["CHOICE_SPEAKER_DEVICE"] in [device["name"] for device in get_output_device_list()]: - self.CHOICE_SPEAKER_DEVICE = config["CHOICE_SPEAKER_DEVICE"] + speaker_device = [device for device in get_output_device_list() if device["name"] == config["CHOICE_SPEAKER_DEVICE"]][0] + if get_default_output_device()["index"] == speaker_device["index"]: + self.CHOICE_SPEAKER_DEVICE = config["CHOICE_SPEAKER_DEVICE"] if "INPUT_SPEAKER_VOICE_LANGUAGE" in config.keys(): if config["INPUT_SPEAKER_VOICE_LANGUAGE"] in list(transcription_lang.keys()): self.INPUT_SPEAKER_VOICE_LANGUAGE = config["INPUT_SPEAKER_VOICE_LANGUAGE"] diff --git a/window_config.py b/window_config.py index 747f21f8..481acea6 100644 --- a/window_config.py +++ b/window_config.py @@ -301,10 +301,14 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "INPUT_MIC_WORD_FILTER", self.parent.INPUT_MIC_WORD_FILTER) def optionmenu_input_speaker_device_callback(self, choice): - self.parent.CHOICE_SPEAKER_DEVICE = choice - save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) - self.checkbox_input_speaker_threshold_check.deselect() - self.checkbox_input_speaker_threshold_check_callback() + speaker_device = [device for device in get_output_device_list() if device["name"] == choice][0] + if get_default_output_device()["index"] == speaker_device["index"]: + self.parent.CHOICE_SPEAKER_DEVICE = choice + save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) + else: + print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") + print_textbox(self.parent.textbox_message_system_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") + self.optionmenu_input_speaker_device.configure(variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE)) def optionmenu_input_speaker_voice_language_callback(self, choice): self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice @@ -339,6 +343,7 @@ class ToplevelWindowConfig(CTkToplevel): self.speaker_energy_plot_progressbar.start() else: print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") + print_textbox(self.parent.textbox_message_system_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") self.checkbox_input_speaker_threshold_check.deselect() else: if self.speaker_energy_get_progressbar != None: From 88155e5b013ce0bb404b890849c16b66c34246ab Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 13 Jul 2023 11:01:25 +0900 Subject: [PATCH 24/54] =?UTF-8?q?=E8=B5=B7=E5=8B=95=E6=99=82=E3=81=ABTople?= =?UTF-8?q?velWindowConfig=E3=82=92=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 14 +++++++++----- window_config.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/VRCT.py b/VRCT.py index 9915b82c..c46216d3 100644 --- a/VRCT.py +++ b/VRCT.py @@ -397,12 +397,16 @@ class App(CTk): # delete window self.protocol("WM_DELETE_WINDOW", self.delete_window) + self.config_window = ToplevelWindowConfig(self) + self.config_window.withdraw() + def button_config_callback(self): - if self.config_window is None or not self.config_window.winfo_exists(): - self.config_window = ToplevelWindowConfig(self) - self.checkbox_translation.configure(state="disabled") - self.checkbox_transcription_send.configure(state="disabled") - self.checkbox_transcription_receive.configure(state="disabled") + # if self.config_window is None or not self.config_window.winfo_exists(): + # # self.config_window = ToplevelWindowConfig(self) + self.config_window.deiconify() + self.checkbox_translation.configure(state="disabled") + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") self.config_window.focus() def button_information_callback(self): diff --git a/window_config.py b/window_config.py index 481acea6..27ab3859 100644 --- a/window_config.py +++ b/window_config.py @@ -406,7 +406,7 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.checkbox_translation.configure(state="normal") self.parent.checkbox_transcription_send.configure(state="normal") self.parent.checkbox_transcription_receive.configure(state="normal") - self.parent.config_window.destroy() + self.parent.config_window.withdraw() def entry_message_format_callback(self, event): value = self.entry_message_format.get() From d11f9d716f402a8f45e1088d841e5cc86a60228f Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 13 Jul 2023 15:43:44 +0900 Subject: [PATCH 25/54] =?UTF-8?q?withdraw=E3=81=AE=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=9F=E3=83=B3=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 2 -- window_config.py | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/VRCT.py b/VRCT.py index c46216d3..66622465 100644 --- a/VRCT.py +++ b/VRCT.py @@ -398,11 +398,9 @@ class App(CTk): self.protocol("WM_DELETE_WINDOW", self.delete_window) self.config_window = ToplevelWindowConfig(self) - self.config_window.withdraw() def button_config_callback(self): # if self.config_window is None or not self.config_window.winfo_exists(): - # # self.config_window = ToplevelWindowConfig(self) self.config_window.deiconify() self.checkbox_translation.configure(state="disabled") self.checkbox_transcription_send.configure(state="disabled") diff --git a/window_config.py b/window_config.py index 27ab3859..1e4be837 100644 --- a/window_config.py +++ b/window_config.py @@ -16,6 +16,7 @@ class ToplevelWindowConfig(CTkToplevel): def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) + self.withdraw() self.parent = parent # self.geometry(f"{350}x{270}") # self.resizable(False, False) @@ -167,6 +168,7 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) def optionmenu_ui_language_callback(self, choice): + self.withdraw() pre_language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") self.parent.UI_LANGUAGE = get_key_by_value(selectable_languages, choice) language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") @@ -186,6 +188,7 @@ class ToplevelWindowConfig(CTkToplevel): # self.parent.information_window.textbox_information.configure(font=customtkinter.CTkFont(family=choice)) # except: # pass + self.deiconify() def optionmenu_translation_translator_callback(self, choice): if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: From 2cc9d6830370e229d45fb67c27a08226d34629f5 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 13 Jul 2023 15:52:30 +0900 Subject: [PATCH 26/54] remove comment out --- VRCT.py | 1 - 1 file changed, 1 deletion(-) diff --git a/VRCT.py b/VRCT.py index 66622465..00a2fc99 100644 --- a/VRCT.py +++ b/VRCT.py @@ -400,7 +400,6 @@ class App(CTk): self.config_window = ToplevelWindowConfig(self) def button_config_callback(self): - # if self.config_window is None or not self.config_window.winfo_exists(): self.config_window.deiconify() self.checkbox_translation.configure(state="disabled") self.checkbox_transcription_send.configure(state="disabled") From c7cc2ff55167abcd6e772aa2c5fd230a94046517 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Thu, 13 Jul 2023 15:53:32 +0900 Subject: [PATCH 27/54] test code CTkScrollableDropdown for font --- CTkScrollableDropdown/__init__.py | 12 + .../ctk_scrollable_dropdown.py | 321 ++++++++++++++++++ .../ctk_scrollable_dropdown_frame.py | 278 +++++++++++++++ window_config.py | 20 +- 4 files changed, 628 insertions(+), 3 deletions(-) create mode 100644 CTkScrollableDropdown/__init__.py create mode 100644 CTkScrollableDropdown/ctk_scrollable_dropdown.py create mode 100644 CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py diff --git a/CTkScrollableDropdown/__init__.py b/CTkScrollableDropdown/__init__.py new file mode 100644 index 00000000..8ba844b7 --- /dev/null +++ b/CTkScrollableDropdown/__init__.py @@ -0,0 +1,12 @@ +""" +CustomTkinter Scrollable Dropdown Menu +Author: Akash Bora +License: MIT +This is a custom dropdown menu for customtkinter. +Homepage: https://github.com/Akascape/CTkScrollableDropdown +""" + +__version__ = '0.9' + +from .ctk_scrollable_dropdown import CTkScrollableDropdown +from .ctk_scrollable_dropdown_frame import CTkScrollableDropdownFrame diff --git a/CTkScrollableDropdown/ctk_scrollable_dropdown.py b/CTkScrollableDropdown/ctk_scrollable_dropdown.py new file mode 100644 index 00000000..c54b6197 --- /dev/null +++ b/CTkScrollableDropdown/ctk_scrollable_dropdown.py @@ -0,0 +1,321 @@ +''' +Advanced Scrollable Dropdown class for customtkinter widgets +Author: Akash Bora +''' + +import customtkinter +import sys +import time + +class CTkScrollableDropdown(customtkinter.CTkToplevel): + + def __init__(self, attach, x=None, y=None, button_color=None, height: int = 200, width: int = None, + fg_color=None, button_height: int = 20, justify="center", scrollbar_button_color=None, + scrollbar=True, scrollbar_button_hover_color=None, frame_border_width=2, values=[], + command=None, image_values=[], alpha: float = 0.97, frame_corner_radius=20, double_click=False, + resize=True, frame_border_color=None, text_color=None, autocomplete=False, **button_kwargs): + + super().__init__(takefocus=1) + + self.focus() + self.alpha = alpha + self.attach = attach + self.corner = frame_corner_radius + self.padding = 0 + self.focus_something = False + self.disable = True + + if sys.platform.startswith("win"): + self.after(100, lambda: self.overrideredirect(True)) + self.transparent_color = self._apply_appearance_mode(self._fg_color) + self.attributes("-transparentcolor", self.transparent_color) + elif sys.platform.startswith("darwin"): + self.overrideredirect(True) + self.transparent_color = 'systemTransparent' + self.attributes("-transparent", True) + self.focus_something = True + else: + self.overrideredirect(True) + self.transparent_color = '#000001' + self.corner = 0 + self.padding = 18 + self.withdraw() + + self.hide = True + self.attach.bind('', lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind('', lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") + + self.attributes('-alpha', 0) + self.disable = False + self.fg_color = customtkinter.ThemeManager.theme["CTkFrame"]["fg_color"] if fg_color is None else fg_color + self.scroll_button_color = customtkinter.ThemeManager.theme["CTkScrollbar"]["button_color"] if scrollbar_button_color is None else scrollbar_button_color + self.scroll_hover_color = customtkinter.ThemeManager.theme["CTkScrollbar"]["button_hover_color"] if scrollbar_button_hover_color is None else scrollbar_button_hover_color + self.frame_border_color = customtkinter.ThemeManager.theme["CTkFrame"]["border_color"] if frame_border_color is None else frame_border_color + self.button_color = customtkinter.ThemeManager.theme["CTkFrame"]["top_fg_color"] if button_color is None else button_color + self.text_color = customtkinter.ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else text_color + + if scrollbar is False: + self.scroll_button_color = self.fg_color + self.scroll_hover_color = self.fg_color + + self.frame = customtkinter.CTkScrollableFrame(self, bg_color=self.transparent_color, fg_color=self.fg_color, + scrollbar_button_hover_color=self.scroll_hover_color, + corner_radius=self.corner, border_width=frame_border_width, + scrollbar_button_color=self.scroll_button_color, + border_color=self.frame_border_color) + self.frame._scrollbar.grid_configure(padx=3) + self.frame.pack(expand=True, fill="both") + self.dummy_entry = customtkinter.CTkEntry(self.frame, fg_color="transparent", border_width=0, height=1, width=1) + self.no_match = customtkinter.CTkLabel(self.frame, text="No Match") + self.height = height + self.height_new = height + self.width = width + self.command = command + self.fade = False + self.resize = resize + self.autocomplete = autocomplete + self.var_update = customtkinter.StringVar() + self.appear = False + + if justify.lower()=="left": + self.justify = "w" + elif justify.lower()=="right": + self.justify = "e" + else: + self.justify = "c" + + self.button_height = button_height + self.values = values + self.button_num = len(self.values) + self.image_values = None if len(image_values)!=len(self.values) else image_values + + self.resizable(width=False, height=False) + self.transient(self.master) + self._init_buttons(**button_kwargs) + + # Add binding for different ctk widgets + if double_click or self.attach.winfo_name().startswith("!ctkentry") or self.attach.winfo_name().startswith("!ctkcombobox"): + self.attach.bind('', lambda e: self._iconify(), add="+") + else: + self.attach.bind('', lambda e: self._iconify(), add="+") + + if self.attach.winfo_name().startswith("!ctkcombobox"): + self.attach._canvas.tag_bind("right_parts", "", lambda e: self._iconify()) + self.attach._canvas.tag_bind("dropdown_arrow", "", lambda e: self._iconify()) + if self.command is None: + self.command = self.attach.set + + if self.attach.winfo_name().startswith("!ctkoptionmenu"): + self.attach._canvas.bind("", lambda e: self._iconify()) + self.attach._text_label.bind("", lambda e: self._iconify()) + if self.command is None: + self.command = self.attach.set + + self.update_idletasks() + self.x = x + self.y = y + + if self.autocomplete: + self.bind_autocomplete() + + self.deiconify() + self.withdraw() + + self.attributes("-alpha", self.alpha) + + def _withdraw(self): + if self.hide is False: self.withdraw() + self.hide = True + + def _update(self, a, b, c): + self.live_update(self.attach._entry.get()) + + def bind_autocomplete(self, ): + def appear(x): + self.appear = True + + if self.attach.winfo_name().startswith("!ctkcombobox"): + self.attach._entry.configure(textvariable=self.var_update) + self.attach._entry.bind("", appear) + self.attach.set(self.values[0]) + self.var_update.trace_add('write', self._update) + + if self.attach.winfo_name().startswith("!ctkentry"): + self.attach.configure(textvariable=self.var_update) + self.attach.bind("", appear) + self.var_update.trace_add('write', self._update) + + def fade_out(self): + for i in range(100,0,-10): + if not self.winfo_exists(): + break + self.attributes("-alpha", i/100) + self.update() + time.sleep(1/100) + + def fade_in(self): + for i in range(0,100,10): + if not self.winfo_exists(): + break + self.attributes("-alpha", i/100) + self.update() + time.sleep(1/100) + + def _init_buttons(self, **button_kwargs): + self.i = 0 + self.widgets = {} + for row in self.values: + self.widgets[self.i] = customtkinter.CTkButton(self.frame, + text=row, + height=self.button_height, + fg_color=self.button_color, + text_color=self.text_color, + image=self.image_values[i] if self.image_values is not None else None, + anchor=self.justify, + command=lambda k=row: self._attach_key_press(k), **button_kwargs) + self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) + self.i+=1 + + self.hide = False + + def destroy_popup(self): + self.destroy() + self.disable = True + + def place_dropdown(self): + self.x_pos = self.attach.winfo_rootx() if self.x is None else self.x + self.attach.winfo_rootx() + self.y_pos = self.attach.winfo_rooty() + self.attach.winfo_reqheight() + 5 if self.y is None else self.y + self.attach.winfo_rooty() + self.width_new = self.attach.winfo_width() if self.width is None else self.width + + if self.resize: + if self.button_num==1: + self.height_new = self.button_height * self.button_num + 45 + else: + self.height_new = self.button_height * self.button_num + 35 + if self.height_new>self.height: + self.height_new = self.height + + self.geometry('{}x{}+{}+{}'.format(self.width_new, self.height_new, + self.x_pos, self.y_pos)) + self.fade_in() + self.attributes('-alpha', self.alpha) + self.attach.focus() + + def _iconify(self): + if self.disable: return + if self.hide: + self._deiconify() + self.focus() + self.hide = False + self.place_dropdown() + if self.focus_something: + self.dummy_entry.pack() + self.dummy_entry.focus_set() + self.after(100, self.dummy_entry.pack_forget) + else: + self.withdraw() + self.hide = True + + def _attach_key_press(self, k): + self.fade = True + if self.command: + self.command(k) + self.fade = False + self.fade_out() + self.withdraw() + self.hide = True + + def live_update(self, string=None): + if not self.appear: return + if self.disable: return + if self.fade: return + if string: + self._deiconify() + i=1 + for key in self.widgets.keys(): + s = self.widgets[key].cget("text") + if not s.startswith(string): + self.widgets[key].pack_forget() + else: + self.widgets[key].pack(fill="x", pady=2, padx=(self.padding, 0)) + i+=1 + + if i==1: + self.no_match.pack(fill="x", pady=2, padx=(self.padding, 0)) + else: + self.no_match.pack_forget() + self.button_num = i + self.place_dropdown() + + else: + self.no_match.pack_forget() + self.button_num = len(self.values) + for key in self.widgets.keys(): + self.widgets[key].destroy() + self._init_buttons() + self.place_dropdown() + + self.frame._parent_canvas.yview_moveto(0.0) + self.appear = False + + def insert(self, value, **kwargs): + self.widgets[self.i] = customtkinter.CTkButton(self.frame, + text=value, + height=self.button_height, + fg_color=self.button_color, + text_color=self.text_color, + anchor=self.justify, + command=lambda k=value: self._attach_key_press(k), **kwargs) + self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) + self.i+=1 + self.values.append(value) + + def _deiconify(self): + if len(self.values)>0: + self.deiconify() + + def popup(self, x=None, y=None): + self.x = x + self.y = y + self.hide = True + self._iconify() + + def configure(self, **kwargs): + if "height" in kwargs: + self.height = kwargs.pop("height") + self.height_new = self.height + + if "alpha" in kwargs: + self.alpha = kwargs.pop("alpha") + + if "width" in kwargs: + self.width = kwargs.pop("width") + + if "fg_color" in kwargs: + self.frame.configure(fg_color=kwargs.pop("fg_color")) + + if "values" in kwargs: + self.values = kwargs.pop("values") + self.image_values = None + for key in self.widgets.keys(): + self.widgets[key].destroy() + self._init_buttons() + + if "image_values" in kwargs: + self.image_values = kwargs.pop("image_values") + self.image_values = None if len(self.image_values)!=len(self.values) else self.image_values + if self.image_values is not None: + i=0 + for key in self.widgets.keys(): + self.widgets[key].configure(image=self.image_values[i]) + i+=1 + + if "button_color" in kwargs: + for key in self.widgets.keys(): + self.widgets[key].configure(fg_color=kwargs.pop("button_color")) + + for key in self.widgets.keys(): + self.widgets[key].configure(**kwargs) diff --git a/CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py b/CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py new file mode 100644 index 00000000..1bd93c2f --- /dev/null +++ b/CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py @@ -0,0 +1,278 @@ +''' +Advanced Scrollable Dropdown Frame class for customtkinter widgets +Author: Akash Bora +''' + +import customtkinter +import sys + +class CTkScrollableDropdownFrame(customtkinter.CTkFrame): + + def __init__(self, attach, x=None, y=None, button_color=None, height: int = 200, width: int = None, + fg_color=None, button_height: int = 20, justify="center", scrollbar_button_color=None, + scrollbar=True, scrollbar_button_hover_color=None, frame_border_width=2, values=[], + command=None, image_values=[], double_click=False, frame_corner_radius=True, resize=True, frame_border_color=None, + text_color=None, autocomplete=False, **button_kwargs): + + super().__init__(master=attach.winfo_toplevel(), bg_color=attach.cget("bg_color")) + + self.attach = attach + self.corner = 11 if frame_corner_radius else 0 + self.padding = 0 + self.disable = True + + self.hide = True + self.attach.bind('', lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") + self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") + + self.disable = False + self.fg_color = customtkinter.ThemeManager.theme["CTkFrame"]["fg_color"] if fg_color is None else fg_color + self.scroll_button_color = customtkinter.ThemeManager.theme["CTkScrollbar"]["button_color"] if scrollbar_button_color is None else scrollbar_button_color + self.scroll_hover_color = customtkinter.ThemeManager.theme["CTkScrollbar"]["button_hover_color"] if scrollbar_button_hover_color is None else scrollbar_button_hover_color + self.frame_border_color = customtkinter.ThemeManager.theme["CTkFrame"]["border_color"] if frame_border_color is None else frame_border_color + self.button_color = customtkinter.ThemeManager.theme["CTkFrame"]["top_fg_color"] if button_color is None else button_color + self.text_color = customtkinter.ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else text_color + + if scrollbar is False: + self.scroll_button_color = self.fg_color + self.scroll_hover_color = self.fg_color + + self.frame = customtkinter.CTkScrollableFrame(self, fg_color=self.fg_color, bg_color=attach.cget("bg_color"), + scrollbar_button_hover_color=self.scroll_hover_color, + corner_radius=self.corner, border_width=frame_border_width, + scrollbar_button_color=self.scroll_button_color, + border_color=self.frame_border_color) + self.frame._scrollbar.grid_configure(padx=3) + self.frame.pack(expand=True, fill="both") + + if self.corner==0: + self.corner = 21 + + self.dummy_entry = customtkinter.CTkEntry(self.frame, fg_color="transparent", border_width=0, height=1, width=1) + self.no_match = customtkinter.CTkLabel(self.frame, text="No Match") + self.height = height + self.height_new = height + self.width = width + self.command = command + self.fade = False + self.resize = resize + self.autocomplete = autocomplete + self.var_update = customtkinter.StringVar() + self.appear = False + + if justify.lower()=="left": + self.justify = "w" + elif justify.lower()=="right": + self.justify = "e" + else: + self.justify = "c" + + self.button_height = button_height + self.values = values + self.button_num = len(self.values) + self.image_values = None if len(image_values)!=len(self.values) else image_values + + self._init_buttons(**button_kwargs) + + # Add binding for different ctk widgets + if double_click or self.attach.winfo_name().startswith("!ctkentry") or self.attach.winfo_name().startswith("!ctkcombobox"): + self.attach.bind('', lambda e: self._iconify(), add="+") + self.attach._entry.bind('', lambda e: self._withdraw() if not self.disable else None, add="+") + else: + self.attach.bind('', lambda e: self._iconify(), add="+") + + if self.attach.winfo_name().startswith("!ctkcombobox"): + self.attach._canvas.tag_bind("right_parts", "", lambda e: self._iconify()) + self.attach._canvas.tag_bind("dropdown_arrow", "", lambda e: self._iconify()) + + if self.command is None: + self.command = self.attach.set + + if self.attach.winfo_name().startswith("!ctkoptionmenu"): + self.attach._canvas.bind("", lambda e: self._iconify()) + self.attach._text_label.bind("", lambda e: self._iconify()) + if self.command is None: + self.command = self.attach.set + + self.x = x + self.y = y + + if self.autocomplete: + self.bind_autocomplete() + + def _withdraw(self): + if self.hide is False: self.place_forget() + self.hide = True + + def _update(self, a, b, c): + self.live_update(self.attach._entry.get()) + + def bind_autocomplete(self, ): + def appear(x): + self.appear = True + + if self.attach.winfo_name().startswith("!ctkcombobox"): + self.attach._entry.configure(textvariable=self.var_update) + self.attach.set(self.values[0]) + self.attach._entry.bind("", appear) + self.var_update.trace_add('write', self._update) + + if self.attach.winfo_name().startswith("!ctkentry"): + self.attach.configure(textvariable=self.var_update) + self.attach.bind("", appear) + self.var_update.trace_add('write', self._update) + + def _init_buttons(self, **button_kwargs): + self.i = 0 + self.widgets = {} + for row in self.values: + self.widgets[self.i] = customtkinter.CTkButton(self.frame, + text=row, + height=self.button_height, + fg_color=self.button_color, + text_color=self.text_color, + image=self.image_values[i] if self.image_values is not None else None, + anchor=self.justify, + command=lambda k=row: self._attach_key_press(k), **button_kwargs) + self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) + self.i+=1 + + self.hide = False + + def destroy_popup(self): + self.destroy() + self.disable = True + + def place_dropdown(self): + self.x_pos = self.attach.winfo_x() if self.x is None else self.x + self.attach.winfo_rootx() + self.y_pos = self.attach.winfo_y() + self.attach.winfo_reqheight() + 5 if self.y is None else self.y + self.attach.winfo_rooty() + self.width_new = self.attach.winfo_width()-45+self.corner if self.width is None else self.width + + if self.resize: + if self.button_num==1: + self.height_new = self.button_height * self.button_num + 45 + else: + self.height_new = self.button_height * self.button_num + 35 + if self.height_new>self.height: + self.height_new = self.height + + self.frame.configure(width=self.width_new, height=self.height_new) + self.place(x=self.x_pos, y=self.y_pos) + + if sys.platform.startswith("darwin"): + self.dummy_entry.pack() + self.after(100, self.dummy_entry.pack_forget()) + + self.lift() + self.attach.focus() + + def _iconify(self): + if self.disable: return + if self.hide: + self.hide = False + self.place_dropdown() + else: + self.place_forget() + self.hide = True + + def _attach_key_press(self, k): + self.fade = True + if self.command: + self.command(k) + self.fade = False + self.place_forget() + self.hide = True + + def live_update(self, string=None): + if not self.appear: return + if self.disable: return + if self.fade: return + if string: + self._deiconify() + i=1 + for key in self.widgets.keys(): + s = self.widgets[key].cget("text") + if not s.startswith(string): + self.widgets[key].pack_forget() + else: + self.widgets[key].pack(fill="x", pady=2, padx=(self.padding, 0)) + i+=1 + + if i==1: + self.no_match.pack(fill="x", pady=2, padx=(self.padding, 0)) + else: + self.no_match.pack_forget() + self.button_num = i + self.place_dropdown() + + else: + self.no_match.pack_forget() + self.button_num = len(self.values) + for key in self.widgets.keys(): + self.widgets[key].destroy() + self._init_buttons() + self.place_dropdown() + + self.frame._parent_canvas.yview_moveto(0.0) + self.appear = False + + def insert(self, value, **kwargs): + self.widgets[self.i] = customtkinter.CTkButton(self.frame, + text=value, + height=self.button_height, + fg_color=self.button_color, + text_color=self.text_color, + anchor=self.justify, + command=lambda k=value: self._attach_key_press(k), **kwargs) + self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) + self.i+=1 + self.values.append(value) + + def _deiconify(self): + if len(self.values)>0: + self.pack_forget() + + def popup(self, x=None, y=None): + self.x = x + self.y = y + self.hide = True + self._iconify() + + def configure(self, **kwargs): + if "height" in kwargs: + self.height = kwargs.pop("height") + self.height_new = self.height + + if "alpha" in kwargs: + self.alpha = kwargs.pop("alpha") + + if "width" in kwargs: + self.width = kwargs.pop("width") + + if "fg_color" in kwargs: + self.frame.configure(fg_color=kwargs.pop("fg_color")) + + if "values" in kwargs: + self.values = kwargs.pop("values") + self.image_values = None + for key in self.widgets.keys(): + self.widgets[key].destroy() + self._init_buttons() + + if "image_values" in kwargs: + self.image_values = kwargs.pop("image_values") + self.image_values = None if len(self.image_values)!=len(self.values) else self.image_values + if self.image_values is not None: + i=0 + for key in self.widgets.keys(): + self.widgets[key].configure(image=self.image_values[i]) + i+=1 + + if "button_color" in kwargs: + for key in self.widgets.keys(): + self.widgets[key].configure(fg_color=kwargs.pop("button_color")) + + for key in self.widgets.keys(): + self.widgets[key].configure(**kwargs) diff --git a/window_config.py b/window_config.py index 1e4be837..214152e0 100644 --- a/window_config.py +++ b/window_config.py @@ -12,6 +12,8 @@ from audio_utils import get_input_device_list, get_output_device_list, get_defau from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder from languages import translation_lang, transcription_lang, selectable_languages +from CTkScrollableDropdown import CTkScrollableDropdown + class ToplevelWindowConfig(CTkToplevel): def __init__(self, parent, *args, **kwargs): @@ -61,6 +63,9 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "UI_SCALING", self.parent.UI_SCALING) def optionmenu_font_family_callback(self, choice): + # set choice font + self.optionmenu_font_family.set(choice) + # tab menu self.tabview_config._segmented_button.configure(font=CTkFont(family=choice)) @@ -75,6 +80,7 @@ class ToplevelWindowConfig(CTkToplevel): self.label_font_family.configure(font=CTkFont(family=choice)) self.optionmenu_font_family.configure(font=CTkFont(family=choice)) self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=choice)) + self.scrollableDropdown_font_family.configure(font=CTkFont(family=choice)) self.label_ui_language.configure(font=CTkFont(family=choice)) self.optionmenu_ui_language.configure(font=CTkFont(family=choice)) self.optionmenu_ui_language._dropdown_menu.configure(font=CTkFont(family=choice)) @@ -520,13 +526,21 @@ class ToplevelWindowConfig(CTkToplevel): font_families = list(tk_font.families()) self.optionmenu_font_family = CTkOptionMenu( self.tabview_config.tab(config_tab_title_ui), - values=font_families, - command=self.optionmenu_font_family_callback, variable=StringVar(value=self.parent.FONT_FAMILY), font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + + ## scrollableDropdown font family + self.scrollableDropdown_font_family = CTkScrollableDropdown( + self.optionmenu_font_family, + values=font_families, + justify="left", + button_color="transparent", + command=self.optionmenu_font_family_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_font_family.frame.bind("", lambda e: self.scrollableDropdown_font_family._iconify()) ## optionmenu ui language row += 1 From bb1a37f28260436cad141cd3e76a92115c428038 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 14 Jul 2023 18:26:53 +0900 Subject: [PATCH 28/54] =?UTF-8?q?scrollableDropdown=5Ffont=5Ffamily?= =?UTF-8?q?=E3=81=8B=E3=82=89=E3=83=9E=E3=82=A6=E3=82=B9=E3=82=AB=E3=83=BC?= =?UTF-8?q?=E3=82=BD=E3=83=AB=E3=81=8C=E9=9B=A2=E3=82=8C=E3=82=8B=E3=81=A8?= =?UTF-8?q?=E9=9D=9E=E8=A1=A8=E7=A4=BA=E3=81=AB=E3=81=AA=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=ABMethod=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CTkScrollableDropdown/ctk_scrollable_dropdown.py | 2 +- window_config.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CTkScrollableDropdown/ctk_scrollable_dropdown.py b/CTkScrollableDropdown/ctk_scrollable_dropdown.py index c54b6197..1f32541d 100644 --- a/CTkScrollableDropdown/ctk_scrollable_dropdown.py +++ b/CTkScrollableDropdown/ctk_scrollable_dropdown.py @@ -167,7 +167,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): def _init_buttons(self, **button_kwargs): self.i = 0 self.widgets = {} - for row in self.values: + for row in self.values: self.widgets[self.i] = customtkinter.CTkButton(self.frame, text=row, height=self.button_height, diff --git a/window_config.py b/window_config.py index 214152e0..3f2af77c 100644 --- a/window_config.py +++ b/window_config.py @@ -1,7 +1,7 @@ from time import sleep from queue import Queue from os import path as os_path -from tkinter import DoubleVar, IntVar +from tkinter import DoubleVar, IntVar from tkinter import font as tk_font import customtkinter from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox, CTkProgressBar @@ -540,7 +540,11 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_font_family_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_font_family.frame.bind("", lambda e: self.scrollableDropdown_font_family._iconify()) + self.scrollableDropdown_font_family.bind( + "", + lambda e: self.scrollableDropdown_font_family._withdraw() if not str(e.widget).startswith(".!ctkscrollabledropdown.") else None, + add="+" + ) ## optionmenu ui language row += 1 From 41d87fbf59fb79f0732474a59f3e700a2dd14f40 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sat, 15 Jul 2023 04:05:27 +0900 Subject: [PATCH 29/54] move ctk_scrollable_dropdown_frame.py to ./ --- CTkScrollableDropdown/__init__.py | 12 - .../ctk_scrollable_dropdown_frame.py | 278 ------------------ ..._dropdown.py => ctk_scrollable_dropdown.py | 14 +- window_config.py | 2 +- 4 files changed, 11 insertions(+), 295 deletions(-) delete mode 100644 CTkScrollableDropdown/__init__.py delete mode 100644 CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py rename CTkScrollableDropdown/ctk_scrollable_dropdown.py => ctk_scrollable_dropdown.py (98%) diff --git a/CTkScrollableDropdown/__init__.py b/CTkScrollableDropdown/__init__.py deleted file mode 100644 index 8ba844b7..00000000 --- a/CTkScrollableDropdown/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -""" -CustomTkinter Scrollable Dropdown Menu -Author: Akash Bora -License: MIT -This is a custom dropdown menu for customtkinter. -Homepage: https://github.com/Akascape/CTkScrollableDropdown -""" - -__version__ = '0.9' - -from .ctk_scrollable_dropdown import CTkScrollableDropdown -from .ctk_scrollable_dropdown_frame import CTkScrollableDropdownFrame diff --git a/CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py b/CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py deleted file mode 100644 index 1bd93c2f..00000000 --- a/CTkScrollableDropdown/ctk_scrollable_dropdown_frame.py +++ /dev/null @@ -1,278 +0,0 @@ -''' -Advanced Scrollable Dropdown Frame class for customtkinter widgets -Author: Akash Bora -''' - -import customtkinter -import sys - -class CTkScrollableDropdownFrame(customtkinter.CTkFrame): - - def __init__(self, attach, x=None, y=None, button_color=None, height: int = 200, width: int = None, - fg_color=None, button_height: int = 20, justify="center", scrollbar_button_color=None, - scrollbar=True, scrollbar_button_hover_color=None, frame_border_width=2, values=[], - command=None, image_values=[], double_click=False, frame_corner_radius=True, resize=True, frame_border_color=None, - text_color=None, autocomplete=False, **button_kwargs): - - super().__init__(master=attach.winfo_toplevel(), bg_color=attach.cget("bg_color")) - - self.attach = attach - self.corner = 11 if frame_corner_radius else 0 - self.padding = 0 - self.disable = True - - self.hide = True - self.attach.bind('', lambda e: self._withdraw() if not self.disable else None, add="+") - self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") - self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") - self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") - - self.disable = False - self.fg_color = customtkinter.ThemeManager.theme["CTkFrame"]["fg_color"] if fg_color is None else fg_color - self.scroll_button_color = customtkinter.ThemeManager.theme["CTkScrollbar"]["button_color"] if scrollbar_button_color is None else scrollbar_button_color - self.scroll_hover_color = customtkinter.ThemeManager.theme["CTkScrollbar"]["button_hover_color"] if scrollbar_button_hover_color is None else scrollbar_button_hover_color - self.frame_border_color = customtkinter.ThemeManager.theme["CTkFrame"]["border_color"] if frame_border_color is None else frame_border_color - self.button_color = customtkinter.ThemeManager.theme["CTkFrame"]["top_fg_color"] if button_color is None else button_color - self.text_color = customtkinter.ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else text_color - - if scrollbar is False: - self.scroll_button_color = self.fg_color - self.scroll_hover_color = self.fg_color - - self.frame = customtkinter.CTkScrollableFrame(self, fg_color=self.fg_color, bg_color=attach.cget("bg_color"), - scrollbar_button_hover_color=self.scroll_hover_color, - corner_radius=self.corner, border_width=frame_border_width, - scrollbar_button_color=self.scroll_button_color, - border_color=self.frame_border_color) - self.frame._scrollbar.grid_configure(padx=3) - self.frame.pack(expand=True, fill="both") - - if self.corner==0: - self.corner = 21 - - self.dummy_entry = customtkinter.CTkEntry(self.frame, fg_color="transparent", border_width=0, height=1, width=1) - self.no_match = customtkinter.CTkLabel(self.frame, text="No Match") - self.height = height - self.height_new = height - self.width = width - self.command = command - self.fade = False - self.resize = resize - self.autocomplete = autocomplete - self.var_update = customtkinter.StringVar() - self.appear = False - - if justify.lower()=="left": - self.justify = "w" - elif justify.lower()=="right": - self.justify = "e" - else: - self.justify = "c" - - self.button_height = button_height - self.values = values - self.button_num = len(self.values) - self.image_values = None if len(image_values)!=len(self.values) else image_values - - self._init_buttons(**button_kwargs) - - # Add binding for different ctk widgets - if double_click or self.attach.winfo_name().startswith("!ctkentry") or self.attach.winfo_name().startswith("!ctkcombobox"): - self.attach.bind('', lambda e: self._iconify(), add="+") - self.attach._entry.bind('', lambda e: self._withdraw() if not self.disable else None, add="+") - else: - self.attach.bind('', lambda e: self._iconify(), add="+") - - if self.attach.winfo_name().startswith("!ctkcombobox"): - self.attach._canvas.tag_bind("right_parts", "", lambda e: self._iconify()) - self.attach._canvas.tag_bind("dropdown_arrow", "", lambda e: self._iconify()) - - if self.command is None: - self.command = self.attach.set - - if self.attach.winfo_name().startswith("!ctkoptionmenu"): - self.attach._canvas.bind("", lambda e: self._iconify()) - self.attach._text_label.bind("", lambda e: self._iconify()) - if self.command is None: - self.command = self.attach.set - - self.x = x - self.y = y - - if self.autocomplete: - self.bind_autocomplete() - - def _withdraw(self): - if self.hide is False: self.place_forget() - self.hide = True - - def _update(self, a, b, c): - self.live_update(self.attach._entry.get()) - - def bind_autocomplete(self, ): - def appear(x): - self.appear = True - - if self.attach.winfo_name().startswith("!ctkcombobox"): - self.attach._entry.configure(textvariable=self.var_update) - self.attach.set(self.values[0]) - self.attach._entry.bind("", appear) - self.var_update.trace_add('write', self._update) - - if self.attach.winfo_name().startswith("!ctkentry"): - self.attach.configure(textvariable=self.var_update) - self.attach.bind("", appear) - self.var_update.trace_add('write', self._update) - - def _init_buttons(self, **button_kwargs): - self.i = 0 - self.widgets = {} - for row in self.values: - self.widgets[self.i] = customtkinter.CTkButton(self.frame, - text=row, - height=self.button_height, - fg_color=self.button_color, - text_color=self.text_color, - image=self.image_values[i] if self.image_values is not None else None, - anchor=self.justify, - command=lambda k=row: self._attach_key_press(k), **button_kwargs) - self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) - self.i+=1 - - self.hide = False - - def destroy_popup(self): - self.destroy() - self.disable = True - - def place_dropdown(self): - self.x_pos = self.attach.winfo_x() if self.x is None else self.x + self.attach.winfo_rootx() - self.y_pos = self.attach.winfo_y() + self.attach.winfo_reqheight() + 5 if self.y is None else self.y + self.attach.winfo_rooty() - self.width_new = self.attach.winfo_width()-45+self.corner if self.width is None else self.width - - if self.resize: - if self.button_num==1: - self.height_new = self.button_height * self.button_num + 45 - else: - self.height_new = self.button_height * self.button_num + 35 - if self.height_new>self.height: - self.height_new = self.height - - self.frame.configure(width=self.width_new, height=self.height_new) - self.place(x=self.x_pos, y=self.y_pos) - - if sys.platform.startswith("darwin"): - self.dummy_entry.pack() - self.after(100, self.dummy_entry.pack_forget()) - - self.lift() - self.attach.focus() - - def _iconify(self): - if self.disable: return - if self.hide: - self.hide = False - self.place_dropdown() - else: - self.place_forget() - self.hide = True - - def _attach_key_press(self, k): - self.fade = True - if self.command: - self.command(k) - self.fade = False - self.place_forget() - self.hide = True - - def live_update(self, string=None): - if not self.appear: return - if self.disable: return - if self.fade: return - if string: - self._deiconify() - i=1 - for key in self.widgets.keys(): - s = self.widgets[key].cget("text") - if not s.startswith(string): - self.widgets[key].pack_forget() - else: - self.widgets[key].pack(fill="x", pady=2, padx=(self.padding, 0)) - i+=1 - - if i==1: - self.no_match.pack(fill="x", pady=2, padx=(self.padding, 0)) - else: - self.no_match.pack_forget() - self.button_num = i - self.place_dropdown() - - else: - self.no_match.pack_forget() - self.button_num = len(self.values) - for key in self.widgets.keys(): - self.widgets[key].destroy() - self._init_buttons() - self.place_dropdown() - - self.frame._parent_canvas.yview_moveto(0.0) - self.appear = False - - def insert(self, value, **kwargs): - self.widgets[self.i] = customtkinter.CTkButton(self.frame, - text=value, - height=self.button_height, - fg_color=self.button_color, - text_color=self.text_color, - anchor=self.justify, - command=lambda k=value: self._attach_key_press(k), **kwargs) - self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) - self.i+=1 - self.values.append(value) - - def _deiconify(self): - if len(self.values)>0: - self.pack_forget() - - def popup(self, x=None, y=None): - self.x = x - self.y = y - self.hide = True - self._iconify() - - def configure(self, **kwargs): - if "height" in kwargs: - self.height = kwargs.pop("height") - self.height_new = self.height - - if "alpha" in kwargs: - self.alpha = kwargs.pop("alpha") - - if "width" in kwargs: - self.width = kwargs.pop("width") - - if "fg_color" in kwargs: - self.frame.configure(fg_color=kwargs.pop("fg_color")) - - if "values" in kwargs: - self.values = kwargs.pop("values") - self.image_values = None - for key in self.widgets.keys(): - self.widgets[key].destroy() - self._init_buttons() - - if "image_values" in kwargs: - self.image_values = kwargs.pop("image_values") - self.image_values = None if len(self.image_values)!=len(self.values) else self.image_values - if self.image_values is not None: - i=0 - for key in self.widgets.keys(): - self.widgets[key].configure(image=self.image_values[i]) - i+=1 - - if "button_color" in kwargs: - for key in self.widgets.keys(): - self.widgets[key].configure(fg_color=kwargs.pop("button_color")) - - for key in self.widgets.keys(): - self.widgets[key].configure(**kwargs) diff --git a/CTkScrollableDropdown/ctk_scrollable_dropdown.py b/ctk_scrollable_dropdown.py similarity index 98% rename from CTkScrollableDropdown/ctk_scrollable_dropdown.py rename to ctk_scrollable_dropdown.py index 1f32541d..8ab5296e 100644 --- a/CTkScrollableDropdown/ctk_scrollable_dropdown.py +++ b/ctk_scrollable_dropdown.py @@ -1,7 +1,13 @@ -''' +""" +CustomTkinter Scrollable Dropdown Menu +Author: Akash Bora +License: MIT +This is a custom dropdown menu for customtkinter. +Homepage: https://github.com/Akascape/CTkScrollableDropdown + Advanced Scrollable Dropdown class for customtkinter widgets Author: Akash Bora -''' +""" import customtkinter import sys @@ -16,7 +22,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): resize=True, frame_border_color=None, text_color=None, autocomplete=False, **button_kwargs): super().__init__(takefocus=1) - + self.transient(self.master) self.focus() self.alpha = alpha self.attach = attach @@ -93,7 +99,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.image_values = None if len(image_values)!=len(self.values) else image_values self.resizable(width=False, height=False) - self.transient(self.master) + # self.transient(self.master) self._init_buttons(**button_kwargs) # Add binding for different ctk widgets diff --git a/window_config.py b/window_config.py index 3f2af77c..17e5efdf 100644 --- a/window_config.py +++ b/window_config.py @@ -12,7 +12,7 @@ from audio_utils import get_input_device_list, get_output_device_list, get_defau from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder from languages import translation_lang, transcription_lang, selectable_languages -from CTkScrollableDropdown import CTkScrollableDropdown +from ctk_scrollable_dropdown import CTkScrollableDropdown class ToplevelWindowConfig(CTkToplevel): From ba8ab43901545c44776c300bf36277b32582c19e Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sat, 15 Jul 2023 04:07:12 +0900 Subject: [PATCH 30/54] =?UTF-8?q?config=E3=82=92=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=81=97=E3=81=9F=E6=99=82=E3=81=AB=E6=9C=80=E5=89=8D=E9=9D=A2?= =?UTF-8?q?=E3=81=AB=E6=9D=A5=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 6 ++++-- window_config.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/VRCT.py b/VRCT.py index 00a2fc99..7fb09bd1 100644 --- a/VRCT.py +++ b/VRCT.py @@ -328,7 +328,6 @@ class App(CTk): image=CTkImage(Image_open(os_path.join(os_path.dirname(__file__), "img", "config-icon-white.png"))) ) self.button_config.grid(row=5, column=1, padx=(5, 10), pady=(5, 5), sticky="wse") - self.config_window = None # load ui language data language_yaml_data = get_localized_text(f"{self.UI_LANGUAGE}") @@ -400,10 +399,13 @@ class App(CTk): self.config_window = ToplevelWindowConfig(self) def button_config_callback(self): - self.config_window.deiconify() self.checkbox_translation.configure(state="disabled") self.checkbox_transcription_send.configure(state="disabled") self.checkbox_transcription_receive.configure(state="disabled") + self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + + self.config_window.deiconify() + self.config_window.focus_set() self.config_window.focus() def button_information_callback(self): diff --git a/window_config.py b/window_config.py index 17e5efdf..9acb8e13 100644 --- a/window_config.py +++ b/window_config.py @@ -415,6 +415,7 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.checkbox_translation.configure(state="normal") self.parent.checkbox_transcription_send.configure(state="normal") self.parent.checkbox_transcription_receive.configure(state="normal") + self.parent.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) self.parent.config_window.withdraw() def entry_message_format_callback(self, event): From 931fe674a6eed24ea6922ccda940ff4c8ad0ea90 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sat, 15 Jul 2023 04:08:16 +0900 Subject: [PATCH 31/54] =?UTF-8?q?=E3=81=99=E3=81=B9=E3=81=A6=E3=81=AEoptio?= =?UTF-8?q?nmenu=E3=81=ABCTkScrollableDropdown=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SCROLLABLE_DROPDOWNで切り替え可 --- window_config.py | 256 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 239 insertions(+), 17 deletions(-) diff --git a/window_config.py b/window_config.py index 9acb8e13..c300ce1f 100644 --- a/window_config.py +++ b/window_config.py @@ -14,10 +14,13 @@ from languages import translation_lang, transcription_lang, selectable_languages from ctk_scrollable_dropdown import CTkScrollableDropdown +SCROLLABLE_DROPDOWN = True + class ToplevelWindowConfig(CTkToplevel): def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) + self.withdraw() self.parent = parent # self.geometry(f"{350}x{270}") @@ -51,19 +54,22 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.TRANSPARENCY = value save_json(self.parent.PATH_CONFIG, "TRANSPARENCY", self.parent.TRANSPARENCY) - def optionmenu_theme_callback(self, choice): + def optionmenu_appearance_theme_callback(self, choice): + self.optionmenu_appearance_theme.set(choice) + customtkinter.set_appearance_mode(choice) self.parent.APPEARANCE_THEME = choice save_json(self.parent.PATH_CONFIG, "APPEARANCE_THEME", self.parent.APPEARANCE_THEME) def optionmenu_ui_scaling_callback(self, choice): + self.optionmenu_ui_scaling.set(choice) + new_scaling_float = int(choice.replace("%", "")) / 100 customtkinter.set_widget_scaling(new_scaling_float) self.parent.UI_SCALING = choice save_json(self.parent.PATH_CONFIG, "UI_SCALING", self.parent.UI_SCALING) def optionmenu_font_family_callback(self, choice): - # set choice font self.optionmenu_font_family.set(choice) # tab menu @@ -174,6 +180,8 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "FONT_FAMILY", self.parent.FONT_FAMILY) def optionmenu_ui_language_callback(self, choice): + self.optionmenu_ui_language.set(choice) + self.withdraw() pre_language_yaml_data = get_localized_text(f"{self.parent.UI_LANGUAGE}") self.parent.UI_LANGUAGE = get_key_by_value(selectable_languages, choice) @@ -187,7 +195,7 @@ class ToplevelWindowConfig(CTkToplevel): # add tabview textbox self.parent.add_tabview_logs(language_yaml_data) self.add_tabview_config(language_yaml_data, selectable_languages) - + # 翻訳予定 # window information # try: @@ -197,6 +205,8 @@ class ToplevelWindowConfig(CTkToplevel): self.deiconify() def optionmenu_translation_translator_callback(self, choice): + self.optionmenu_translation_translator.set(choice) + if self.parent.translator.authentication(choice, self.parent.AUTH_KEYS[choice]) is False: print_textbox(self.parent.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.parent.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") @@ -226,33 +236,47 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) def optionmenu_translation_input_source_language_callback(self, choice): + self.optionmenu_translation_input_source_language.set(choice) + self.parent.INPUT_SOURCE_LANG = choice save_json(self.parent.PATH_CONFIG, "INPUT_SOURCE_LANG", self.parent.INPUT_SOURCE_LANG) def optionmenu_translation_input_target_language_callback(self, choice): + self.optionmenu_translation_input_target_language.set(choice) + self.parent.INPUT_TARGET_LANG = choice save_json(self.parent.PATH_CONFIG, "INPUT_TARGET_LANG", self.parent.INPUT_TARGET_LANG) def optionmenu_translation_output_source_language_callback(self, choice): + self.optionmenu_translation_output_source_language.set(choice) + self.parent.OUTPUT_SOURCE_LANG = choice save_json(self.parent.PATH_CONFIG, "OUTPUT_SOURCE_LANG", self.parent.OUTPUT_SOURCE_LANG) def optionmenu_translation_output_target_language_callback(self, choice): + self.optionmenu_translation_output_target_language.set(choice) + self.parent.OUTPUT_TARGET_LANG = choice save_json(self.parent.PATH_CONFIG, "OUTPUT_TARGET_LANG", self.parent.OUTPUT_TARGET_LANG) def optionmenu_input_mic_host_callback(self, choice): + self.optionmenu_input_mic_host.set(choice) + self.parent.CHOICE_MIC_HOST = choice save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_HOST", self.parent.CHOICE_MIC_HOST) self.optionmenu_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]]) def optionmenu_input_mic_device_callback(self, choice): + self.optionmenu_input_mic_device.set(choice) + self.parent.CHOICE_MIC_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) self.checkbox_input_mic_threshold_check.deselect() self.checkbox_input_mic_threshold_check_callback() def optionmenu_input_mic_voice_language_callback(self, choice): + self.optionmenu_input_mic_voice_language.set(choice) + self.parent.INPUT_MIC_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_MIC_VOICE_LANGUAGE", self.parent.INPUT_MIC_VOICE_LANGUAGE) @@ -312,6 +336,7 @@ class ToplevelWindowConfig(CTkToplevel): def optionmenu_input_speaker_device_callback(self, choice): speaker_device = [device for device in get_output_device_list() if device["name"] == choice][0] if get_default_output_device()["index"] == speaker_device["index"]: + self.optionmenu_input_speaker_device.set(choice) self.parent.CHOICE_SPEAKER_DEVICE = choice save_json(self.parent.PATH_CONFIG, "CHOICE_SPEAKER_DEVICE", self.parent.CHOICE_SPEAKER_DEVICE) else: @@ -320,6 +345,8 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_speaker_device.configure(variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE)) def optionmenu_input_speaker_voice_language_callback(self, choice): + self.optionmenu_input_speaker_voice_language.set(choice) + self.parent.INPUT_SPEAKER_VOICE_LANGUAGE = choice save_json(self.parent.PATH_CONFIG, "INPUT_SPEAKER_VOICE_LANGUAGE", self.parent.INPUT_SPEAKER_VOICE_LANGUAGE) @@ -489,13 +516,28 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_appearance_theme = CTkOptionMenu( self.tabview_config.tab(config_tab_title_ui), values=["Light", "Dark", "System"], - command=self.optionmenu_theme_callback, + command=self.optionmenu_appearance_theme_callback, variable=StringVar(value=self.parent.APPEARANCE_THEME), font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_appearance_theme.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_appearance_theme._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown appearance theme + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_appearance_theme = CTkScrollableDropdown( + self.optionmenu_appearance_theme, + values=["Light", "Dark", "System"], + justify="left", + button_color="transparent", + command=self.optionmenu_appearance_theme_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_appearance_theme.frame.bind( + "", + lambda e: self.scrollableDropdown_appearance_theme._iconify(), + ) + ## optionmenu UI scaling row += 1 self.label_ui_scaling = CTkLabel( @@ -515,6 +557,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_ui_scaling.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_ui_scaling._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown ui scaling + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_ui_scaling = CTkScrollableDropdown( + self.optionmenu_ui_scaling, + values=["80%", "90%", "100%", "110%", "120%"], + justify="left", + button_color="transparent", + command=self.optionmenu_ui_scaling_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_ui_scaling.frame.bind( + "", + lambda e: self.scrollableDropdown_ui_scaling._iconify(), + ) + ## optionmenu font family row += 1 self.label_font_family = CTkLabel( @@ -533,19 +590,19 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") ## scrollableDropdown font family - self.scrollableDropdown_font_family = CTkScrollableDropdown( - self.optionmenu_font_family, - values=font_families, - justify="left", - button_color="transparent", - command=self.optionmenu_font_family_callback, - font=CTkFont(family=self.parent.FONT_FAMILY), - ) - self.scrollableDropdown_font_family.bind( - "", - lambda e: self.scrollableDropdown_font_family._withdraw() if not str(e.widget).startswith(".!ctkscrollabledropdown.") else None, - add="+" - ) + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_font_family = CTkScrollableDropdown( + self.optionmenu_font_family, + values=font_families, + justify="left", + button_color="transparent", + command=self.optionmenu_font_family_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_font_family.frame.bind( + "", + lambda e: self.scrollableDropdown_font_family._iconify(), + ) ## optionmenu ui language row += 1 @@ -567,6 +624,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_ui_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_ui_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown ui language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_ui_language = CTkScrollableDropdown( + self.optionmenu_ui_language, + values=selectable_languages_values, + justify="left", + button_color="transparent", + command=self.optionmenu_ui_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_ui_language.frame.bind( + "", + lambda e: self.scrollableDropdown_ui_language._iconify(), + ) + # tab Translation ## optionmenu translation translator row = 0 @@ -589,6 +661,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3, padx=padx, pady=pady, sticky="nsew") self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown translation translator + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_translation_translator = CTkScrollableDropdown( + self.optionmenu_translation_translator, + values=list(self.parent.translator.translator_status.keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_translation_translator_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_translation_translator.frame.bind( + "", + lambda e: self.scrollableDropdown_translation_translator._iconify(), + ) + ## optionmenu translation input language row +=1 self.label_translation_input_language = CTkLabel( @@ -610,6 +697,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_input_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown translation input source language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_translation_input_source_language = CTkScrollableDropdown( + self.optionmenu_translation_input_source_language, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_translation_input_source_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_translation_input_source_language.frame.bind( + "", + lambda e: self.scrollableDropdown_translation_input_source_language._iconify(), + ) + ## label translation input arrow self.label_translation_input_arrow = CTkLabel( self.tabview_config.tab(config_tab_title_translation), @@ -630,6 +732,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_input_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown translation input target language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_translation_input_target_language = CTkScrollableDropdown( + self.optionmenu_translation_input_target_language, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_translation_input_target_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_translation_input_target_language.frame.bind( + "", + lambda e: self.scrollableDropdown_translation_input_target_language._iconify(), + ) + ## optionmenu translation output language row +=1 self.label_translation_output_language = CTkLabel( @@ -651,6 +768,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_output_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown translation output source language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_translation_output_source_language = CTkScrollableDropdown( + self.optionmenu_translation_output_source_language, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_translation_output_source_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_translation_output_source_language.frame.bind( + "", + lambda e: self.scrollableDropdown_translation_output_source_language._iconify(), + ) + ## label translation output arrow self.label_translation_output_arrow = CTkLabel( self.tabview_config.tab(config_tab_title_translation), @@ -671,6 +803,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_translation_output_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown translation output target language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_translation_output_target_language = CTkScrollableDropdown( + self.optionmenu_translation_output_target_language, + values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_translation_output_target_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_translation_output_target_language.frame.bind( + "", + lambda e: self.scrollableDropdown_translation_output_target_language._iconify(), + ) + # tab Transcription ## optionmenu input mic device's host row = 0 @@ -693,6 +840,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown input mic device's host + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_input_mic_host = CTkScrollableDropdown( + self.optionmenu_input_mic_host, + values=[host for host in get_input_device_list().keys()], + justify="left", + button_color="transparent", + command=self.optionmenu_input_mic_host_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_input_mic_host.frame.bind( + "", + lambda e: self.scrollableDropdown_input_mic_host._iconify(), + ) + ## optionmenu input mic device row += 1 self.label_input_mic_device = CTkLabel( @@ -712,6 +874,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown input mic device + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_input_mic_device = CTkScrollableDropdown( + self.optionmenu_input_mic_device, + values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]], + justify="left", + button_color="transparent", + command=self.optionmenu_input_mic_device_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_input_mic_device.frame.bind( + "", + lambda e: self.scrollableDropdown_input_mic_device._iconify(), + ) + ## optionmenu input mic voice language row +=1 self.label_input_mic_voice_language = CTkLabel( @@ -731,6 +908,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown input mic voice language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_input_voice_language = CTkScrollableDropdown( + self.optionmenu_input_mic_voice_language, + values=list(transcription_lang.keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_input_mic_voice_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_input_voice_language.frame.bind( + "", + lambda e: self.scrollableDropdown_input_voice_language._iconify(), + ) + ## slider input mic energy threshold row +=1 self.label_input_mic_energy_threshold = CTkLabel( @@ -883,6 +1075,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown input speaker device + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_input_speaker_device = CTkScrollableDropdown( + self.optionmenu_input_speaker_device, + values=[device["name"] for device in get_output_device_list()], + justify="left", + button_color="transparent", + command=self.optionmenu_input_speaker_device_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_input_speaker_device.frame.bind( + "", + lambda e: self.scrollableDropdown_input_speaker_device._iconify(), + ) + ## optionmenu input speaker voice language row +=1 self.label_input_speaker_voice_language = CTkLabel( @@ -902,6 +1109,21 @@ class ToplevelWindowConfig(CTkToplevel): self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) + ## scrollableDropdown input speaker voice language + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_input_speaker_voice_language = CTkScrollableDropdown( + self.optionmenu_input_speaker_voice_language, + values=list(transcription_lang.keys()), + justify="left", + button_color="transparent", + command=self.optionmenu_input_speaker_voice_language_callback, + font=CTkFont(family=self.parent.FONT_FAMILY), + ) + self.scrollableDropdown_input_speaker_voice_language.frame.bind( + "", + lambda e: self.scrollableDropdown_input_speaker_voice_language._iconify(), + ) + ## entry input speaker energy threshold row +=1 self.label_input_speaker_energy_threshold = CTkLabel( From 631fb1e6fb31a25bc8f34c83beece9d1ac2be37f Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sat, 15 Jul 2023 09:42:06 +0900 Subject: [PATCH 32/54] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AD=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E3=83=90=E3=83=BC=E3=81=AE=E6=B6=88=E3=81=88=E3=82=8B?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=9F=E3=83=B3=E3=82=B0=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ctk_scrollable_dropdown.py | 90 +++++++++++++++++++------------------- window_config.py | 56 ++++++++++++------------ 2 files changed, 72 insertions(+), 74 deletions(-) diff --git a/ctk_scrollable_dropdown.py b/ctk_scrollable_dropdown.py index 8ab5296e..091e92e3 100644 --- a/ctk_scrollable_dropdown.py +++ b/ctk_scrollable_dropdown.py @@ -8,29 +8,27 @@ Homepage: https://github.com/Akascape/CTkScrollableDropdown Advanced Scrollable Dropdown class for customtkinter widgets Author: Akash Bora """ - import customtkinter import sys import time class CTkScrollableDropdown(customtkinter.CTkToplevel): - + def __init__(self, attach, x=None, y=None, button_color=None, height: int = 200, width: int = None, fg_color=None, button_height: int = 20, justify="center", scrollbar_button_color=None, scrollbar=True, scrollbar_button_hover_color=None, frame_border_width=2, values=[], command=None, image_values=[], alpha: float = 0.97, frame_corner_radius=20, double_click=False, resize=True, frame_border_color=None, text_color=None, autocomplete=False, **button_kwargs): - + super().__init__(takefocus=1) self.transient(self.master) - self.focus() self.alpha = alpha self.attach = attach self.corner = frame_corner_radius self.padding = 0 self.focus_something = False self.disable = True - + if sys.platform.startswith("win"): self.after(100, lambda: self.overrideredirect(True)) self.transparent_color = self._apply_appearance_mode(self._fg_color) @@ -53,7 +51,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") self.attach.winfo_toplevel().bind("", lambda e: self._withdraw() if not self.disable else None, add="+") - + self.attributes('-alpha', 0) self.disable = False self.fg_color = customtkinter.ThemeManager.theme["CTkFrame"]["fg_color"] if fg_color is None else fg_color @@ -62,11 +60,11 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.frame_border_color = customtkinter.ThemeManager.theme["CTkFrame"]["border_color"] if frame_border_color is None else frame_border_color self.button_color = customtkinter.ThemeManager.theme["CTkFrame"]["top_fg_color"] if button_color is None else button_color self.text_color = customtkinter.ThemeManager.theme["CTkLabel"]["text_color"] if text_color is None else text_color - + if scrollbar is False: self.scroll_button_color = self.fg_color self.scroll_hover_color = self.fg_color - + self.frame = customtkinter.CTkScrollableFrame(self, bg_color=self.transparent_color, fg_color=self.fg_color, scrollbar_button_hover_color=self.scroll_hover_color, corner_radius=self.corner, border_width=frame_border_width, @@ -74,6 +72,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): border_color=self.frame_border_color) self.frame._scrollbar.grid_configure(padx=3) self.frame.pack(expand=True, fill="both") + self.dummy_entry = customtkinter.CTkEntry(self.frame, fg_color="transparent", border_width=0, height=1, width=1) self.no_match = customtkinter.CTkLabel(self.frame, text="No Match") self.height = height @@ -85,21 +84,20 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.autocomplete = autocomplete self.var_update = customtkinter.StringVar() self.appear = False - + if justify.lower()=="left": self.justify = "w" elif justify.lower()=="right": self.justify = "e" else: self.justify = "c" - + self.button_height = button_height self.values = values self.button_num = len(self.values) self.image_values = None if len(image_values)!=len(self.values) else image_values - + self.resizable(width=False, height=False) - # self.transient(self.master) self._init_buttons(**button_kwargs) # Add binding for different ctk widgets @@ -113,47 +111,47 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.attach._canvas.tag_bind("dropdown_arrow", "", lambda e: self._iconify()) if self.command is None: self.command = self.attach.set - + if self.attach.winfo_name().startswith("!ctkoptionmenu"): self.attach._canvas.bind("", lambda e: self._iconify()) self.attach._text_label.bind("", lambda e: self._iconify()) if self.command is None: self.command = self.attach.set - + self.update_idletasks() self.x = x self.y = y if self.autocomplete: self.bind_autocomplete() - + self.deiconify() self.withdraw() - + self.attributes("-alpha", self.alpha) - + def _withdraw(self): if self.hide is False: self.withdraw() self.hide = True def _update(self, a, b, c): self.live_update(self.attach._entry.get()) - + def bind_autocomplete(self, ): def appear(x): self.appear = True - + if self.attach.winfo_name().startswith("!ctkcombobox"): self.attach._entry.configure(textvariable=self.var_update) self.attach._entry.bind("", appear) self.attach.set(self.values[0]) self.var_update.trace_add('write', self._update) - + if self.attach.winfo_name().startswith("!ctkentry"): self.attach.configure(textvariable=self.var_update) self.attach.bind("", appear) self.var_update.trace_add('write', self._update) - + def fade_out(self): for i in range(100,0,-10): if not self.winfo_exists(): @@ -161,7 +159,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.attributes("-alpha", i/100) self.update() time.sleep(1/100) - + def fade_in(self): for i in range(0,100,10): if not self.winfo_exists(): @@ -169,7 +167,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.attributes("-alpha", i/100) self.update() time.sleep(1/100) - + def _init_buttons(self, **button_kwargs): self.i = 0 self.widgets = {} @@ -184,9 +182,9 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): command=lambda k=row: self._attach_key_press(k), **button_kwargs) self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) self.i+=1 - + self.hide = False - + def destroy_popup(self): self.destroy() self.disable = True @@ -195,9 +193,9 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.x_pos = self.attach.winfo_rootx() if self.x is None else self.x + self.attach.winfo_rootx() self.y_pos = self.attach.winfo_rooty() + self.attach.winfo_reqheight() + 5 if self.y is None else self.y + self.attach.winfo_rooty() self.width_new = self.attach.winfo_width() if self.width is None else self.width - + if self.resize: - if self.button_num==1: + if self.button_num==1: self.height_new = self.button_height * self.button_num + 45 else: self.height_new = self.button_height * self.button_num + 35 @@ -208,23 +206,23 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.x_pos, self.y_pos)) self.fade_in() self.attributes('-alpha', self.alpha) - self.attach.focus() def _iconify(self): if self.disable: return if self.hide: - self._deiconify() - self.focus() - self.hide = False + self._deiconify() self.place_dropdown() if self.focus_something: self.dummy_entry.pack() self.dummy_entry.focus_set() self.after(100, self.dummy_entry.pack_forget) + self.hide = False + self.focus_set() + self.focus() else: self.withdraw() self.hide = True - + def _attach_key_press(self, k): self.fade = True if self.command: @@ -233,7 +231,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.fade_out() self.withdraw() self.hide = True - + def live_update(self, string=None): if not self.appear: return if self.disable: return @@ -248,14 +246,14 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): else: self.widgets[key].pack(fill="x", pady=2, padx=(self.padding, 0)) i+=1 - + if i==1: self.no_match.pack(fill="x", pady=2, padx=(self.padding, 0)) else: self.no_match.pack_forget() self.button_num = i self.place_dropdown() - + else: self.no_match.pack_forget() self.button_num = len(self.values) @@ -263,10 +261,10 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.widgets[key].destroy() self._init_buttons() self.place_dropdown() - + self.frame._parent_canvas.yview_moveto(0.0) self.appear = False - + def insert(self, value, **kwargs): self.widgets[self.i] = customtkinter.CTkButton(self.frame, text=value, @@ -278,7 +276,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.widgets[self.i].pack(fill="x", pady=2, padx=(self.padding, 0)) self.i+=1 self.values.append(value) - + def _deiconify(self): if len(self.values)>0: self.deiconify() @@ -288,28 +286,28 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): self.y = y self.hide = True self._iconify() - + def configure(self, **kwargs): if "height" in kwargs: self.height = kwargs.pop("height") self.height_new = self.height - + if "alpha" in kwargs: self.alpha = kwargs.pop("alpha") - + if "width" in kwargs: self.width = kwargs.pop("width") - + if "fg_color" in kwargs: self.frame.configure(fg_color=kwargs.pop("fg_color")) - + if "values" in kwargs: self.values = kwargs.pop("values") self.image_values = None for key in self.widgets.keys(): self.widgets[key].destroy() self._init_buttons() - + if "image_values" in kwargs: self.image_values = kwargs.pop("image_values") self.image_values = None if len(self.image_values)!=len(self.values) else self.image_values @@ -318,10 +316,10 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): for key in self.widgets.keys(): self.widgets[key].configure(image=self.image_values[i]) i+=1 - + if "button_color" in kwargs: for key in self.widgets.keys(): self.widgets[key].configure(fg_color=kwargs.pop("button_color")) - + for key in self.widgets.keys(): self.widgets[key].configure(**kwargs) diff --git a/window_config.py b/window_config.py index c300ce1f..c6087fbd 100644 --- a/window_config.py +++ b/window_config.py @@ -533,9 +533,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_appearance_theme_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_appearance_theme.frame.bind( + self.scrollableDropdown_appearance_theme.bind( "", - lambda e: self.scrollableDropdown_appearance_theme._iconify(), + lambda e: self.scrollableDropdown_appearance_theme._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_appearance_theme.frame._parent_frame)) else None, ) ## optionmenu UI scaling @@ -567,9 +567,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_ui_scaling_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_ui_scaling.frame.bind( + self.scrollableDropdown_ui_scaling.bind( "", - lambda e: self.scrollableDropdown_ui_scaling._iconify(), + lambda e: self.scrollableDropdown_ui_scaling._iconify() if not str(e.widget).startswith(str(self.scrollableDropdown_ui_scaling.frame._parent_frame)) else None, ) ## optionmenu font family @@ -599,9 +599,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_font_family_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_font_family.frame.bind( + self.scrollableDropdown_font_family.bind( "", - lambda e: self.scrollableDropdown_font_family._iconify(), + lambda e: self.scrollableDropdown_font_family._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_font_family.frame._parent_frame)) else None, ) ## optionmenu ui language @@ -634,9 +634,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_ui_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_ui_language.frame.bind( + self.scrollableDropdown_ui_language.bind( "", - lambda e: self.scrollableDropdown_ui_language._iconify(), + lambda e: self.scrollableDropdown_ui_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_ui_language.frame._parent_frame)) else None, ) # tab Translation @@ -671,9 +671,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_translation_translator_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_translation_translator.frame.bind( + self.scrollableDropdown_translation_translator.bind( "", - lambda e: self.scrollableDropdown_translation_translator._iconify(), + lambda e: self.scrollableDropdown_translation_translator._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_translation_translator.frame._parent_frame)) else None, ) ## optionmenu translation input language @@ -707,9 +707,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_translation_input_source_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_translation_input_source_language.frame.bind( + self.scrollableDropdown_translation_input_source_language.bind( "", - lambda e: self.scrollableDropdown_translation_input_source_language._iconify(), + lambda e: self.scrollableDropdown_translation_input_source_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_translation_input_source_language.frame._parent_frame)) else None, ) ## label translation input arrow @@ -742,9 +742,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_translation_input_target_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_translation_input_target_language.frame.bind( + self.scrollableDropdown_translation_input_target_language.bind( "", - lambda e: self.scrollableDropdown_translation_input_target_language._iconify(), + lambda e: self.scrollableDropdown_translation_input_target_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_translation_input_target_language.frame._parent_frame)) else None, ) ## optionmenu translation output language @@ -778,9 +778,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_translation_output_source_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_translation_output_source_language.frame.bind( + self.scrollableDropdown_translation_output_source_language.bind( "", - lambda e: self.scrollableDropdown_translation_output_source_language._iconify(), + lambda e: self.scrollableDropdown_translation_output_source_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_translation_output_source_language.frame._parent_frame)) else None, ) ## label translation output arrow @@ -813,9 +813,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_translation_output_target_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_translation_output_target_language.frame.bind( + self.scrollableDropdown_translation_output_target_language.bind( "", - lambda e: self.scrollableDropdown_translation_output_target_language._iconify(), + lambda e: self.scrollableDropdown_translation_output_target_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_translation_output_target_language.frame._parent_frame)) else None, ) # tab Transcription @@ -850,9 +850,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_mic_host_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_input_mic_host.frame.bind( + self.scrollableDropdown_input_mic_host.bind( "", - lambda e: self.scrollableDropdown_input_mic_host._iconify(), + lambda e: self.scrollableDropdown_input_mic_host._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_input_mic_host.frame._parent_frame)) else None, ) ## optionmenu input mic device @@ -884,9 +884,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_mic_device_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_input_mic_device.frame.bind( + self.scrollableDropdown_input_mic_device.bind( "", - lambda e: self.scrollableDropdown_input_mic_device._iconify(), + lambda e: self.scrollableDropdown_input_mic_device._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_input_mic_device.frame._parent_frame)) else None, ) ## optionmenu input mic voice language @@ -918,9 +918,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_mic_voice_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_input_voice_language.frame.bind( + self.scrollableDropdown_input_voice_language.bind( "", - lambda e: self.scrollableDropdown_input_voice_language._iconify(), + lambda e: self.scrollableDropdown_input_voice_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_input_voice_language.frame._parent_frame)) else None, ) ## slider input mic energy threshold @@ -1085,9 +1085,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_speaker_device_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_input_speaker_device.frame.bind( + self.scrollableDropdown_input_speaker_device.bind( "", - lambda e: self.scrollableDropdown_input_speaker_device._iconify(), + lambda e: self.scrollableDropdown_input_speaker_device._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_input_speaker_device.frame._parent_frame)) else None, ) ## optionmenu input speaker voice language @@ -1119,9 +1119,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_speaker_voice_language_callback, font=CTkFont(family=self.parent.FONT_FAMILY), ) - self.scrollableDropdown_input_speaker_voice_language.frame.bind( + self.scrollableDropdown_input_speaker_voice_language.bind( "", - lambda e: self.scrollableDropdown_input_speaker_voice_language._iconify(), + lambda e: self.scrollableDropdown_input_speaker_voice_language._withdraw() if not str(e.widget).startswith(str(self.scrollableDropdown_input_speaker_voice_language.frame._parent_frame)) else None, ) ## entry input speaker energy threshold From 101f2361236bf46e5af38fa7d60771fae2c034e8 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Sat, 15 Jul 2023 16:45:09 +0900 Subject: [PATCH 33/54] =?UTF-8?q?[bugfix]=E8=B5=B7=E5=8B=95=E6=99=82?= =?UTF-8?q?=E3=81=AB=E7=9E=AC=E9=96=93=E7=9A=84=E3=81=AB=E9=96=8B=E3=81=84?= =?UTF-8?q?=E3=81=A6=E9=96=89=E3=81=98=E3=81=A6=E3=81=8C=E8=A1=8C=E3=82=8F?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=83=95=E3=82=A9=E3=83=BC=E3=82=AB=E3=82=B9?= =?UTF-8?q?=E3=81=8C=E3=83=81=E3=82=AB=E3=83=81=E3=82=AB=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=83=90=E3=82=B0=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ctk_scrollable_dropdown.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctk_scrollable_dropdown.py b/ctk_scrollable_dropdown.py index 091e92e3..81b98205 100644 --- a/ctk_scrollable_dropdown.py +++ b/ctk_scrollable_dropdown.py @@ -125,7 +125,7 @@ class CTkScrollableDropdown(customtkinter.CTkToplevel): if self.autocomplete: self.bind_autocomplete() - self.deiconify() + # self.deiconify() self.withdraw() self.attributes("-alpha", self.alpha) From 08b5496f6d763d96616fac9d725c256f522171fa Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 18 Jul 2023 06:59:11 +0900 Subject: [PATCH 34/54] =?UTF-8?q?[bugfix]=20=E5=8D=8A=E8=A7=92=E5=85=A5?= =?UTF-8?q?=E5=8A=9B=E6=99=82=E3=81=ABkeysym=E3=81=8C=E5=AE=9F=E8=A1=8C?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=A6=E6=AD=A3=E3=81=97=E3=81=8F=E6=96=87?= =?UTF-8?q?=E5=AD=97=E3=81=8C=E8=A1=A8=E7=A4=BA=E3=81=95=E3=82=8C=E3=81=AA?= =?UTF-8?q?=E3=81=84=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 https://minekoa.hatenadiary.org/entry/20090315/1237125640 https://stackoverflow.com/questions/18568988/tkinter-prevent-deletion-of-selected-text-with-return-key https://anzeljg.github.io/rin2/book2/2405/docs/tkinter/key-names.html --- VRCT.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/VRCT.py b/VRCT.py index 9915b82c..6b344587 100644 --- a/VRCT.py +++ b/VRCT.py @@ -339,7 +339,7 @@ class App(CTk): self.entry_message_box = CTkEntry( self, placeholder_text="message", - font=CTkFont(family=self.FONT_FAMILY) + font=CTkFont(family=self.FONT_FAMILY), ) self.entry_message_box.grid(row=1, column=1, columnspan=2, padx=5, pady=(5, 10), sticky="nsew") @@ -614,12 +614,21 @@ class App(CTk): if self.ENABLE_AUTO_CLEAR_CHATBOX == True: self.entry_message_box.delete(0, customtkinter.END) + BREAK_KEYSYM_LIST = [ + "Delete", "Select", "Up", "Down", "Next", "End", "Print", + "Prior","Insert","Home", "Left", "Clear", "Right", "Linefeed" + ] def entry_message_box_press_key_any(self, event): # send OSC typing send_typing(True, self.OSC_IP_ADDRESS, self.OSC_PORT) if self.ENABLE_FOREGROUND: self.attributes("-topmost", False) + if event.keysym != "??": + if len(event.char) != 0 and event.keysym in self.BREAK_KEYSYM_LIST: + self.entry_message_box.insert("end", event.char) + return "break" + def entry_message_box_leave(self, event): # send OSC typing send_typing(False, self.OSC_IP_ADDRESS, self.OSC_PORT) From 9ebb452c3d2aa6ece04054bad89f9bb0ae305f6c Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 18 Jul 2023 07:09:34 +0900 Subject: [PATCH 35/54] =?UTF-8?q?[bugfix]=20=E7=92=B0=E5=A2=83=E3=81=AB?= =?UTF-8?q?=E4=BE=9D=E3=81=A3=E3=81=A6=E3=83=9E=E3=82=A4=E3=82=AF=E3=81=A8?= =?UTF-8?q?=E3=82=B9=E3=83=94=E3=83=BC=E3=82=AB=E3=83=BC=E3=82=92=E5=90=8C?= =?UTF-8?q?=E6=99=82=E8=B5=B7=E5=8B=95=E3=81=99=E3=82=8B=E3=81=A8=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=8C=E7=99=BA=E7=94=9F=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=80=81=E8=B5=B7=E5=8B=95=E6=99=82=E3=81=AF?= =?UTF-8?q?=E5=BC=B7=E5=88=B6=E7=9A=84=E3=81=ABOFF=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/VRCT.py b/VRCT.py index 6b344587..94bbbcec 100644 --- a/VRCT.py +++ b/VRCT.py @@ -85,12 +85,15 @@ class App(CTk): if "ENABLE_TRANSLATION" in config.keys(): if type(config["ENABLE_TRANSLATION"]) is bool: self.ENABLE_TRANSLATION = config["ENABLE_TRANSLATION"] - if "ENABLE_TRANSCRIPTION_SEND" in config.keys(): - if type(config["ENABLE_TRANSCRIPTION_SEND"]) is bool: - self.ENABLE_TRANSCRIPTION_SEND = config["ENABLE_TRANSCRIPTION_SEND"] - if "ENABLE_TRANSCRIPTION_RECEIVE" in config.keys(): - if type(config["ENABLE_TRANSCRIPTION_RECEIVE"]) is bool: - self.ENABLE_TRANSCRIPTION_RECEIVE = config["ENABLE_TRANSCRIPTION_RECEIVE"] + + # 環境に依ってマイクとスピーカーを同時起動するとエラーが発生するため、起動時は強制的にOFFにする + # if "ENABLE_TRANSCRIPTION_SEND" in config.keys(): + # if type(config["ENABLE_TRANSCRIPTION_SEND"]) is bool: + # self.ENABLE_TRANSCRIPTION_SEND = config["ENABLE_TRANSCRIPTION_SEND"] + # if "ENABLE_TRANSCRIPTION_RECEIVE" in config.keys(): + # if type(config["ENABLE_TRANSCRIPTION_RECEIVE"]) is bool: + # self.ENABLE_TRANSCRIPTION_RECEIVE = config["ENABLE_TRANSCRIPTION_RECEIVE"] + if "ENABLE_FOREGROUND" in config.keys(): if type(config["ENABLE_FOREGROUND"]) is bool: self.ENABLE_FOREGROUND = config["ENABLE_FOREGROUND"] @@ -208,8 +211,8 @@ class App(CTk): with open(self.PATH_CONFIG, 'w') as fp: config = { "ENABLE_TRANSLATION": self.ENABLE_TRANSLATION, - "ENABLE_TRANSCRIPTION_SEND": self.ENABLE_TRANSCRIPTION_SEND, - "ENABLE_TRANSCRIPTION_RECEIVE": self.ENABLE_TRANSCRIPTION_RECEIVE, + # "ENABLE_TRANSCRIPTION_SEND": self.ENABLE_TRANSCRIPTION_SEND, + # "ENABLE_TRANSCRIPTION_RECEIVE": self.ENABLE_TRANSCRIPTION_RECEIVE, "ENABLE_FOREGROUND": self.ENABLE_FOREGROUND, "TRANSPARENCY": self.TRANSPARENCY, "APPEARANCE_THEME": self.APPEARANCE_THEME, @@ -357,19 +360,19 @@ class App(CTk): else: self.checkbox_translation.deselect() - ## set checkbox enable transcription send - if self.ENABLE_TRANSCRIPTION_SEND: - self.checkbox_transcription_send.select() - self.checkbox_transcription_send_callback() - else: - self.checkbox_transcription_send.deselect() + # ## set checkbox enable transcription send + # if self.ENABLE_TRANSCRIPTION_SEND: + # self.checkbox_transcription_send.select() + # self.checkbox_transcription_send_callback() + # else: + # self.checkbox_transcription_send.deselect() - ## set checkbox enable transcription receive - if self.ENABLE_TRANSCRIPTION_RECEIVE: - self.checkbox_transcription_receive.select() - self.checkbox_transcription_receive_callback() - else: - self.checkbox_transcription_receive.deselect() + # ## set checkbox enable transcription receive + # if self.ENABLE_TRANSCRIPTION_RECEIVE: + # self.checkbox_transcription_receive.select() + # self.checkbox_transcription_receive_callback() + # else: + # self.checkbox_transcription_receive.deselect() ## set set checkbox enable foreground if self.ENABLE_FOREGROUND: From c6ac2eff81e5397d8d4326cf40d3b4e09a285827 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Tue, 18 Jul 2023 23:49:55 +0900 Subject: [PATCH 36/54] =?UTF-8?q?[update]=20main=20window=E3=81=AEcheckbox?= =?UTF-8?q?=E3=82=92=E3=81=99=E3=81=B9=E3=81=A6OFF=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VRCT.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/VRCT.py b/VRCT.py index 94bbbcec..eb4bcaee 100644 --- a/VRCT.py +++ b/VRCT.py @@ -82,9 +82,10 @@ class App(CTk): with open(self.PATH_CONFIG, 'r') as fp: config = json_load(fp) # main window - if "ENABLE_TRANSLATION" in config.keys(): - if type(config["ENABLE_TRANSLATION"]) is bool: - self.ENABLE_TRANSLATION = config["ENABLE_TRANSLATION"] + # main windowは初期はすべてOFFにする + # if "ENABLE_TRANSLATION" in config.keys(): + # if type(config["ENABLE_TRANSLATION"]) is bool: + # self.ENABLE_TRANSLATION = config["ENABLE_TRANSLATION"] # 環境に依ってマイクとスピーカーを同時起動するとエラーが発生するため、起動時は強制的にOFFにする # if "ENABLE_TRANSCRIPTION_SEND" in config.keys(): @@ -94,9 +95,9 @@ class App(CTk): # if type(config["ENABLE_TRANSCRIPTION_RECEIVE"]) is bool: # self.ENABLE_TRANSCRIPTION_RECEIVE = config["ENABLE_TRANSCRIPTION_RECEIVE"] - if "ENABLE_FOREGROUND" in config.keys(): - if type(config["ENABLE_FOREGROUND"]) is bool: - self.ENABLE_FOREGROUND = config["ENABLE_FOREGROUND"] + # if "ENABLE_FOREGROUND" in config.keys(): + # if type(config["ENABLE_FOREGROUND"]) is bool: + # self.ENABLE_FOREGROUND = config["ENABLE_FOREGROUND"] # tab ui if "TRANSPARENCY" in config.keys(): @@ -210,10 +211,10 @@ class App(CTk): with open(self.PATH_CONFIG, 'w') as fp: config = { - "ENABLE_TRANSLATION": self.ENABLE_TRANSLATION, + # "ENABLE_TRANSLATION": self.ENABLE_TRANSLATION, # "ENABLE_TRANSCRIPTION_SEND": self.ENABLE_TRANSCRIPTION_SEND, # "ENABLE_TRANSCRIPTION_RECEIVE": self.ENABLE_TRANSCRIPTION_RECEIVE, - "ENABLE_FOREGROUND": self.ENABLE_FOREGROUND, + # "ENABLE_FOREGROUND": self.ENABLE_FOREGROUND, "TRANSPARENCY": self.TRANSPARENCY, "APPEARANCE_THEME": self.APPEARANCE_THEME, "UI_SCALING": self.UI_SCALING, @@ -353,12 +354,12 @@ class App(CTk): print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") - ## set checkbox enable translation - if self.ENABLE_TRANSLATION: - self.checkbox_translation.select() - self.checkbox_translation_callback() - else: - self.checkbox_translation.deselect() + # ## set checkbox enable translation + # if self.ENABLE_TRANSLATION: + # self.checkbox_translation.select() + # self.checkbox_translation_callback() + # else: + # self.checkbox_translation.deselect() # ## set checkbox enable transcription send # if self.ENABLE_TRANSCRIPTION_SEND: @@ -374,12 +375,12 @@ class App(CTk): # else: # self.checkbox_transcription_receive.deselect() - ## set set checkbox enable foreground - if self.ENABLE_FOREGROUND: - self.checkbox_foreground.select() - self.checkbox_foreground_callback() - else: - self.checkbox_foreground.deselect() + # ## set set checkbox enable foreground + # if self.ENABLE_FOREGROUND: + # self.checkbox_foreground.select() + # self.checkbox_foreground_callback() + # else: + # self.checkbox_foreground.deselect() ## set word filter for f in self.INPUT_MIC_WORD_FILTER: From b9df31dab3952769d44e6925020bea870e3b17ec Mon Sep 17 00:00:00 2001 From: misygauziya Date: Wed, 19 Jul 2023 17:14:34 +0900 Subject: [PATCH 37/54] =?UTF-8?q?[update]translation=5Flang=E3=81=AE?= =?UTF-8?q?=E5=85=88=E9=A0=AD=E3=82=92=E5=A4=A7=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 --- languages.py | 244 +++++++++++++++++++++++++-------------------------- 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/languages.py b/languages.py index 186fd747..9436745a 100644 --- a/languages.py +++ b/languages.py @@ -154,130 +154,130 @@ translation_lang["DeepL(auth)"] = { "Chinese":"zh" } translation_lang["Google(web)"] = { - "japanese":"ja", - "english":"en", - "chinese":"zh", - "arabic":"ar", - "russian":"ru", - "french":"fr", - "german":"de", - "spanish":"es", - "portuguese":"pt", - "italian":"it", - "korean":"ko", - "greek":"el", - "dutch":"nl", - "hindi":"hi", - "turkish":"tr", - "malay":"ms", - "thai":"th", - "vietnamese":"vi", - "indonesian":"id", - "hebrew":"he", - "polish":"pl", - "mongolian":"mn", - "czech":"cs", - "hungarian":"hu", - "estonian":"et", - "bulgarian":"bg", - "danish":"da", - "finnish":"fi", - "romanian":"ro", - "swedish":"sv", - "slovenian":"sl", - "persian/farsi":"fa", - "bosnian":"bs", - "serbian":"sr", - "filipino":"tl", - "haitiancreole":"ht", - "catalan":"ca", - "croatian":"hr", - "latvian":"lv", - "lithuanian":"lt", - "urdu":"ur", - "ukrainian":"uk", - "welsh":"cy", - "swahili":"sw", - "samoan":"sm", - "slovak":"sk", - "afrikaans":"af", - "norwegian":"no", - "bengali":"bn", - "malagasy":"mg", - "maltese":"mt", - "gujarati":"gu", - "tamil":"ta", - "telugu":"te", - "punjabi":"pa", - "amharic":"am", - "azerbaijani":"az", - "belarusian":"be", - "cebuano":"ceb", - "esperanto":"eo", - "basque":"eu", - "irish":"ga" + "Japanese":"ja", + "English":"en", + "Chinese":"zh", + "Arabic":"ar", + "Russian":"ru", + "French":"fr", + "German":"de", + "Spanish":"es", + "Portuguese":"pt", + "Italian":"it", + "Korean":"ko", + "Greek":"el", + "Dutch":"nl", + "Hindi":"hi", + "Turkish":"tr", + "Malay":"ms", + "Thai":"th", + "Vietnamese":"vi", + "Indonesian":"id", + "Hebrew":"he", + "Polish":"pl", + "Mongolian":"mn", + "Czech":"cs", + "Hungarian":"hu", + "Estonian":"et", + "Bulgarian":"bg", + "Danish":"da", + "Finnish":"fi", + "Romanian":"ro", + "Swedish":"sv", + "Slovenian":"sl", + "Persian/Farsi":"fa", + "Bosnian":"bs", + "Serbian":"sr", + "Filipino":"tl", + "Haitiancreole":"ht", + "Catalan":"ca", + "Croatian":"hr", + "Latvian":"lv", + "Lithuanian":"lt", + "Urdu":"ur", + "Ukrainian":"uk", + "Welsh":"cy", + "Swahili":"sw", + "Samoan":"sm", + "Slovak":"sk", + "Afrikaans":"af", + "Norwegian":"no", + "Bengali":"bn", + "Malagasy":"mg", + "Maltese":"mt", + "Gujarati":"gu", + "Tamil":"ta", + "Telugu":"te", + "Punjabi":"pa", + "Amharic":"am", + "Azerbaijani":"az", + "Belarusian":"be", + "Cebuano":"ceb", + "Esperanto":"eo", + "Basque":"eu", + "Irish":"ga" } translation_lang["Bing(web)"] = { - "japanese":"ja", - "english":"en", - "chinese":"zh", - "arabic":"ar", - "russian":"ru", - "french":"fr", - "german":"de", - "spanish":"es", - "portuguese":"pt", - "italian":"it", - "korean":"ko", - "greek":"el", - "dutch":"nl", - "hindi":"hi", - "turkish":"tr", - "malay":"ms", - "thai":"th", - "vietnamese":"vi", - "indonesian":"id", - "hebrew":"he", - "polish":"pl", - "czech":"cs", - "hungarian":"hu", - "estonian":"et", - "bulgarian":"bg", - "danish":"da", - "finnish":"fi", - "romanian":"ro", - "swedish":"sv", - "slovenian":"sl", - "persian/farsi":"fa", - "bosnian":"bs", - "serbian":"sr", - "fijian":"fj", - "filipino":"tl", - "haitiancreole":"ht", - "catalan":"ca", - "croatian":"hr", - "latvian":"lv", - "lithuanian":"lt", - "urdu":"ur", - "ukrainian":"uk", - "welsh":"cy", - "tahiti":"ty", - "tongan":"to", - "swahili":"sw", - "samoan":"sm", - "slovak":"sk", - "afrikaans":"af", - "norwegian":"no", - "bengali":"bn", - "malagasy":"mg", - "maltese":"mt", - "queretaro otomi":"otq", - "klingon/tlhingan hol":"tlh", - "gujarati":"gu", - "tamil":"ta", - "telugu":"te", - "punjabi":"pa", - "irish":"ga" + "Japanese":"ja", + "English":"en", + "Chinese":"zh", + "Arabic":"ar", + "Russian":"ru", + "French":"fr", + "German":"de", + "Spanish":"es", + "Portuguese":"pt", + "Italian":"it", + "Korean":"ko", + "Greek":"el", + "Dutch":"nl", + "Hindi":"hi", + "Turkish":"tr", + "Malay":"ms", + "Thai":"th", + "Vietnamese":"vi", + "Indonesian":"id", + "Hebrew":"he", + "Polish":"pl", + "Czech":"cs", + "Hungarian":"hu", + "Estonian":"et", + "Bulgarian":"bg", + "Danish":"da", + "Finnish":"fi", + "Romanian":"ro", + "Swedish":"sv", + "Slovenian":"sl", + "Persian/Farsi":"fa", + "Bosnian":"bs", + "Serbian":"sr", + "Fijian":"fj", + "Filipino":"tl", + "Haitiancreole":"ht", + "Catalan":"ca", + "Croatian":"hr", + "Latvian":"lv", + "Lithuanian":"lt", + "Urdu":"ur", + "Ukrainian":"uk", + "Welsh":"cy", + "Tahiti":"ty", + "Tongan":"to", + "Swahili":"sw", + "Samoan":"sm", + "Slovak":"sk", + "Afrikaans":"af", + "Norwegian":"no", + "Bengali":"bn", + "Malagasy":"mg", + "Maltese":"mt", + "Queretaro otomi":"otq", + "Klingon/tlhingan Hol":"tlh", + "Gujarati":"gu", + "Tamil":"ta", + "Telugu":"te", + "Punjabi":"pa", + "Irish":"ga" } selectable_languages = { From 7a8e522a1973a3be9a92ec6fa23f30a7628f61b3 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Wed, 19 Jul 2023 17:17:04 +0900 Subject: [PATCH 38/54] =?UTF-8?q?[bugfix]=20#18=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E6=BC=8F=E3=82=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 翻訳エンジンまたはHOSTAPI変更時にscrollableDropdownのvaluesが更新されない問題を修正 --- window_config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/window_config.py b/window_config.py index c6087fbd..edbee71c 100644 --- a/window_config.py +++ b/window_config.py @@ -224,6 +224,16 @@ class ToplevelWindowConfig(CTkToplevel): values=list(translation_lang[choice].keys()), variable=StringVar(value=list(translation_lang[choice].keys())[0])) + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_translation_input_source_language.configure( + values=list(translation_lang[choice].keys())) + self.scrollableDropdown_translation_input_target_language.configure( + values=list(translation_lang[choice].keys())) + self.scrollableDropdown_translation_output_source_language.configure( + values=list(translation_lang[choice].keys())) + self.scrollableDropdown_translation_output_target_language.configure( + values=list(translation_lang[choice].keys())) + self.parent.CHOICE_TRANSLATOR = choice self.parent.INPUT_SOURCE_LANG = list(translation_lang[choice].keys())[0] self.parent.INPUT_TARGET_LANG = list(translation_lang[choice].keys())[1] @@ -265,6 +275,8 @@ class ToplevelWindowConfig(CTkToplevel): self.parent.CHOICE_MIC_HOST = choice save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_HOST", self.parent.CHOICE_MIC_HOST) self.optionmenu_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]]) + if SCROLLABLE_DROPDOWN: + self.scrollableDropdown_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]]) def optionmenu_input_mic_device_callback(self, choice): self.optionmenu_input_mic_device.set(choice) From b40c074e4d006bdaf624446dd9626a7c46e233a1 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Wed, 19 Jul 2023 17:56:36 +0900 Subject: [PATCH 39/54] =?UTF-8?q?[bugfix]HOST=20API=E5=88=87=E6=9B=BF?= =?UTF-8?q?=E6=99=82=E3=81=ABCHOICE=5FMIC=5FDEVICE=E3=81=ABdevice=E5=90=8D?= =?UTF-8?q?=E3=82=92=E4=BF=9D=E6=8C=81=E3=81=99=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/window_config.py b/window_config.py index edbee71c..61f5ed24 100644 --- a/window_config.py +++ b/window_config.py @@ -272,11 +272,17 @@ class ToplevelWindowConfig(CTkToplevel): def optionmenu_input_mic_host_callback(self, choice): self.optionmenu_input_mic_host.set(choice) - self.parent.CHOICE_MIC_HOST = choice - save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_HOST", self.parent.CHOICE_MIC_HOST) - self.optionmenu_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]]) + self.optionmenu_input_mic_device.configure( + values=[device["name"] for device in get_input_device_list()[choice]], + variable=StringVar(value=[device["name"] for device in get_input_device_list()[choice]][0])) + if SCROLLABLE_DROPDOWN: - self.scrollableDropdown_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST]]) + self.scrollableDropdown_input_mic_device.configure(values=[device["name"] for device in get_input_device_list()[choice]]) + + self.parent.CHOICE_MIC_HOST = choice + self.parent.CHOICE_MIC_DEVICE = [device["name"] for device in get_input_device_list()[choice]][0] + save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_HOST", self.parent.CHOICE_MIC_HOST) + save_json(self.parent.PATH_CONFIG, "CHOICE_MIC_DEVICE", self.parent.CHOICE_MIC_DEVICE) def optionmenu_input_mic_device_callback(self, choice): self.optionmenu_input_mic_device.set(choice) From e2d13d09974c25165e2d4b104d2206a4679b5271 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 01:05:22 +0900 Subject: [PATCH 40/54] =?UTF-8?q?[bugfix]=20SCROLLABLE=5FDROPDOWN=3DFalse?= =?UTF-8?q?=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AB=E8=A8=AD=E5=AE=9A=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E9=A0=85=E7=9B=AE?= =?UTF-8?q?=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index 61f5ed24..59f52c5f 100644 --- a/window_config.py +++ b/window_config.py @@ -86,7 +86,6 @@ class ToplevelWindowConfig(CTkToplevel): self.label_font_family.configure(font=CTkFont(family=choice)) self.optionmenu_font_family.configure(font=CTkFont(family=choice)) self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=choice)) - self.scrollableDropdown_font_family.configure(font=CTkFont(family=choice)) self.label_ui_language.configure(font=CTkFont(family=choice)) self.optionmenu_ui_language.configure(font=CTkFont(family=choice)) self.optionmenu_ui_language._dropdown_menu.configure(font=CTkFont(family=choice)) @@ -602,10 +601,13 @@ class ToplevelWindowConfig(CTkToplevel): font_families = list(tk_font.families()) self.optionmenu_font_family = CTkOptionMenu( self.tabview_config.tab(config_tab_title_ui), + values=font_families, + command=self.optionmenu_font_family_callback, variable=StringVar(value=self.parent.FONT_FAMILY), font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") + self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown font family if SCROLLABLE_DROPDOWN: From c3d9a66fda197ae90d6e0bc50a4d76122701a778 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 01:33:11 +0900 Subject: [PATCH 41/54] =?UTF-8?q?[update]=20dropdown=5Ffont=E3=82=92option?= =?UTF-8?q?menu=E8=A8=AD=E5=AE=9A=E6=99=82=E3=81=AB=E5=85=A5=E3=82=8C?= =?UTF-8?q?=E8=BE=BC=E3=82=80=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_config.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/window_config.py b/window_config.py index 59f52c5f..1b95400a 100644 --- a/window_config.py +++ b/window_config.py @@ -536,9 +536,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_appearance_theme_callback, variable=StringVar(value=self.parent.APPEARANCE_THEME), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_appearance_theme.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_appearance_theme._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown appearance theme if SCROLLABLE_DROPDOWN: @@ -570,9 +570,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_ui_scaling_callback, variable=StringVar(value=self.parent.UI_SCALING), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_ui_scaling.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_ui_scaling._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown ui scaling if SCROLLABLE_DROPDOWN: @@ -605,9 +605,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_font_family_callback, variable=StringVar(value=self.parent.FONT_FAMILY), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_font_family.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_font_family._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown font family if SCROLLABLE_DROPDOWN: @@ -640,9 +640,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_ui_language_callback, variable=StringVar(value=selectable_languages[self.parent.UI_LANGUAGE]), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_ui_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_ui_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown ui language if SCROLLABLE_DROPDOWN: @@ -677,9 +677,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_translation_translator_callback, variable=StringVar(value=self.parent.CHOICE_TRANSLATOR), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_translator.grid(row=row, column=1, columnspan=3, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_translator._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown translation translator if SCROLLABLE_DROPDOWN: @@ -713,9 +713,9 @@ class ToplevelWindowConfig(CTkToplevel): values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), variable=StringVar(value=self.parent.INPUT_SOURCE_LANG), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_input_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_input_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown translation input source language if SCROLLABLE_DROPDOWN: @@ -748,9 +748,9 @@ class ToplevelWindowConfig(CTkToplevel): values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), variable=StringVar(value=self.parent.INPUT_TARGET_LANG), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_input_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_input_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown translation input target language if SCROLLABLE_DROPDOWN: @@ -784,9 +784,9 @@ class ToplevelWindowConfig(CTkToplevel): values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), variable=StringVar(value=self.parent.OUTPUT_SOURCE_LANG), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_output_source_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_output_source_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown translation output source language if SCROLLABLE_DROPDOWN: @@ -819,9 +819,9 @@ class ToplevelWindowConfig(CTkToplevel): values=list(translation_lang[self.parent.CHOICE_TRANSLATOR].keys()), variable=StringVar(value=self.parent.OUTPUT_TARGET_LANG), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_translation_output_target_language.grid(row=row, column=3, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_translation_output_target_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown translation output target language if SCROLLABLE_DROPDOWN: @@ -856,9 +856,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_mic_host_callback, variable=StringVar(value=self.parent.CHOICE_MIC_HOST), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_mic_host.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_host._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown input mic device's host if SCROLLABLE_DROPDOWN: @@ -890,9 +890,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_mic_device_callback, variable=StringVar(value=self.parent.CHOICE_MIC_DEVICE), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_mic_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown input mic device if SCROLLABLE_DROPDOWN: @@ -924,9 +924,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_mic_voice_language_callback, variable=StringVar(value=self.parent.INPUT_MIC_VOICE_LANGUAGE), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_mic_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_mic_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown input mic voice language if SCROLLABLE_DROPDOWN: @@ -1091,9 +1091,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_speaker_device_callback, variable=StringVar(value=self.parent.CHOICE_SPEAKER_DEVICE), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_speaker_device.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_speaker_device._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown input speaker device if SCROLLABLE_DROPDOWN: @@ -1125,9 +1125,9 @@ class ToplevelWindowConfig(CTkToplevel): command=self.optionmenu_input_speaker_voice_language_callback, variable=StringVar(value=self.parent.INPUT_SPEAKER_VOICE_LANGUAGE), font=CTkFont(family=self.parent.FONT_FAMILY), + dropdown_font=CTkFont(family=self.parent.FONT_FAMILY), ) self.optionmenu_input_speaker_voice_language.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") - self.optionmenu_input_speaker_voice_language._dropdown_menu.configure(font=CTkFont(family=self.parent.FONT_FAMILY)) ## scrollableDropdown input speaker voice language if SCROLLABLE_DROPDOWN: From 60ce296289e5cfc6ab5b435262cce8e13d575a72 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 01:33:50 +0900 Subject: [PATCH 42/54] =?UTF-8?q?[update]=20v1.3=E3=83=AA=E3=83=AA?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=81=AE=E3=81=9F=E3=82=81=E3=80=81SCROLLABL?= =?UTF-8?q?E=5FDROPDOWN=20=3D=20False=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index 1b95400a..2fed895d 100644 --- a/window_config.py +++ b/window_config.py @@ -14,7 +14,7 @@ from languages import translation_lang, transcription_lang, selectable_languages from ctk_scrollable_dropdown import CTkScrollableDropdown -SCROLLABLE_DROPDOWN = True +SCROLLABLE_DROPDOWN = False class ToplevelWindowConfig(CTkToplevel): From 600635738155110350bcddd560faeb1b0b1dea1c Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 02:01:11 +0900 Subject: [PATCH 43/54] =?UTF-8?q?[update]=20information=E3=81=AB=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E5=86=85=E5=AE=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- window_information.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/window_information.py b/window_information.py index 39f9d713..fa868a44 100644 --- a/window_information.py +++ b/window_information.py @@ -18,7 +18,7 @@ class ToplevelWindowInformation(CTkToplevel): font=CTkFont(family=self.parent.FONT_FAMILY) ) self.textbox_information.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nsew") - textbox_information_message = """VRCT(v1.2) + textbox_information_message = """VRCT(v1.3) # 概要 VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツールになります。 @@ -61,20 +61,25 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ Appearance Theme: ウィンドウテーマを選択 UI Scaling: UIサイズを調整 Font Family: 表示フォントを選択 + (New!) UI Language: UIの表示言語を選択 Translationタブ Select Translator: 翻訳エンジンの変更 Send Language: 送信するメッセージに対して翻訳する言語[source, target]を選択 Receive Language: 受信したメッセージに対して翻訳する言語[source, target]を選択 Transcriptionタブ + (New!) Input Mic Host: マイクのホストAPIを選択 Input Mic Device: マイクを選択 Input Mic Voice Language: 入力する音声の言語 Input Mic Energy Threshold: 音声取得のしきい値 + (New!) Check threshold point: Input Mic Energy Thresholdのしきい値を視覚化 Input Mic Dynamic Energy Threshold: 音声取得のしきい値の自動調整 Input Mic Record Timeout: 音声の区切りの無音時間 Input Mic Max Phrases: 保留する単語の上限 + (New!) Input Mic Word Filter: MICの文字起こし時にWord Filterで設定した文字が入っていた場合にChatboxに表示しない (ex AAA,BBB,CCC) Input Speaker Device: スピーカーを選択 Input Speaker Voice Language: 受信する音声の言語 Input Speaker Energy Threshold: 音声取得のしきい値 + (New!) Check threshold point: (New!)Input Speaker Energy Thresholdのしきい値を視覚化 Input Speaker Dynamic Energy Threshold: 音声取得のしきい値の自動調整 Input Speaker Record Timeout: 音声の区切りの無音時間 Input Speaker Max Phrases: 保留する単語の上限 @@ -86,6 +91,8 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ [message]がメッセージボックスに記入したメッセージに置換される [translation]が翻訳されたメッセージに置換される 初期フォーマット:"[message]([translation])" + Othersタブ + (New!) Auto clear chat box: メッセージ送信後に書き込んだメッセージを空にする 設定の初期化 config.jsonを削除 @@ -118,6 +125,17 @@ https://twitter.com/misya_ai - いくつかのバクを修正 - 翻訳/文字起こし言語の表記を略称からわかりやすい文字に変更 - 文字起こしの処理の軽量化 +[2023-07-05: v1.2] +- 文字起こし精度の向上 +[2023-07-21: v1.3] +- UIの表示言語を日本語/英語を選択できる機能を追加 +- Energy Thresholdの視覚化機能を追加 +- 文字起こしの誤認識対策のため、Word Filterを追加 +- WASAPI以外のHostAPIでもマイクとして使用できるようにHostAPIを選択できる機能を追加 +- メッセージ送信後に書き込んだメッセージを空にするか選択できる機能を追加 +- バグ対策のため、translation/voice2chatbox/speaker2log/foregroundは起動時はOFFになるように変更 +- バグ対策のため、スピーカーについて既定デバイス以外を選択した時にERRORが出るように変更 +- 半角入力時に一部の文字が書き込めないバグを修正 # 注意事項 再配布とかはやめてね From ee600cfd3d2396703686d68b62489b7fa75fb804 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 02:22:22 +0900 Subject: [PATCH 44/54] =?UTF-8?q?[update]information=E3=81=AE=E8=A8=98?= =?UTF-8?q?=E5=85=A5=E6=BC=8F=E3=82=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 --- window_information.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/window_information.py b/window_information.py index fa868a44..69e87b47 100644 --- a/window_information.py +++ b/window_information.py @@ -74,6 +74,7 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ (New!) Check threshold point: Input Mic Energy Thresholdのしきい値を視覚化 Input Mic Dynamic Energy Threshold: 音声取得のしきい値の自動調整 Input Mic Record Timeout: 音声の区切りの無音時間 + Input Mic Phase Timeout: 文字起こしする音声時間の上限 Input Mic Max Phrases: 保留する単語の上限 (New!) Input Mic Word Filter: MICの文字起こし時にWord Filterで設定した文字が入っていた場合にChatboxに表示しない (ex AAA,BBB,CCC) Input Speaker Device: スピーカーを選択 @@ -82,6 +83,7 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ (New!) Check threshold point: (New!)Input Speaker Energy Thresholdのしきい値を視覚化 Input Speaker Dynamic Energy Threshold: 音声取得のしきい値の自動調整 Input Speaker Record Timeout: 音声の区切りの無音時間 + Input Speaker Phase Timeout: 文字起こしする音声時間の上限 Input Speaker Max Phrases: 保留する単語の上限 Parameterタブ OSC IP address: 変更不要 From 97a9958d1b3986364dab47f2cb5a6aae22362f3a Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 02:23:36 +0900 Subject: [PATCH 45/54] [update] README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新内容を追加 --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b3891b50..1e459209 100644 --- a/README.md +++ b/README.md @@ -75,22 +75,29 @@ ptyhon VRCT.py - Appearance Theme: ウィンドウテーマを選択 - UI Scaling: UIサイズを調整 - Font Family: 表示フォントを選択 + - **(New!) UI Language: UIの表示言語を選択** - Translation tab - Select Translator: 翻訳エンジンの変更 - Send Language: 送信するメッセージに対して翻訳する言語[source, target]を選択 - Receive Language: 受信したメッセージに対して翻訳する言語[source, target]を選択 - Transcription tab + - **(New!) Input Mic Host: マイクのホストAPIを選択** - Input Mic Device: マイクを選択 - Input Mic Voice Language: 入力する音声の言語 - Input Mic Energy Threshold: 音声取得のしきい値 + - **(New!) Check threshold point: Input Mic Energy Thresholdのしきい値を視覚化** - Input Mic Dynamic Energy Threshold: 音声取得のしきい値の自動調整 + - Input Mic Phase Timeout: 文字起こしする音声時間の上限 - Input Mic Record Timeout: 音声の区切りの無音時間 - Input Mic Max Phrases: 保留する単語の上限 + - **(New!) Input Mic Word Filter: MICの文字起こし時にWord Filterで設定した文字が入っていた場合にChatboxに表示しない (ex AAA,BBB,CCC)** - Input Speaker Device: スピーカーを選択 - Input Speaker Voice Language: 受信する音声の言語 - Input Speaker Energy Threshold: 音声取得のしきい値 + - **(New!) Check threshold point: (New!)Input Speaker Energy Thresholdのしきい値を視覚化** - Input Speaker Dynamic Energy Threshold: 音声取得のしきい値の自動調整 - Input Speaker Record Timeout: 音声の区切りの無音時間 + - Input Speaker Phase Timeout: 文字起こしする音声時間の上限 - Input Speaker Max Phrases: 保留する単語の上限 - Parameter tab - OSC IP address: 変更不要 @@ -101,9 +108,11 @@ ptyhon VRCT.py - [translation]が翻訳されたメッセージに置換される - 初期フォーマット:`[message]([translation])` - Others tab - - Auto clear chat box: チャット送信時にチャットボックスを空にする + - **(New!) Auto clear chat box: メッセージ送信後に書き込んだメッセージを空にする** ## Author みしゃ(misyaguzi) twitter: https://twitter.com/misya_ai -booth: https://misyaguziya.booth.pm/items/4814313 \ No newline at end of file +booth: https://misyaguziya.booth.pm/items/4814313 + +Shiina_12siy \ No newline at end of file From 28be2b38409872fd5bbe2731dc200fa84b7e6032 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 02:24:12 +0900 Subject: [PATCH 46/54] [update] README.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 更新内容を追加 --- README.txt | 138 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 79 insertions(+), 59 deletions(-) diff --git a/README.txt b/README.txt index 5a28b468..3a5c23cd 100644 --- a/README.txt +++ b/README.txt @@ -1,79 +1,90 @@ ご購入ありがとうございます。 フィードバックお待ちしております。 -概要 +# 概要 VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツールになります。 翻訳エンジンを使用してメッセージとその翻訳部分を同時に送信することができます。 (翻訳エンジンはDeepL,Google,Bingに対応) -使用方法 - 初期設定時 -  0. VRChatのOSCを有効にする(重要) +# 使用方法 + 初期設定時 + 0. VRChatのOSCを有効にする(重要) -  (任意) -  1. DeepLのAPIを使用するためにアカウント登録し、認証キーを取得する -  2. ギアアイコンのボタンでconfigウィンドウを開く -  3. ParameterタブのDeepL Auth Keyに認証キーを記載し、フロッピーアイコンのボタンを押す -  4. configウィンドウを閉じる + (任意) + 1. DeepLのAPIを使用するためにアカウント登録し、認証キーを取得する + 2. ギアアイコンのボタンでconfigウィンドウを開く + 3. ParameterタブのDeepL Auth Keyに認証キーを記載し、フロッピーアイコンのボタンを押す + 4. configウィンドウを閉じる - 通常使用時 -  1. メッセージボックスにメッセージを記入 -  2. Enterキーを押し、メッセージを送信する + 通常使用時 + 1. メッセージボックスにメッセージを記入 + 2. Enterキーを押し、メッセージを送信する - その他の設定 -  - translation チェックボックス: 翻訳の有効無効 -  - voice2chatbox チェックボックス : マイクの音声を文字起こししてチャットボックスに送信する -  - speaker2log チェックボックス : スピーカーの音声から文字起こししてログに表示する -  - foreground チェックボックス: 最前面表示の有効無効 +# その他の設定 + translation チェックボックス: 翻訳の有効無効 + voice2chatbox チェックボックス : マイクの音声を文字起こししてチャットボックスに送信する + speaker2log チェックボックス : スピーカーの音声から文字起こししてログに表示する + foreground チェックボックス: 最前面表示の有効無効 -   - テキストボックス -    - logタブ: すべてのログを表示 -    - sendタブ: 送信したメッセージを表示 -    - receiveタブ: 受信したメッセージを表示 -    - systemタブ: 機能についてのメッセージを表示 + テキストボックス + logタブ + すべてのログを表示 + sendタブ + 送信したメッセージを表示 + receiveタブ + 受信したメッセージを表示 + systemタブ + 機能についてのメッセージを表示 -  - Configウィンドウ -   - UIタブ -    - Transparency: ウィンドウの透過度の調整 -    - Appearance Theme: ウィンドウテーマを選択 -    - UI Scaling: UIサイズを調整 -    - Font Family: 表示フォントを選択 -   - Translationタブ -    - Select Translator: 翻訳エンジンの変更 -    - Send Language: 送信するメッセージに対して翻訳する言語[source, target]を選択 -    - Receive Language: 受信したメッセージに対して翻訳する言語[source, target]を選択 -   - Transcriptionタブ -    - Input Mic Device: マイクを選択 -    - Input Mic Voice Language: 入力する音声の言語 -    - Input Mic Energy Threshold: 音声取得のしきい値 -    - Input Mic Dynamic Energy Threshold: 音声取得のしきい値の自動調整 -    - Input Mic Record Timeout: 音声の区切りの無音時間 -    - Input Mic Max Phrases: 保留する単語の上限 -    - Input Speaker Device: スピーカーを選択 -    - Input Speaker Voice Language: 受信する音声の言語 -    - Input Speaker Energy Threshold: 音声取得のしきい値 -    - Input Speaker Dynamic Energy Threshold: 音声取得のしきい値の自動調整 -    - Input Speaker Record Timeout: 音声の区切りの無音時間 -    - Input Speaker Max Phrases: 保留する単語の上限 -  - Parameterタブ -    - OSC IP address: 変更不要 -    - OSC port: 変更不要 -    - DeepL Auth key: DeepLの認証キーの設定 -    - Message Format: 送信するメッセージのデコレーションの設定 -     - [message]がメッセージボックスに記入したメッセージに置換される -     - [translation]が翻訳されたメッセージに置換される -     - 初期フォーマット:"[message]([translation])" -  - Othersタブ -    - Auto clear chat box: チャット送信時にチャットボックスを空にする + configウィンドウ + UIタブ + Transparency: ウィンドウの透過度の調整 + Appearance Theme: ウィンドウテーマを選択 + UI Scaling: UIサイズを調整 + Font Family: 表示フォントを選択 + (New!) UI Language: UIの表示言語を選択 + Translationタブ + Select Translator: 翻訳エンジンの変更 + Send Language: 送信するメッセージに対して翻訳する言語[source, target]を選択 + Receive Language: 受信したメッセージに対して翻訳する言語[source, target]を選択 + Transcriptionタブ + (New!) Input Mic Host: マイクのホストAPIを選択 + Input Mic Device: マイクを選択 + Input Mic Voice Language: 入力する音声の言語 + Input Mic Energy Threshold: 音声取得のしきい値 + (New!) Check threshold point: Input Mic Energy Thresholdのしきい値を視覚化 + Input Mic Dynamic Energy Threshold: 音声取得のしきい値の自動調整 + Input Mic Record Timeout: 音声の区切りの無音時間 + Input Mic Phase Timeout: 文字起こしする音声時間の上限 + Input Mic Max Phrases: 保留する単語の上限 + (New!) Input Mic Word Filter: MICの文字起こし時にWord Filterで設定した文字が入っていた場合にChatboxに表示しない (ex AAA,BBB,CCC) + Input Speaker Device: スピーカーを選択 + Input Speaker Voice Language: 受信する音声の言語 + Input Speaker Energy Threshold: 音声取得のしきい値 + (New!) Check threshold point: (New!)Input Speaker Energy Thresholdのしきい値を視覚化 + Input Speaker Dynamic Energy Threshold: 音声取得のしきい値の自動調整 + Input Speaker Record Timeout: 音声の区切りの無音時間 + Input Speaker Phase Timeout: 文字起こしする音声時間の上限 + Input Speaker Max Phrases: 保留する単語の上限 + Parameterタブ + OSC IP address: 変更不要 + OSC port: 変更不要 + DeepL Auth key: DeepLの認証キーの設定 + Message Format: 送信するメッセージのデコレーションの設定 + [message]がメッセージボックスに記入したメッセージに置換される + [translation]が翻訳されたメッセージに置換される + 初期フォーマット:"[message]([translation])" + Othersタブ + (New!) Auto clear chat box: メッセージ送信後に書き込んだメッセージを空にする - 設定の初期化 -  - config.jsonを削除 + 設定の初期化 + config.jsonを削除 -お問い合わせ +# お問い合わせ 要望などはTwitterまで https://twitter.com/misya_ai -アップデート履歴 +# アップデート履歴 [2023-05-29: v0.1b] v0.1b リリース [2023-05-30: v0.2b] - configボタンをギアアイコンに変更 @@ -99,6 +110,15 @@ https://twitter.com/misya_ai - 文字起こしの処理の軽量化 [2023-07-05: v1.2] - 文字起こし精度の向上 +[2023-07-21: v1.3] +- UIの表示言語を日本語/英語を選択できる機能を追加 +- Energy Thresholdの視覚化機能を追加 +- 文字起こしの誤認識対策のため、Word Filterを追加 +- WASAPI以外のHostAPIでもマイクとして使用できるようにHostAPIを選択できる機能を追加 +- メッセージ送信後に書き込んだメッセージを空にするか選択できる機能を追加 +- バグ対策のため、translation/voice2chatbox/speaker2log/foregroundは起動時はOFFになるように変更 +- バグ対策のため、スピーカーについて既定デバイス以外を選択した時にERRORが出るように変更 +- 半角入力時に一部の文字が書き込めないバグを修正 # 注意事項 再配布とかはやめてね \ No newline at end of file From b69476b246bbb44708d69208a01a2626a9d36d19 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 02:37:04 +0900 Subject: [PATCH 47/54] [update] window_config.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit entry_input_mic_word_filterにplaceholder_textを追加 --- window_config.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/window_config.py b/window_config.py index 2fed895d..b7bdb8c0 100644 --- a/window_config.py +++ b/window_config.py @@ -344,7 +344,11 @@ class ToplevelWindowConfig(CTkToplevel): save_json(self.parent.PATH_CONFIG, "INPUT_MIC_MAX_PHRASES", self.parent.INPUT_MIC_MAX_PHRASES) def entry_input_mic_word_filters_callback(self, event): - self.parent.INPUT_MIC_WORD_FILTER = self.entry_input_mic_word_filter.get().split(",") + word_filter = self.entry_input_mic_word_filter.get() + if len(word_filter) > 0: + self.parent.INPUT_MIC_WORD_FILTER = self.entry_input_mic_word_filter.get().split(",") + else: + self.parent.INPUT_MIC_WORD_FILTER = [] self.parent.keyword_processor = KeywordProcessor() for f in self.parent.INPUT_MIC_WORD_FILTER: self.parent.keyword_processor.add_keyword(f) @@ -1068,9 +1072,14 @@ class ToplevelWindowConfig(CTkToplevel): font=CTkFont(family=self.parent.FONT_FAMILY) ) self.label_input_mic_word_filter.grid(row=row, column=0, columnspan=1, padx=padx, pady=pady, sticky="nsw") + if len(self.parent.INPUT_MIC_WORD_FILTER) > 0: + textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)) + else: + textvariable=None self.entry_input_mic_word_filter = CTkEntry( self.tabview_config.tab(config_tab_title_transcription), - textvariable=StringVar(value=",".join(self.parent.INPUT_MIC_WORD_FILTER)), + textvariable=textvariable, + placeholder_text="AAA,BBB,CCC", font=CTkFont(family=self.parent.FONT_FAMILY) ) self.entry_input_mic_word_filter.grid(row=row, column=1, columnspan=1, padx=padx, pady=pady, sticky="nsew") From f670925d6ad10df9270b132f69719feaadc784f7 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 02:51:07 +0900 Subject: [PATCH 48/54] [update] locales.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 日本語化してない部分を修正 --- locales.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/locales.yml b/locales.yml index 38dbe6e4..6ee9596d 100644 --- a/locales.yml +++ b/locales.yml @@ -101,17 +101,20 @@ ja: label_input_mic_device: "マイク入力デバイス" label_input_mic_voice_language: "マイクで話す言語" label_input_mic_energy_threshold: "音声取得のしきい値" + checkbox_input_mic_threshold_check: "音声取得のしきい値の視覚化" label_input_mic_dynamic_energy_threshold: "音声取得のしきい値の自動調整" label_input_mic_record_timeout: "マイク音声の区切りの無音時間" - # label_input_mic_phrase_timeout: "" + label_input_mic_phrase_timeout: "文字起こしする音声時間の上限" label_input_mic_max_phrases: "保留する単語の上限(マイク)" + label_input_mic_word_filter: "ワードフィルタ" label_input_speaker_device: "スピーカー(聞き取りたいデバイス)" label_input_speaker_voice_language: "聞き取る音声の言語" label_input_speaker_energy_threshold: "音声取得のしきい値" + checkbox_input_speaker_threshold_check: "音声取得のしきい値の視覚化" label_input_speaker_dynamic_energy_threshold: "音声取得のしきい値の自動調整" label_input_speaker_record_timeout: "スピーカー音声の区切りの無音時間" - # label_input_speaker_phrase_timeout: "" + label_input_speaker_phrase_timeout: "文字起こしする音声時間の上限" label_input_speaker_max_phrases: "保留する単語の上限(スピーカー)" # tab Parameter From 94c751af853ce20798ceb3e02a00084da1eb2666 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 03:31:38 +0900 Subject: [PATCH 49/54] [bugfix] README.md, README.txt, window_information.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 旧UIの文言を削除 --- README.md | 2 +- README.txt | 2 +- window_information.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1e459209..6997bcd4 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ ptyhon VRCT.py (任意) 1. DeepLのAPIを使用するためにアカウント登録し、認証キーを取得する 2. ギアアイコンのボタンでconfigウィンドウを開く -3. ParameterタブのDeepL Auth Keyに認証キーを記載し、フロッピーアイコンのボタンを押す +3. ParameterタブのDeepL Auth Keyに認証キーを記載 4. configウィンドウを閉じる ### Normal use diff --git a/README.txt b/README.txt index 3a5c23cd..57cdbfe5 100644 --- a/README.txt +++ b/README.txt @@ -13,7 +13,7 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ (任意) 1. DeepLのAPIを使用するためにアカウント登録し、認証キーを取得する 2. ギアアイコンのボタンでconfigウィンドウを開く - 3. ParameterタブのDeepL Auth Keyに認証キーを記載し、フロッピーアイコンのボタンを押す + 3. ParameterタブのDeepL Auth Keyに認証キーを記載 4. configウィンドウを閉じる 通常使用時 diff --git a/window_information.py b/window_information.py index 69e87b47..85e50035 100644 --- a/window_information.py +++ b/window_information.py @@ -32,7 +32,7 @@ VRChatで使用されるChatBoxをOSC経由でメッセージを送信するツ (任意) 1. DeepLのAPIを使用するためにアカウント登録し、認証キーを取得する 2. ギアアイコンのボタンでconfigウィンドウを開く - 3. ParameterタブのDeepL Auth Keyに認証キーを記載し、フロッピーアイコンのボタンを押す + 3. ParameterタブのDeepL Auth Keyに認証キーを記載 4. configウィンドウを閉じる 通常使用時 From bbd7e0d6ea9b1ff67b67c9fecda0dbb6e52f5ad9 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 13:47:16 +0900 Subject: [PATCH 50/54] [bugfix]VRCT.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit メインウィンドウのcheckboxをclick連打すると落ちる現象に対策 --- VRCT.py | 138 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 58 deletions(-) diff --git a/VRCT.py b/VRCT.py index 6480a7f2..d9e1c32c 100644 --- a/VRCT.py +++ b/VRCT.py @@ -8,6 +8,7 @@ from customtkinter import CTk, CTkFrame, CTkCheckBox, CTkFont, CTkButton, CTkIma from PIL.Image import open as Image_open from flashtext import KeywordProcessor +from threading import Thread from utils import save_json, print_textbox, thread_fnc, get_localized_text, widget_main_window_label_setter from osc_tools import send_typing, send_message from window_config import ToplevelWindowConfig @@ -432,65 +433,75 @@ class App(CTk): print_textbox(self.textbox_message_system_log, "Stop translation", "INFO") save_json(self.PATH_CONFIG, "ENABLE_TRANSLATION", self.ENABLE_TRANSLATION) + def transcription_send(self): + self.mic_audio_queue = Queue() + mic_device = [device for device in get_input_device_list()[self.CHOICE_MIC_HOST] if device["name"] == self.CHOICE_MIC_DEVICE][0] + self.mic_audio_recorder = SelectedMicRecorder( + mic_device, + self.INPUT_MIC_ENERGY_THRESHOLD, + self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, + self.INPUT_MIC_RECORD_TIMEOUT, + ) + self.mic_audio_recorder.record_into_queue(self.mic_audio_queue) + self.mic_transcriber = AudioTranscriber( + speaker=False, + source=self.mic_audio_recorder.source, + language=transcription_lang[self.INPUT_MIC_VOICE_LANGUAGE], + phrase_timeout=self.INPUT_MIC_PHRASE_TIMEOUT, + max_phrases=self.INPUT_MIC_MAX_PHRASES, + ) + def mic_transcript_to_chatbox(): + self.mic_transcriber.transcribe_audio_queue(self.mic_audio_queue) + message = self.mic_transcriber.get_transcript() + if len(message) > 0: + # word filter + if len(self.keyword_processor.extract_keywords(message)) != 0: + print_textbox(self.textbox_message_log, f"Detect WordFilter :{message}", "INFO") + print_textbox(self.textbox_message_system_log, f"Detect WordFilter :{message}", "INFO") + return + + # translate + if self.checkbox_translation.get() is False: + voice_message = f"{message}" + elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: + print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") + print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") + voice_message = f"{message}" + else: + result = self.translator.translate( + translator_name=self.CHOICE_TRANSLATOR, + source_language=self.INPUT_SOURCE_LANG, + target_language=self.INPUT_TARGET_LANG, + message=message + ) + voice_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) + + if self.checkbox_transcription_send.get() is True: + # send OSC message + send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) + # update textbox message log + print_textbox(self.textbox_message_log, f"{voice_message}", "SEND") + print_textbox(self.textbox_message_send_log, f"{voice_message}", "SEND") + + self.mic_print_transcript = thread_fnc(mic_transcript_to_chatbox) + self.mic_print_transcript.daemon = True + self.mic_print_transcript.start() + print_textbox(self.textbox_message_log, "Start voice2chatbox", "INFO") + print_textbox(self.textbox_message_system_log, "Start voice2chatbox", "INFO") + self.checkbox_transcription_send.configure(state="normal") + self.checkbox_transcription_receive.configure(state="normal") + def checkbox_transcription_send_callback(self): self.ENABLE_TRANSCRIPTION_SEND = self.checkbox_transcription_send.get() if self.ENABLE_TRANSCRIPTION_SEND is True: + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.mic_audio_queue = Queue() - mic_device = [device for device in get_input_device_list()[self.CHOICE_MIC_HOST] if device["name"] == self.CHOICE_MIC_DEVICE][0] - self.mic_audio_recorder = SelectedMicRecorder( - mic_device, - self.INPUT_MIC_ENERGY_THRESHOLD, - self.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, - self.INPUT_MIC_RECORD_TIMEOUT, - ) - self.mic_audio_recorder.record_into_queue(self.mic_audio_queue) - self.mic_transcriber = AudioTranscriber( - speaker=False, - source=self.mic_audio_recorder.source, - language=transcription_lang[self.INPUT_MIC_VOICE_LANGUAGE], - phrase_timeout=self.INPUT_MIC_PHRASE_TIMEOUT, - max_phrases=self.INPUT_MIC_MAX_PHRASES, - ) - def mic_transcript_to_chatbox(): - self.mic_transcriber.transcribe_audio_queue(self.mic_audio_queue) - message = self.mic_transcriber.get_transcript() - if len(message) > 0: - # word filter - if len(self.keyword_processor.extract_keywords(message)) != 0: - print_textbox(self.textbox_message_log, f"Detect WordFilter :{message}", "INFO") - print_textbox(self.textbox_message_system_log, f"Detect WordFilter :{message}", "INFO") - return + self.update() - # translate - if self.checkbox_translation.get() is False: - voice_message = f"{message}" - elif self.translator.translator_status[self.CHOICE_TRANSLATOR] is False: - print_textbox(self.textbox_message_log, "Auth Key or language setting is incorrect", "ERROR") - print_textbox(self.textbox_message_system_log, "Auth Key or language setting is incorrect", "ERROR") - voice_message = f"{message}" - else: - result = self.translator.translate( - translator_name=self.CHOICE_TRANSLATOR, - source_language=self.INPUT_SOURCE_LANG, - target_language=self.INPUT_TARGET_LANG, - message=message - ) - voice_message = self.MESSAGE_FORMAT.replace("[message]", message).replace("[translation]", result) - - if self.checkbox_transcription_send.get() is True: - # send OSC message - send_message(voice_message, self.OSC_IP_ADDRESS, self.OSC_PORT) - # update textbox message log - print_textbox(self.textbox_message_log, f"{voice_message}", "SEND") - print_textbox(self.textbox_message_send_log, f"{voice_message}", "SEND") - - self.mic_print_transcript = thread_fnc(mic_transcript_to_chatbox) - self.mic_print_transcript.daemon = True - self.mic_print_transcript.start() - - print_textbox(self.textbox_message_log, "Start voice2chatbox", "INFO") - print_textbox(self.textbox_message_system_log, "Start voice2chatbox", "INFO") + th_transcription_send = Thread(target=self.transcription_send) + th_transcription_send.daemon = True + th_transcription_send.start() else: if ((self.checkbox_translation.get() is False) and (self.checkbox_transcription_send.get() is False) and @@ -506,10 +517,7 @@ class App(CTk): print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO") save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_SEND", self.ENABLE_TRANSCRIPTION_SEND) - def checkbox_transcription_receive_callback(self): - self.ENABLE_TRANSCRIPTION_RECEIVE = self.checkbox_transcription_receive.get() - if self.ENABLE_TRANSCRIPTION_RECEIVE is True: - self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + def transcription_receive(self): self.spk_audio_queue = Queue() spk_device = [device for device in get_output_device_list() if device["name"] == self.CHOICE_SPEAKER_DEVICE][0] self.spk_audio_recorder = SelectedSpeakerRecorder( @@ -559,6 +567,20 @@ class App(CTk): self.spk_print_transcript.start() print_textbox(self.textbox_message_log, "Start speaker2log", "INFO") print_textbox(self.textbox_message_system_log, "Start speaker2log", "INFO") + self.checkbox_transcription_send.configure(state="normal") + self.checkbox_transcription_receive.configure(state="normal") + + def checkbox_transcription_receive_callback(self): + self.ENABLE_TRANSCRIPTION_RECEIVE = self.checkbox_transcription_receive.get() + if self.ENABLE_TRANSCRIPTION_RECEIVE is True: + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") + self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + self.update() + + th_transcription_receive = Thread(target=self.transcription_receive) + th_transcription_receive.daemon = True + th_transcription_receive.start() else: if ((self.checkbox_translation.get() is False) and (self.checkbox_transcription_send.get() is False) and From 3a8e02f986782a3448480ebdd5b42c143d395ab6 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 14:22:19 +0900 Subject: [PATCH 51/54] [bugfix] VRCT.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit checkboxを外した時にも排他処理を実装 --- VRCT.py | 85 +++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/VRCT.py b/VRCT.py index d9e1c32c..84dfcb55 100644 --- a/VRCT.py +++ b/VRCT.py @@ -433,7 +433,7 @@ class App(CTk): print_textbox(self.textbox_message_system_log, "Stop translation", "INFO") save_json(self.PATH_CONFIG, "ENABLE_TRANSLATION", self.ENABLE_TRANSLATION) - def transcription_send(self): + def transcription_send_start(self): self.mic_audio_queue = Queue() mic_device = [device for device in get_input_device_list()[self.CHOICE_MIC_HOST] if device["name"] == self.CHOICE_MIC_DEVICE][0] self.mic_audio_recorder = SelectedMicRecorder( @@ -491,6 +491,22 @@ class App(CTk): self.checkbox_transcription_send.configure(state="normal") self.checkbox_transcription_receive.configure(state="normal") + def transcription_send_stop(self): + if isinstance(self.mic_print_transcript, thread_fnc): + self.mic_print_transcript.stop() + if self.mic_audio_recorder.stop != None: + self.mic_audio_recorder.stop() + self.mic_audio_recorder.stop = None + + print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO") + print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO") + if ((self.checkbox_translation.get() is False) and + (self.checkbox_transcription_send.get() is False) and + (self.checkbox_transcription_receive.get() is False)): + self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) + self.checkbox_transcription_send.configure(state="normal") + self.checkbox_transcription_receive.configure(state="normal") + def checkbox_transcription_send_callback(self): self.ENABLE_TRANSCRIPTION_SEND = self.checkbox_transcription_send.get() if self.ENABLE_TRANSCRIPTION_SEND is True: @@ -499,25 +515,21 @@ class App(CTk): self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) self.update() - th_transcription_send = Thread(target=self.transcription_send) - th_transcription_send.daemon = True - th_transcription_send.start() + th_transcription_send_start = Thread(target=self.transcription_send_start) + th_transcription_send_start.daemon = True + th_transcription_send_start.start() else: - if ((self.checkbox_translation.get() is False) and - (self.checkbox_transcription_send.get() is False) and - (self.checkbox_transcription_receive.get() is False)): - self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) - if isinstance(self.mic_print_transcript, thread_fnc): - self.mic_print_transcript.stop() - if self.mic_audio_recorder.stop != None: - self.mic_audio_recorder.stop() - self.mic_audio_recorder.stop = None + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") + self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + self.update() - print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO") - print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO") + th_transcription_send_stop = Thread(target=self.transcription_send_stop) + th_transcription_send_stop.daemon = True + th_transcription_send_stop.start() save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_SEND", self.ENABLE_TRANSCRIPTION_SEND) - def transcription_receive(self): + def transcription_receive_start(self): self.spk_audio_queue = Queue() spk_device = [device for device in get_output_device_list() if device["name"] == self.CHOICE_SPEAKER_DEVICE][0] self.spk_audio_recorder = SelectedSpeakerRecorder( @@ -570,6 +582,22 @@ class App(CTk): self.checkbox_transcription_send.configure(state="normal") self.checkbox_transcription_receive.configure(state="normal") + def transcription_receive_stop(self): + if isinstance(self.spk_print_transcript, thread_fnc): + self.spk_print_transcript.stop() + if self.spk_audio_recorder.stop != None: + self.spk_audio_recorder.stop() + self.spk_audio_recorder.stop = None + + print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO") + print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO") + if ((self.checkbox_translation.get() is False) and + (self.checkbox_transcription_send.get() is False) and + (self.checkbox_transcription_receive.get() is False)): + self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) + self.checkbox_transcription_send.configure(state="normal") + self.checkbox_transcription_receive.configure(state="normal") + def checkbox_transcription_receive_callback(self): self.ENABLE_TRANSCRIPTION_RECEIVE = self.checkbox_transcription_receive.get() if self.ENABLE_TRANSCRIPTION_RECEIVE is True: @@ -578,21 +606,18 @@ class App(CTk): self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) self.update() - th_transcription_receive = Thread(target=self.transcription_receive) - th_transcription_receive.daemon = True - th_transcription_receive.start() + th_transcription_receive_start = Thread(target=self.transcription_receive_start) + th_transcription_receive_start.daemon = True + th_transcription_receive_start.start() else: - if ((self.checkbox_translation.get() is False) and - (self.checkbox_transcription_send.get() is False) and - (self.checkbox_transcription_receive.get() is False)): - self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"]) - if isinstance(self.spk_print_transcript, thread_fnc): - self.spk_print_transcript.stop() - if self.spk_audio_recorder.stop != None: - self.spk_audio_recorder.stop() - self.spk_audio_recorder.stop = None - print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO") - print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO") + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") + self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + self.update() + th_transcription_receive_stop = Thread(target=self.transcription_receive_stop) + th_transcription_receive_stop.daemon = True + th_transcription_receive_stop.start() + save_json(self.PATH_CONFIG, "ENABLE_TRANSCRIPTION_RECEIVE", self.ENABLE_TRANSCRIPTION_RECEIVE) def checkbox_foreground_callback(self): From 731eb76040a964cc9a20058ae92cc152a7853d5f Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 15:38:21 +0900 Subject: [PATCH 52/54] [update] window_config.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit word filterに全角半角スペースを除くように修正 --- window_config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/window_config.py b/window_config.py index b7bdb8c0..8e75cd4b 100644 --- a/window_config.py +++ b/window_config.py @@ -345,8 +345,10 @@ class ToplevelWindowConfig(CTkToplevel): def entry_input_mic_word_filters_callback(self, event): word_filter = self.entry_input_mic_word_filter.get() + word_filter = [w.strip() for w in word_filter.split(",") if len(w.strip()) > 0] + word_filter = ",".join(word_filter) if len(word_filter) > 0: - self.parent.INPUT_MIC_WORD_FILTER = self.entry_input_mic_word_filter.get().split(",") + self.parent.INPUT_MIC_WORD_FILTER = word_filter.split(",") else: self.parent.INPUT_MIC_WORD_FILTER = [] self.parent.keyword_processor = KeywordProcessor() From 4942193b473bc14cc33ae73c434a55a3f0d5542c Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 17:08:48 +0900 Subject: [PATCH 53/54] [bugfix] window_config.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit energy checkのAPI干渉を軽減する処理を追加 --- window_config.py | 102 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 33 deletions(-) diff --git a/window_config.py b/window_config.py index 8e75cd4b..89adde9a 100644 --- a/window_config.py +++ b/window_config.py @@ -7,6 +7,7 @@ import customtkinter from customtkinter import CTkToplevel, CTkTabview, CTkFont, CTkLabel, CTkSlider, CTkOptionMenu, StringVar, CTkEntry, CTkCheckBox, CTkProgressBar from flashtext import KeywordProcessor +from threading import Thread from utils import save_json, print_textbox, thread_fnc, get_localized_text, get_key_by_value, widget_config_window_label_setter from audio_utils import get_input_device_list, get_output_device_list, get_default_output_device from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder @@ -306,21 +307,38 @@ class ToplevelWindowConfig(CTkToplevel): pass sleep(0.01) + def mic_threshold_check_start(self): + self.mic_energy_queue = Queue() + mic_device = [device for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST] if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] + self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) + self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) + self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) + self.mic_energy_plot_progressbar.daemon = True + self.mic_energy_plot_progressbar.start() + self.checkbox_input_mic_threshold_check.configure(state="normal") + self.checkbox_input_speaker_threshold_check.configure(state="normal") + + def mic_threshold_check_stop(self): + if self.mic_energy_recorder != None: + self.mic_energy_recorder.stop() + if self.mic_energy_plot_progressbar != None: + self.mic_energy_plot_progressbar.stop() + self.progressBar_input_mic_energy_threshold.set(0) + self.checkbox_input_mic_threshold_check.configure(state="normal") + self.checkbox_input_speaker_threshold_check.configure(state="normal") + def checkbox_input_mic_threshold_check_callback(self): + self.checkbox_input_mic_threshold_check.configure(state="disabled") + self.checkbox_input_speaker_threshold_check.configure(state="disabled") + self.update() if self.checkbox_input_mic_threshold_check.get(): - self.mic_energy_queue = Queue() - mic_device = [device for device in get_input_device_list()[self.parent.CHOICE_MIC_HOST] if device["name"] == self.parent.CHOICE_MIC_DEVICE][0] - self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) - self.mic_energy_recorder.record_into_queue(self.mic_energy_queue) - self.mic_energy_plot_progressbar = thread_fnc(self.progressBar_input_mic_energy_plot) - self.mic_energy_plot_progressbar.daemon = True - self.mic_energy_plot_progressbar.start() + th_mic_threshold_check_start = Thread(target=self.mic_threshold_check_start) + th_mic_threshold_check_start.daemon = True + th_mic_threshold_check_start.start() else: - if self.mic_energy_recorder != None: - self.mic_energy_recorder.stop() - if self.mic_energy_plot_progressbar != None: - self.mic_energy_plot_progressbar.stop() - self.progressBar_input_mic_energy_threshold.set(0) + th_mic_threshold_check_stop = Thread(target=self.mic_threshold_check_stop) + th_mic_threshold_check_stop.daemon = True + th_mic_threshold_check_stop.start() def slider_input_mic_energy_threshold_callback(self, value): self.parent.INPUT_MIC_ENERGY_THRESHOLD = int(value) @@ -387,29 +405,47 @@ class ToplevelWindowConfig(CTkToplevel): energy = self.speaker_energy_recorder.recorder.listen_energy(source) self.speaker_energy_queue.put(energy) - def checkbox_input_speaker_threshold_check_callback(self): - if self.checkbox_input_speaker_threshold_check.get(): - self.speaker_energy_queue = Queue() - speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] + def speaker_threshold_check_start(self): + speaker_device = [device for device in get_output_device_list() if device["name"] == self.parent.CHOICE_SPEAKER_DEVICE][0] - if get_default_output_device()["index"] == speaker_device["index"]: - self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) - self.speaker_energy_get_progressbar = thread_fnc(self.progressBar_input_speaker_energy_get) - self.speaker_energy_get_progressbar.daemon = True - self.speaker_energy_get_progressbar.start() - self.speaker_energy_plot_progressbar = thread_fnc(self.progressBar_input_speaker_energy_plot) - self.speaker_energy_plot_progressbar.daemon = True - self.speaker_energy_plot_progressbar.start() - else: - print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") - print_textbox(self.parent.textbox_message_system_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") - self.checkbox_input_speaker_threshold_check.deselect() + if get_default_output_device()["index"] == speaker_device["index"]: + self.speaker_energy_queue = Queue() + self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) + self.speaker_energy_get_progressbar = thread_fnc(self.progressBar_input_speaker_energy_get) + self.speaker_energy_get_progressbar.daemon = True + self.speaker_energy_get_progressbar.start() + self.speaker_energy_plot_progressbar = thread_fnc(self.progressBar_input_speaker_energy_plot) + self.speaker_energy_plot_progressbar.daemon = True + self.speaker_energy_plot_progressbar.start() else: - if self.speaker_energy_get_progressbar != None: - self.speaker_energy_get_progressbar.stop() - if self.speaker_energy_plot_progressbar != None: - self.speaker_energy_plot_progressbar.stop() - self.progressBar_input_speaker_energy_threshold.set(0) + print_textbox(self.parent.textbox_message_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") + print_textbox(self.parent.textbox_message_system_log, "Windows playback device and selected device do not match. Change the Windows playback device.", "ERROR") + self.checkbox_input_speaker_threshold_check.deselect() + self.checkbox_input_mic_threshold_check.configure(state="normal") + self.checkbox_input_speaker_threshold_check.configure(state="normal") + + def speaker_threshold_check_stop(self): + if self.speaker_energy_get_progressbar != None: + self.speaker_energy_get_progressbar.stop() + if self.speaker_energy_plot_progressbar != None: + self.speaker_energy_plot_progressbar.stop() + + self.progressBar_input_speaker_energy_threshold.set(0) + self.checkbox_input_mic_threshold_check.configure(state="normal") + self.checkbox_input_speaker_threshold_check.configure(state="normal") + + def checkbox_input_speaker_threshold_check_callback(self): + self.checkbox_input_mic_threshold_check.configure(state="disabled") + self.checkbox_input_speaker_threshold_check.configure(state="disabled") + self.update() + if self.checkbox_input_speaker_threshold_check.get(): + th_speaker_threshold_check_start = Thread(target=self.speaker_threshold_check_start) + th_speaker_threshold_check_start.daemon = True + th_speaker_threshold_check_start.start() + else: + th_speaker_threshold_check_stop = Thread(target=self.speaker_threshold_check_stop) + th_speaker_threshold_check_stop.daemon = True + th_speaker_threshold_check_stop.start() def slider_input_speaker_energy_threshold_callback(self, value): self.parent.INPUT_SPEAKER_ENERGY_THRESHOLD = int(value) From 4937d7b1f152052ba6d8f8b3649df7cf4bae5838 Mon Sep 17 00:00:00 2001 From: misygauziya Date: Fri, 21 Jul 2023 17:09:16 +0900 Subject: [PATCH 54/54] [update] VRCT.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 処理の重複を削除 --- VRCT.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/VRCT.py b/VRCT.py index 84dfcb55..84c72f23 100644 --- a/VRCT.py +++ b/VRCT.py @@ -508,22 +508,16 @@ class App(CTk): self.checkbox_transcription_receive.configure(state="normal") def checkbox_transcription_send_callback(self): + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") + self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + self.update() self.ENABLE_TRANSCRIPTION_SEND = self.checkbox_transcription_send.get() if self.ENABLE_TRANSCRIPTION_SEND is True: - self.checkbox_transcription_send.configure(state="disabled") - self.checkbox_transcription_receive.configure(state="disabled") - self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.update() - th_transcription_send_start = Thread(target=self.transcription_send_start) th_transcription_send_start.daemon = True th_transcription_send_start.start() else: - self.checkbox_transcription_send.configure(state="disabled") - self.checkbox_transcription_receive.configure(state="disabled") - self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.update() - th_transcription_send_stop = Thread(target=self.transcription_send_stop) th_transcription_send_stop.daemon = True th_transcription_send_stop.start() @@ -599,21 +593,16 @@ class App(CTk): self.checkbox_transcription_receive.configure(state="normal") def checkbox_transcription_receive_callback(self): + self.checkbox_transcription_send.configure(state="disabled") + self.checkbox_transcription_receive.configure(state="disabled") + self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) + self.update() self.ENABLE_TRANSCRIPTION_RECEIVE = self.checkbox_transcription_receive.get() if self.ENABLE_TRANSCRIPTION_RECEIVE is True: - self.checkbox_transcription_send.configure(state="disabled") - self.checkbox_transcription_receive.configure(state="disabled") - self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.update() - th_transcription_receive_start = Thread(target=self.transcription_receive_start) th_transcription_receive_start.daemon = True th_transcription_receive_start.start() else: - self.checkbox_transcription_send.configure(state="disabled") - self.checkbox_transcription_receive.configure(state="disabled") - self.button_config.configure(state="disabled", fg_color=["gray92", "gray14"]) - self.update() th_transcription_receive_stop = Thread(target=self.transcription_receive_stop) th_transcription_receive_stop.daemon = True th_transcription_receive_stop.start()