diff --git a/controller.py b/controller.py index 1154a7e7..3a1f4ad4 100644 --- a/controller.py +++ b/controller.py @@ -190,7 +190,10 @@ def messageBoxPressKeyEnter(e): sendChatMessage(message) def messageBoxPressKeyAny(e): - model.oscStartSendTyping() + if config.ENABLE_SEND_MESSAGE_TO_VRC is True: + model.oscStartSendTyping() + else: + model.oscStopSendTyping() # func select languages def initSetLanguageAndCountry(): @@ -493,12 +496,12 @@ def callbackSetMicWordFilter(value): model.addKeywords() # Transcription Tab (Speaker) -def callbackSetSpeakerDevice(value): - print("callbackSetSpeakerDevice", value) - config.CHOICE_SPEAKER_DEVICE = value +# def callbackSetSpeakerDevice(value): +# print("callbackSetSpeakerDevice", value) +# config.CHOICE_SPEAKER_DEVICE = value - model.stopCheckSpeakerEnergy() - view.replaceSpeakerThresholdCheckButton_Passive() +# model.stopCheckSpeakerEnergy() +# view.replaceSpeakerThresholdCheckButton_Passive() def callbackSetSpeakerEnergyThreshold(value): print("callbackSetSpeakerEnergyThreshold", value) @@ -710,7 +713,7 @@ def createMainWindow(): "callback_set_mic_word_filter": callbackSetMicWordFilter, # Transcription Tab (Speaker) - "callback_set_speaker_device": callbackSetSpeakerDevice, + # "callback_set_speaker_device": callbackSetSpeakerDevice, "list_speaker_device": model.getListOutputDevice(), "callback_set_speaker_energy_threshold": callbackSetSpeakerEnergyThreshold, "callback_set_speaker_dynamic_energy_threshold": callbackSetSpeakerDynamicEnergyThreshold, diff --git a/model.py b/model.py index 7b148552..93ad8882 100644 --- a/model.py +++ b/model.py @@ -13,6 +13,7 @@ from requests import get as requests_get import webbrowser from flashtext import KeywordProcessor +import pyaudiowpatch from models.translation.translation_translator import Translator from models.transcription.transcription_utils import getInputDevices, getOutputDevices, getDefaultInputDevice, getDefaultOutputDevice from models.osc.osc_tools import sendTyping, sendMessage, sendTestAction, receiveOscParameters @@ -66,8 +67,8 @@ class Model: self.mic_audio_recorder = None self.mic_energy_recorder = None self.mic_energy_plot_progressbar = None - self.spk_print_transcript = None - self.spk_audio_recorder = None + self.speaker_print_transcript = None + self.speaker_audio_recorder = None self.speaker_energy_recorder = None self.speaker_energy_plot_progressbar = None self.translator = Translator() @@ -150,6 +151,18 @@ class Model: def getInputTranslate(self, message): try: + if config.CHOICE_TRANSLATOR == "DeepL(auth)": + if config.TARGET_LANGUAGE == "English": + if config.TARGET_COUNTRY in ["United States", "Canada", "Philippines"]: + config.TARGET_LANGUAGE = "English American" + else: + config.TARGET_LANGUAGE = "English British" + elif config.TARGET_LANGUAGE in ["Portuguese"]: + if config.TARGET_COUNTRY == "Portugal": + config.TARGET_LANGUAGE = "Portuguese European" + else: + config.TARGET_LANGUAGE = "Portuguese Brazilian" + translation = self.translator.translate( translator_name=config.CHOICE_TRANSLATOR, source_language=config.SOURCE_LANGUAGE, @@ -162,6 +175,18 @@ class Model: def getOutputTranslate(self, message): try: + if config.CHOICE_TRANSLATOR == "DeepL(auth)": + if config.SOURCE_LANGUAGE == "English": + if config.SOURCE_COUNTRY in ["United States", "Canada", "Philippines"]: + config.SOURCE_LANGUAGE = "English American" + else: + config.SOURCE_LANGUAGE = "English British" + elif config.SOURCE_LANGUAGE in ["Portuguese"]: + if config.SOURCE_COUNTRY == "Portugal": + config.SOURCE_LANGUAGE = "Portuguese European" + else: + config.SOURCE_LANGUAGE = "Portuguese Brazilian" + translation = self.translator.translate( translator_name=config.CHOICE_TRANSLATOR, source_language=config.TARGET_LANGUAGE, @@ -287,13 +312,6 @@ class Model: def getListOutputDevice(): return [device["name"] for device in getOutputDevices()] - @staticmethod - def checkSpeakerStatus(choice=config.CHOICE_SPEAKER_DEVICE): - 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): if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice": return @@ -368,50 +386,53 @@ class Model: self.mic_energy_recorder = None def startSpeakerTranscript(self, fnc): + speaker_device = getDefaultOutputDevice() + config.CHOICE_SPEAKER_DEVICE = speaker_device["name"] if config.CHOICE_SPEAKER_DEVICE == "NoDevice": return - spk_audio_queue = Queue() - spk_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0] + speaker_audio_queue = Queue() record_timeout = config.INPUT_SPEAKER_RECORD_TIMEOUT phase_timeout = config.INPUT_SPEAKER_PHRASE_TIMEOUT if record_timeout > phase_timeout: record_timeout = phase_timeout - self.spk_audio_recorder = SelectedSpeakerRecorder( - device=spk_device, + self.speaker_audio_recorder = SelectedSpeakerRecorder( + device=speaker_device, energy_threshold=config.INPUT_SPEAKER_ENERGY_THRESHOLD, dynamic_energy_threshold=config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD, record_timeout=record_timeout, ) - self.spk_audio_recorder.recordIntoQueue(spk_audio_queue) - spk_transcriber = AudioTranscriber( + self.speaker_audio_recorder.recordIntoQueue(speaker_audio_queue) + speaker_transcriber = AudioTranscriber( speaker=True, - source=self.spk_audio_recorder.source, + source=self.speaker_audio_recorder.source, phrase_timeout=phase_timeout, max_phrases=config.INPUT_SPEAKER_MAX_PHRASES, ) - def sendSpkTranscript(): - spk_transcriber.transcribeAudioQueue(spk_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY) - message = spk_transcriber.getTranscript() + def sendSpeakerTranscript(): + speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY) + message = speaker_transcriber.getTranscript() try: fnc(message) except: pass - self.spk_print_transcript = threadFnc(sendSpkTranscript) - self.spk_print_transcript.daemon = True - self.spk_print_transcript.start() + self.speaker_print_transcript = threadFnc(sendSpeakerTranscript) + self.speaker_print_transcript.daemon = True + self.speaker_print_transcript.start() def stopSpeakerTranscript(self): - if isinstance(self.spk_print_transcript, threadFnc): - self.spk_print_transcript.stop() - self.spk_print_transcript = None - if isinstance(self.spk_audio_recorder, SelectedSpeakerRecorder): - self.spk_audio_recorder.stop() - self.spk_audio_recorder = None + if isinstance(self.speaker_print_transcript, threadFnc): + self.speaker_print_transcript.stop() + self.speaker_print_transcript = None + if isinstance(self.speaker_audio_recorder, SelectedSpeakerRecorder): + self.speaker_audio_recorder.stop() + self.speaker_audio_recorder = None def startCheckSpeakerEnergy(self, fnc, end_fnc): + speaker_device = getDefaultOutputDevice() + config.CHOICE_SPEAKER_DEVICE = speaker_device["name"] if config.CHOICE_SPEAKER_DEVICE == "NoDevice": return @@ -424,7 +445,6 @@ class Model: pass # sleep(0.01) - 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_recorder.recordIntoQueue(speaker_energy_queue)