👍️[Update] Controller : run_mappingに以下を追加

"selected_mic_device":"/run/selected_mic_device",
    "selected_speaker_device":"/run/selected_speaker_device",
    "selected_translation_engine":"/run/selected_translation_engine",
    "translation_engines":"/run/translation_engines",
    "mic_host_list":"/run/mic_host_list",
    "mic_device_list":"/run/mic_device_list",
    "speaker_device_list":"/run/speaker_device_list",
This commit is contained in:
misyaguziya
2024-09-25 11:32:25 +09:00
parent 14470e5217
commit 03165cb3b7
3 changed files with 307 additions and 305 deletions

View File

@@ -37,6 +37,9 @@ class DeviceManager:
self.callback_default_input_device = None self.callback_default_input_device = None
self.callback_default_output_device = None self.callback_default_output_device = None
self.callback_host_list = None
self.callback_input_device_list = None
self.callback_output_device_list = None
self.monitoring_flag = False self.monitoring_flag = False
self.startMonitoring() self.startMonitoring()
@@ -156,11 +159,35 @@ class DeviceManager:
def clearCallbackDefaultOutputDevice(self): def clearCallbackDefaultOutputDevice(self):
self.callback_default_output_device = None self.callback_default_output_device = None
def setCallbackHostList(self, callback):
self.callback_host_list = callback
def clearCallbackHostList(self):
self.callback_host_list = None
def setCallbackInputDeviceList(self, callback):
self.callback_input_device_list = callback
def clearCallbackInputDeviceList(self):
self.callback_input_device_list = None
def setCallbackOutputDeviceList(self, callback):
self.callback_output_device_list = callback
def clearCallbackOutputDeviceList(self):
self.callback_output_device_list = None
def noticeDefaultDevice(self): def noticeDefaultDevice(self):
if self.callback_default_input_device is not None: if self.callback_default_input_device is not None:
self.callback_default_input_device(self.default_input_device["host"]["name"], self.default_input_device["device"]["name"]) self.callback_default_input_device(self.default_input_device["host"]["name"], self.default_input_device["device"]["name"])
if self.callback_default_output_device is not None: if self.callback_default_output_device is not None:
self.callback_default_output_device(self.default_output_device["device"]["name"]) self.callback_default_output_device(self.default_output_device["device"]["name"])
if self.callback_host_list is not None:
self.callback_host_list()
if self.callback_input_device_list is not None:
self.callback_input_device_list()
if self.callback_output_device_list is not None:
self.callback_output_device_list()
def getInputDevices(self): def getInputDevices(self):
return self.input_devices return self.input_devices

View File

