Merge remote-tracking branch 'origin/UI_2.0' into UI_2.0

This commit is contained in:
Sakamoto Shiina
2023-10-16 10:20:58 +09:00
7 changed files with 71 additions and 259 deletions

View File

@@ -429,19 +429,6 @@ class Config:
self._OSC_PORT = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
@json_serializable('AUTH_KEYS')
def AUTH_KEYS(self):
return self._AUTH_KEYS
@AUTH_KEYS.setter
def AUTH_KEYS(self, value):
if type(value) is dict and set(value.keys()) == set(self.AUTH_KEYS.keys()):
for key, value in value.items():
if type(value) is str:
self._AUTH_KEYS[key] = value
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS)
@property
@json_serializable('MESSAGE_FORMAT')
def MESSAGE_FORMAT(self):
@@ -578,12 +565,6 @@ class Config:
self._INPUT_SPEAKER_MAX_PHRASES = 10
self._OSC_IP_ADDRESS = "127.0.0.1"
self._OSC_PORT = 9000
self._AUTH_KEYS = {
"DeepL(web)": None,
"DeepL(auth)": None,
"Bing(web)": None,
"Google(web)": None,
}
self._MESSAGE_FORMAT = "[message]([translation])"
self._ENABLE_AUTO_CLEAR_MESSAGE_BOX = True
self._ENABLE_NOTICE_XSOVERLAY = False

View File

