🚧[WIP/TEST] Main/Controller : 送信形式を修正

This commit is contained in:
misyaguziya
2024-08-07 15:17:22 +09:00
parent e4fe2dd907
commit 1fdccbcb0d
2 changed files with 278 additions and 256 deletions

View File

@@ -83,7 +83,7 @@ class MicMessage:
addSentMessageLog(message) addSentMessageLog(message)
translation = "" translation = ""
if model.checkKeywords(message): if model.checkKeywords(message):
self.action({"status":"error", "message":f"Detected by word filter:{message}"}) self.action("mic", {"status":"error", "message":f"Detected by word filter:{message}"})
return return
elif model.detectRepeatSendMessage(message): elif model.detectRepeatSendMessage(message):
return return
@@ -105,7 +105,7 @@ class MicMessage:
osc_message = messageFormatter("SEND", translation, message) osc_message = messageFormatter("SEND", translation, message)
model.oscSendMessage(osc_message) model.oscSendMessage(osc_message)
self.action({"status":"success", "message":message, "translation":translation}) self.action("mic", {"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})"
@@ -123,7 +123,7 @@ def startTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
def stopTranscriptionSendMessage(action:Callable[[dict], None]) -> None: def stopTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
model.stopMicTranscript() model.stopMicTranscript()
action({"status":"success", "message":"Stopped sending messages"}) action("mic", {"status":"success", "message":"Stopped sending messages"})
def startThreadingTranscriptionSendMessage(action:Callable[[dict], None]) -> None: def startThreadingTranscriptionSendMessage(action:Callable[[dict], None]) -> None:
th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage, args=(action,)) th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessage, args=(action,))
@@ -142,12 +142,12 @@ def startTranscriptionSendMessageOnCloseConfigWindow(action:Callable[[dict], Non
def stopTranscriptionSendMessageOnOpenConfigWindow(): def stopTranscriptionSendMessageOnOpenConfigWindow():
model.stopMicTranscript() model.stopMicTranscript()
def startThreadingTranscriptionSendMessageOnCloseConfigWindow(): def startThreadingTranscriptionSendMessageOnCloseConfigWindow(action:Callable[[dict], None]) -> None:
th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessageOnCloseConfigWindow) th_startTranscriptionSendMessage = Thread(target=startTranscriptionSendMessageOnCloseConfigWindow, args=(action,))
th_startTranscriptionSendMessage.daemon = True th_startTranscriptionSendMessage.daemon = True
th_startTranscriptionSendMessage.start() th_startTranscriptionSendMessage.start()
def stopThreadingTranscriptionSendMessageOnOpenConfigWindow(): def stopThreadingTranscriptionSendMessageOnOpenConfigWindow() -> None:
th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessageOnOpenConfigWindow) th_stopTranscriptionSendMessage = Thread(target=stopTranscriptionSendMessageOnOpenConfigWindow)
th_stopTranscriptionSendMessage.daemon = True th_stopTranscriptionSendMessage.daemon = True
th_stopTranscriptionSendMessage.start() th_stopTranscriptionSendMessage.start()
@@ -159,7 +159,7 @@ class SpeakerMessage:
def receive(self, message): def receive(self, message):
if isinstance(message, bool) and message is False: if isinstance(message, bool) and message is False:
self.action({"status":"error", "message":"No mic device detected."}) self.action("speaker", {"status":"error", "message":"No mic device detected."})
elif isinstance(message, str) and len(message) > 0: elif isinstance(message, str) and len(message) > 0:
translation = "" translation = ""
if model.detectRepeatReceiveMessage(message): if model.detectRepeatReceiveMessage(message):
@@ -192,7 +192,7 @@ class SpeakerMessage:
# ------------Speaker2Chatbox------------ # ------------Speaker2Chatbox------------
# update textbox message log (Received) # update textbox message log (Received)
self.action({"status":"success", "message":message, "translation":translation}) self.action("speaker",{"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})"
@@ -223,8 +223,8 @@ def startTranscriptionReceiveMessageOnCloseConfigWindow(action:Callable[[dict],
def stopTranscriptionReceiveMessageOnOpenConfigWindow(): def stopTranscriptionReceiveMessageOnOpenConfigWindow():
model.stopSpeakerTranscript() model.stopSpeakerTranscript()
def startThreadingTranscriptionReceiveMessageOnCloseConfigWindow(): def startThreadingTranscriptionReceiveMessageOnCloseConfigWindow(action:Callable[[dict], None]) -> None:
th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessageOnCloseConfigWindow) th_startTranscriptionReceiveMessage = Thread(target=startTranscriptionReceiveMessageOnCloseConfigWindow, args=(action,))
th_startTranscriptionReceiveMessage.daemon = True th_startTranscriptionReceiveMessage.daemon = True
th_startTranscriptionReceiveMessage.start() th_startTranscriptionReceiveMessage.start()
@@ -360,7 +360,14 @@ def setYourLanguageAndCountry(select:dict, *args, **kwargs) -> dict:
config.SOURCE_LANGUAGE = select["language"] config.SOURCE_LANGUAGE = select["language"]
config.SOURCE_COUNTRY = select["country"] config.SOURCE_COUNTRY = select["country"]
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
return {"status":"success"} return {"status":"success",
"data":{
"your":{
"language":config.SOURCE_LANGUAGE,
"country":config.SOURCE_COUNTRY
}
}
}
def setTargetLanguageAndCountry(select:dict, *args, **kwargs) -> dict: def setTargetLanguageAndCountry(select:dict, *args, **kwargs) -> dict:
print("setTargetLanguageAndCountry", select) print("setTargetLanguageAndCountry", select)
@@ -370,7 +377,14 @@ def setTargetLanguageAndCountry(select:dict, *args, **kwargs) -> dict:
config.TARGET_LANGUAGE = select["language"] config.TARGET_LANGUAGE = select["language"]
config.TARGET_COUNTRY = select["country"] config.TARGET_COUNTRY = select["country"]
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
return {"status":"success"} return {"status":"success",
"data":{
"target":{
"language":config.TARGET_LANGUAGE,
"country":config.TARGET_COUNTRY
},
}
}
def swapYourLanguageAndTargetLanguage(*args, **kwargs) -> dict: def swapYourLanguageAndTargetLanguage(*args, **kwargs) -> dict:
print("swapYourLanguageAndTargetLanguage") print("swapYourLanguageAndTargetLanguage")
@@ -378,7 +392,17 @@ def swapYourLanguageAndTargetLanguage(*args, **kwargs) -> dict:
target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO] target_language = config.SELECTED_TAB_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
setYourLanguageAndCountry(target_language) setYourLanguageAndCountry(target_language)
setTargetLanguageAndCountry(your_language) setTargetLanguageAndCountry(your_language)
return {"status":"success"} return {"status":"success",
"data":{
"your":{"language":config.SOURCE_LANGUAGE,
"country":config.SOURCE_COUNTRY,
},
"target":{
"language":config.TARGET_LANGUAGE,
"country":config.TARGET_COUNTRY,
},
},
}
def callbackSelectedLanguagePresetTab(selected_tab_no:str, *args, **kwargs) -> dict: def callbackSelectedLanguagePresetTab(selected_tab_no:str, *args, **kwargs) -> dict:
print("callbackSelectedLanguagePresetTab", selected_tab_no) print("callbackSelectedLanguagePresetTab", selected_tab_no)
@@ -402,13 +426,13 @@ def callbackSelectedLanguagePresetTab(selected_tab_no:str, *args, **kwargs) -> d
config.TARGET_LANGUAGE = select["language"] config.TARGET_LANGUAGE = select["language"]
config.TARGET_COUNTRY = select["country"] config.TARGET_COUNTRY = select["country"]
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
return {"status":"success"} return {"status":"success", "data":config.SELECTED_TAB_NO}
def callbackSelectedTranslationEngine(selected_translation_engine:str, *args, **kwargs) -> dict: def callbackSelectedTranslationEngine(selected_translation_engine:str, *args, **kwargs) -> dict:
print("callbackSelectedTranslationEngine", selected_translation_engine) print("callbackSelectedTranslationEngine", selected_translation_engine)
setYourTranslateEngine(selected_translation_engine) setYourTranslateEngine(selected_translation_engine)
setTargetTranslateEngine(selected_translation_engine) setTargetTranslateEngine(selected_translation_engine)
return {"status":"success"} return {"status":"success", "data":selected_translation_engine}
# command func # command func
def callbackEnableTranslation(*args, **kwargs) -> dict: def callbackEnableTranslation(*args, **kwargs) -> dict:
@@ -427,12 +451,12 @@ def callbackEnableTranscriptionSend(data, action, *args, **kwargs) -> dict:
print("callbackEnableTranscriptionSend") print("callbackEnableTranscriptionSend")
config.ENABLE_TRANSCRIPTION_SEND = True config.ENABLE_TRANSCRIPTION_SEND = True
startThreadingTranscriptionSendMessage(action) startThreadingTranscriptionSendMessage(action)
return {"status":"success"} return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_SEND}
def callbackDisableTranscriptionSend(data, action, *args, **kwargs) -> dict: def callbackDisableTranscriptionSend(data, action, *args, **kwargs) -> dict:
config.ENABLE_TRANSCRIPTION_SEND = False config.ENABLE_TRANSCRIPTION_SEND = False
stopThreadingTranscriptionSendMessage(action) stopThreadingTranscriptionSendMessage(action)
return {"status":"success"} return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_SEND}
def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict: def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict:
config.ENABLE_TRANSCRIPTION_RECEIVE = True config.ENABLE_TRANSCRIPTION_RECEIVE = True
@@ -441,109 +465,109 @@ def callbackEnableTranscriptionReceive(data, action, *args, **kwargs) -> dict:
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", "data":config.ENABLE_TRANSCRIPTION_RECEIVE}
def callbackDisableTranscriptionReceive(data, action, *args, **kwargs) -> dict: def callbackDisableTranscriptionReceive(data, action, *args, **kwargs) -> dict:
config.ENABLE_TRANSCRIPTION_RECEIVE = False config.ENABLE_TRANSCRIPTION_RECEIVE = False
stopThreadingTranscriptionReceiveMessage(action) stopThreadingTranscriptionReceiveMessage(action)
return {"status":"success"} return {"status":"success", "data":config.ENABLE_TRANSCRIPTION_RECEIVE}
def callbackEnableForeground() -> None: def callbackEnableForeground(*args, **kwargs) -> dict:
config.ENABLE_FOREGROUND = True config.ENABLE_FOREGROUND = True
return {"status":"success"} return {"status":"success", "data":config.ENABLE_FOREGROUND}
def callbackDisableForeground() -> None: def callbackDisableForeground(*args, **kwargs) -> dict:
config.ENABLE_FOREGROUND = False config.ENABLE_FOREGROUND = False
return {"status":"success"} return {"status":"success", "data":config.ENABLE_FOREGROUND}
def callbackEnableMainWindowSidebarCompactMode() -> None: def callbackEnableMainWindowSidebarCompactMode(*args, **kwargs) -> dict:
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = True
return {"status":"success"} return {"status":"success", "data":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE}
def callbackDisableMainWindowSidebarCompactMode() -> None: def callbackDisableMainWindowSidebarCompactMode(*args, **kwargs) -> dict:
config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE = False
return {"status":"success"} return {"status":"success", "data":config.IS_MAIN_WINDOW_SIDEBAR_COMPACT_MODE}
# Config Window # Config Window
def callbackOpenConfigWindow() -> dict: def callbackOpenConfigWindow(*args, **kwargs) -> 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() -> dict: def callbackCloseConfigWindow(data, action, *args, **kwargs) -> dict:
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
model.stopCheckSpeakerEnergy() model.stopCheckSpeakerEnergy()
if config.ENABLE_TRANSCRIPTION_SEND is True: if config.ENABLE_TRANSCRIPTION_SEND is True:
startThreadingTranscriptionSendMessageOnCloseConfigWindow() startThreadingTranscriptionSendMessageOnCloseConfigWindow(action)
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
sleep(2) sleep(2)
if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.ENABLE_TRANSCRIPTION_RECEIVE is True:
startThreadingTranscriptionReceiveMessageOnCloseConfigWindow() startThreadingTranscriptionReceiveMessageOnCloseConfigWindow(action)
return {"status":"success"} return {"status":"success"}
# Compact Mode Switch # Compact Mode Switch
def callbackEnableConfigWindowCompactMode() -> dict: def callbackEnableConfigWindowCompactMode(*args, **kwargs) -> 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", "data":config.IS_CONFIG_WINDOW_COMPACT_MODE}
def callbackDisableConfigWindowCompactMode() -> dict: def callbackDisableConfigWindowCompactMode(*args, **kwargs) -> 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", "data":config.IS_CONFIG_WINDOW_COMPACT_MODE}
# Appearance Tab # Appearance Tab
def callbackSetTransparency(value) -> dict: def callbackSetTransparency(data, *args, **kwargs) -> dict:
print("callbackSetTransparency", int(value)) print("callbackSetTransparency", int(data))
config.TRANSPARENCY = int(value) config.TRANSPARENCY = int(data)
return {"status":"success"} return {"status":"success", "data":config.TRANSPARENCY}
def callbackSetAppearance(value) -> dict: def callbackSetAppearance(data, *args, **kwargs) -> dict:
print("callbackSetAppearance", value) print("callbackSetAppearance", data)
config.APPEARANCE_THEME = value config.APPEARANCE_THEME = data
return {"status":"success"} return {"status":"success", "data":config.APPEARANCE_THEME}
def callbackSetUiScaling(value) -> dict: def callbackSetUiScaling(data, *args, **kwargs) -> dict:
print("callbackSetUiScaling", value) print("callbackSetUiScaling", data)
config.UI_SCALING = value config.UI_SCALING = data
return {"status":"success"} return {"status":"success", "data":config.UI_SCALING}
def callbackSetTextboxUiScaling(value) -> dict: def callbackSetTextboxUiScaling(data, *args, **kwargs) -> dict:
print("callbackSetTextboxUiScaling", int(value)) print("callbackSetTextboxUiScaling", int(data))
config.TEXTBOX_UI_SCALING = int(value) config.TEXTBOX_UI_SCALING = int(data)
return {"status":"success"} return {"status":"success", "data":config.TEXTBOX_UI_SCALING}
def callbackSetMessageBoxRatio(value) -> dict: def callbackSetMessageBoxRatio(data, *args, **kwargs) -> dict:
print("callbackSetMessageBoxRatio", int(value)) print("callbackSetMessageBoxRatio", int(data))
config.MESSAGE_BOX_RATIO = int(value) config.MESSAGE_BOX_RATIO = int(data)
return {"status":"success"} return {"status":"success", "data":config.MESSAGE_BOX_RATIO}
def callbackSetFontFamily(value) -> dict: def callbackSetFontFamily(data, *args, **kwargs) -> dict:
print("callbackSetFontFamily", value) print("callbackSetFontFamily", data)
config.FONT_FAMILY = value config.FONT_FAMILY = data
return {"status":"success"} return {"status":"success", "data":config.FONT_FAMILY}
def callbackSetUiLanguage(value) -> dict: def callbackSetUiLanguage(data, *args, **kwargs) -> dict:
print("callbackSetUiLanguage", value) print("callbackSetUiLanguage", data)
value = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, value) data = getKeyByValue(config.SELECTABLE_UI_LANGUAGES_DICT, data)
print("callbackSetUiLanguage__after_getKeyByValue", value) print("callbackSetUiLanguage__after_getKeyByValue", data)
config.UI_LANGUAGE = value config.UI_LANGUAGE = data
return {"status":"success"} return {"status":"success", "data":config.UI_LANGUAGE}
def callbackSetEnableRestoreMainWindowGeometry(value) -> dict: def callbackSetEnableRestoreMainWindowGeometry(data, *args, **kwargs) -> dict:
print("callbackSetEnableRestoreMainWindowGeometry", value) print("callbackSetEnableRestoreMainWindowGeometry", data)
config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = value config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY = data
return {"status":"success"} return {"status":"success", "data":config.ENABLE_RESTORE_MAIN_WINDOW_GEOMETRY}
# Translation Tab # Translation Tab
def callbackSetUseTranslationFeature(value) -> dict: def callbackSetUseTranslationFeature(data, *args, **kwargs) -> dict:
print("callbackSetUseTranslationFeature", value) print("callbackSetUseTranslationFeature", data)
config.USE_TRANSLATION_FEATURE = value config.USE_TRANSLATION_FEATURE = data
if config.USE_TRANSLATION_FEATURE is True: if config.USE_TRANSLATION_FEATURE is True:
if model.checkCTranslatorCTranslate2ModelWeight(): if model.checkCTranslatorCTranslate2ModelWeight():
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
@@ -556,11 +580,16 @@ def callbackSetUseTranslationFeature(value) -> dict:
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True
else: else:
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
return {"status":"success"} return {"status":"success",
"data":{
"feature":config.USE_TRANSLATION_FEATURE,
"reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION,
},
}
def callbackSetCtranslate2WeightType(value) -> dict: def callbackSetCtranslate2WeightType(data, *args, **kwargs) -> dict:
print("callbackSetCtranslate2WeightType", value) print("callbackSetCtranslate2WeightType", data)
config.CTRANSLATE2_WEIGHT_TYPE = str(value) config.CTRANSLATE2_WEIGHT_TYPE = str(data)
if model.checkCTranslatorCTranslate2ModelWeight(): if model.checkCTranslatorCTranslate2ModelWeight():
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = False
def callback(): def callback():
@@ -570,15 +599,20 @@ def callbackSetCtranslate2WeightType(value) -> dict:
th_callback.start() th_callback.start()
else: else:
config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION = True
return {"status":"success"} return {"status":"success",
"data":{
"feature":config.CTRANSLATE2_WEIGHT_TYPE,
"reset":config.IS_RESET_BUTTON_DISPLAYED_FOR_TRANSLATION,
},
}
def callbackSetDeeplAuthKey(value) -> dict: def callbackSetDeeplAuthKey(data, *args, **kwargs) -> dict:
status = "error" status = "error"
print("callbackSetDeeplAuthKey", str(value)) print("callbackSetDeeplAuthKey", str(data))
if len(value) == 36 or len(value) == 39: if len(data) == 36 or len(data) == 39:
result = model.authenticationTranslatorDeepLAuthKey(auth_key=value) result = model.authenticationTranslatorDeepLAuthKey(auth_key=data)
if result is True: if result is True:
key = value key = data
status = "success" status = "success"
else: else:
key = None key = None
@@ -586,112 +620,121 @@ def callbackSetDeeplAuthKey(value) -> dict:
auth_keys["DeepL_API"] = key auth_keys["DeepL_API"] = key
config.AUTH_KEYS = auth_keys config.AUTH_KEYS = auth_keys
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
return {"status":status} return {"status":status, "data":config.AUTH_KEYS["DeepL_API"]}
def callbackClearDeeplAuthKey() -> dict: def callbackClearDeeplAuthKey(*args, **kwargs) -> 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
updateTranslationEngineAndEngineList() updateTranslationEngineAndEngineList()
return {"status":"success"} return {"status":"success", "data":config.AUTH_KEYS["DeepL_API"]}
# Transcription Tab # Transcription Tab
# Transcription (Mic) # Transcription (Mic)
def callbackSetMicHost(value) -> dict: def callbackSetMicHost(data, *args, **kwargs) -> dict:
print("callbackSetMicHost", value) print("callbackSetMicHost", data)
config.CHOICE_MIC_HOST = value config.CHOICE_MIC_HOST = data
config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice() config.CHOICE_MIC_DEVICE = model.getInputDefaultDevice()
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
return {"status":"success"} return {"status":"success",
"data":{
"host":config.CHOICE_MIC_HOST,
"device":config.CHOICE_MIC_DEVICE,
},
}
def callbackSetMicDevice(value) -> dict: def callbackSetMicDevice(data, *args, **kwargs) -> dict:
print("callbackSetMicDevice", value) print("callbackSetMicDevice", data)
config.CHOICE_MIC_DEVICE = value config.CHOICE_MIC_DEVICE = data
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
return {"status":"success"} return {"status":"success",
"data":{
"host":config.CHOICE_MIC_HOST,
},
}
def callbackSetMicEnergyThreshold(value) -> dict: def callbackSetMicEnergyThreshold(data, *args, **kwargs) -> dict:
status = "error" status = "error"
print("callbackSetMicEnergyThreshold", value) print("callbackSetMicEnergyThreshold", data)
value = int(value) data = int(data)
if 0 <= value <= config.MAX_MIC_ENERGY_THRESHOLD: if 0 <= data <= config.MAX_MIC_ENERGY_THRESHOLD:
config.INPUT_MIC_ENERGY_THRESHOLD = value config.INPUT_MIC_ENERGY_THRESHOLD = data
status = "success" status = "success"
return {"status": status} return {"status": status, "data": config.INPUT_MIC_ENERGY_THRESHOLD}
def callbackSetMicDynamicEnergyThreshold(value) -> dict: def callbackSetMicDynamicEnergyThreshold(data, *args, **kwargs) -> dict:
print("callbackSetMicDynamicEnergyThreshold", value) print("callbackSetMicDynamicEnergyThreshold", data)
config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = value config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = data
return {"status":"success"} return {"status":"success", "data":config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD}
class ProgressBarMicEnergy: class ProgressBarEnergy:
def __init__(self, action): def __init__(self, action):
self.action = action self.action = action
def set(self, energy) -> None: def set(self, energy) -> None:
self.action({"status":"success", "energy":energy}) self.action("energy", {"status":"success", "energy":energy})
def callbackEnableCheckMicThreshold(data, action, *args, **kwargs) -> dict: def callbackEnableCheckMicThreshold(data, action, *args, **kwargs) -> dict:
print("callbackEnableCheckMicThreshold") print("callbackEnableCheckMicThreshold")
progressbar_mic_energy = ProgressBarMicEnergy(action) progressbar_mic_energy = ProgressBarEnergy(action)
model.startCheckMicEnergy(progressbar_mic_energy.set) model.startCheckMicEnergy(progressbar_mic_energy.set)
return {"status":"success"} return {"status":"success"}
def callbackDisableCheckMicThreshold() -> dict: def callbackDisableCheckMicThreshold(*args, **kwargs) -> dict:
print("callbackDisableCheckMicThreshold") print("callbackDisableCheckMicThreshold")
model.stopCheckMicEnergy() model.stopCheckMicEnergy()
return {"status":"success"} return {"status":"success"}
def callbackSetMicRecordTimeout(value) -> dict: def callbackSetMicRecordTimeout(data, *args, **kwargs) -> dict:
print("callbackSetMicRecordTimeout", value) print("callbackSetMicRecordTimeout", data)
response = {"status":"success"}
if value != "":
try: try:
value = int(value) data = int(data)
if 0 <= value <= config.INPUT_MIC_PHRASE_TIMEOUT: if 0 <= data <= config.INPUT_MIC_PHRASE_TIMEOUT:
config.INPUT_MIC_RECORD_TIMEOUT = value config.INPUT_MIC_RECORD_TIMEOUT = data
else: else:
raise ValueError() raise ValueError()
except Exception: except Exception:
response = {"status":"error", "message":"Error Mic Record Timeout"} response = {"status":"error", "message":"Error Mic Record Timeout"}
else:
response = {"status":"success", "data":config.INPUT_MIC_RECORD_TIMEOUT}
return response return response
def callbackSetMicPhraseTimeout(value) -> dict: def callbackSetMicPhraseTimeout(data, *args, **kwargs) -> dict:
print("callbackSetMicPhraseTimeout", value) print("callbackSetMicPhraseTimeout", data)
response = {"status":"success"}
if value != "":
try: try:
value = int(value) data = int(data)
if value >= config.INPUT_MIC_RECORD_TIMEOUT: if data >= config.INPUT_MIC_RECORD_TIMEOUT:
config.INPUT_MIC_PHRASE_TIMEOUT = value config.INPUT_MIC_PHRASE_TIMEOUT = data
else: else:
raise ValueError() raise ValueError()
except Exception: except Exception:
response = {"status":"error", "message":"Error Mic Phrase Timeout"} response = {"status":"error", "message":"Error Mic Phrase Timeout"}
else:
response = {"status":"success", "data":config.INPUT_MIC_PHRASE_TIMEOUT}
return response return response
def callbackSetMicMaxPhrases(value) -> dict: def callbackSetMicMaxPhrases(data, *args, **kwargs) -> dict:
print("callbackSetMicMaxPhrases", value) print("callbackSetMicMaxPhrases", data)
response = {"status":"success"}
if value != "":
try: try:
value = int(value) data = int(data)
if 0 <= value: if 0 <= data:
config.INPUT_MIC_MAX_PHRASES = value config.INPUT_MIC_MAX_PHRASES = data
else: else:
raise ValueError() raise ValueError()
except Exception: except Exception:
response = {"status":"error", "message":"Error Mic Max Phrases"} response = {"status":"error", "message":"Error Mic Max Phrases"}
else:
response = {"status":"success", "data":config.INPUT_MIC_MAX_PHRASES}
return response return response
def callbackSetMicWordFilter(values) -> dict: def callbackSetMicWordFilter(data, *args, **kwargs) -> dict:
print("callbackSetMicWordFilter", values) print("callbackSetMicWordFilter", data)
values = str(values) data = str(data)
values = [w.strip() for w in values.split(",") if len(w.strip()) > 0] data = [w.strip() for w in data.split(",") if len(w.strip()) > 0]
# Copy the list # Copy the list
new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER new_input_mic_word_filter_list = config.INPUT_MIC_WORD_FILTER
new_added_value = [] new_added_value = []
for value in values: for value in data:
if value in new_input_mic_word_filter_list: if value in new_input_mic_word_filter_list:
# If the value is already in the list, do nothing. # If the value is already in the list, do nothing.
pass pass
@@ -702,122 +745,100 @@ def callbackSetMicWordFilter(values) -> dict:
model.resetKeywordProcessor() model.resetKeywordProcessor()
model.addKeywords() model.addKeywords()
return {"status":"success"} return {"status":"success", "data":config.INPUT_MIC_WORD_FILTER}
def callbackDeleteMicWordFilter(value) -> dict: def callbackDeleteMicWordFilter(data, *args, **kwargs) -> dict:
print("callbackDeleteMicWordFilter", value) print("callbackDeleteMicWordFilter", data)
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(data))
config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list config.INPUT_MIC_WORD_FILTER = new_input_mic_word_filter_list
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"} return {"status":"success", "data":config.INPUT_MIC_WORD_FILTER}
# Transcription (Speaker) # Transcription (Speaker)
def callbackSetSpeakerDevice(value) -> dict: def callbackSetSpeakerDevice(data, *args, **kwargs) -> dict:
print("callbackSetSpeakerDevice", value) print("callbackSetSpeakerDevice", data)
config.CHOICE_SPEAKER_DEVICE = value config.CHOICE_SPEAKER_DEVICE = data
model.stopCheckSpeakerEnergy() model.stopCheckSpeakerEnergy()
return {"status":"success"} return {"status":"success", "data":config.CHOICE_SPEAKER_DEVICE}
def callbackSetSpeakerEnergyThreshold(value) -> dict: def callbackSetSpeakerEnergyThreshold(data, *args, **kwargs) -> dict:
print("callbackSetSpeakerEnergyThreshold", value) print("callbackSetSpeakerEnergyThreshold", data)
response = {"status":"success"}
if value != "":
try: try:
value = int(value) data = int(data)
if 0 <= value and value <= config.MAX_SPEAKER_ENERGY_THRESHOLD: if 0 <= data <= config.MAX_SPEAKER_ENERGY_THRESHOLD:
# view.clearNotificationMessage() # view.clearNotificationMessage()
config.INPUT_SPEAKER_ENERGY_THRESHOLD = value config.INPUT_SPEAKER_ENERGY_THRESHOLD = data
# 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:
response = {"status":"error", "message":"Error Set Speaker Energy Threshold"} response = {"status":"error", "message":"Error Set Speaker Energy Threshold"}
else:
response = {"status":"success", "data":config.INPUT_SPEAKER_ENERGY_THRESHOLD}
return response return response
def callbackSetSpeakerDynamicEnergyThreshold(value) -> dict: def callbackSetSpeakerDynamicEnergyThreshold(data, *args, **kwargs) -> dict:
print("callbackSetSpeakerDynamicEnergyThreshold", value) print("callbackSetSpeakerDynamicEnergyThreshold", data)
config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = value config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = data
if config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD is True: return {"status":"success", "data":config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD}
# view.closeSpeakerEnergyThresholdWidget()
pass def callbackEnableCheckSpeakerThreshold(data, action, *args, **kwargs) -> dict:
else: print("callbackEnableCheckSpeakerThreshold")
# view.openSpeakerEnergyThresholdWidget() progressbar_speaker_energy = ProgressBarEnergy(action)
pass model.startCheckSpeakerEnergy(progressbar_speaker_energy.set)
return {"status":"success"} return {"status":"success"}
def setProgressBarSpeakerEnergy(energy): def callbackDisableCheckSpeakerThreshold(*args, **kwargs) -> dict:
# view.updateSetProgressBar_SpeakerEnergy(energy) print("callbackDisableCheckSpeakerThreshold")
pass
def callbackCheckSpeakerThreshold(is_turned_on):
print("callbackCheckSpeakerThreshold", is_turned_on)
if is_turned_on is True:
# view.replaceSpeakerThresholdCheckButton_Disabled()
model.startCheckSpeakerEnergy(
setProgressBarSpeakerEnergy,
# view.initProgressBar_SpeakerEnergy,
# view.showErrorMessage_CheckSpeakerThreshold_NoDevice
)
# view.replaceSpeakerThresholdCheckButton_Active()
else:
# view.replaceSpeakerThresholdCheckButton_Disabled()
model.stopCheckSpeakerEnergy() model.stopCheckSpeakerEnergy()
# view.replaceSpeakerThresholdCheckButton_Passive() return {"status":"success"}
def callbackSetSpeakerRecordTimeout(value): def callbackSetSpeakerRecordTimeout(data, *args, **kwargs) -> dict:
print("callbackSetSpeakerRecordTimeout", value) print("callbackSetSpeakerRecordTimeout", data)
if value == "":
return
try: try:
value = int(value) data = int(data)
if 0 <= value and value <= config.INPUT_SPEAKER_PHRASE_TIMEOUT: if 0 <= data <= config.INPUT_SPEAKER_PHRASE_TIMEOUT:
# view.clearNotificationMessage() config.INPUT_SPEAKER_RECORD_TIMEOUT = data
config.INPUT_SPEAKER_RECORD_TIMEOUT = value
# view.setGuiVariable_SpeakerRecordTimeout(config.INPUT_SPEAKER_RECORD_TIMEOUT)
else: else:
raise ValueError() raise ValueError()
except Exception: except Exception:
# view.showErrorMessage_SpeakerRecordTimeout() response = {"status":"error", "message":"Error Speaker Record Timeout"}
pass else:
response = {"status":"success", "data":config.INPUT_SPEAKER_RECORD_TIMEOUT}
return response
def callbackSetSpeakerPhraseTimeout(value): def callbackSetSpeakerPhraseTimeout(data, *args, **kwargs) -> dict:
print("callbackSetSpeakerPhraseTimeout", value) print("callbackSetSpeakerPhraseTimeout", data)
if value == "":
return
try: try:
value = int(value) data = int(data)
if 0 <= value and value >= config.INPUT_SPEAKER_RECORD_TIMEOUT: if 0 <= data and data >= config.INPUT_SPEAKER_RECORD_TIMEOUT:
# view.clearNotificationMessage() config.INPUT_SPEAKER_PHRASE_TIMEOUT = data
config.INPUT_SPEAKER_PHRASE_TIMEOUT = value
# view.setGuiVariable_SpeakerPhraseTimeout(config.INPUT_SPEAKER_PHRASE_TIMEOUT)
else: else:
raise ValueError() raise ValueError()
except Exception: except Exception:
# view.showErrorMessage_SpeakerPhraseTimeout() response = {"status":"error", "message":"Error Speaker Phrase Timeout"}
pass else:
response = {"status":"success", "data":config.INPUT_SPEAKER_PHRASE_TIMEOUT}
return response
def callbackSetSpeakerMaxPhrases(value): def callbackSetSpeakerMaxPhrases(data, *args, **kwargs) -> dict:
print("callbackSetSpeakerMaxPhrases", value) print("callbackSetSpeakerMaxPhrases", data)
if value == "":
return
try: try:
value = int(value) data = int(data)
if 0 <= value: if 0 <= data:
# view.clearNotificationMessage() config.INPUT_SPEAKER_MAX_PHRASES = data
config.INPUT_SPEAKER_MAX_PHRASES = value
# view.setGuiVariable_SpeakerMaxPhrases(config.INPUT_SPEAKER_MAX_PHRASES)
else: else:
raise ValueError() raise ValueError()
except Exception: except Exception:
# view.showErrorMessage_SpeakerMaxPhrases() response = {"status":"error", "message":"Error Speaker Max Phrases"}
pass else:
response = {"status":"success", "data":config.INPUT_SPEAKER_MAX_PHRASES}
return response
# Transcription (Internal AI Model) # Transcription (Internal AI Model)
def callbackSetUserWhisperFeature(value): def callbackSetUserWhisperFeature(value):

