[Update] model.pyからprint_textboxをすべて引き剥がした。

UIの依存関係はなくなったはず
This commit is contained in:
misygauziya
2023-08-19 19:09:01 +09:00
parent e3a37c576c
commit 31e786f2a8
4 changed files with 184 additions and 143 deletions

187
VRCT.py
View File

@@ -56,8 +56,7 @@ class App(CTk):
# set translator
if model.authenticationTranslator() is False:
# error update Auth key
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")
self.printLogAuthenticationError()
# set word filter
model.addKeywords()
@@ -93,32 +92,27 @@ class App(CTk):
def checkbox_translation_callback(self):
config.ENABLE_TRANSLATION = self.checkbox_translation.get()
if config.ENABLE_TRANSLATION is True:
print_textbox(self.textbox_message_log, "Start translation", "INFO")
print_textbox(self.textbox_message_system_log, "Start translation", "INFO")
self.printLogStartTranslation()
else:
print_textbox(self.textbox_message_log, "Stop translation", "INFO")
print_textbox(self.textbox_message_system_log, "Stop translation", "INFO")
self.printLogStopTranslation()
def transcription_send_start(self):
model.startMicTranscript(self.textbox_message_log, self.textbox_message_send_log, self.textbox_message_system_log)
print_textbox(self.textbox_message_log, "Start voice2chatbox", "INFO")
print_textbox(self.textbox_message_system_log, "Start voice2chatbox", "INFO")
model.startMicTranscript(self.sendMicMessage)
self.printLogStartVoice2chatbox()
self.checkbox_transcription_send.configure(state="normal")
self.checkbox_transcription_receive.configure(state="normal")
self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"])
def transcription_send_stop(self):
model.stopMicTranscript()
print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO")
print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO")
self.printLogStopVoice2chatbox()
self.checkbox_transcription_send.configure(state="normal")
self.checkbox_transcription_receive.configure(state="normal")
self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"])
def transcription_send_stop_for_config(self):
model.stopMicTranscript()
print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO")
print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO")
self.printLogStopVoice2chatbox()
def checkbox_transcription_send_callback(self):
config.ENABLE_TRANSCRIPTION_SEND = self.checkbox_transcription_send.get()
@@ -135,25 +129,22 @@ class App(CTk):
th_transcription_send_stop.start()
def transcription_receive_start(self):
model.startSpeakerTranscript(self.textbox_message_log, self.textbox_message_receive_log, self.textbox_message_system_log)
print_textbox(self.textbox_message_log, "Start speaker2log", "INFO")
print_textbox(self.textbox_message_system_log, "Start speaker2log", "INFO")
model.startSpeakerTranscript(self.receiveSpeakerMessage)
self.printLogStartSpeaker2log()
self.checkbox_transcription_send.configure(state="normal")
self.checkbox_transcription_receive.configure(state="normal")
self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"])
def transcription_receive_stop(self):
model.stopSpeakerTranscript()
print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO")
print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO")
self.printLogStopSpeaker2log()
self.checkbox_transcription_send.configure(state="normal")
self.checkbox_transcription_receive.configure(state="normal")
self.button_config.configure(state="normal", fg_color=["#3B8ED0", "#1F6AA5"])
def transcription_receive_stop_for_config(self):
model.stopSpeakerTranscript()
print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO")
print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO")
self.printLogStopSpeaker2log()
def checkbox_transcription_receive_callback(self):
config.ENABLE_TRANSCRIPTION_RECEIVE = self.checkbox_transcription_receive.get()
@@ -194,24 +185,20 @@ class App(CTk):
config.ENABLE_FOREGROUND = self.checkbox_foreground.get()
if config.ENABLE_FOREGROUND:
self.attributes("-topmost", True)
print_textbox(self.textbox_message_log, "Start foreground", "INFO")
print_textbox(self.textbox_message_system_log, "Start foreground", "INFO")
self.printLogStartForeground()
else:
self.attributes("-topmost", False)
print_textbox(self.textbox_message_log, "Stop foreground", "INFO")
print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO")
self.printLogStopForeground()
def foreground_start(self):
if config.ENABLE_FOREGROUND:
self.attributes("-topmost", True)
print_textbox(self.textbox_message_log, "Start foreground", "INFO")
print_textbox(self.textbox_message_system_log, "Start foreground", "INFO")
self.printLogStartForeground()
def foreground_stop(self):
if config.ENABLE_FOREGROUND:
self.attributes("-topmost", False)
print_textbox(self.textbox_message_log, "Stop foreground", "INFO")
print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO")
self.printLogStopForeground()
def entry_message_box_press_key_enter(self, event):
# osc stop send typing
@@ -221,31 +208,7 @@ class App(CTk):
self.attributes("-topmost", True)
message = self.entry_message_box.get()
if len(message) > 0:
# translate
if config.ENABLE_TRANSLATION is False:
chat_message = f"{message}"
elif model.getTranslatorStatus() 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")
chat_message = f"{message}"
else:
chat_message = model.getInputTranslate(message)
# send OSC message
if config.ENABLE_OSC is True:
model.oscSendMessage(chat_message)
else:
print_textbox(self.textbox_message_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR")
print_textbox(self.textbox_message_system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR")
# update textbox message log
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
if config.ENABLE_AUTO_CLEAR_CHATBOX is True:
self.entry_message_box.delete(0, customtkinter.END)
self.sendChatMessage(message)
def entry_message_box_press_key_any(self, event):
# osc start send typing
@@ -405,6 +368,124 @@ class App(CTk):
widget_main_window_label_setter(self, language_yaml_data)
def printLogAuthenticationError(self):
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")
def printLogStartTranslation(self):
print_textbox(self.textbox_message_log, "Start translation", "INFO")
print_textbox(self.textbox_message_system_log, "Start translation", "INFO")
def printLogStopTranslation(self):
print_textbox(self.textbox_message_log, "Stop translation", "INFO")
print_textbox(self.textbox_message_system_log, "Stop translation", "INFO")
def printLogStartVoice2chatbox(self):
print_textbox(self.textbox_message_log, "Start voice2chatbox", "INFO")
print_textbox(self.textbox_message_system_log, "Start voice2chatbox", "INFO")
def printLogStopVoice2chatbox(self):
print_textbox(self.textbox_message_log, "Stop voice2chatbox", "INFO")
print_textbox(self.textbox_message_system_log, "Stop voice2chatbox", "INFO")
def printLogStartSpeaker2log(self):
print_textbox(self.textbox_message_log, "Start speaker2log", "INFO")
print_textbox(self.textbox_message_system_log, "Start speaker2log", "INFO")
def printLogStopSpeaker2log(self):
print_textbox(self.textbox_message_log, "Stop speaker2log", "INFO")
print_textbox(self.textbox_message_system_log, "Stop speaker2log", "INFO")
def printLogStartForeground(self):
print_textbox(self.textbox_message_log, "Start foreground", "INFO")
print_textbox(self.textbox_message_system_log, "Start foreground", "INFO")
def printLogStopForeground(self):
print_textbox(self.textbox_message_log, "Stop foreground", "INFO")
print_textbox(self.textbox_message_system_log, "Stop foreground", "INFO")
def printLogDetectWordFilter(self, message):
print_textbox(self.textbox_message_log, f"Detect WordFilter :{message}", "INFO")
print_textbox(self.textbox_message_system_log, f"Detect WordFilter :{message}", "INFO")
def printLogOSCError(self):
print_textbox(self.textbox_message_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR")
print_textbox(self.textbox_message_system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR")
def printLogSendMessage(self, message):
print_textbox(self.textbox_message_log, f"{message}", "SEND")
print_textbox(self.textbox_message_send_log, f"{message}", "SEND")
def printLogReceiveMessage(self, message):
print_textbox(self.textbox_message_log, f"{message}", "RECEIVE")
print_textbox(self.textbox_message_receive_log, f"{message}", "RECEIVE")
def sendChatMessage(self, message):
if len(message) > 0:
# translate
if config.ENABLE_TRANSLATION is False:
chat_message = f"{message}"
elif model.getTranslatorStatus() is False:
self.printLogAuthenticationError()
chat_message = f"{message}"
else:
chat_message = model.getInputTranslate(message)
# send OSC message
if config.ENABLE_OSC is True:
model.oscSendMessage(chat_message)
else:
self.printLogOSCError()
# update textbox message log
self.printLogSendMessage(chat_message)
# delete message in entry message box
if config.ENABLE_AUTO_CLEAR_CHATBOX is True:
self.entry_message_box.delete(0, customtkinter.END)
def sendMicMessage(self, message):
if len(message) > 0:
# word filter
if model.checkKeywords(message):
self.printLogDetectWordFilter(message)
return
# translate
if config.ENABLE_TRANSLATION is False:
voice_message = f"{message}"
elif model.getTranslatorStatus() is False:
self.printLogAuthenticationError()
voice_message = f"{message}"
else:
voice_message = model.getInputTranslate(message)
if config.ENABLE_TRANSCRIPTION_SEND is True:
if config.ENABLE_OSC is True:
# osc send message
model.oscSendMessage(voice_message)
else:
self.printLogOSCError()
# update textbox message log
self.printLogSendMessage(voice_message)
def receiveSpeakerMessage(self, message):
if len(message) > 0:
# translate
if config.ENABLE_TRANSLATION is False:
voice_message = f"{message}"
elif model.getTranslatorStatus() is False:
self.printLogAuthenticationError()
voice_message = f"{message}"
else:
voice_message = model.getOutputTranslate(message)
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
# update textbox message receive log
self.printLogReceiveMessage(voice_message)
if config.ENABLE_NOTICE_XSOVERLAY is True:
model.notificationXsoverlay(voice_message)
if __name__ == "__main__":
try:
app = App()

View File

@@ -1,13 +1,20 @@
from json import load, dump
import inspect
from os import path as os_path
from json import load as json_load
from json import dump as json_dump
import tkinter as tk
from tkinter import font
from utils import save_json
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
def saveJson(path, key, value):
with open(path, "r") as fp:
json_data = load(fp)
json_data[key] = value
with open(path, "w") as fp:
dump(json_data, fp, indent=4)
class Config:
_instance = None
@@ -70,7 +77,7 @@ class Config:
def TRANSPARENCY(self, value):
if type(value) is int and 0 <= value <= 100:
self._TRANSPARENCY = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def APPEARANCE_THEME(self):
@@ -80,7 +87,7 @@ class Config:
def APPEARANCE_THEME(self, value):
if value in ["Light", "Dark", "System"]:
self._APPEARANCE_THEME = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def UI_SCALING(self):
@@ -90,7 +97,7 @@ class Config:
def UI_SCALING(self, value):
if value in ["80%", "90%", "100%", "110%", "120%"]:
self._UI_SCALING = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def FONT_FAMILY(self):
@@ -102,7 +109,7 @@ class Config:
root.withdraw()
if value in list(font.families()):
self._FONT_FAMILY = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
root.destroy()
@property
@@ -113,7 +120,7 @@ class Config:
def UI_LANGUAGE(self, value):
if value in list(selectable_languages.keys()):
self._UI_LANGUAGE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_TRANSLATOR(self):
@@ -123,7 +130,7 @@ class Config:
def CHOICE_TRANSLATOR(self, value):
if value in translators:
self._CHOICE_TRANSLATOR = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SOURCE_LANG(self):
@@ -133,7 +140,7 @@ class Config:
def INPUT_SOURCE_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()):
self._INPUT_SOURCE_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_TARGET_LANG(self):
@@ -143,7 +150,7 @@ class Config:
def INPUT_TARGET_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()):
self._INPUT_TARGET_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OUTPUT_SOURCE_LANG(self):
@@ -153,7 +160,7 @@ class Config:
def OUTPUT_SOURCE_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys()):
self._OUTPUT_SOURCE_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OUTPUT_TARGET_LANG(self):
@@ -163,7 +170,7 @@ class Config:
def OUTPUT_TARGET_LANG(self, value):
if value in list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys()):
self._OUTPUT_TARGET_LANG = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_MIC_HOST(self):
@@ -173,7 +180,7 @@ class Config:
def CHOICE_MIC_HOST(self, value):
if value in [host for host in get_input_device_list().keys()]:
self._CHOICE_MIC_HOST = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_MIC_DEVICE(self):
@@ -183,7 +190,7 @@ class Config:
def CHOICE_MIC_DEVICE(self, value):
if value in [device["name"] for device in get_input_device_list()[self.CHOICE_MIC_HOST]]:
self._CHOICE_MIC_DEVICE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_VOICE_LANGUAGE(self):
@@ -193,7 +200,7 @@ class Config:
def INPUT_MIC_VOICE_LANGUAGE(self, value):
if value in list(transcription_lang.keys()):
self._INPUT_MIC_VOICE_LANGUAGE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_ENERGY_THRESHOLD(self):
@@ -203,7 +210,7 @@ class Config:
def INPUT_MIC_ENERGY_THRESHOLD(self, value):
if type(value) is int:
self._INPUT_MIC_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self):
@@ -213,7 +220,7 @@ class Config:
def INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD(self, value):
if type(value) is bool:
self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_RECORD_TIMEOUT(self):
@@ -223,7 +230,7 @@ class Config:
def INPUT_MIC_RECORD_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_MIC_RECORD_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_PHRASE_TIMEOUT(self):
@@ -233,7 +240,7 @@ class Config:
def INPUT_MIC_PHRASE_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_MIC_PHRASE_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_MAX_PHRASES(self):
@@ -243,7 +250,7 @@ class Config:
def INPUT_MIC_MAX_PHRASES(self, value):
if type(value) is int:
self._INPUT_MIC_MAX_PHRASES = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_MIC_WORD_FILTER(self):
@@ -253,7 +260,7 @@ class Config:
def INPUT_MIC_WORD_FILTER(self, value):
if type(value) is list:
self._INPUT_MIC_WORD_FILTER = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def CHOICE_SPEAKER_DEVICE(self):
@@ -265,7 +272,7 @@ class Config:
speaker_device = [device for device in get_output_device_list() if device["name"] == value][0]
if get_default_output_device()["index"] == speaker_device["index"]:
self._CHOICE_SPEAKER_DEVICE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_VOICE_LANGUAGE(self):
@@ -275,7 +282,7 @@ class Config:
def INPUT_SPEAKER_VOICE_LANGUAGE(self, value):
if value in list(transcription_lang.keys()):
self._INPUT_SPEAKER_VOICE_LANGUAGE = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_ENERGY_THRESHOLD(self):
@@ -285,7 +292,7 @@ class Config:
def INPUT_SPEAKER_ENERGY_THRESHOLD(self, value):
if type(value) is int:
self._INPUT_SPEAKER_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self):
@@ -295,7 +302,7 @@ class Config:
def INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD(self, value):
if type(value) is bool:
self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_RECORD_TIMEOUT(self):
@@ -305,7 +312,7 @@ class Config:
def INPUT_SPEAKER_RECORD_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_SPEAKER_RECORD_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_PHRASE_TIMEOUT(self):
@@ -315,7 +322,7 @@ class Config:
def INPUT_SPEAKER_PHRASE_TIMEOUT(self, value):
if type(value) is int:
self._INPUT_SPEAKER_PHRASE_TIMEOUT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def INPUT_SPEAKER_MAX_PHRASES(self):
@@ -325,7 +332,7 @@ class Config:
def INPUT_SPEAKER_MAX_PHRASES(self, value):
if type(value) is int:
self._INPUT_SPEAKER_MAX_PHRASES = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OSC_IP_ADDRESS(self):
@@ -335,7 +342,7 @@ class Config:
def OSC_IP_ADDRESS(self, value):
if type(value) is str:
self._OSC_IP_ADDRESS = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def OSC_PORT(self):
@@ -345,7 +352,7 @@ class Config:
def OSC_PORT(self, value):
if type(value) is int:
self._OSC_PORT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def AUTH_KEYS(self):
@@ -357,7 +364,7 @@ class Config:
for key, value in value.items():
if type(value) is str:
self._AUTH_KEYS[key] = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS)
@property
def MESSAGE_FORMAT(self):
@@ -367,7 +374,7 @@ class Config:
def MESSAGE_FORMAT(self, value):
if type(value) is str:
self._MESSAGE_FORMAT = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def ENABLE_AUTO_CLEAR_CHATBOX(self):
@@ -377,7 +384,7 @@ class Config:
def ENABLE_AUTO_CLEAR_CHATBOX(self, value):
if type(value) is bool:
self._ENABLE_AUTO_CLEAR_CHATBOX = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def ENABLE_NOTICE_XSOVERLAY(self):
@@ -387,7 +394,7 @@ class Config:
def ENABLE_NOTICE_XSOVERLAY(self, value):
if type(value) is bool:
self._ENABLE_NOTICE_XSOVERLAY = value
save_json(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value)
@property
def ENABLE_OSC(self):

