👍️[Update] Model : Deviceの変更監視処理を追加

マイク/スピーカーの別々のスレッドの処理を一つにまとめたら動いた
This commit is contained in:
misyaguziya
2024-09-14 03:09:19 +09:00
parent a40529aaa5
commit 551bc424b8
3 changed files with 48 additions and 62 deletions

View File

@@ -778,30 +778,50 @@ def callbackClearDeeplAuthKey(*args, **kwargs) -> dict:
# Transcription Tab
# Transcription (Mic)
class UpdateMicDevice:
class UpdateSelectedDevice:
def __init__(self, action):
self.action = action
def set(self, device) -> None:
def set_mic(self, device) -> None:
printLog("Update Mic Device", device)
self.action("mic", {
"status":200,
"result":device
})
def set_speaker(self, device) -> None:
printLog("Update Speaker Device", device)
self.action("speaker", {
"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)
update_device = UpdateSelectedDevice(action)
model.startAutomaticDeviceSelection(update_device.set_mic, update_device.set_speaker)
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()
model.stopAutomaticDeviceSelection()
config.ENABLE_MIC_AUTOMATIC_SELECTION = False
return {"status":200, "result":config.ENABLE_MIC_AUTOMATIC_SELECTION}
def callbackEnableSpeakerAutomaticSelection(data, action, *args, **kwargs) -> dict:
printLog("Enable Speaker Automatic Selection")
update_device = UpdateSelectedDevice(action)
model.startAutomaticDeviceSelection(update_device.set_mic, update_device.set_speaker)
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.stopAutomaticDeviceSelection()
config.ENABLE_SPEAKER_AUTOMATIC_SELECTION = False
return {"status":200, "result":config.ENABLE_SPEAKER_AUTOMATIC_SELECTION}
def callbackSetMicHost(data, *args, **kwargs) -> dict:
printLog("Set Mic Host", data)
config.CHOICE_MIC_HOST = data
@@ -943,30 +963,6 @@ 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 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}
def callbackSetSpeakerDevice(data, *args, **kwargs) -> dict:
printLog("Set Speaker Device", data)
config.CHOICE_SPEAKER_DEVICE = data
@@ -1416,12 +1412,9 @@ def init(endpoints:dict, *args, **kwargs) -> None:
# init Auto device selection
printLog("Init Auto Device Selection")
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
def callback(device):
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True or config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
def mic_callback(device):
printResponse(200, endpoints["check_mic_device"], device)
model.startAutomaticMicSelection(callback)
if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
def callback(device):
def speaker_callback(device):
printResponse(200, endpoints["check_speaker_device"], device)
model.startAutomaticSpeakerSelection(callback)
model.startAutomaticDeviceSelection(mic_callback, speaker_callback)