@@ -22,13 +22,10 @@ def sendMicMessage(message):
return
elif config.ENABLE_TRANSLATION is False:
pass
elif model.getTranslatorStatus() is False:
view.printToTextbox_AuthenticationError()
else:
translation = model.getInputTranslate(message)
if translation == None:
view.printToTextbox_AuthenticationError()
translation = ""
if config.ENABLE_TRANSCRIPTION_SEND is True:
@@ -88,13 +85,10 @@ def receiveSpeakerMessage(message):
translation = ""
if config.ENABLE_TRANSLATION is False:
pass
elif model.getTranslatorStatus() is False:
view.printToTextbox_AuthenticationError()
else:
translation = model.getOutputTranslate(message)
if translation == None:
view.printToTextbox_AuthenticationError()
translation = ""
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
@@ -155,13 +149,10 @@ def sendChatMessage(message):
translation = ""
if config.ENABLE_TRANSLATION is False:
pass
elif model.getTranslatorStatus() is False:
view.printToTextbox_AuthenticationError()
else:
translation = model.getInputTranslate(message)
if translation == None:
view.printToTextbox_AuthenticationError()
translation = ""
# send OSC message
@@ -190,7 +181,10 @@ def messageBoxPressKeyEnter(e):
sendChatMessage(message)
def messageBoxPressKeyAny(e):
model.oscStartSendTyping()
if config.ENABLE_SEND_MESSAGE_TO_VRC is True:
model.oscStartSendTyping()
else:
model.oscStopSendTyping()
# func select languages
def initSetLanguageAndCountry():
@@ -198,14 +192,11 @@ def initSetLanguageAndCountry():
language, country = model.getLanguageAndCountry(select)
config.SOURCE_LANGUAGE = language
config.SOURCE_COUNTRY = country
select = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
language, country = model.getLanguageAndCountry(select)
config.TARGET_LANGUAGE = language
config.TARGET_COUNTRY = country
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
model.authenticationTranslator(callbackSetAuthKeys)
def setYourLanguageAndCountry(select):
languages = config.SELECTED_TAB_YOUR_LANGUAGES
@@ -215,7 +206,6 @@ def setYourLanguageAndCountry(select):
config.SOURCE_LANGUAGE = language
config.SOURCE_COUNTRY = country
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
model.authenticationTranslator(callbackSetAuthKeys)
view.printToTextbox_selectedYourLanguages(select)
def setTargetLanguageAndCountry(select):
@@ -226,7 +216,6 @@ def setTargetLanguageAndCountry(select):
config.TARGET_LANGUAGE = language
config.TARGET_COUNTRY = country
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
model.authenticationTranslator(callbackSetAuthKeys)
view.printToTextbox_selectedTargetLanguages(select)
def callbackSelectedLanguagePresetTab(selected_tab_no):
@@ -243,11 +232,8 @@ def callbackSelectedLanguagePresetTab(selected_tab_no):
config.TARGET_LANGUAGE = language
config.TARGET_COUNTRY = country
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
model.authenticationTranslator(callbackSetAuthKeys)
view.printToTextbox_changedLanguagePresetTab(config.SELECTED_TAB_NO)
def callbackSetAuthKeys(keys):
config.AUTH_KEYS = keys
# command func
def callbackToggleTranslation(is_turned_on):
@@ -367,21 +353,6 @@ def callbackSetUiLanguage(value):
config.UI_LANGUAGE = value
view.showRestartButton(locale=config.UI_LANGUAGE)
# Translation Tab
def callbackSetDeeplAuthkey(value):
print("callbackSetDeeplAuthkey", str(value))
if len(value) > 0 and model.authenticationTranslator(callbackSetAuthKeys, choice_translator="DeepL(auth)", auth_key=value) is True:
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
model.authenticationTranslator(callbackSetAuthKeys)
view.printToTextbox_AuthenticationSuccess()
elif len(value) == 0:
auth_keys = config.AUTH_KEYS
auth_keys["DeepL(auth)"] = None
config.AUTH_KEYS = auth_keys
model.authenticationTranslator(callbackSetAuthKeys)
else:
view.printToTextbox_AuthenticationError()
# Transcription Tab (Mic)
def callbackSetMicHost(value):
print("callbackSetMicHost", value)
@@ -493,12 +464,12 @@ def callbackSetMicWordFilter(value):
model.addKeywords()
# Transcription Tab (Speaker)
def callbackSetSpeakerDevice(value):
print("callbackSetSpeakerDevice", value)
config.CHOICE_SPEAKER_DEVICE = value
# def callbackSetSpeakerDevice(value):
# print("callbackSetSpeakerDevice", value)
# config.CHOICE_SPEAKER_DEVICE = value
model.stopCheckSpeakerEnergy()
view.replaceSpeakerThresholdCheckButton_Passive()
# model.stopCheckSpeakerEnergy()
# view.replaceSpeakerThresholdCheckButton_Passive()
def callbackSetSpeakerEnergyThreshold(value):
print("callbackSetSpeakerEnergyThreshold", value)
@@ -630,12 +601,6 @@ def createMainWindow():
# init config
initSetLanguageAndCountry()
if model.authenticationTranslator(callbackSetAuthKeys) is False:
# error update Auth key
view.printToTextbox_AuthenticationError()
config.CHOICE_TRANSLATOR = model.findTranslationEngine(config.SOURCE_LANGUAGE, config.TARGET_LANGUAGE)
model.authenticationTranslator(callbackSetAuthKeys)
# set word filter
model.addKeywords()
@@ -693,9 +658,6 @@ def createMainWindow():
"callback_set_font_family": callbackSetFontFamily,
"callback_set_ui_language": callbackSetUiLanguage,
# Translation Tab
"callback_set_deepl_authkey": callbackSetDeeplAuthkey,
# Transcription Tab (Mic)
"callback_set_mic_host": callbackSetMicHost,
"list_mic_host": model.getListInputHost(),
@@ -710,7 +672,7 @@ def createMainWindow():
"callback_set_mic_word_filter": callbackSetMicWordFilter,
# Transcription Tab (Speaker)
"callback_set_speaker_device": callbackSetSpeakerDevice,
# "callback_set_speaker_device": callbackSetSpeakerDevice,
"list_speaker_device": model.getListOutputDevice(),
"callback_set_speaker_energy_threshold": callbackSetSpeakerEnergyThreshold,
"callback_set_speaker_dynamic_energy_threshold": callbackSetSpeakerDynamicEnergyThreshold,

View File