View File

@@ -143,11 +143,11 @@ controller_mapping = {
"/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,
"/controller/callback_check_speaker_threshold": controller.callbackCheckSpeakerThreshold, "/controller/callback_enable_check_speaker_threshold": controller.callbackEnableCheckSpeakerThreshold,
"/controller/callback_disable_check_speaker_threshold": controller.callbackDisableCheckSpeakerThreshold,
"/controller/callback_set_speaker_record_timeout": controller.callbackSetSpeakerRecordTimeout, "/controller/callback_set_speaker_record_timeout": controller.callbackSetSpeakerRecordTimeout,
"/controller/callback_set_speaker_phrase_timeout": controller.callbackSetSpeakerPhraseTimeout, "/controller/callback_set_speaker_phrase_timeout": controller.callbackSetSpeakerPhraseTimeout,
"/controller/callback_set_speaker_max_phrases": controller.callbackSetSpeakerMaxPhrases, "/controller/callback_set_speaker_max_phrases": controller.callbackSetSpeakerMaxPhrases,
@@ -173,11 +173,12 @@ controller_mapping = {
} }
action_mapping = { action_mapping = {
"/controller/callback_enable_transcription_send": "/action/transcription_send_message", "/controller/callback_close_config_window": {"mic":"/action/transcription_send_message", "speaker":"/action/transcription_receive_message"},
"/controller/callback_disable_transcription_send": "/action/transcription_send_stopped", "/controller/callback_enable_transcription_send": {"mic":"/action/transcription_send_message"},
"/controller/callback_enable_transcription_receive": "/action/transcription_receive_message", "/controller/callback_disable_transcription_send": {"mic":"/action/transcription_send_stopped"},
"/controller/callback_disable_transcription_receive": "/action/transcription_receive_stopped", "/controller/callback_enable_transcription_receive": {"speaker":"/action/transcription_receive_message"},
"/controller/callback_enable_check_mic_threshold": "/action/check_mic_threshold_energy", "/controller/callback_disable_transcription_receive": {"speaker":"/action/transcription_receive_stopped"},
"/controller/callback_enable_check_mic_threshold": {"mic":"/action/check_mic_threshold_energy"},
} }
def handleConfigRequest(endpoint): def handleConfigRequest(endpoint):
@@ -205,12 +206,12 @@ def handleControllerRequest(endpoint, data=None):
return response, status return response, status
class Action: class Action:
def __init__(self, endpoint:str) -> None: def __init__(self, endpoints:dict) -> None:
self.endpoint = endpoint self.endpoints = endpoints
def transmit(self, data:dict) -> None: def transmit(self, key:str, data:dict) -> None:
response = { response = {
"endpoint": self.endpoint, "endpoint": self.endpoints[key],
"status": 200, "status": 200,
"data": data, "data": data,
} }