diff --git a/src-python/model.py b/src-python/model.py index 7c5ebb16..6c7b7acf 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -69,6 +69,7 @@ class Model: def init(self): self.logger = None + self.device_access = False self.th_check_device = None self.mic_print_transcript = None self.mic_audio_recorder = None @@ -407,33 +408,53 @@ class Model: command = [os_path.join(current_directory, batch_name), program_name] Popen(command, cwd=current_directory) - @staticmethod - def getListInputHost(): - return [host for host in getInputDevices().keys()] + def startAccessDevice(self): + while self.device_access is True: + sleep(0.1) + self.device_access = True - @staticmethod - def getInputDefaultDevice(): - return getInputDevices().get(config.CHOICE_MIC_HOST, [{"name": "NoDevice"}])[0]["name"] + def stopAccessDevice(self): + self.device_access = False - @staticmethod - def getListInputDevice(): - return [device["name"] for device in getInputDevices().get(config.CHOICE_MIC_HOST, [{"name": "NoDevice"}])] + def getListInputHost(self): + self.startAccessDevice() + result = [host for host in getInputDevices().keys()] + self.stopAccessDevice() + return result - @staticmethod - def getListOutputDevice(): - return [device["name"] for device in getOutputDevices()] + def getInputDefaultDevice(self): + self.startAccessDevice() + result = getInputDevices().get(config.CHOICE_MIC_HOST, [{"name": "NoDevice"}])[0]["name"] + self.stopAccessDevice() + return result + + def getListInputDevice(self): + self.startAccessDevice() + result = [device["name"] for device in getInputDevices().get(config.CHOICE_MIC_HOST, [{"name": "NoDevice"}])] + self.stopAccessDevice() + return result + + def getListOutputDevice(self): + self.startAccessDevice() + result = [device["name"] for device in getOutputDevices()] + self.stopAccessDevice() + return result def startAutomaticDeviceSelection(self, fnc_mic, fnc_speaker): def checkDevice(fnc_mic, fnc_speaker): if config.ENABLE_MIC_AUTOMATIC_SELECTION is True: + self.startAccessDevice() default_device = getDefaultInputDevice() + self.stopAccessDevice() 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: + self.startAccessDevice() default_device = getDefaultOutputDevice() + self.stopAccessDevice() speaker_device_name = default_device["device"]["name"] if speaker_device_name != config.CHOICE_SPEAKER_DEVICE: fnc_speaker(speaker_device_name) @@ -452,14 +473,18 @@ class Model: def startMicTranscript(self, fnc): if config.ENABLE_MIC_AUTOMATIC_SELECTION is True: + self.startAccessDevice() default_device = getDefaultInputDevice() + self.stopAccessDevice() mic_host_name = default_device["host"]["name"] mic_device_name = default_device["device"]["name"] else: mic_host_name = config.CHOICE_MIC_HOST mic_device_name = config.CHOICE_MIC_DEVICE + self.startAccessDevice() mic_device_list = getInputDevices().get(mic_host_name, [{"name": "NoDevice"}]) + self.stopAccessDevice() choice_mic_device = [device for device in mic_device_list if device["name"] == mic_device_name] if len(choice_mic_device) == 0: @@ -586,14 +611,18 @@ class Model: self.check_mic_energy_fnc = fnc if config.ENABLE_MIC_AUTOMATIC_SELECTION is True: + self.startAccessDevice() default_device = getDefaultInputDevice() + self.stopAccessDevice() mic_host_name = default_device["host"]["name"] mic_device_name = default_device["device"]["name"] else: mic_host_name = config.CHOICE_MIC_HOST mic_device_name = config.CHOICE_MIC_DEVICE + self.startAccessDevice() mic_device_list = getInputDevices().get(mic_host_name, [{"name": "NoDevice"}]) + self.stopAccessDevice() choice_mic_device = [device for device in mic_device_list if device["name"] == mic_device_name] if len(choice_mic_device) == 0: @@ -628,12 +657,16 @@ class Model: def startSpeakerTranscript(self, fnc): if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True: + self.startAccessDevice() default_device = getDefaultOutputDevice() + self.stopAccessDevice() speaker_device_name = default_device["device"]["name"] else: speaker_device_name = config.CHOICE_SPEAKER_DEVICE + self.startAccessDevice() speaker_device_list = getOutputDevices() + self.stopAccessDevice() choice_speaker_device = [device for device in speaker_device_list if device["name"] == speaker_device_name] if len(choice_speaker_device) == 0: @@ -720,12 +753,16 @@ class Model: self.check_speaker_energy_fnc = fnc if config.ENABLE_SPEAKER_AUTOMATIC_SELECTION is True: + self.startAccessDevice() default_device = getDefaultOutputDevice() + self.stopAccessDevice() speaker_device_name = default_device["device"]["name"] else: speaker_device_name = config.CHOICE_SPEAKER_DEVICE + self.startAccessDevice() speaker_device_list = getOutputDevices() + self.stopAccessDevice() choice_speaker_device = [device for device in speaker_device_list if device["name"] == speaker_device_name] if len(choice_speaker_device) == 0: