diff --git a/config.py b/config.py index ced57eab..2b99e4dc 100644 --- a/config.py +++ b/config.py @@ -8,7 +8,7 @@ from tkinter import font from languages import selectable_languages from models.translation.translation_languages import translatorEngine, translation_lang from models.transcription.transcription_languages import transcription_lang -from models.transcription.transcription_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device +from models.transcription.transcription_utils import getInputDevices, getOutputDevices, getDefaultInputDevice, getDefaultOutputDevice def saveJson(path, key, value): with open(path, "r") as fp: @@ -180,7 +180,7 @@ class Config: @CHOICE_MIC_HOST.setter def CHOICE_MIC_HOST(self, value): - if value in [host for host in get_input_device_list().keys()]: + if value in [host for host in getInputDevices().keys()]: self._CHOICE_MIC_HOST = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) @@ -190,7 +190,7 @@ class Config: @CHOICE_MIC_DEVICE.setter def CHOICE_MIC_DEVICE(self, value): - if value in [device["name"] for device in get_input_device_list()[self.CHOICE_MIC_HOST]]: + if value in [device["name"] for device in getInputDevices()[self.CHOICE_MIC_HOST]]: self._CHOICE_MIC_DEVICE = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) @@ -270,9 +270,9 @@ class Config: @CHOICE_SPEAKER_DEVICE.setter def CHOICE_SPEAKER_DEVICE(self, value): - if value in [device["name"] for device in get_output_device_list()]: - speaker_device = [device for device in get_output_device_list() if device["name"] == value][0] - if get_default_output_device()["index"] == speaker_device["index"]: + if value in [device["name"] for device in getOutputDevices()]: + speaker_device = [device for device in getOutputDevices() if device["name"] == value][0] + if getDefaultOutputDevice()["index"] == speaker_device["index"]: self._CHOICE_SPEAKER_DEVICE = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) @@ -449,8 +449,8 @@ class Config: self._INPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys())[1] self._OUTPUT_SOURCE_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["source"].keys())[1] self._OUTPUT_TARGET_LANG = list(translation_lang[self.CHOICE_TRANSLATOR]["target"].keys())[0] - self._CHOICE_MIC_HOST = get_default_input_device()["host"]["name"] - self._CHOICE_MIC_DEVICE = get_default_input_device()["device"]["name"] + self._CHOICE_MIC_HOST = getDefaultInputDevice()["host"]["name"] + self._CHOICE_MIC_DEVICE = getDefaultInputDevice()["device"]["name"] self._INPUT_MIC_VOICE_LANGUAGE = list(transcription_lang.keys())[0] self._INPUT_MIC_ENERGY_THRESHOLD = 300 self._INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD = True @@ -458,7 +458,7 @@ class Config: self._INPUT_MIC_PHRASE_TIMEOUT = 3 self._INPUT_MIC_MAX_PHRASES = 10 self._INPUT_MIC_WORD_FILTER = [] - self._CHOICE_SPEAKER_DEVICE = get_default_output_device()["name"] + self._CHOICE_SPEAKER_DEVICE = getDefaultOutputDevice()["name"] self._INPUT_SPEAKER_VOICE_LANGUAGE = list(transcription_lang.keys())[1] self._INPUT_SPEAKER_ENERGY_THRESHOLD = 300 self._INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD = True diff --git a/model.py b/model.py index 5f2409cb..37a488c1 100644 --- a/model.py +++ b/model.py @@ -5,7 +5,7 @@ from requests import get as requests_get from flashtext import KeywordProcessor from models.translation.translation_translator import Translator -from models.transcription.transcription_utils import get_input_device_list, get_output_device_list, get_default_input_device, get_default_output_device +from models.transcription.transcription_utils import getInputDevices, getOutputDevices, getDefaultInputDevice, getDefaultOutputDevice from models.osc.osc_tools import sendTyping, sendMessage, sendTestAction, receiveOscParameters from models.transcription.transcription_recorder import SelectedMicRecorder, SelectedSpeakerRecorder from models.transcription.transcription_recorder import SelectedMicEnergyRecorder, SelectedSpeakeEnergyRecorder @@ -133,31 +133,31 @@ class Model: @staticmethod def getListInputHost(): - return [host for host in get_input_device_list().keys()] + return [host for host in getInputDevices().keys()] @staticmethod def getListInputDevice(): - return [device["name"] for device in get_input_device_list()[config.CHOICE_MIC_HOST]] + return [device["name"] for device in getInputDevices()[config.CHOICE_MIC_HOST]] @staticmethod def getInputDefaultDevice(): - return [device["name"] for device in get_input_device_list()[config.CHOICE_MIC_HOST]][0] + return [device["name"] for device in getInputDevices()[config.CHOICE_MIC_HOST]][0] @staticmethod def getListOutputDevice(): - return [device["name"] for device in get_output_device_list()] + return [device["name"] for device in getOutputDevices()] @staticmethod def checkSpeakerStatus(choice=config.CHOICE_SPEAKER_DEVICE): - speaker_device = [device for device in get_output_device_list() if device["name"] == choice][0] - if get_default_output_device()["index"] == speaker_device["index"]: + speaker_device = [device for device in getOutputDevices() if device["name"] == choice][0] + if getDefaultOutputDevice()["index"] == speaker_device["index"]: return True return False def startMicTranscript(self, fnc): mic_audio_queue = Queue() self.mic_audio_recorder = SelectedMicRecorder( - [device for device in get_input_device_list()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0], + [device for device in getInputDevices()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0], config.INPUT_MIC_ENERGY_THRESHOLD, config.INPUT_MIC_DYNAMIC_ENERGY_THRESHOLD, config.INPUT_MIC_RECORD_TIMEOUT, @@ -192,7 +192,7 @@ class Model: fnc(energy) sleep(0.01) mic_energy_queue = Queue() - mic_device = [device for device in get_input_device_list()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0] + mic_device = [device for device in getInputDevices()[config.CHOICE_MIC_HOST] if device["name"] == config.CHOICE_MIC_DEVICE][0] self.mic_energy_recorder = SelectedMicEnergyRecorder(mic_device) self.mic_energy_recorder.record_into_queue(mic_energy_queue) self.mic_energy_plot_progressbar = threadFnc(progressBarInputMicEnergyPlot) @@ -207,7 +207,7 @@ class Model: def startSpeakerTranscript(self, fnc): spk_audio_queue = Queue() - spk_device = [device for device in get_output_device_list() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] + spk_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] self.spk_audio_recorder = SelectedSpeakerRecorder( spk_device, config.INPUT_SPEAKER_ENERGY_THRESHOLD, @@ -249,7 +249,7 @@ class Model: energy = self.speaker_energy_recorder.recorder.listen_energy(source) speaker_energy_queue.put(energy) - speaker_device = [device for device in get_output_device_list() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] + speaker_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] speaker_energy_queue = Queue() self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device) self.speaker_energy_get_progressbar = threadFnc(progressBar_input_speaker_energy_get) diff --git a/models/transcription/transcription_utils.py b/models/transcription/transcription_utils.py index b66172c2..4c72a8fa 100644 --- a/models/transcription/transcription_utils.py +++ b/models/transcription/transcription_utils.py @@ -1,6 +1,6 @@ from pyaudiowpatch import PyAudio, paWASAPI -def get_input_device_list(): +def getInputDevices(): devices = {} with PyAudio() as p: for host_index in range(0, p.get_host_api_count()): @@ -14,7 +14,7 @@ def get_input_device_list(): devices[host["name"]] = [device] return devices -def get_output_device_list(): +def getOutputDevices(): devices =[] with PyAudio() as p: wasapi_info = p.get_host_api_info_by_type(paWASAPI) @@ -23,7 +23,7 @@ def get_output_device_list(): devices.append(device) return devices -def get_default_input_device(): +def getDefaultInputDevice(): with PyAudio() as p: api_info = p.get_default_host_api_info() defaultInputDevice = api_info["defaultInputDevice"] @@ -35,7 +35,7 @@ def get_default_input_device(): if device["index"] == defaultInputDevice: return {"host":host, "device": device} -def get_default_output_device(): +def getDefaultOutputDevice(): with PyAudio() as p: wasapi_info = p.get_host_api_info_by_type(paWASAPI) defaultOutputDevice = wasapi_info["defaultOutputDevice"] diff --git a/window_config.py b/window_config.py index 326a7a11..b45a61c1 100644 --- a/window_config.py +++ b/window_config.py @@ -332,7 +332,6 @@ class ToplevelWindowConfig(CTkToplevel): def speaker_threshold_check_start(self): def plotProgressBar(energy): try: - print(energy) self.progressBar_input_speaker_energy_threshold.set(energy/config.MAX_MIC_ENERGY_THRESHOLD) except: pass