From 7cdd9d19d7561966b0dd7f2f46c598880a7cf7fc Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Tue, 13 Feb 2024 23:25:31 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7[WIP/TEST]=20Model=20:=20=E6=96=87?= =?UTF-8?q?=E5=AD=97=E8=B5=B7=E3=81=93=E3=81=97=E8=B5=B7=E5=8B=95=E6=99=82?= =?UTF-8?q?=E3=81=AB=E3=82=A8=E3=83=B3=E3=82=B8=E3=83=B3=E3=82=92=E9=81=B8?= =?UTF-8?q?=E6=8A=9E=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89?= =?UTF-8?q?=E6=9B=B4#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model.py | 4 ++-- models/transcription/transcription_transcriber.py | 13 ++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/model.py b/model.py index e68c01bc..62d727cd 100644 --- a/model.py +++ b/model.py @@ -346,7 +346,7 @@ class Model: whisper_weight_type=config.WHISPER_WEIGHT_TYPE, ) def sendMicTranscript(): - mic_transcriber.transcribeAudioQueue(mic_audio_queue, config.SOURCE_LANGUAGE, config.SOURCE_COUNTRY, config.SELECTED_TRANSCRIPTION_ENGINE) + mic_transcriber.transcribeAudioQueue(mic_audio_queue, config.SOURCE_LANGUAGE, config.SOURCE_COUNTRY) message = mic_transcriber.getTranscript() try: fnc(message) @@ -449,7 +449,7 @@ class Model: whisper_weight_type=config.WHISPER_WEIGHT_TYPE, ) def sendSpeakerTranscript(): - speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY, config.SELECTED_TRANSCRIPTION_ENGINE) + speaker_transcriber.transcribeAudioQueue(speaker_audio_queue, config.TARGET_LANGUAGE, config.TARGET_COUNTRY) message = speaker_transcriber.getTranscript() try: fnc(message) diff --git a/models/transcription/transcription_transcriber.py b/models/transcription/transcription_transcriber.py index 35f79c43..c5a6cbff 100644 --- a/models/transcription/transcription_transcriber.py +++ b/models/transcription/transcription_transcriber.py @@ -37,21 +37,16 @@ class AudioTranscriber: self.whisper_model = getWhisperModel(root, whisper_weight_type) self.transcription_engine = "Whisper" - def transcribeAudioQueue(self, audio_queue, language, country, transcription_engine): + def transcribeAudioQueue(self, audio_queue, language, country): audio, time_spoken = audio_queue.get() self.updateLastSampleAndPhraseStatus(audio, time_spoken) text = '' try: - # Whisperが使用できない場合はGoogle Speech-to-Textを使用する - if transcription_engine == "Whisper": - if self.whisper_model is None: - transcription_engine = "Google" - audio_data = self.audio_sources["process_data_func"]() - match transcription_engine: + match self.transcription_engine: case "Google": - text = self.audio_recognizer.recognize_google(audio_data, language=transcription_lang[language][country][transcription_engine]) + text = self.audio_recognizer.recognize_google(audio_data, language=transcription_lang[language][country][self.transcription_engine]) case "Whisper": audio_data = np.frombuffer(audio_data.get_raw_data(convert_rate=16000, convert_width=2), np.int16).flatten().astype(np.float32) / 32768.0 if isinstance(audio_data, torch.Tensor): @@ -62,7 +57,7 @@ class AudioTranscriber: temperature=0.0, log_prob_threshold=-0.8, no_speech_threshold=0.6, - language=transcription_lang[language][country][transcription_engine], + language=transcription_lang[language][country][self.transcription_engine], word_timestamps=False, without_timestamps=True, task="transcribe",