@@ -20,122 +20,107 @@ class Controller:
self.run = run self.run = run
# response functions # response functions
class DownloadSoftwareProgressBar: def downloadSoftwareProgressBar(self, progress) -> None:
def __init__(self, parent) -> None: self.run(
self.parent = parent
def set(self, progress) -> None:
self.parent.run(
200, 200,
self.parent.run_mapping["download_software"], self.run_mapping["download_software"],
progress, progress,
) )
class UpdateSoftwareProgressBar: def updateSoftwareProgressBar(self, progress) -> None:
def __init__(self, parent) -> None: self.run(
self.parent = parent
def set(self, progress) -> None:
self.parent.run(
200, 200,
self.parent.run_mapping["update_software"], self.run_mapping["update_software"],
progress, progress,
) )
class UpdateSelectedMicDevice: def updateMicHostList(self) -> None:
def __init__(self, parent) -> None: self.run(
self.parent = parent 200,
self.run_mapping["mic_host_list"],
model.getListInputHost(),
)
def set(self, host, device) -> None: def updateMicDeviceList(self) -> None:
self.run(
200,
self.run_mapping["mic_device_list"],
model.getListInputDevice(),
)
def updateSpeakerDeviceList(self) -> None:
self.run(
200,
self.run_mapping["speaker_device_list"],
model.getListOutputDevice(),
)
def updateSelectedMicDevice(self, host, device) -> None:
config.SELECTED_MIC_HOST = host config.SELECTED_MIC_HOST = host
config.SELECTED_MIC_DEVICE = device config.SELECTED_MIC_DEVICE = device
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["selected_mic_device"], self.run_mapping["selected_mic_device"],
{"host":host, "device":device}, {"host":host, "device":device},
) )
class UpdateSelectedSpeakerDevice: def updateSelectedSpeakerDevice(self, device) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def set(self, device) -> None:
config.SELECTED_SPEAKER_DEVICE = device config.SELECTED_SPEAKER_DEVICE = device
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["selected_speaker_device"], self.run_mapping["selected_speaker_device"],
device, device,
) )
class ProgressBarMicEnergy: def progressBarMicEnergy(self, energy) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def set(self, energy) -> None:
if energy is False: if energy is False:
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_device"], self.run_mapping["error_device"],
{"message":"No mic device detected."}, {"message":"No mic device detected."},
) )
else: else:
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["check_mic_volume"], self.run_mapping["check_mic_volume"],
energy, energy,
) )
class ProgressBarSpeakerEnergy: def progressBarSpeakerEnergy(self, energy) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def set(self, energy) -> None:
if energy is False: if energy is False:
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_device"], self.run_mapping["error_device"],
{"message":"No mic device detected."}, {"message":"No mic device detected."},
) )
else: else:
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["check_speaker_volume"], self.run_mapping["check_speaker_volume"],
energy, energy,
) )
class DownloadCTranslate2ProgressBar: def downloadCTranslate2ProgressBar(self, progress) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def set(self, progress) -> None:
printLog("CTranslate2 Weight Download Progress", progress) printLog("CTranslate2 Weight Download Progress", progress)
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["download_ctranslate2"], self.run_mapping["download_ctranslate2"],
progress, progress,
) )
class DownloadWhisperProgressBar: def downloadWhisperProgressBar(self, progress) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def set(self, progress) -> None:
printLog("Whisper Weight Download Progress", progress) printLog("Whisper Weight Download Progress", progress)
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["download_whisper"], self.run_mapping["download_whisper"],
progress, progress,
) )
class MicMessage: def micMessage(self, message: Union[str, bool]) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def send(self, message: Union[str, bool]) -> None:
if isinstance(message, bool) and message is False: if isinstance(message, bool) and message is False:
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_device"], self.run_mapping["error_device"],
{"message":"No mic device detected."}, {"message":"No mic device detected."},
) )
@@ -144,9 +129,9 @@ class Controller:
translation = [] translation = []
transliteration = [] transliteration = []
if model.checkKeywords(message): if model.checkKeywords(message):
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["word_filter"], self.run_mapping["word_filter"],
{"message":f"Detected by word filter:{message}"}, {"message":f"Detected by word filter:{message}"},
) )
return return
@@ -157,10 +142,10 @@ class Controller:
else: else:
translation, success = model.getInputTranslate(message) translation, success = model.getInputTranslate(message)
if all(success) is not True: if all(success) is not True:
self.parent.changeToCTranslate2Process() self.changeToCTranslate2Process()
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_translation_engine"], self.run_mapping["error_translation_engine"],
{"message":"translation engine limit error"}, {"message":"translation engine limit error"},
) )
@@ -172,16 +157,16 @@ class Controller:
if config.SEND_MESSAGE_TO_VRC is True: if config.SEND_MESSAGE_TO_VRC is True:
if config.SEND_ONLY_TRANSLATED_MESSAGES is True: if config.SEND_ONLY_TRANSLATED_MESSAGES is True:
if config.ENABLE_TRANSLATION is False: if config.ENABLE_TRANSLATION is False:
osc_message = self.parent.messageFormatter("SEND", "", [message]) osc_message = self.messageFormatter("SEND", "", [message])
else: else:
osc_message = self.parent.messageFormatter("SEND", "", translation) osc_message = self.messageFormatter("SEND", "", translation)
else: else:
osc_message = self.parent.messageFormatter("SEND", translation, [message]) osc_message = self.messageFormatter("SEND", translation, [message])
model.oscSendMessage(osc_message) model.oscSendMessage(osc_message)
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["transcription_mic"], self.run_mapping["transcription_mic"],
{ {
"message":message, "message":message,
"translation":translation, "translation":translation,
@@ -198,15 +183,11 @@ class Controller:
# overlay_image = model.createOverlayImageLong("send", message, translation) # overlay_image = model.createOverlayImageLong("send", message, translation)
# model.updateOverlay(overlay_image) # model.updateOverlay(overlay_image)
class SpeakerMessage: def speakerMessage(self, message) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def receive(self, message):
if isinstance(message, bool) and message is False: if isinstance(message, bool) and message is False:
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_device"], self.run_mapping["error_device"],
{"message":"No mic device detected."}, {"message":"No mic device detected."},
) )
elif isinstance(message, str) and len(message) > 0: elif isinstance(message, str) and len(message) > 0:
@@ -219,10 +200,10 @@ class Controller:
else: else:
translation, success = model.getOutputTranslate(message) translation, success = model.getOutputTranslate(message)
if all(success) is not True: if all(success) is not True:
self.parent.changeToCTranslate2Process() self.changeToCTranslate2Process()
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_translation_engine"], self.run_mapping["error_translation_engine"],
{"message":"translation engine limit error"}, {"message":"translation engine limit error"},
) )
@@ -242,14 +223,14 @@ class Controller:
if config.ENABLE_SPEAKER2CHATBOX is True: if config.ENABLE_SPEAKER2CHATBOX is True:
# send OSC message # send OSC message
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True: if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
osc_message = self.parent.messageFormatter("RECEIVED", translation, [message]) osc_message = self.messageFormatter("RECEIVED", translation, [message])
model.oscSendMessage(osc_message) model.oscSendMessage(osc_message)
# ------------Speaker2Chatbox------------ # ------------Speaker2Chatbox------------
# update textbox message log (Received) # update textbox message log (Received)
self.parent.run( self.run(
200, 200,
self.parent.run_mapping["speaker"], self.run_mapping["speaker"],
{ {
"message":message, "message":message,
"translation":translation, "translation":translation,
@@ -260,11 +241,7 @@ class Controller:
translation = " (" + "/".join(translation) + ")" translation = " (" + "/".join(translation) + ")"
model.logger.info(f"[RECEIVED] {message}{translation}") model.logger.info(f"[RECEIVED] {message}{translation}")
class ChatMessage: def chatMessage(self, data) -> None:
def __init__(self, parent) -> None:
self.parent = parent
def send(self, data):
id = data["id"] id = data["id"]
message = data["message"] message = data["message"]
if len(message) > 0: if len(message) > 0:
@@ -275,20 +252,20 @@ class Controller:
pass pass
else: else:
if config.USE_EXCLUDE_WORDS is True: if config.USE_EXCLUDE_WORDS is True:
replacement_message, replacement_dict = self.parent.replaceExclamationsWithRandom(message) replacement_message, replacement_dict = self.replaceExclamationsWithRandom(message)
translation, success = model.getInputTranslate(replacement_message) translation, success = model.getInputTranslate(replacement_message)
message = self.parent.removeExclamations(message) message = self.removeExclamations(message)
for i in range(len(translation)): for i in range(len(translation)):
translation[i] = self.parent.restoreText(translation[i], replacement_dict) translation[i] = self.restoreText(translation[i], replacement_dict)
else: else:
translation, success = model.getInputTranslate(message) translation, success = model.getInputTranslate(message)
if all(success) is not True: if all(success) is not True:
self.parent.changeToCTranslate2Process() self.changeToCTranslate2Process()
self.parent.run( self.run(
400, 400,
self.parent.run_mapping["error_translation_engine"], self.run_mapping["error_translation_engine"],
{"message":"translation engine limit error"}, {"message":"translation engine limit error"},
) )
@@ -300,11 +277,11 @@ class Controller:
if config.SEND_MESSAGE_TO_VRC is True: if config.SEND_MESSAGE_TO_VRC is True:
if config.SEND_ONLY_TRANSLATED_MESSAGES is True: if config.SEND_ONLY_TRANSLATED_MESSAGES is True:
if config.ENABLE_TRANSLATION is False: if config.ENABLE_TRANSLATION is False:
osc_message = self.parent.messageFormatter("SEND", "", [message]) osc_message = self.messageFormatter("SEND", "", [message])
else: else:
osc_message = self.parent.messageFormatter("SEND", "", translation) osc_message = self.messageFormatter("SEND", "", translation)
else: else:
osc_message = self.parent.messageFormatter("SEND", translation, [message]) osc_message = self.messageFormatter("SEND", translation, [message])
model.oscSendMessage(osc_message) model.oscSendMessage(osc_message)
# if config.OVERLAY_SMALL_LOG is True: # if config.OVERLAY_SMALL_LOG is True:
@@ -624,8 +601,7 @@ class Controller:
def setEnableAutoMicSelect(self, *args, **kwargs) -> dict: def setEnableAutoMicSelect(self, *args, **kwargs) -> dict:
config.AUTO_MIC_SELECT = True config.AUTO_MIC_SELECT = True
update_device = self.UpdateSelectedMicDevice(self) device_manager.setCallbackDefaultInputDevice(self.updateSelectedMicDevice)
device_manager.setCallbackDefaultInputDevice(update_device.set)
device_manager.noticeDefaultDevice() device_manager.noticeDefaultDevice()
return {"status":200, "result":config.AUTO_MIC_SELECT} return {"status":200, "result":config.AUTO_MIC_SELECT}
@@ -807,8 +783,7 @@ class Controller:
def setEnableAutoSpeakerSelect(self, *args, **kwargs) -> dict: def setEnableAutoSpeakerSelect(self, *args, **kwargs) -> dict:
config.AUTO_SPEAKER_SELECT = True config.AUTO_SPEAKER_SELECT = True
update_device = self.UpdateSelectedSpeakerDevice(self) device_manager.setCallbackDefaultOutputDevice(self.updateSelectedSpeakerDevice)
device_manager.setCallbackDefaultOutputDevice(update_device.set)
device_manager.noticeDefaultDevice() device_manager.noticeDefaultDevice()
return {"status":200, "result":config.AUTO_SPEAKER_SELECT} return {"status":200, "result":config.AUTO_SPEAKER_SELECT}
@@ -1285,9 +1260,8 @@ class Controller:
return {"status":200, "result":config.VRC_MIC_MUTE_SYNC} return {"status":200, "result":config.VRC_MIC_MUTE_SYNC}
def setEnableCheckSpeakerThreshold(self, *args, **kwargs) -> dict: def setEnableCheckSpeakerThreshold(self, *args, **kwargs) -> dict:
progressbar_speaker_energy = self.ProgressBarSpeakerEnergy(self)
model.startCheckSpeakerEnergy( model.startCheckSpeakerEnergy(
progressbar_speaker_energy.set, self.progressBarSpeakerEnergy,
) )
config.ENABLE_CHECK_ENERGY_RECEIVE = True config.ENABLE_CHECK_ENERGY_RECEIVE = True
return {"status":200, "result":config.ENABLE_CHECK_ENERGY_RECEIVE} return {"status":200, "result":config.ENABLE_CHECK_ENERGY_RECEIVE}
@@ -1299,9 +1273,8 @@ class Controller:
return {"status":200, "result":config.ENABLE_CHECK_ENERGY_RECEIVE} return {"status":200, "result":config.ENABLE_CHECK_ENERGY_RECEIVE}
def setEnableCheckMicThreshold(self, *args, **kwargs) -> dict: def setEnableCheckMicThreshold(self, *args, **kwargs) -> dict:
progressbar_mic_energy = self.ProgressBarMicEnergy(self)
model.startCheckMicEnergy( model.startCheckMicEnergy(
progressbar_mic_energy.set, self.progressBarMicEnergy,
) )
config.ENABLE_CHECK_ENERGY_SEND = True config.ENABLE_CHECK_ENERGY_SEND = True
return {"status":200, "result":config.ENABLE_CHECK_ENERGY_SEND} return {"status":200, "result":config.ENABLE_CHECK_ENERGY_SEND}
@@ -1314,9 +1287,7 @@ class Controller:
# def updateSoftware(*args, **kwargs) -> dict: # def updateSoftware(*args, **kwargs) -> dict:
# printLog("Update callbackUpdateSoftware") # printLog("Update callbackUpdateSoftware")
# download = DownloadSoftwareProgressBar(self) # model.updateSoftware(restart=True, download=self.downloadSoftwareProgressBar, update=self.updateSoftwareProgressBar)
# update = UpdateSoftwareProgressBar(self)
# model.updateSoftware(restart=True, download=download.set, update=update.set)
# return {"status":200, "result":True} # return {"status":200, "result":True}
# def restartSoftware(*args, **kwargs) -> dict: # def restartSoftware(*args, **kwargs) -> dict:
@@ -1358,8 +1329,7 @@ class Controller:
return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE} return {"status":200, "result":config.ENABLE_TRANSCRIPTION_RECEIVE}
def sendMessageBox(self, data, *args, **kwargs) -> dict: def sendMessageBox(self, data, *args, **kwargs) -> dict:
chat = self.ChatMessage(self) response = self.chatMessage(data)
response = chat.send(data)
return response return response
@staticmethod @staticmethod
@@ -1395,13 +1365,11 @@ class Controller:
} }
def downloadCtranslate2Weight(self, *args, **kwargs) -> dict: def downloadCtranslate2Weight(self, *args, **kwargs) -> dict:
download = self.DownloadCTranslate2ProgressBar(self) self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar)
self.startThreadingDownloadCtranslate2Weight(download.set)
return {"status":200} return {"status":200}
def downloadWhisperWeight(self, *args, **kwargs) -> dict: def downloadWhisperWeight(self, *args, **kwargs) -> dict:
download = self.DownloadWhisperProgressBar(self) self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar)
self.startThreadingDownloadWhisperWeight(download.set)
return {"status":200} return {"status":200}
@staticmethod @staticmethod
@@ -1427,8 +1395,7 @@ class Controller:
config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = "CTranslate2" config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = "CTranslate2"
def startTranscriptionSendMessage(self) -> None: def startTranscriptionSendMessage(self) -> None:
mic_message = self.MicMessage(self) model.startMicTranscript(self.micMessage)
model.startMicTranscript(mic_message.send)
@staticmethod @staticmethod
def stopTranscriptionSendMessage() -> None: def stopTranscriptionSendMessage() -> None:
@@ -1464,8 +1431,7 @@ class Controller:
th_stopTranscriptionSendMessage.start() th_stopTranscriptionSendMessage.start()
def startTranscriptionReceiveMessage(self) -> None: def startTranscriptionReceiveMessage(self) -> None:
speaker_message = self.SpeakerMessage(self) model.startSpeakerTranscript(self.speakerMessage)
model.startSpeakerTranscript(speaker_message.receive)
@staticmethod @staticmethod
def stopTranscriptionReceiveMessage() -> None: def stopTranscriptionReceiveMessage() -> None:
@@ -1546,6 +1512,8 @@ class Controller:
if engine not in engines: if engine not in engines:
engine = engines[0] engine = engines[0]
config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = engine config.SELECTED_TRANSLATION_ENGINES[config.SELECTED_TAB_NO] = engine
self.run(200, self.run_mapping["selected_translation_engine"], engine)
self.run(200, self.run_mapping["translation_engines"], engines)
@staticmethod @staticmethod
def startThreadingDownloadCtranslate2Weight(callback:Callable[[float], None]) -> None: def startThreadingDownloadCtranslate2Weight(callback:Callable[[float], None]) -> None:
@@ -1577,8 +1545,7 @@ class Controller:
# check Downloaded CTranslate2 Model Weight # check Downloaded CTranslate2 Model Weight
printLog("Check Downloaded CTranslate2 Model Weight") printLog("Check Downloaded CTranslate2 Model Weight")
if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False: if config.USE_TRANSLATION_FEATURE is True and model.checkCTranslatorCTranslate2ModelWeight() is False:
download = self.DownloadCTranslate2ProgressBar(self) self.startThreadingDownloadCtranslate2Weight(self.downloadCTranslate2ProgressBar)
self.startThreadingDownloadCtranslate2Weight(download.set)
# set Transcription Engine # set Transcription Engine
printLog("Set Transcription Engine") printLog("Set Transcription Engine")
@@ -1590,8 +1557,7 @@ class Controller:
# check Downloaded Whisper Model Weight # check Downloaded Whisper Model Weight
printLog("Check Downloaded Whisper Model Weight") printLog("Check Downloaded Whisper Model Weight")
if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False: if config.USE_WHISPER_FEATURE is True and model.checkTranscriptionWhisperModelWeight() is False:
download = self.DownloadWhisperProgressBar(self) self.startThreadingDownloadWhisperWeight(self.downloadWhisperProgressBar)
self.startThreadingDownloadWhisperWeight(download.set)
# set word filter # set word filter
printLog("Set Word Filter") printLog("Set Word Filter")
@@ -1616,11 +1582,13 @@ class Controller:
# init Auto device selection # init Auto device selection
printLog("Init Auto Device Selection") printLog("Init Auto Device Selection")
if config.AUTO_MIC_SELECT is True: if config.AUTO_MIC_SELECT is True:
update_mic_device = self.UpdateSelectedMicDevice(self) device_manager.setCallbackDefaultInputDevice(self.updateSelectedMicDevice)
device_manager.setCallbackDefaultInputDevice(update_mic_device.set)
if config.AUTO_SPEAKER_SELECT is True: if config.AUTO_SPEAKER_SELECT is True:
update_speaker_device = self.UpdateSelectedSpeakerDevice(self) device_manager.setCallbackDefaultOutputDevice(self.updateSelectedSpeakerDevice)
device_manager.setCallbackDefaultOutputDevice(update_speaker_device.set)
device_manager.setCallbackHostList(self.updateMicHostList)
device_manager.setCallbackInputDeviceList(self.updateMicDeviceList)
device_manager.setCallbackOutputDeviceList(self.updateSpeakerDeviceList)
printLog("End Initialization") printLog("End Initialization")

View File

@@ -26,8 +26,15 @@ run_mapping = {
"download_ctranslate2":"/run/download_ctranslate2_weight", "download_ctranslate2":"/run/download_ctranslate2_weight",
"download_whisper":"/run/download_whisper_weight", "download_whisper":"/run/download_whisper_weight",
"selected_mic_device":"/set/data/selected_mic_host", "selected_mic_device":"/run/selected_mic_device",
"selected_speaker_device":"/set/data/selected_speaker_device", "selected_speaker_device":"/run/selected_speaker_device",
"selected_translation_engine":"/run/selected_translation_engine",
"translation_engines":"/run/translation_engines",
"mic_host_list":"/run/mic_host_list",
"mic_device_list":"/run/mic_device_list",
"speaker_device_list":"/run/speaker_device_list",
} }
controller.setRunMapping(run_mapping) controller.setRunMapping(run_mapping)