@@ -66,8 +66,8 @@ class Model:
self.mic_audio_recorder = None
self.mic_energy_recorder = None
self.mic_energy_plot_progressbar = None
self.spk_print_transcript = None
self.spk_audio_recorder = None
self.speaker_print_transcript = None
self.speaker_audio_recorder = None
self.speaker_energy_recorder = None
self.speaker_energy_plot_progressbar = None
self.translator = Translator()
@@ -81,22 +81,6 @@ class Model:
del self.keyword_processor
self.keyword_processor = KeywordProcessor()
def authenticationTranslator(self, fnc, choice_translator=None, auth_key=None):
if choice_translator == None:
choice_translator = config.CHOICE_TRANSLATOR
if auth_key == None:
auth_key = config.AUTH_KEYS[choice_translator]
result = self.translator.authentication(choice_translator, auth_key)
if result:
auth_keys = config.AUTH_KEYS
auth_keys[choice_translator] = auth_key
try:
fnc(auth_keys)
except:
pass
return result
def startLogger(self):
os_makedirs(os_path.join(os_path.dirname(sys.argv[0]), "logs"), exist_ok=True)
logger = getLogger()
@@ -137,17 +121,8 @@ class Model:
if source_lang in source_languages and target_lang in target_languages:
compatible_engines.append(engine)
engine_name = compatible_engines[0]
if engine_name == "DeepL(web)" and config.AUTH_KEYS["DeepL(auth)"] != None:
engine_name = "DeepL(auth)"
return engine_name
def getTranslatorStatus(self):
return self.translator.translator_status[config.CHOICE_TRANSLATOR]
def getListTranslatorName(self):
return list(self.translator.translator_status.keys())
def getInputTranslate(self, message):
try:
translation = self.translator.translate(
@@ -287,13 +262,6 @@ class Model:
def getListOutputDevice():
return [device["name"] for device in getOutputDevices()]
@staticmethod
def checkSpeakerStatus(choice=config.CHOICE_SPEAKER_DEVICE):
speaker_device = [device for device in getOutputDevices() if device["name"] == choice][0]
if getDefaultOutputDevice()["index"] == speaker_device["index"]:
return True
return False
def startMicTranscript(self, fnc):
if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice":
return
@@ -368,50 +336,53 @@ class Model:
self.mic_energy_recorder = None
def startSpeakerTranscript(self, fnc):
speaker_device = getDefaultOutputDevice()
config.CHOICE_SPEAKER_DEVICE = speaker_device["name"]
if config.CHOICE_SPEAKER_DEVICE == "NoDevice":
return
spk_audio_queue = Queue()
spk_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0]
speaker_audio_queue = Queue()
record_timeout = config.INPUT_SPEAKER_RECORD_TIMEOUT
phase_timeout = config.INPUT_SPEAKER_PHRASE_TIMEOUT
if record_timeout > phase_timeout:
record_timeout = phase_timeout
self.spk_audio_recorder = SelectedSpeakerRecorder(
device=spk_device,
self.speaker_audio_recorder = SelectedSpeakerRecorder(
device=speaker_device,
energy_threshold=config.INPUT_SPEAKER_ENERGY_THRESHOLD,
dynamic_energy_threshold=config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD,
record_timeout=record_timeout,
)
self.spk_audio_recorder.recordIntoQueue(spk_audio_queue)
spk_transcriber = AudioTranscriber(
self.speaker_audio_recorder.recordIntoQueue(speaker_audio_queue)
speaker_transcriber = AudioTranscriber(
speaker=True,
source=self.spk_audio_recorder.source,
source=self.speaker_audio_recorder.source,
phrase_timeout=phase_timeout,
max_phrases=config.INPUT_SPEAKER_MAX_PHRASES,
)
def sendSpkTranscript():
spk_transcriber.transcribeAudioQueue(spk_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY)
message = spk_transcriber.getTranscript()
def sendSpeakerTranscript():
speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY)
message = speaker_transcriber.getTranscript()
try:
fnc(message)
except:
pass
self.spk_print_transcript = threadFnc(sendSpkTranscript)
self.spk_print_transcript.daemon = True
self.spk_print_transcript.start()
self.speaker_print_transcript = threadFnc(sendSpeakerTranscript)
self.speaker_print_transcript.daemon = True
self.speaker_print_transcript.start()
def stopSpeakerTranscript(self):
if isinstance(self.spk_print_transcript, threadFnc):
self.spk_print_transcript.stop()
self.spk_print_transcript = None
if isinstance(self.spk_audio_recorder, SelectedSpeakerRecorder):
self.spk_audio_recorder.stop()
self.spk_audio_recorder = None
if isinstance(self.speaker_print_transcript, threadFnc):
self.speaker_print_transcript.stop()
self.speaker_print_transcript = None
if isinstance(self.speaker_audio_recorder, SelectedSpeakerRecorder):
self.speaker_audio_recorder.stop()
self.speaker_audio_recorder = None
def startCheckSpeakerEnergy(self, fnc, end_fnc):
speaker_device = getDefaultOutputDevice()
config.CHOICE_SPEAKER_DEVICE = speaker_device["name"]
if config.CHOICE_SPEAKER_DEVICE == "NoDevice":
return
@@ -424,7 +395,6 @@ class Model:
pass
# sleep(0.01)
speaker_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0]
speaker_energy_queue = Queue()
self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device)
self.speaker_energy_recorder.recordIntoQueue(speaker_energy_queue)

