🚧[WIP/TEST] Main: webuiのためのmain実装途中#4
This commit is contained in:
8
model.py
8
model.py
@@ -389,15 +389,11 @@ class Model:
|
|||||||
def getListOutputDevice():
|
def getListOutputDevice():
|
||||||
return [device["name"] for device in getOutputDevices()]
|
return [device["name"] for device in getOutputDevices()]
|
||||||
|
|
||||||
def startMicTranscript(self, fnc, error_fnc=None):
|
def startMicTranscript(self, fnc):
|
||||||
mic_device_list = getInputDevices().get(config.CHOICE_MIC_HOST, [{"name": "NoDevice"}])
|
mic_device_list = getInputDevices().get(config.CHOICE_MIC_HOST, [{"name": "NoDevice"}])
|
||||||
choice_mic_device = [device for device in mic_device_list if device["name"] == config.CHOICE_MIC_DEVICE]
|
choice_mic_device = [device for device in mic_device_list if device["name"] == config.CHOICE_MIC_DEVICE]
|
||||||
if len(choice_mic_device) == 0:
|
if len(choice_mic_device) == 0:
|
||||||
try:
|
return False
|
||||||
error_fnc()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
return
|
|
||||||
|
|
||||||
self.mic_audio_queue = Queue()
|
self.mic_audio_queue = Queue()
|
||||||
# self.mic_energy_queue = Queue()
|
# self.mic_energy_queue = Queue()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Callable
|
from typing import Callable, Union
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from subprocess import Popen
|
from subprocess import Popen
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@@ -71,47 +71,54 @@ def changeToCTranslate2Process():
|
|||||||
view.printToTextbox_TranslationEngineLimitError()
|
view.printToTextbox_TranslationEngineLimitError()
|
||||||
|
|
||||||
# func transcription send message
|
# func transcription send message
|
||||||
def sendMicMessage(message:str, action:Callable[[dict], None]) -> None:
|
class MicMessage:
|
||||||
if len(message) > 0:
|
def __init__(self, action:Callable[[dict], None]) -> None:
|
||||||
addSentMessageLog(message)
|
self.action = action
|
||||||
translation = ""
|
|
||||||
if model.checkKeywords(message):
|
|
||||||
action({"status":"error", f"message":"Detected by word filter:{message}"})
|
|
||||||
return
|
|
||||||
elif model.detectRepeatSendMessage(message):
|
|
||||||
return
|
|
||||||
elif config.ENABLE_TRANSLATION is False:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
translation, success = model.getInputTranslate(message)
|
|
||||||
if success is False:
|
|
||||||
changeToCTranslate2Process()
|
|
||||||
|
|
||||||
if config.ENABLE_TRANSCRIPTION_SEND is True:
|
def send(self, message: Union[str, bool]) -> None:
|
||||||
if config.ENABLE_SEND_MESSAGE_TO_VRC is True:
|
if isinstance(message, bool) and message is False:
|
||||||
if config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES is True:
|
self.action({"status":"error", "message":"No mic device detected."})
|
||||||
if config.ENABLE_TRANSLATION is False:
|
elif isinstance(message, str) and len(message) > 0:
|
||||||
osc_message = messageFormatter("SEND", "", message)
|
addSentMessageLog(message)
|
||||||
|
translation = ""
|
||||||
|
if model.checkKeywords(message):
|
||||||
|
self.action({"status":"error", f"message":"Detected by word filter:{message}"})
|
||||||
|
return
|
||||||
|
elif model.detectRepeatSendMessage(message):
|
||||||
|
return
|
||||||
|
elif config.ENABLE_TRANSLATION is False:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
translation, success = model.getInputTranslate(message)
|
||||||
|
if success is False:
|
||||||
|
changeToCTranslate2Process()
|
||||||
|
|
||||||
|
if config.ENABLE_TRANSCRIPTION_SEND is True:
|
||||||
|
if config.ENABLE_SEND_MESSAGE_TO_VRC is True:
|
||||||
|
if config.ENABLE_SEND_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
|
if config.ENABLE_TRANSLATION is False:
|
||||||
|
osc_message = messageFormatter("SEND", "", message)
|
||||||
|
else:
|
||||||
|
osc_message = messageFormatter("SEND", "", translation)
|
||||||
else:
|
else:
|
||||||
osc_message = messageFormatter("SEND", "", translation)
|
osc_message = messageFormatter("SEND", translation, message)
|
||||||
else:
|
model.oscSendMessage(osc_message)
|
||||||
osc_message = messageFormatter("SEND", translation, message)
|
|
||||||
model.oscSendMessage(osc_message)
|
|
||||||
|
|
||||||
action({"status":"success", "message":message, "translation":translation})
|
self.action({"status":"success", "message":message, "translation":translation})
|
||||||
if config.ENABLE_LOGGER is True:
|
if config.ENABLE_LOGGER is True:
|
||||||
if len(translation) > 0:
|
if len(translation) > 0:
|
||||||
translation = f" ({translation})"
|
translation = f" ({translation})"
|
||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
# if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
# if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
||||||
# overlay_image = model.createOverlayImageShort(message, translation)
|
# overlay_image = model.createOverlayImageShort(message, translation)
|
||||||
# model.updateOverlay(overlay_image)
|
# model.updateOverlay(overlay_image)
|
||||||
# overlay_image = model.createOverlayImageLong("send", message, translation)
|
# overlay_image = model.createOverlayImageLong("send", message, translation)
|
||||||
# model.updateOverlay(overlay_image)
|
# model.updateOverlay(overlay_image)
|
||||||
|
|
||||||
def startTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
|
def startTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
|
||||||
model.startMicTranscript(sendMicMessage, action)
|
mic_message = MicMessage(action)
|
||||||
|
model.startMicTranscript(mic_message.send)
|
||||||
|
|
||||||
def stopTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
|
def stopTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
|
||||||
model.stopMicTranscript()
|
model.stopMicTranscript()
|
||||||
@@ -122,8 +129,7 @@ def startThreadingTranscriptionSendMessage(action:Callable[[dict], None]) -> Non
|
|||||||
th_startTranscriptionSendMessage.daemon = True
|
th_startTranscriptionSendMessage.daemon = True
|
||||||
th_startTranscriptionSendMessage.start()
|
th_startTranscriptionSendMessage.start()
|
||||||
|
|
||||||
def stopThreadingTranscriptionSendMessage(action:Callable[[dict], None]):
|
def stopThreadingTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
|
||||||
view.printToTextbox_disableTranscriptionSend()
|
|
||||||
th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessage, args=(action,))
|
th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessage, args=(action,))
|
||||||
th_stopTranscriptionSendMessage.daemon = True
|
th_stopTranscriptionSendMessage.daemon = True
|
||||||
th_stopTranscriptionSendMessage.start()
|
th_stopTranscriptionSendMessage.start()
|
||||||
@@ -145,62 +151,66 @@ def stopThreadingTranscriptionSendMessageOnOpenConfigWindow():
|
|||||||
th_stopTranscriptionSendMessage.start()
|
th_stopTranscriptionSendMessage.start()
|
||||||
|
|
||||||
# func transcription receive message
|
# func transcription receive message
|
||||||
def receiveSpeakerMessage(message):
|
class SpeakerMessage:
|
||||||
if len(message) > 0:
|
def __init__(self, action:Callable[[dict], None]) -> None:
|
||||||
translation = ""
|
self.action = action
|
||||||
if model.detectRepeatReceiveMessage(message):
|
|
||||||
return
|
|
||||||
elif config.ENABLE_TRANSLATION is False:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
translation, success = model.getOutputTranslate(message)
|
|
||||||
if success is False:
|
|
||||||
changeToCTranslate2Process()
|
|
||||||
|
|
||||||
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
def receive(self, message):
|
||||||
if config.ENABLE_NOTICE_XSOVERLAY is True:
|
if isinstance(message, bool) and message is False:
|
||||||
xsoverlay_message = messageFormatter("RECEIVED", translation, message)
|
self.action({"status":"error", "message":"No mic device detected."})
|
||||||
model.notificationXSOverlay(xsoverlay_message)
|
elif isinstance(message, str) and len(message) > 0:
|
||||||
|
translation = ""
|
||||||
|
if model.detectRepeatReceiveMessage(message):
|
||||||
|
return
|
||||||
|
elif config.ENABLE_TRANSLATION is False:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
translation, success = model.getOutputTranslate(message)
|
||||||
|
if success is False:
|
||||||
|
changeToCTranslate2Process()
|
||||||
|
|
||||||
if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
||||||
if model.overlay.initialized is True:
|
if config.ENABLE_NOTICE_XSOVERLAY is True:
|
||||||
overlay_image = model.createOverlayImageShort(message, translation)
|
xsoverlay_message = messageFormatter("RECEIVED", translation, message)
|
||||||
model.updateOverlay(overlay_image)
|
model.notificationXSOverlay(xsoverlay_message)
|
||||||
# overlay_image = model.createOverlayImageLong("receive", message, translation)
|
|
||||||
# model.updateOverlay(overlay_image)
|
|
||||||
|
|
||||||
# ------------Speaker2Chatbox------------
|
if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
||||||
if config.ENABLE_SPEAKER2CHATBOX is True:
|
if model.overlay.initialized is True:
|
||||||
# send OSC message
|
overlay_image = model.createOverlayImageShort(message, translation)
|
||||||
if config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
model.updateOverlay(overlay_image)
|
||||||
osc_message = messageFormatter("RECEIVED", translation, message)
|
# overlay_image = model.createOverlayImageLong("receive", message, translation)
|
||||||
model.oscSendMessage(osc_message)
|
# model.updateOverlay(overlay_image)
|
||||||
# ------------Speaker2Chatbox------------
|
|
||||||
|
|
||||||
# update textbox message log (Received)
|
# ------------Speaker2Chatbox------------
|
||||||
view.printToTextbox_ReceivedMessage(message, translation)
|
if config.ENABLE_SPEAKER2CHATBOX is True:
|
||||||
if config.ENABLE_LOGGER is True:
|
# send OSC message
|
||||||
if len(translation) > 0:
|
if config.ENABLE_SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
||||||
translation = f" ({translation})"
|
osc_message = messageFormatter("RECEIVED", translation, message)
|
||||||
model.logger.info(f"[RECEIVED] {message}{translation}")
|
model.oscSendMessage(osc_message)
|
||||||
|
# ------------Speaker2Chatbox------------
|
||||||
|
|
||||||
def startTranscriptionReceiveMessage():
|
# update textbox message log (Received)
|
||||||
model.startSpeakerTranscript(receiveSpeakerMessage, view.printToTextbox_TranscriptionReceiveNoDeviceError)
|
self.action({"status":"success", "message":message, "translation":translation})
|
||||||
view.setMainWindowAllWidgetsStatusToNormal()
|
if config.ENABLE_LOGGER is True:
|
||||||
|
if len(translation) > 0:
|
||||||
|
translation = f" ({translation})"
|
||||||
|
model.logger.info(f"[RECEIVED] {message}{translation}")
|
||||||
|
|
||||||
def stopTranscriptionReceiveMessage():
|
def startTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None:
|
||||||
|
speaker_message = SpeakerMessage(action)
|
||||||
|
model.startSpeakerTranscript(speaker_message.receive)
|
||||||
|
|
||||||
|
def stopTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None:
|
||||||
model.stopSpeakerTranscript()
|
model.stopSpeakerTranscript()
|
||||||
view.setMainWindowAllWidgetsStatusToNormal()
|
action({"status":"success", "message":"Stopped receiving messages"})
|
||||||
|
|
||||||
def startThreadingTranscriptionReceiveMessage():
|
def startThreadingTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None:
|
||||||
view.printToTextbox_enableTranscriptionReceive()
|
th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage, args=(action,))
|
||||||
th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessage)
|
|
||||||
th_startTranscriptionReceiveMessage.daemon = True
|
th_startTranscriptionReceiveMessage.daemon = True
|
||||||
th_startTranscriptionReceiveMessage.start()
|
th_startTranscriptionReceiveMessage.start()
|
||||||
|
|
||||||
def stopThreadingTranscriptionReceiveMessage():
|
def stopThreadingTranscriptionReceiveMessage(action:Callable[[dict], None]) -> None:
|
||||||
view.printToTextbox_disableTranscriptionReceive()
|
th_stopTranscriptionReceiveMessage = Thread(target=stopTranscriptionReceiveMessage, args=(action,))
|
||||||
th_stopTranscriptionReceiveMessage = Thread(target=stopTranscriptionReceiveMessage)
|
|
||||||
th_stopTranscriptionReceiveMessage.daemon = True
|
th_stopTranscriptionReceiveMessage.daemon = True
|
||||||
th_stopTranscriptionReceiveMessage.start()
|
th_stopTranscriptionReceiveMessage.start()
|
||||||
|
|
||||||
@@ -419,45 +429,45 @@ def callbackDisableTranscriptionSend(data, action, *args, **kwargs) -> dict:
|
|||||||
stopThreadingTranscriptionSendMessage(action)
|
stopThreadingTranscriptionSendMessage(action)
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackEnableTranscriptionReceive():
|
def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict:
|
||||||
config.ENABLE_TRANSCRIPTION_RECEIVE = True
|
config.ENABLE_TRANSCRIPTION_RECEIVE = True
|
||||||
startThreadingTranscriptionReceiveMessage()
|
startThreadingTranscriptionReceiveMessage(action)
|
||||||
|
|
||||||
if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
if config.ENABLE_OVERLAY_SMALL_LOG is True:
|
||||||
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
|
if model.overlay.initialized is False and model.overlay.checkSteamvrRunning() is True:
|
||||||
model.startOverlay()
|
model.startOverlay()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackDisableTranscriptionReceive():
|
def callbackDisableTranscriptionReceive(data, action, *args, **kwargs) -> dict:
|
||||||
config.ENABLE_TRANSCRIPTION_RECEIVE = False
|
config.ENABLE_TRANSCRIPTION_RECEIVE = False
|
||||||
stopThreadingTranscriptionReceiveMessage()
|
stopThreadingTranscriptionReceiveMessage(action)
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackEnableForeground():
|
def callbackEnableForeground() -> None:
|
||||||
config.ENABLE_FOREGROUND = True
|
config.ENABLE_FOREGROUND = True
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackDisableForeground():
|
def callbackDisableForeground() -> None:
|
||||||
config.ENABLE_FOREGROUND = False
|
config.ENABLE_FOREGROUND = False
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackEnableMainWindowSidebarCompactMode():
|
def callbackEnableMainWindowSidebarCompactMode() -> None:
|
||||||
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True
|
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackDisableMainWindowSidebarCompactMode():
|
def callbackDisableMainWindowSidebarCompactMode() -> None:
|
||||||
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False
|
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
# Config Window
|
# Config Window
|
||||||
def callbackOpenConfigWindow():
|
def callbackOpenConfigWindow() -> dict:
|
||||||
if config.ENABLE_TRANSCRIPTION_SEND is True:
|
if config.ENABLE_TRANSCRIPTION_SEND is True:
|
||||||
stopThreadingTranscriptionSendMessageOnOpenConfigWindow()
|
stopThreadingTranscriptionSendMessageOnOpenConfigWindow()
|
||||||
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
|
||||||
stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow()
|
stopThreadingTranscriptionReceiveMessageOnOpenConfigWindow()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackCloseConfigWindow():
|
def callbackCloseConfigWindow() -> dict:
|
||||||
model.stopCheckMicEnergy()
|
model.stopCheckMicEnergy()
|
||||||
model.stopCheckSpeakerEnergy()
|
model.stopCheckSpeakerEnergy()
|
||||||
|
|
||||||
@@ -470,63 +480,63 @@ def callbackCloseConfigWindow():
|
|||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
# Compact Mode Switch
|
# Compact Mode Switch
|
||||||
def callbackEnableConfigWindowCompactMode():
|
def callbackEnableConfigWindowCompactMode() -> dict:
|
||||||
config.IS_CONFIG_WINDOW_COMPACT_MODE = True
|
config.IS_CONFIG_WINDOW_COMPACT_MODE = True
|
||||||
model.stopCheckMicEnergy()
|
model.stopCheckMicEnergy()
|
||||||
model.stopCheckSpeakerEnergy()
|
model.stopCheckSpeakerEnergy()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackDisableConfigWindowCompactMode():
|
def callbackDisableConfigWindowCompactMode() -> dict:
|
||||||
config.IS_CONFIG_WINDOW_COMPACT_MODE = False
|
config.IS_CONFIG_WINDOW_COMPACT_MODE = False
|
||||||
model.stopCheckMicEnergy()
|
model.stopCheckMicEnergy()
|
||||||
model.stopCheckSpeakerEnergy()
|
model.stopCheckSpeakerEnergy()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
# Appearance Tab
|
# Appearance Tab
|
||||||
def callbackSetTransparency(value):
|
def callbackSetTransparency(value) -> dict:
|
||||||
print("callbackSetTransparency", int(value))
|
print("callbackSetTransparency", int(value))
|
||||||
config.TRANSPARENCY = int(value)
|
config.TRANSPARENCY = int(value)
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetAppearance(value):
|
def callbackSetAppearance(value) -> dict:
|
||||||
print("callbackSetAppearance", value)
|
print("callbackSetAppearance", value)
|
||||||
config.APPEARANCE_THEME = value
|
config.APPEARANCE_THEME = value
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetUiScaling(value):
|
def callbackSetUiScaling(value) -> dict:
|
||||||
print("callbackSetUiScaling", value)
|
print("callbackSetUiScaling", value)
|
||||||
config.UI_SCALING = value
|
config.UI_SCALING = value
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetTextboxUiScaling(value):
|
def callbackSetTextboxUiScaling(value) -> dict:
|
||||||
print("callbackSetTextboxUiScaling", int(value))
|
print("callbackSetTextboxUiScaling", int(value))
|
||||||
config.TEXTBOX_UI_SCALING = int(value)
|
config.TEXTBOX_UI_SCALING = int(value)
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetMessageBoxRatio(value):
|
def callbackSetMessageBoxRatio(value) -> dict:
|
||||||
print("callbackSetMessageBoxRatio", int(value))
|
print("callbackSetMessageBoxRatio", int(value))
|
||||||
config.MESSAGE_BOX_RATIO = int(value)
|
config.MESSAGE_BOX_RATIO = int(value)
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetFontFamily(value):
|
def callbackSetFontFamily(value) -> dict:
|
||||||
print("callbackSetFontFamily", value)
|
print("callbackSetFontFamily", value)
|
||||||
config.FONT_FAMILY = value
|
config.FONT_FAMILY = value
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetUiLanguage(value):
|
def callbackSetUiLanguage(value) -> dict:
|
||||||
print("callbackSetUiLanguage", value)
|
print("callbackSetUiLanguage", value)
|
||||||
value = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, value)
|
value = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, value)
|
||||||
print("callbackSetUiLanguage__after_getKeyByValue", value)
|
print("callbackSetUiLanguage__after_getKeyByValue", value)
|
||||||
config.UI_LANGUAGE = value
|
config.UI_LANGUAGE = value
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetEnableRestoreMainWindowGeometry(value):
|
def callbackSetEnableRestoreMainWindowGeometry(value) -> dict:
|
||||||
print("callbackSetEnableRestoreMainWindowGeometry", value)
|
print("callbackSetEnableRestoreMainWindowGeometry", value)
|
||||||
config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value
|
config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
# Translation Tab
|
# Translation Tab
|
||||||
def callbackSetUseTranslationFeature(value):
|
def callbackSetUseTranslationFeature(value) -> dict:
|
||||||
print("callbackSetUseTranslationFeature", value)
|
print("callbackSetUseTranslationFeature", value)
|
||||||
config.USE_TRANSLATION_FEATURE = value
|
config.USE_TRANSLATION_FEATURE = value
|
||||||
if config.USE_TRANSLATION_FEATURE is True:
|
if config.USE_TRANSLATION_FEATURE is True:
|
||||||
@@ -543,7 +553,7 @@ def callbackSetUseTranslationFeature(value):
|
|||||||
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
|
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetCtranslate2WeightType(value):
|
def callbackSetCtranslate2WeightType(value) -> dict:
|
||||||
print("callbackSetCtranslate2WeightType", value)
|
print("callbackSetCtranslate2WeightType", value)
|
||||||
config.CTRANSLATE2_WEIGHT_TYPE = str(value)
|
config.CTRANSLATE2_WEIGHT_TYPE = str(value)
|
||||||
if model.checkCTranslatorCTranslate2ModelWeight():
|
if model.checkCTranslatorCTranslate2ModelWeight():
|
||||||
@@ -557,7 +567,7 @@ def callbackSetCtranslate2WeightType(value):
|
|||||||
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True
|
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetDeeplAuthKey(value):
|
def callbackSetDeeplAuthKey(value) -> dict:
|
||||||
status = "error"
|
status = "error"
|
||||||
print("callbackSetDeeplAuthKey", str(value))
|
print("callbackSetDeeplAuthKey", str(value))
|
||||||
if len(value) == 36 or len(value) == 39:
|
if len(value) == 36 or len(value) == 39:
|
||||||
@@ -573,7 +583,7 @@ def callbackSetDeeplAuthKey(value):
|
|||||||
updateTranslationEngineAndEngineList()
|
updateTranslationEngineAndEngineList()
|
||||||
return {"status":status}
|
return {"status":status}
|
||||||
|
|
||||||
def callbackClearDeeplAuthKey():
|
def callbackClearDeeplAuthKey() -> dict:
|
||||||
auth_keys = config.AUTH_KEYS
|
auth_keys = config.AUTH_KEYS
|
||||||
auth_keys["DeepL_API"] = None
|
auth_keys["DeepL_API"] = None
|
||||||
config.AUTH_KEYS = auth_keys
|
config.AUTH_KEYS = auth_keys
|
||||||
@@ -582,92 +592,94 @@ def callbackClearDeeplAuthKey():
|
|||||||
|
|
||||||
# Transcription Tab
|
# Transcription Tab
|
||||||
# Transcription (Mic)
|
# Transcription (Mic)
|
||||||
def callbackSetMicHost(value):
|
def callbackSetMicHost(value) -> dict:
|
||||||
print("callbackSetMicHost", value)
|
print("callbackSetMicHost", value)
|
||||||
config.CHOICE_MIC_HOST = value
|
config.CHOICE_MIC_HOST = value
|
||||||
config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice()
|
config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice()
|
||||||
model.stopCheckMicEnergy()
|
model.stopCheckMicEnergy()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetMicDevice(value):
|
def callbackSetMicDevice(value) -> dict:
|
||||||
print("callbackSetMicDevice", value)
|
print("callbackSetMicDevice", value)
|
||||||
config.CHOICE_MIC_DEVICE = value
|
config.CHOICE_MIC_DEVICE = value
|
||||||
model.stopCheckMicEnergy()
|
model.stopCheckMicEnergy()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetMicEnergyThreshold(value):
|
def callbackSetMicEnergyThreshold(value) -> dict:
|
||||||
status = "error"
|
status = "error"
|
||||||
print("callbackSetMicEnergyThreshold", value)
|
print("callbackSetMicEnergyThreshold", value)
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if 0 <= value <= config.MAX_MIC_ENERGY_THRESHOLD:
|
if 0 <= value <= config.MAX_MIC_ENERGY_THRESHOLD:
|
||||||
config.INPUT_MIC_ENERGY_THRESHOLD = value
|
config.INPUT_MIC_ENERGY_THRESHOLD = value
|
||||||
status = "success"
|
status = "success"
|
||||||
return {"status":status}
|
return {"status": status}
|
||||||
|
|
||||||
def callbackSetMicDynamicEnergyThreshold(value):
|
def callbackSetMicDynamicEnergyThreshold(value) -> dict:
|
||||||
print("callbackSetMicDynamicEnergyThreshold", value)
|
print("callbackSetMicDynamicEnergyThreshold", value)
|
||||||
config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value
|
config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def setProgressBarMicEnergy(energy):
|
class ProgressBarMicEnergy:
|
||||||
|
def __init__(self, action):
|
||||||
|
self.action = action
|
||||||
|
|
||||||
def callbackEnableCheckMicThreshold():
|
def set(self, energy) -> None:
|
||||||
|
self.action({"status":"success", "energy":energy})
|
||||||
|
|
||||||
|
def callbackEnableCheckMicThreshold(data, action, *args, **kwargs) -> dict:
|
||||||
print("callbackEnableCheckMicThreshold")
|
print("callbackEnableCheckMicThreshold")
|
||||||
model.startCheckMicEnergy(setProgressBarMicEnergy)
|
progressbar_mic_energy = ProgressBarMicEnergy(action)
|
||||||
|
model.startCheckMicEnergy(progressbar_mic_energy.set)
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackDisableCheckMicThreshold():
|
def callbackDisableCheckMicThreshold() -> dict:
|
||||||
print("callbackDisableCheckMicThreshold")
|
print("callbackDisableCheckMicThreshold")
|
||||||
model.stopCheckMicEnergy()
|
model.stopCheckMicEnergy()
|
||||||
return {"status":"success"}
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetMicRecordTimeout(value):
|
def callbackSetMicRecordTimeout(value) -> dict:
|
||||||
print("callbackSetMicRecordTimeout", value)
|
print("callbackSetMicRecordTimeout", value)
|
||||||
if value == "":
|
response = {"status":"success"}
|
||||||
return
|
if value != "":
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if 0 <= value and value <= config.INPUT_MIC_PHRASE_TIMEOUT:
|
if 0 <= value <= config.INPUT_MIC_PHRASE_TIMEOUT:
|
||||||
view.clearNotificationMessage()
|
config.INPUT_MIC_RECORD_TIMEOUT = value
|
||||||
config.INPUT_MIC_RECORD_TIMEOUT = value
|
else:
|
||||||
view.setGuiVariable_MicRecordTimeout(config.INPUT_MIC_RECORD_TIMEOUT)
|
raise ValueError()
|
||||||
else:
|
except Exception:
|
||||||
raise ValueError()
|
response = {"status":"error", "message":"Error Mic Record Timeout"}
|
||||||
except Exception:
|
return response
|
||||||
view.showErrorMessage_MicRecordTimeout()
|
|
||||||
|
|
||||||
def callbackSetMicPhraseTimeout(value):
|
def callbackSetMicPhraseTimeout(value) -> dict:
|
||||||
print("callbackSetMicPhraseTimeout", value)
|
print("callbackSetMicPhraseTimeout", value)
|
||||||
if value == "":
|
response = {"status":"success"}
|
||||||
return
|
if value != "":
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if 0 <= value and value >= config.INPUT_MIC_RECORD_TIMEOUT:
|
if value >= config.INPUT_MIC_RECORD_TIMEOUT:
|
||||||
view.clearNotificationMessage()
|
config.INPUT_MIC_PHRASE_TIMEOUT = value
|
||||||
config.INPUT_MIC_PHRASE_TIMEOUT = value
|
else:
|
||||||
view.setGuiVariable_MicPhraseTimeout(config.INPUT_MIC_PHRASE_TIMEOUT)
|
raise ValueError()
|
||||||
else:
|
except Exception:
|
||||||
raise ValueError()
|
response = {"status":"error", "message":"Error Mic Phrase Timeout"}
|
||||||
except Exception:
|
return response
|
||||||
view.showErrorMessage_MicPhraseTimeout()
|
|
||||||
|
|
||||||
def callbackSetMicMaxPhrases(value):
|
def callbackSetMicMaxPhrases(value) -> dict:
|
||||||
print("callbackSetMicMaxPhrases", value)
|
print("callbackSetMicMaxPhrases", value)
|
||||||
if value == "":
|
response = {"status":"success"}
|
||||||
return
|
if value != "":
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if 0 <= value:
|
if 0 <= value:
|
||||||
view.clearNotificationMessage()
|
config.INPUT_MIC_MAX_PHRASES = value
|
||||||
config.INPUT_MIC_MAX_PHRASES = value
|
else:
|
||||||
view.setGuiVariable_MicMaxPhrases(config.INPUT_MIC_MAX_PHRASES)
|
raise ValueError()
|
||||||
else:
|
except Exception:
|
||||||
raise ValueError()
|
response = {"status":"error", "message":"Error Mic Max Phrases"}
|
||||||
except Exception:
|
return response
|
||||||
view.showErrorMessage_MicMaxPhrases()
|
|
||||||
|
|
||||||
def callbackSetMicWordFilter(values):
|
def callbackSetMicWordFilter(values) -> dict:
|
||||||
print("callbackSetMicWordFilter", values)
|
print("callbackSetMicWordFilter", values)
|
||||||
values = str(values)
|
values = str(values)
|
||||||
values = [w.strip() for w in values.split(",") if len(w.strip()) > 0]
|
values = [w.strip() for w in values.split(",") if len(w.strip()) > 0]
|
||||||
@@ -683,55 +695,54 @@ def callbackSetMicWordFilter(values):
|
|||||||
new_added_value.append(value)
|
new_added_value.append(value)
|
||||||
config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list
|
config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list
|
||||||
|
|
||||||
view.addValueToList_WordFilter(new_added_value)
|
|
||||||
view.clearEntryBox_WordFilter()
|
|
||||||
view.setLatestConfigVariable("MicMicWordFilter")
|
|
||||||
|
|
||||||
model.resetKeywordProcessor()
|
model.resetKeywordProcessor()
|
||||||
model.addKeywords()
|
model.addKeywords()
|
||||||
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackDeleteMicWordFilter(value):
|
def callbackDeleteMicWordFilter(value) -> dict:
|
||||||
print("callbackDeleteMicWordFilter", value)
|
print("callbackDeleteMicWordFilter", value)
|
||||||
try:
|
try:
|
||||||
new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER
|
new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER
|
||||||
new_input_mic_word_filter_list.remove(str(value))
|
new_input_mic_word_filter_list.remove(str(value))
|
||||||
config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list
|
config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list
|
||||||
view.setLatestConfigVariable("MicMicWordFilter")
|
|
||||||
model.resetKeywordProcessor()
|
model.resetKeywordProcessor()
|
||||||
model.addKeywords()
|
model.addKeywords()
|
||||||
except Exception:
|
except Exception:
|
||||||
print("There was no the target word in config.INPUT_MIC_WORD_FILTER")
|
print("There was no the target word in config.INPUT_MIC_WORD_FILTER")
|
||||||
|
return {"status":"success"}
|
||||||
|
|
||||||
# Transcription (Speaker)
|
# Transcription (Speaker)
|
||||||
def callbackSetSpeakerDevice(value):
|
def callbackSetSpeakerDevice(value) -> dict:
|
||||||
print("callbackSetSpeakerDevice", value)
|
print("callbackSetSpeakerDevice", value)
|
||||||
config.CHOICE_SPEAKER_DEVICE = value
|
config.CHOICE_SPEAKER_DEVICE = value
|
||||||
|
|
||||||
model.stopCheckSpeakerEnergy()
|
model.stopCheckSpeakerEnergy()
|
||||||
view.replaceSpeakerThresholdCheckButton_Passive()
|
return {"status":"success"}
|
||||||
|
|
||||||
def callbackSetSpeakerEnergyThreshold(value):
|
def callbackSetSpeakerEnergyThreshold(value) -> dict:
|
||||||
print("callbackSetSpeakerEnergyThreshold", value)
|
print("callbackSetSpeakerEnergyThreshold", value)
|
||||||
if value == "":
|
response = {"status":"success"}
|
||||||
return
|
if value != "":
|
||||||
try:
|
try:
|
||||||
value = int(value)
|
value = int(value)
|
||||||
if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD:
|
if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD:
|
||||||
view.clearNotificationMessage()
|
view.clearNotificationMessage()
|
||||||
config.INPUT_SPEAKER_ENERGY_THRESHOLD = value
|
config.INPUT_SPEAKER_ENERGY_THRESHOLD = value
|
||||||
view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD)
|
view.setGuiVariable_SpeakerEnergyThreshold(config.INPUT_SPEAKER_ENERGY_THRESHOLD)
|
||||||
else:
|
else:
|
||||||
raise ValueError()
|
raise ValueError()
|
||||||
except Exception:
|
except Exception:
|
||||||
view.showErrorMessage_SpeakerEnergyThreshold()
|
response = {"status":"error", "message":"Error Set Speaker Energy Threshold"}
|
||||||
|
return response
|
||||||
|
|
||||||
def callbackSetSpeakerDynamicEnergyThreshold(value):
|
def callbackSetSpeakerDynamicEnergyThreshold(value) -> dict:
|
||||||
print("callbackSetSpeakerDynamicEnergyThreshold", value)
|
print("callbackSetSpeakerDynamicEnergyThreshold", value)
|
||||||
config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value
|
config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value
|
||||||
if config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True:
|
if config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True:
|
||||||
view.closeSpeakerEnergyThresholdWidget()
|
view.closeSpeakerEnergyThresholdWidget()
|
||||||
else:
|
else:
|
||||||
view.openSpeakerEnergyThresholdWidget()
|
view.openSpeakerEnergyThresholdWidget()
|
||||||
|
return {"status":"success"}
|
||||||
|
|
||||||
def setProgressBarSpeakerEnergy(energy):
|
def setProgressBarSpeakerEnergy(energy):
|
||||||
view.updateSetProgressBar_SpeakerEnergy(energy)
|
view.updateSetProgressBar_SpeakerEnergy(energy)
|
||||||
|
|||||||
@@ -113,17 +113,13 @@ controller_mapping = {
|
|||||||
"/controller/callback_disable_transcription_receive": controller.callbackDisableTranscriptionReceive,
|
"/controller/callback_disable_transcription_receive": controller.callbackDisableTranscriptionReceive,
|
||||||
"/controller/callback_enable_foreground": controller.callbackEnableForeground,
|
"/controller/callback_enable_foreground": controller.callbackEnableForeground,
|
||||||
"/controller/callback_disable_foreground": controller.callbackDisableForeground,
|
"/controller/callback_disable_foreground": controller.callbackDisableForeground,
|
||||||
|
|
||||||
"/controller/set_your_language_and_country": controller.setYourLanguageAndCountry,
|
"/controller/set_your_language_and_country": controller.setYourLanguageAndCountry,
|
||||||
"/controller/set_target_language_and_country": controller.setTargetLanguageAndCountry,
|
"/controller/set_target_language_and_country": controller.setTargetLanguageAndCountry,
|
||||||
"/controller/swap_your_language_and_target_language": controller.swapYourLanguageAndTargetLanguage,
|
"/controller/swap_your_language_and_target_language": controller.swapYourLanguageAndTargetLanguage,
|
||||||
|
|
||||||
"/controller/callback_selected_language_preset_tab": controller.callbackSelectedLanguagePresetTab,
|
"/controller/callback_selected_language_preset_tab": controller.callbackSelectedLanguagePresetTab,
|
||||||
"/controller/callback_selected_translation_engine": controller.callbackSelectedTranslationEngine,
|
"/controller/callback_selected_translation_engine": controller.callbackSelectedTranslationEngine,
|
||||||
|
|
||||||
"/controller/callback_disable_config_window_compact_mode": controller.callbackEnableConfigWindowCompactMode,
|
"/controller/callback_disable_config_window_compact_mode": controller.callbackEnableConfigWindowCompactMode,
|
||||||
"/controller/callback_enable_config_window_compact_mode": controller.callbackDisableConfigWindowCompactMode,
|
"/controller/callback_enable_config_window_compact_mode": controller.callbackDisableConfigWindowCompactMode,
|
||||||
|
|
||||||
"/controller/callback_set_transparency": controller.callbackSetTransparency,
|
"/controller/callback_set_transparency": controller.callbackSetTransparency,
|
||||||
"/controller/callback_set_appearance": controller.callbackSetAppearance,
|
"/controller/callback_set_appearance": controller.callbackSetAppearance,
|
||||||
"/controller/callback_set_ui_scaling": controller.callbackSetUiScaling,
|
"/controller/callback_set_ui_scaling": controller.callbackSetUiScaling,
|
||||||
@@ -132,22 +128,22 @@ controller_mapping = {
|
|||||||
"/controller/callback_set_font_family": controller.callbackSetFontFamily,
|
"/controller/callback_set_font_family": controller.callbackSetFontFamily,
|
||||||
"/controller/callback_set_ui_language": controller.callbackSetUiLanguage,
|
"/controller/callback_set_ui_language": controller.callbackSetUiLanguage,
|
||||||
"/controller/callback_set_enable_restore_main_window_geometry": controller.callbackSetEnableRestoreMainWindowGeometry,
|
"/controller/callback_set_enable_restore_main_window_geometry": controller.callbackSetEnableRestoreMainWindowGeometry,
|
||||||
|
|
||||||
"/controller/callback_set_use_translation_feature": controller.callbackSetUseTranslationFeature,
|
"/controller/callback_set_use_translation_feature": controller.callbackSetUseTranslationFeature,
|
||||||
"/controller/callback_set_ctranslate2_weight_type": controller.callbackSetCtranslate2WeightType,
|
"/controller/callback_set_ctranslate2_weight_type": controller.callbackSetCtranslate2WeightType,
|
||||||
|
|
||||||
"/controller/callback_set_deepl_auth_key": controller.callbackSetDeeplAuthKey,
|
"/controller/callback_set_deepl_auth_key": controller.callbackSetDeeplAuthKey,
|
||||||
"/controller/callback_clear_deepl_auth_key": controller.callbackClearDeeplAuthKey,
|
"/controller/callback_clear_deepl_auth_key": controller.callbackClearDeeplAuthKey,
|
||||||
"/controller/callback_set_mic_host": controller.callbackSetMicHost,
|
"/controller/callback_set_mic_host": controller.callbackSetMicHost,
|
||||||
"/controller/callback_set_mic_device": controller.callbackSetMicDevice,
|
"/controller/callback_set_mic_device": controller.callbackSetMicDevice,
|
||||||
"/controller/callback_set_mic_energy_threshold": controller.callbackSetMicEnergyThreshold,
|
"/controller/callback_set_mic_energy_threshold": controller.callbackSetMicEnergyThreshold,
|
||||||
"/controller/callback_set_mic_dynamic_energy_threshold": controller.callbackSetMicDynamicEnergyThreshold,
|
"/controller/callback_set_mic_dynamic_energy_threshold": controller.callbackSetMicDynamicEnergyThreshold,
|
||||||
"/controller/callback_check_mic_threshold": controller.callbackCheckMicThreshold,
|
"/controller/callback_enable_check_mic_threshold": controller.callbackEnableCheckMicThreshold,
|
||||||
|
"/controller/callback_disable_check_mic_threshold": controller.callbackDisableCheckMicThreshold,
|
||||||
"/controller/callback_set_mic_record_timeout": controller.callbackSetMicRecordTimeout,
|
"/controller/callback_set_mic_record_timeout": controller.callbackSetMicRecordTimeout,
|
||||||
"/controller/callback_set_mic_phrase_timeout": controller.callbackSetMicPhraseTimeout,
|
"/controller/callback_set_mic_phrase_timeout": controller.callbackSetMicPhraseTimeout,
|
||||||
"/controller/callback_set_mic_max_phrases": controller.callbackSetMicMaxPhrases,
|
"/controller/callback_set_mic_max_phrases": controller.callbackSetMicMaxPhrases,
|
||||||
"/controller/callback_set_mic_word_filter": controller.callbackSetMicWordFilter,
|
"/controller/callback_set_mic_word_filter": controller.callbackSetMicWordFilter,
|
||||||
"/controller/callback_delete_mic_word_filter": controller.callbackDeleteMicWordFilter,
|
"/controller/callback_delete_mic_word_filter": controller.callbackDeleteMicWordFilter,
|
||||||
|
|
||||||
"/controller/callback_set_speaker_device": controller.callbackSetSpeakerDevice,
|
"/controller/callback_set_speaker_device": controller.callbackSetSpeakerDevice,
|
||||||
"/controller/callback_set_speaker_energy_threshold": controller.callbackSetSpeakerEnergyThreshold,
|
"/controller/callback_set_speaker_energy_threshold": controller.callbackSetSpeakerEnergyThreshold,
|
||||||
"/controller/callback_set_speaker_dynamic_energy_threshold": controller.callbackSetSpeakerDynamicEnergyThreshold,
|
"/controller/callback_set_speaker_dynamic_energy_threshold": controller.callbackSetSpeakerDynamicEnergyThreshold,
|
||||||
@@ -179,6 +175,9 @@ controller_mapping = {
|
|||||||
action_mapping = {
|
action_mapping = {
|
||||||
"/controller/callback_enable_transcription_send": "/action/transcription_send_message",
|
"/controller/callback_enable_transcription_send": "/action/transcription_send_message",
|
||||||
"/controller/callback_disable_transcription_send": "/action/transcription_send_stopped",
|
"/controller/callback_disable_transcription_send": "/action/transcription_send_stopped",
|
||||||
|
"/controller/callback_enable_transcription_receive": "/action/transcription_receive_message",
|
||||||
|
"/controller/callback_disable_transcription_receive": "/action/transcription_receive_stopped",
|
||||||
|
"/controller/callback_enable_check_mic_threshold": "/action/check_mic_threshold_energy",
|
||||||
}
|
}
|
||||||
|
|
||||||
def handleConfigRequest(endpoint):
|
def handleConfigRequest(endpoint):
|
||||||
|
|||||||
Reference in New Issue
Block a user