Merge branch 'model' into UI_2.0
This commit is contained in:
@@ -190,7 +190,10 @@ def messageBoxPressKeyEnter(e):
|
|||||||
sendChatMessage(message)
|
sendChatMessage(message)
|
||||||
|
|
||||||
def messageBoxPressKeyAny(e):
|
def messageBoxPressKeyAny(e):
|
||||||
model.oscStartSendTyping()
|
if config.ENABLE_SEND_MESSAGE_TO_VRC is True:
|
||||||
|
model.oscStartSendTyping()
|
||||||
|
else:
|
||||||
|
model.oscStopSendTyping()
|
||||||
|
|
||||||
# func select languages
|
# func select languages
|
||||||
def initSetLanguageAndCountry():
|
def initSetLanguageAndCountry():
|
||||||
@@ -493,12 +496,12 @@ def callbackSetMicWordFilter(value):
|
|||||||
model.addKeywords()
|
model.addKeywords()
|
||||||
|
|
||||||
# Transcription Tab (Speaker)
|
# Transcription Tab (Speaker)
|
||||||
def callbackSetSpeakerDevice(value):
|
# def callbackSetSpeakerDevice(value):
|
||||||
print("callbackSetSpeakerDevice", value)
|
# print("callbackSetSpeakerDevice", value)
|
||||||
config.CHOICE_SPEAKER_DEVICE = value
|
# config.CHOICE_SPEAKER_DEVICE = value
|
||||||
|
|
||||||
model.stopCheckSpeakerEnergy()
|
# model.stopCheckSpeakerEnergy()
|
||||||
view.replaceSpeakerThresholdCheckButton_Passive()
|
# view.replaceSpeakerThresholdCheckButton_Passive()
|
||||||
|
|
||||||
def callbackSetSpeakerEnergyThreshold(value):
|
def callbackSetSpeakerEnergyThreshold(value):
|
||||||
print("callbackSetSpeakerEnergyThreshold", value)
|
print("callbackSetSpeakerEnergyThreshold", value)
|
||||||
@@ -710,7 +713,7 @@ def createMainWindow():
|
|||||||
"callback_set_mic_word_filter": callbackSetMicWordFilter,
|
"callback_set_mic_word_filter": callbackSetMicWordFilter,
|
||||||
|
|
||||||
# Transcription Tab (Speaker)
|
# Transcription Tab (Speaker)
|
||||||
"callback_set_speaker_device": callbackSetSpeakerDevice,
|
# "callback_set_speaker_device": callbackSetSpeakerDevice,
|
||||||
"list_speaker_device": model.getListOutputDevice(),
|
"list_speaker_device": model.getListOutputDevice(),
|
||||||
"callback_set_speaker_energy_threshold": callbackSetSpeakerEnergyThreshold,
|
"callback_set_speaker_energy_threshold": callbackSetSpeakerEnergyThreshold,
|
||||||
"callback_set_speaker_dynamic_energy_threshold": callbackSetSpeakerDynamicEnergyThreshold,
|
"callback_set_speaker_dynamic_energy_threshold": callbackSetSpeakerDynamicEnergyThreshold,
|
||||||
|
|||||||
78
model.py
78
model.py
@@ -13,6 +13,7 @@ from requests import get as requests_get
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
|
|
||||||
from flashtext import KeywordProcessor
|
from flashtext import KeywordProcessor
|
||||||
|
import pyaudiowpatch
|
||||||
from models.translation.translation_translator import Translator
|
from models.translation.translation_translator import Translator
|
||||||
from models.transcription.transcription_utils import getInputDevices, getOutputDevices, getDefaultInputDevice, getDefaultOutputDevice
|
from models.transcription.transcription_utils import getInputDevices, getOutputDevices, getDefaultInputDevice, getDefaultOutputDevice
|
||||||
from models.osc.osc_tools import sendTyping, sendMessage, sendTestAction, receiveOscParameters
|
from models.osc.osc_tools import sendTyping, sendMessage, sendTestAction, receiveOscParameters
|
||||||
@@ -66,8 +67,8 @@ class Model:
|
|||||||
self.mic_audio_recorder = None
|
self.mic_audio_recorder = None
|
||||||
self.mic_energy_recorder = None
|
self.mic_energy_recorder = None
|
||||||
self.mic_energy_plot_progressbar = None
|
self.mic_energy_plot_progressbar = None
|
||||||
self.spk_print_transcript = None
|
self.speaker_print_transcript = None
|
||||||
self.spk_audio_recorder = None
|
self.speaker_audio_recorder = None
|
||||||
self.speaker_energy_recorder = None
|
self.speaker_energy_recorder = None
|
||||||
self.speaker_energy_plot_progressbar = None
|
self.speaker_energy_plot_progressbar = None
|
||||||
self.translator = Translator()
|
self.translator = Translator()
|
||||||
@@ -150,6 +151,18 @@ class Model:
|
|||||||
|
|
||||||
def getInputTranslate(self, message):
|
def getInputTranslate(self, message):
|
||||||
try:
|
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(
|
translation = self.translator.translate(
|
||||||
translator_name=config.CHOICE_TRANSLATOR,
|
translator_name=config.CHOICE_TRANSLATOR,
|
||||||
source_language=config.SOURCE_LANGUAGE,
|
source_language=config.SOURCE_LANGUAGE,
|
||||||
@@ -162,6 +175,18 @@ class Model:
|
|||||||
|
|
||||||
def getOutputTranslate(self, message):
|
def getOutputTranslate(self, message):
|
||||||
try:
|
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(
|
translation = self.translator.translate(
|
||||||
translator_name=config.CHOICE_TRANSLATOR,
|
translator_name=config.CHOICE_TRANSLATOR,
|
||||||
source_language=config.TARGET_LANGUAGE,
|
source_language=config.TARGET_LANGUAGE,
|
||||||
@@ -287,13 +312,6 @@ class Model:
|
|||||||
def getListOutputDevice():
|
def getListOutputDevice():
|
||||||
return [device["name"] for device in getOutputDevices()]
|
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):
|
def startMicTranscript(self, fnc):
|
||||||
if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice":
|
if config.CHOICE_MIC_HOST == "NoHost" or config.CHOICE_MIC_DEVICE == "NoDevice":
|
||||||
return
|
return
|
||||||
@@ -368,50 +386,53 @@ class Model:
|
|||||||
self.mic_energy_recorder = None
|
self.mic_energy_recorder = None
|
||||||
|
|
||||||
def startSpeakerTranscript(self, fnc):
|
def startSpeakerTranscript(self, fnc):
|
||||||
|
speaker_device = getDefaultOutputDevice()
|
||||||
|
config.CHOICE_SPEAKER_DEVICE = speaker_device["name"]
|
||||||
if config.CHOICE_SPEAKER_DEVICE == "NoDevice":
|
if config.CHOICE_SPEAKER_DEVICE == "NoDevice":
|
||||||
return
|
return
|
||||||
spk_audio_queue = Queue()
|
speaker_audio_queue = Queue()
|
||||||
spk_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0]
|
|
||||||
|
|
||||||
record_timeout = config.INPUT_SPEAKER_RECORD_TIMEOUT
|
record_timeout = config.INPUT_SPEAKER_RECORD_TIMEOUT
|
||||||
phase_timeout = config.INPUT_SPEAKER_PHRASE_TIMEOUT
|
phase_timeout = config.INPUT_SPEAKER_PHRASE_TIMEOUT
|
||||||
if record_timeout > phase_timeout:
|
if record_timeout > phase_timeout:
|
||||||
record_timeout = phase_timeout
|
record_timeout = phase_timeout
|
||||||
|
|
||||||
self.spk_audio_recorder = SelectedSpeakerRecorder(
|
self.speaker_audio_recorder = SelectedSpeakerRecorder(
|
||||||
device=spk_device,
|
device=speaker_device,
|
||||||
energy_threshold=config.INPUT_SPEAKER_ENERGY_THRESHOLD,
|
energy_threshold=config.INPUT_SPEAKER_ENERGY_THRESHOLD,
|
||||||
dynamic_energy_threshold=config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD,
|
dynamic_energy_threshold=config.INPUT_SPEAKER_DYNAMIC_ENERGY_THRESHOLD,
|
||||||
record_timeout=record_timeout,
|
record_timeout=record_timeout,
|
||||||
)
|
)
|
||||||
self.spk_audio_recorder.recordIntoQueue(spk_audio_queue)
|
self.speaker_audio_recorder.recordIntoQueue(speaker_audio_queue)
|
||||||
spk_transcriber = AudioTranscriber(
|
speaker_transcriber = AudioTranscriber(
|
||||||
speaker=True,
|
speaker=True,
|
||||||
source=self.spk_audio_recorder.source,
|
source=self.speaker_audio_recorder.source,
|
||||||
phrase_timeout=phase_timeout,
|
phrase_timeout=phase_timeout,
|
||||||
max_phrases=config.INPUT_SPEAKER_MAX_PHRASES,
|
max_phrases=config.INPUT_SPEAKER_MAX_PHRASES,
|
||||||
)
|
)
|
||||||
def sendSpkTranscript():
|
def sendSpeakerTranscript():
|
||||||
spk_transcriber.transcribeAudioQueue(spk_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY)
|
speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY)
|
||||||
message = spk_transcriber.getTranscript()
|
message = speaker_transcriber.getTranscript()
|
||||||
try:
|
try:
|
||||||
fnc(message)
|
fnc(message)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.spk_print_transcript = threadFnc(sendSpkTranscript)
|
self.speaker_print_transcript = threadFnc(sendSpeakerTranscript)
|
||||||
self.spk_print_transcript.daemon = True
|
self.speaker_print_transcript.daemon = True
|
||||||
self.spk_print_transcript.start()
|
self.speaker_print_transcript.start()
|
||||||
|
|
||||||
def stopSpeakerTranscript(self):
|
def stopSpeakerTranscript(self):
|
||||||
if isinstance(self.spk_print_transcript, threadFnc):
|
if isinstance(self.speaker_print_transcript, threadFnc):
|
||||||
self.spk_print_transcript.stop()
|
self.speaker_print_transcript.stop()
|
||||||
self.spk_print_transcript = None
|
self.speaker_print_transcript = None
|
||||||
if isinstance(self.spk_audio_recorder, SelectedSpeakerRecorder):
|
if isinstance(self.speaker_audio_recorder, SelectedSpeakerRecorder):
|
||||||
self.spk_audio_recorder.stop()
|
self.speaker_audio_recorder.stop()
|
||||||
self.spk_audio_recorder = None
|
self.speaker_audio_recorder = None
|
||||||
|
|
||||||
def startCheckSpeakerEnergy(self, fnc, end_fnc):
|
def startCheckSpeakerEnergy(self, fnc, end_fnc):
|
||||||
|
speaker_device = getDefaultOutputDevice()
|
||||||
|
config.CHOICE_SPEAKER_DEVICE = speaker_device["name"]
|
||||||
if config.CHOICE_SPEAKER_DEVICE == "NoDevice":
|
if config.CHOICE_SPEAKER_DEVICE == "NoDevice":
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -424,7 +445,6 @@ class Model:
|
|||||||
pass
|
pass
|
||||||
# sleep(0.01)
|
# sleep(0.01)
|
||||||
|
|
||||||
speaker_device = [device for device in getOutputDevices() if device["name"] == config.CHOICE_SPEAKER_DEVICE][0]
|
|
||||||
speaker_energy_queue = Queue()
|
speaker_energy_queue = Queue()
|
||||||
self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device)
|
self.speaker_energy_recorder = SelectedSpeakeEnergyRecorder(speaker_device)
|
||||||
self.speaker_energy_recorder.recordIntoQueue(speaker_energy_queue)
|
self.speaker_energy_recorder.recordIntoQueue(speaker_energy_queue)
|
||||||
|
|||||||
Reference in New Issue
Block a user