View File

@@ -11,9 +11,9 @@ from audio_utils import get_input_device_list, get_output_device_list, get_defau
from audio_recorder import SelectedMicRecorder, SelectedSpeakerRecorder
from audio_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder
from audio_transcriber import AudioTranscriber
from utils import print_textbox, thread_fnc
from config import config
from notification import notification_xsoverlay_for_vrct
from utils import thread_fnc
from config import config
class Model:
_instance = None
@@ -141,7 +141,7 @@ class Model:
return True
return False
def startMicTranscript(self, log, send_log, system_log):
def startMicTranscript(self, fnc):
mic_audio_queue = Queue()
self.mic_audio_recorder = SelectedMicRecorder(
[device for device in get_input_device_list()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0],
@@ -159,33 +159,7 @@ class Model:
def mic_transcript_to_chatbox():
mic_transcriber.transcribe_audio_queue(mic_audio_queue, transcription_lang[config.INPUT_MIC_VOICE_LANGUAGE])
message = mic_transcriber.get_transcript()
if len(message) > 0:
# word filter
if self.checkKeywords(message):
print_textbox(log, f"Detect WordFilter :{message}", "INFO")
print_textbox(system_log, f"Detect WordFilter :{message}", "INFO")
return
# translate
if config.ENABLE_TRANSLATION is False:
voice_message = f"{message}"
elif self.getTranslatorStatus() is False:
print_textbox(log, "Auth Key or language setting is incorrect", "ERROR")
print_textbox(system_log, "Auth Key or language setting is incorrect", "ERROR")
voice_message = f"{message}"
else:
voice_message = self.getInputTranslate(message)
if config.ENABLE_TRANSCRIPTION_SEND is True:
if config.ENABLE_OSC is True:
# osc send message
model.oscSendMessage(voice_message)
else:
print_textbox(log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR")
print_textbox(system_log, "OSC is not enabled, please enable OSC and rejoin.", "ERROR")
# update textbox message log
print_textbox(log, f"{voice_message}", "SEND")
print_textbox(send_log, f"{voice_message}", "SEND")
fnc(message)
self.mic_print_transcript = thread_fnc(mic_transcript_to_chatbox)
self.mic_print_transcript.daemon = True
@@ -221,7 +195,7 @@ class Model:
if self.mic_energy_plot_progressbar != None:
self.mic_energy_plot_progressbar.stop()
def startSpeakerTranscript(self, log, receive_log, system_log):
def startSpeakerTranscript(self, fnc):
spk_audio_queue = Queue()
spk_device = [device for device in get_output_device_list() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0]
self.spk_audio_recorder = SelectedSpeakerRecorder(
@@ -240,23 +214,7 @@ class Model:
def spk_transcript_to_textbox():
spk_transcriber.transcribe_audio_queue(spk_audio_queue, transcription_lang[config.INPUT_SPEAKER_VOICE_LANGUAGE])
message = spk_transcriber.get_transcript()
if len(message) > 0:
# translate
if config.ENABLE_TRANSLATION is False:
voice_message = f"{message}"
elif model.getTranslatorStatus() is False:
print_textbox(log, "Auth Key or language setting is incorrect", "ERROR")
print_textbox(system_log, "Auth Key or language setting is incorrect", "ERROR")
voice_message = f"{message}"
else:
voice_message = model.getOutputTranslate(message)
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
# update textbox message receive log
print_textbox(log, f"{voice_message}", "RECEIVE")
print_textbox(receive_log, f"{voice_message}", "RECEIVE")
if config.ENABLE_NOTICE_XSOVERLAY is True:
notification_xsoverlay_for_vrct(content=f"{voice_message}")
fnc(message)
self.spk_print_transcript = thread_fnc(spk_transcript_to_textbox)
self.spk_print_transcript.daemon = True
@@ -300,4 +258,7 @@ class Model:
if self.speaker_energy_plot_progressbar != None:
self.speaker_energy_plot_progressbar.stop()
def notificationXsoverlay(self, message):
notification_xsoverlay_for_vrct(content=f"{message}")
model = Model()

View File

@@ -1,16 +1,8 @@
from json import load, dump
from os import path as os_path
import yaml
from datetime import datetime
from threading import Thread, Event
def save_json(path, key, value):
with open(path, "r") as fp:
json_data = load(fp)
json_data[key] = value
with open(path, "w") as fp:
dump(json_data, fp, indent=4)
def print_textbox(textbox, message, tags=None):
now = datetime.now()
now = now.strftime('%H:%M:%S')
@@ -58,7 +50,7 @@ def get_localized_text(language):
return localized_text
else:
return None
def get_key_by_value(dictionary, value):
for key, val in dictionary.items():
if val == value: