👍️[Update] Model: ENABLE_MIC_AUTOMATIC_SELECTION/ENABLE_SPEAKER_AUTOMATIC_SELECTIONの処理をdevice_managerのcallbackで実行するように変更
This commit is contained in:
@@ -423,33 +423,6 @@ class Model:
|
||||
result = [device["name"] for device in device_manager.getOutputDevices()]
|
||||
return result
|
||||
|
||||
def startAutomaticDeviceSelection(self, fnc_mic, fnc_speaker):
|
||||
def checkDevice(fnc_mic, fnc_speaker):
|
||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
||||
default_device = device_manager.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:
|
||||
fnc_mic(mic_host_name, mic_device_name)
|
||||
|
||||
if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
|
||||
default_device = device_manager.getDefaultOutputDevice()
|
||||
speaker_device_name = default_device["device"]["name"]
|
||||
if speaker_device_name != config.CHOICE_SPEAKER_DEVICE:
|
||||
fnc_speaker(speaker_device_name)
|
||||
sleep(1)
|
||||
|
||||
if isinstance(self.th_check_device, threadFnc) is False:
|
||||
self.th_check_device = threadFnc(checkDevice, args=(fnc_mic, fnc_speaker,))
|
||||
self.th_check_device.daemon = True
|
||||
self.th_check_device.start()
|
||||
|
||||
def stopAutomaticDeviceSelection(self):
|
||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is False and config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is False:
|
||||
if isinstance(self.th_check_device, threadFnc):
|
||||
self.th_check_device.stop()
|
||||
self.th_check_device = None
|
||||
|
||||
def startMicTranscript(self, fnc):
|
||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
||||
default_device = device_manager.getDefaultInputDevice()
|
||||
|
||||
@@ -35,6 +35,9 @@ class DeviceManager:
|
||||
self.default_output_device = {"device": {"name": "NoDevice"}}
|
||||
self.update()
|
||||
|
||||
self.callback_default_input_device = None
|
||||
self.callback_default_output_device = None
|
||||
|
||||
self.monitoring_flag = False
|
||||
self.startMonitoring()
|
||||
|
||||
@@ -123,6 +126,11 @@ class DeviceManager:
|
||||
enumerator.UnregisterEndpointNotificationCallback(cb)
|
||||
self.update()
|
||||
|
||||
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"])
|
||||
if self.callback_default_output_device is not None:
|
||||
self.callback_default_output_device(self.default_output_device["device"]["name"])
|
||||
|
||||
cb = Client()
|
||||
enumerator = AudioUtilities.GetDeviceEnumerator()
|
||||
enumerator.RegisterEndpointNotificationCallback(cb)
|
||||
@@ -140,6 +148,18 @@ class DeviceManager:
|
||||
self.monitoring_flag = False
|
||||
self.th_monitoring.join()
|
||||
|
||||
def setCallbackDefaultInputDevice(self, callback):
|
||||
self.callback_default_input_device = callback
|
||||
|
||||
def clearCallbackDefaultInputDevice(self):
|
||||
self.callback_default_input_device = None
|
||||
|
||||
def setCallbackDefaultOutputDevice(self, callback):
|
||||
self.callback_default_output_device = callback
|
||||
|
||||
def clearCallbackDefaultOutputDevice(self):
|
||||
self.callback_default_output_device = None
|
||||
|
||||
def getInputDevices(self):
|
||||
return self.input_devices
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import re
|
||||
from config import config
|
||||
from model import model
|
||||
from utils import isUniqueStrings, printLog
|
||||
from models.transcription.transcription_utils import device_manager
|
||||
|
||||
# Common
|
||||
class DownloadSoftwareProgressBar:
|
||||
@@ -778,11 +779,11 @@ def callbackClearDeeplAuthKey(*args, **kwargs) -> dict:
|
||||
|
||||
# Transcription Tab
|
||||
# Transcription (Mic)
|
||||
class UpdateSelectedDevice:
|
||||
class UpdateSelectedMicDevice:
|
||||
def __init__(self, action):
|
||||
self.action = action
|
||||
|
||||
def set_mic(self, host, device) -> None:
|
||||
def set(self, host, device) -> None:
|
||||
config.CHOICE_MIC_HOST = host
|
||||
config.CHOICE_MIC_DEVICE = device
|
||||
printLog("Update Host/Mic Device", f"{host}/{device}")
|
||||
@@ -791,7 +792,11 @@ class UpdateSelectedDevice:
|
||||
"result":{"host":host, "device":device}
|
||||
})
|
||||
|
||||
def set_speaker(self, device) -> None:
|
||||
class UpdateSelectedSpeakerDevice:
|
||||
def __init__(self, action):
|
||||
self.action = action
|
||||
|
||||
def set(self, device) -> None:
|
||||
config.CHOICE_SPEAKER_DEVICE = device
|
||||
printLog("Update Speaker Device", device)
|
||||
self.action("speaker", {
|
||||
@@ -801,27 +806,27 @@ class UpdateSelectedDevice:
|
||||
|
||||
def callbackEnableMicAutomaticSelection(data, action, *args, **kwargs) -> dict:
|
||||
printLog("Enable Mic Automatic Selection")
|
||||
update_device = UpdateSelectedDevice(action)
|
||||
model.startAutomaticDeviceSelection(update_device.set_mic, update_device.set_speaker)
|
||||
update_device = UpdateSelectedMicDevice(action)
|
||||
device_manager.setCallbackDefaultInputDevice(update_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.stopAutomaticDeviceSelection()
|
||||
device_manager.clearCallbackDefaultInputDevice()
|
||||
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)
|
||||
update_device = UpdateSelectedSpeakerDevice(action)
|
||||
device_manager.setCallbackDefaultOutputDevice(update_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.stopAutomaticDeviceSelection()
|
||||
device_manager.clearCallbackDefaultInputDevice()
|
||||
config.ENABLE_SPEAKER_AUTOMATIC_SELECTION = False
|
||||
return {"status":200, "result":config.ENABLE_SPEAKER_AUTOMATIC_SELECTION}
|
||||
|
||||
@@ -1412,8 +1417,12 @@ def init(actions:dict, *args, **kwargs) -> None:
|
||||
|
||||
# init Auto device selection
|
||||
printLog("Init Auto Device Selection")
|
||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True or config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
|
||||
update_device = UpdateSelectedDevice(actions["update_selected_device"])
|
||||
model.startAutomaticDeviceSelection(update_device.set_mic, update_device.set_speaker)
|
||||
if config.ENABLE_MIC_AUTOMATIC_SELECTION is True:
|
||||
update_mic_device = UpdateSelectedMicDevice(actions["update_selected_mic_device"])
|
||||
device_manager.setCallbackDefaultInputDevice(update_mic_device.set)
|
||||
|
||||
if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True:
|
||||
update_speaker_device = UpdateSelectedSpeakerDevice(actions["update_selected_speaker_device"])
|
||||
device_manager.setCallbackDefaultOutputDevice(update_speaker_device.set)
|
||||
|
||||
printLog("End Initialization")
|
||||
@@ -244,10 +244,8 @@ action_mapping = {
|
||||
},
|
||||
"/controller/callback_enable_mic_automatic_selection": {
|
||||
"mic":"/controller/callback_set_mic_host",
|
||||
"speaker":"/controller/callback_set_speaker_device",
|
||||
},
|
||||
"/controller/callback_enable_speaker_automatic_selection": {
|
||||
"mic":"/controller/callback_set_mic_host",
|
||||
"speaker":"/controller/callback_set_speaker_device",
|
||||
}
|
||||
}
|
||||
@@ -391,7 +389,8 @@ if __name__ == "__main__":
|
||||
controller.init({
|
||||
"download_ctranslate2": Action(action_mapping["/controller/callback_download_ctranslate2_weight"]).transmit,
|
||||
"download_whisper": Action(action_mapping["/controller/callback_download_whisper_weight"]).transmit,
|
||||
"update_selected_device": Action(action_mapping["/controller/callback_enable_mic_automatic_selection"]).transmit,
|
||||
"update_selected_mic_device": Action(action_mapping["/controller/callback_enable_mic_automatic_selection"]).transmit,
|
||||
"update_selected_speaker_device": Action(action_mapping["/controller/callback_enable_speaker_automatic_selection"]).transmit,
|
||||
})
|
||||
|
||||
# mappingのすべてのstatusをTrueにする
|
||||
|
||||
Reference in New Issue
Block a user