👍️[Update] Model : Deviceの変更監視処理を追加
マイク/スピーカーの別々のスレッドの処理を一つにまとめたら動いた
This commit is contained in:
@@ -69,6 +69,7 @@ class Model:
|
|||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
self.logger = None
|
self.logger = None
|
||||||
|
self.th_check_device = None
|
||||||
self.mic_print_transcript = None
|
self.mic_print_transcript = None
|
||||||
self.mic_audio_recorder = None
|
self.mic_audio_recorder = None
|
||||||
self.mic_energy_recorder = None
|
self.mic_energy_recorder = None
|
||||||
@@ -422,8 +423,8 @@ class Model:
|
|||||||
def getListOutputDevice():
|
def getListOutputDevice():
|
||||||
return [device["name"] for device in getOutputDevices()]
|
return [device["name"] for device in getOutputDevices()]
|
||||||
|
|
||||||
def startAutomaticMicSelection(self, fnc):
|
def startAutomaticDeviceSelection(self, fnc_mic, fnc_speaker):
|
||||||
def checkMicDevice(fnc):
|
def checkDevice(fnc_mic, fnc_speaker):
|
||||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
||||||
default_device = getDefaultInputDevice()
|
default_device = getDefaultInputDevice()
|
||||||
mic_host_name = default_device["host"]["name"]
|
mic_host_name = default_device["host"]["name"]
|
||||||
@@ -431,36 +432,26 @@ class Model:
|
|||||||
if mic_host_name != config.CHOICE_MIC_HOST or mic_device_name != config.CHOICE_MIC_DEVICE:
|
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_HOST = mic_host_name
|
||||||
config.CHOICE_MIC_DEVICE = mic_device_name
|
config.CHOICE_MIC_DEVICE = mic_device_name
|
||||||
fnc(config.CHOICE_MIC_DEVICE)
|
fnc_mic(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:
|
if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
|
||||||
default_device = getDefaultOutputDevice()
|
default_device = getDefaultOutputDevice()
|
||||||
speaker_device_name = default_device["device"]["name"]
|
speaker_device_name = default_device["device"]["name"]
|
||||||
if speaker_device_name != config.CHOICE_SPEAKER_DEVICE:
|
if speaker_device_name != config.CHOICE_SPEAKER_DEVICE:
|
||||||
config.CHOICE_SPEAKER_DEVICE = speaker_device_name
|
config.CHOICE_SPEAKER_DEVICE = speaker_device_name
|
||||||
fnc(config.CHOICE_SPEAKER_DEVICE)
|
fnc_speaker(config.CHOICE_SPEAKER_DEVICE)
|
||||||
sleep(2)
|
sleep(1)
|
||||||
|
|
||||||
self.th_check_speaker_device = threadFnc(checkSpeakerDevice, args=(fnc,))
|
if isinstance(self.th_check_device, threadFnc) is False:
|
||||||
self.th_check_speaker_device.daemon = True
|
self.th_check_device = threadFnc(checkDevice, args=(fnc_mic, fnc_speaker,))
|
||||||
self.th_check_speaker_device.start()
|
self.th_check_device.daemon = True
|
||||||
|
self.th_check_device.start()
|
||||||
|
|
||||||
def stopAutomaticSpeakerSelection(self):
|
def stopAutomaticDeviceSelection(self):
|
||||||
if isinstance(self.th_check_speaker_device, threadFnc):
|
if config.ENABLE_MIC_AUTOMATIC_SELECTION is False and config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is False:
|
||||||
self.th_check_speaker_device.stop()
|
if isinstance(self.th_check_device, threadFnc):
|
||||||
self.th_check_speaker_device = None
|
self.th_check_device.stop()
|
||||||
|
self.th_check_device = None
|
||||||
|
|
||||||
def startMicTranscript(self, fnc):
|
def startMicTranscript(self, fnc):
|
||||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
||||||
|
|||||||
@@ -778,30 +778,50 @@ def callbackClearDeeplAuthKey(*args, **kwargs) -> dict:
|
|||||||
|
|
||||||
# Transcription Tab
|
# Transcription Tab
|
||||||
# Transcription (Mic)
|
# Transcription (Mic)
|
||||||
class UpdateMicDevice:
|
class UpdateSelectedDevice:
|
||||||
def __init__(self, action):
|
def __init__(self, action):
|
||||||
self.action = action
|
self.action = action
|
||||||
|
|
||||||
def set(self, device) -> None:
|
def set_mic(self, device) -> None:
|
||||||
printLog("Update Mic Device", device)
|
printLog("Update Mic Device", device)
|
||||||
self.action("mic", {
|
self.action("mic", {
|
||||||
"status":200,
|
"status":200,
|
||||||
"result":device
|
"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:
|
def callbackEnableMicAutomaticSelection(data, action, *args, **kwargs) -> dict:
|
||||||
printLog("Enable Mic Automatic Selection")
|
printLog("Enable Mic Automatic Selection")
|
||||||
update_mic_device = UpdateMicDevice(action)
|
update_device = UpdateSelectedDevice(action)
|
||||||
model.startAutomaticMicSelection(update_mic_device.set)
|
model.startAutomaticDeviceSelection(update_device.set_mic, update_device.set_speaker)
|
||||||
config.ENABLE_MIC_AUTOMATIC_SELECTION = True
|
config.ENABLE_MIC_AUTOMATIC_SELECTION = True
|
||||||
return {"status":200, "result":config.ENABLE_MIC_AUTOMATIC_SELECTION}
|
return {"status":200, "result":config.ENABLE_MIC_AUTOMATIC_SELECTION}
|
||||||
|
|
||||||
def callbackDisableMicAutomaticSelection(*args, **kwargs) -> dict:
|
def callbackDisableMicAutomaticSelection(*args, **kwargs) -> dict:
|
||||||
printLog("Disable Mic Automatic Selection")
|
printLog("Disable Mic Automatic Selection")
|
||||||
model.stopAutomaticMicSelection()
|
model.stopAutomaticDeviceSelection()
|
||||||
config.ENABLE_MIC_AUTOMATIC_SELECTION = False
|
config.ENABLE_MIC_AUTOMATIC_SELECTION = False
|
||||||
return {"status":200, "result":config.ENABLE_MIC_AUTOMATIC_SELECTION}
|
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:
|
def callbackSetMicHost(data, *args, **kwargs) -> dict:
|
||||||
printLog("Set Mic Host", data)
|
printLog("Set Mic Host", data)
|
||||||
config.CHOICE_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}
|
return {"status":200, "result":config.INPUT_MIC_WORD_FILTER}
|
||||||
|
|
||||||
# Transcription (Speaker)
|
# 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:
|
def callbackSetSpeakerDevice(data, *args, **kwargs) -> dict:
|
||||||
printLog("Set Speaker Device", data)
|
printLog("Set Speaker Device", data)
|
||||||
config.CHOICE_SPEAKER_DEVICE = data
|
config.CHOICE_SPEAKER_DEVICE = data
|
||||||
@@ -1416,12 +1412,9 @@ def init(endpoints:dict, *args, **kwargs) -> None:
|
|||||||
|
|
||||||
# init Auto device selection
|
# init Auto device selection
|
||||||
printLog("Init Auto Device Selection")
|
printLog("Init Auto Device Selection")
|
||||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True or config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
|
||||||
def callback(device):
|
def mic_callback(device):
|
||||||
printResponse(200, endpoints["check_mic_device"], device)
|
printResponse(200, endpoints["check_mic_device"], device)
|
||||||
model.startAutomaticMicSelection(callback)
|
def speaker_callback(device):
|
||||||
|
|
||||||
if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
|
|
||||||
def callback(device):
|
|
||||||
printResponse(200, endpoints["check_speaker_device"], device)
|
printResponse(200, endpoints["check_speaker_device"], device)
|
||||||
model.startAutomaticSpeakerSelection(callback)
|
model.startAutomaticDeviceSelection(mic_callback, speaker_callback)
|
||||||
@@ -241,10 +241,12 @@ action_mapping = {
|
|||||||
"download":"/action/download_whisper_weight"
|
"download":"/action/download_whisper_weight"
|
||||||
},
|
},
|
||||||
"/controller/callback_enable_mic_automatic_selection": {
|
"/controller/callback_enable_mic_automatic_selection": {
|
||||||
"mic":"/controller/callback_set_mic_device"
|
"mic":"/controller/callback_set_mic_device",
|
||||||
|
"speaker":"/controller/callback_set_speaker_device",
|
||||||
},
|
},
|
||||||
"/controller/callback_enable_speaker_automatic_selection": {
|
"/controller/callback_enable_speaker_automatic_selection": {
|
||||||
"speaker":"/controller/callback_set_speaker_device"
|
"mic":"/controller/callback_set_mic_device",
|
||||||
|
"speaker":"/controller/callback_set_speaker_device",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user