View File

@@ -1,6 +1,6 @@
translatorEngine = ["DeepL(web)", "DeepL(auth)", "Google(web)", "Bing(web)"]
translatorEngine = ["DeepL", "Google", "Bing"]
translation_lang = {}
dict_deepl_web_languages = {
dict_deepl_languages = {
"Japanese":"JA",
"English":"EN",
"Korean":"KO",
@@ -31,82 +31,12 @@ dict_deepl_web_languages = {
"Turkish":"TR",
"Norwegian":"NB",
}
translation_lang["DeepL(web)"] = {
"source":dict_deepl_web_languages,
"target":dict_deepl_web_languages,
translation_lang["DeepL"] = {
"source":dict_deepl_languages,
"target":dict_deepl_languages,
}
dict_deepl_auth_source_languages = {
"Japanese":"ja",
"English":"en",
"Bulgarian":"bg",
"Czech":"cs",
"Danish":"da",
"German":"de",
"Greek":"el",
"Spanish":"es",
"Estonian":"et",
"Finnish":"fi",
"French":"fr",
"Hungarian":"hu",
"Indonesian":"id",
"Italian":"it",
"Korean":"ko",
"Lithuanian":"lt",
"Latvian":"lv",
"Norwegian":"nb",
"Dutch":"nl",
"Polish":"pl",
"Portuguese":"pt",
"Romanian":"ro",
"Russian":"ru",
"Slovak":"sk",
"Slovenian":"sl",
"Swedish":"sv",
"Turkish":"tr",
"Ukrainian":"uk",
"Chinese":"zh"
}
dict_deepl_auth_target_languages = {
"Japanese":"ja",
"English American":"en-US",
"English British":"en-GB",
"Bulgarian":"bg",
"Czech":"cs",
"Danish":"da",
"German":"de",
"Greek":"el",
"English":"en",
"Spanish":"es",
"Estonian":"et",
"Finnish":"fi",
"French":"fr",
"Hungarian":"hu",
"Indonesian":"id",
"Italian":"it",
"Korean":"ko",
"Lithuanian":"lt",
"Latvian":"lv",
"Norwegian":"nb",
"Dutch":"nl",
"Polish":"pl",
"Portuguese Brazilian":"pt-BR",
"Portuguese European":"pt-PT",
"Romanian":"ro",
"Russian":"ru",
"Slovak":"sk",
"Slovenian":"sl",
"Swedish":"sv",
"Turkish":"tr",
"Ukrainian":"uk",
"Chinese":"zh"
}
translation_lang["DeepL(auth)"] = {
"source": dict_deepl_auth_source_languages,
"target": dict_deepl_auth_target_languages,
}
dict_google_web_languages = {
dict_google_languages = {
"Japanese":"ja",
"English":"en",
"Chinese":"zh",
@@ -170,12 +100,12 @@ dict_google_web_languages = {
"Basque":"eu",
"Irish":"ga"
}
translation_lang["Google(web)"] = {
"source":dict_google_web_languages,
"target":dict_google_web_languages,
translation_lang["Google"] = {
"source":dict_google_languages,
"target":dict_google_languages,
}
dict_bing_web_languages = {
dict_bing_languages = {
"Japanese":"ja",
"English":"en",
"Chinese":"zh",
@@ -237,7 +167,7 @@ dict_bing_web_languages = {
"Punjabi":"pa",
"Irish":"ga"
}
translation_lang["Bing(web)"] = {
"source":dict_bing_web_languages,
"target":dict_bing_web_languages,
translation_lang["Bing"] = {
"source":dict_bing_languages,
"target":dict_bing_languages,
}

View File

@@ -1,4 +1,3 @@
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 .translation_languages import translatorEngine, translation_lang
@@ -6,63 +5,34 @@ from .translation_languages import translatorEngine, translation_lang
# Translator
class Translator():
def __init__(self):
self.translator_status = {}
for translator in translatorEngine:
self.translator_status[translator] = False
self.deepl_client = None
def authentication(self, translator_name, authkey=None):
result = False
if translator_name == "DeepL(web)":
self.translator_status[translator_name] = True
result = True
elif translator_name == "DeepL(auth)":
try:
self.deepl_client = deepl_Translator(authkey)
self.deepl_client.translate_text(" ", target_lang="EN-US")
self.translator_status[translator_name] = True
result = True
except:
self.translator_status[translator_name] = False
elif translator_name == "Google(web)":
self.translator_status[translator_name] = True
result = True
elif translator_name == "Bing(web)":
self.translator_status[translator_name] = True
result = True
return result
pass
def translate(self, translator_name, source_language, target_language, message):
result = ""
try:
result = ""
source_language=translation_lang[translator_name]["source"][source_language]
target_language=translation_lang[translator_name]["target"][target_language]
if translator_name == "DeepL(web)":
result = deepl_web_Translator(
source_language=source_language,
target_language=target_language,
text=message
)
elif translator_name == "DeepL(auth)":
result = self.deepl_client.translate_text(
message,
source_lang=source_language,
target_lang=target_language,
).text
elif translator_name == "Google(web)":
result = other_web_Translator(
query_text=message,
translator="google",
from_language=source_language,
to_language=target_language,
)
elif translator_name == "Bing(web)":
result = other_web_Translator(
query_text=message,
translator="bing",
from_language=source_language,
to_language=target_language,
)
match translator_name:
case "DeepL":
result = deepl_web_Translator(
source_language=source_language,
target_language=target_language,
text=message
)
case "Google":
result = other_web_Translator(
query_text=message,
translator="google",
from_language=source_language,
to_language=target_language,
)
case "Bing":
result = other_web_Translator(
query_text=message,
translator="bing",
from_language=source_language,
to_language=target_language,
)
except:
pass
return result

View File

@@ -2,7 +2,6 @@ pillow == 10.0.0
PyAudioWPatch == 0.2.12.6
python-osc == 1.8.3
customtkinter == 5.2.0
deepl == 1.15.0
flashtext == 2.7
pyyaml == 6.0.1
python-i18n == 0.3.9

View File

@@ -197,7 +197,7 @@ class View():
VAR_LABEL_DEEPL_AUTH_KEY=StringVar(value=i18n.t("config_window.deepl_auth_key.label")),
VAR_DESC_DEEPL_AUTH_KEY=None,
CALLBACK_SET_DEEPL_AUTH_KEY=None,
VAR_DEEPL_AUTH_KEY=StringVar(value=config.AUTH_KEYS["DeepL(auth)"]),
VAR_DEEPL_AUTH_KEY=StringVar(value=""),
# Transcription Tab (Mic)