🚧[WIP/TEST] Model : Deviceの変更監視処理を追加

マイク/スピーカー両方とも自動選択ONの場合にUIが固まる
This commit is contained in:
misyaguziya
2024-09-14 00:22:03 +09:00
parent 6254a93b20
commit a40529aaa5
3 changed files with 89 additions and 3 deletions

View File

@@ -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()

View File

@@ -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")
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)

View File

@@ -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"