From a40529aaa525444c579996ea3f772cf4e36d9fde Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sat, 14 Sep 2024 00:22:03 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7[WIP/TEST]=20Model=20:=20Device?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4=E7=9B=A3=E8=A6=96=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit マイク/スピーカー両方とも自動選択ONの場合にUIが固まる --- src-python/model.py | 40 +++++++++++++++++++++++++++++++ src-python/webui_controller.py | 44 +++++++++++++++++++++++++++++++--- src-python/webui_mainloop.py | 8 +++++++ 3 files changed, 89 insertions(+), 3 deletions(-) diff --git a/src-python/model.py b/src-python/model.py index 7e37d14c..d66da83e 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -422,6 +422,46 @@ class Model: def getListOutputDevice(): return [device["name"] for device in getOutputDevices()] + def startAutomaticMicSelection(self, fnc): + def checkMicDevice(fnc): + if config.ENABLE_MIC_AUTOMATIC_SELECTION is True: + default_device = getDefaultInputDevice() + mic_host_name = default_device["host"]["name"] + mic_device_name = default_device["device"]["name"] + if mic_host_name != config.CHOICE_MIC_HOST or mic_device_name != config.CHOICE_MIC_DEVICE: + config.CHOICE_MIC_HOST = mic_host_name + config.CHOICE_MIC_DEVICE = mic_device_name + fnc(config.CHOICE_MIC_DEVICE) + sleep(2) + + self.th_check_mic_device = threadFnc(checkMicDevice, args=(fnc,)) + self.th_check_mic_device.daemon = True + self.th_check_mic_device.start() + + def stopAutomaticMicSelection(self): + if isinstance(self.th_check_mic_device, threadFnc): + self.th_check_mic_device.stop() + self.th_check_mic_device = None + + def startAutomaticSpeakerSelection(self, fnc): + def checkSpeakerDevice(fnc): + if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True: + default_device = getDefaultOutputDevice() + speaker_device_name = default_device["device"]["name"] + if speaker_device_name != config.CHOICE_SPEAKER_DEVICE: + config.CHOICE_SPEAKER_DEVICE = speaker_device_name + fnc(config.CHOICE_SPEAKER_DEVICE) + sleep(2) + + self.th_check_speaker_device = threadFnc(checkSpeakerDevice, args=(fnc,)) + self.th_check_speaker_device.daemon = True + self.th_check_speaker_device.start() + + def stopAutomaticSpeakerSelection(self): + if isinstance(self.th_check_speaker_device, threadFnc): + self.th_check_speaker_device.stop() + self.th_check_speaker_device = None + def startMicTranscript(self, fnc): if config.ENABLE_MIC_AUTOMATIC_SELECTION is True: default_device = getDefaultInputDevice() diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index f2cfb2e4..673fb06c 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -778,14 +778,27 @@ def callbackClearDeeplAuthKey(*args, **kwargs) -> dict: # Transcription Tab # Transcription (Mic) +class UpdateMicDevice: + def __init__(self, action): + self.action = action -def callbackEnableMicAutomaticSelection(*args, **kwargs) -> dict: + def set(self, device) -> None: + printLog("Update Mic Device", device) + self.action("mic", { + "status":200, + "result":device + }) + +def callbackEnableMicAutomaticSelection(data, action, *args, **kwargs) -> dict: printLog("Enable Mic Automatic Selection") + update_mic_device = UpdateMicDevice(action) + model.startAutomaticMicSelection(update_mic_device.set) config.ENABLE_MIC_AUTOMATIC_SELECTION = True return {"status":200, "result":config.ENABLE_MIC_AUTOMATIC_SELECTION} def callbackDisableMicAutomaticSelection(*args, **kwargs) -> dict: printLog("Disable Mic Automatic Selection") + model.stopAutomaticMicSelection() config.ENABLE_MIC_AUTOMATIC_SELECTION = False return {"status":200, "result":config.ENABLE_MIC_AUTOMATIC_SELECTION} @@ -930,14 +943,27 @@ def callbackDeleteMicWordFilter(data, *args, **kwargs) -> dict: return {"status":200, "result":config.INPUT_MIC_WORD_FILTER} # Transcription (Speaker) +class UpdateSpeakerDevice: + def __init__(self, action): + self.action = action -def callbackEnableSpeakerAutomaticSelection(*args, **kwargs) -> dict: + def set(self, device) -> None: + printLog("Update Speaker Device", device) + self.action("speaker", { + "status":200, + "result":device + }) + +def callbackEnableSpeakerAutomaticSelection(data, action, *args, **kwargs) -> dict: printLog("Enable Speaker Automatic Selection") + update_speaker_device = UpdateSpeakerDevice(action) + model.startAutomaticSpeakerSelection(update_speaker_device.set) config.ENABLE_SPEAKER_AUTOMATIC_SELECTION = True return {"status":200, "result":config.ENABLE_SPEAKER_AUTOMATIC_SELECTION} def callbackDisableSpeakerAutomaticSelection(*args, **kwargs) -> dict: printLog("Disable Speaker Automatic Selection") + model.stopAutomaticSpeakerSelection() config.ENABLE_SPEAKER_AUTOMATIC_SELECTION = False return {"status":200, "result":config.ENABLE_SPEAKER_AUTOMATIC_SELECTION} @@ -1386,4 +1412,16 @@ def init(endpoints:dict, *args, **kwargs) -> None: model.startReceiveOSC() if config.ENABLE_VRC_MIC_MUTE_SYNC is True: model.startCheckMuteSelfStatus() - printLog("End Initialization") \ No newline at end of file + printLog("End Initialization") + + # init Auto device selection + printLog("Init Auto Device Selection") + if config.ENABLE_MIC_AUTOMATIC_SELECTION is True: + def callback(device): + printResponse(200, endpoints["check_mic_device"], device) + model.startAutomaticMicSelection(callback) + + if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True: + def callback(device): + printResponse(200, endpoints["check_speaker_device"], device) + model.startAutomaticSpeakerSelection(callback) \ No newline at end of file diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 1e96b257..a0d473a7 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -240,6 +240,12 @@ action_mapping = { "/controller/callback_download_whisper_weight": { "download":"/action/download_whisper_weight" }, + "/controller/callback_enable_mic_automatic_selection": { + "mic":"/controller/callback_set_mic_device" + }, + "/controller/callback_enable_speaker_automatic_selection": { + "speaker":"/controller/callback_set_speaker_device" + } } def handleConfigRequest(endpoint): @@ -303,6 +309,8 @@ if __name__ == "__main__": controller.init({ "ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"], "whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"], + "check_mic_device": action_mapping["/controller/callback_enable_mic_automatic_selection"]["mic"], + "check_speaker_device": action_mapping["/controller/callback_enable_speaker_automatic_selection"]["speaker"], }) process = "main"