🚧[WIP/TEST] Model : 文字起こし起動時にエンジンを選択するように変更#2
This commit is contained in:
4
model.py
4
model.py
@@ -346,7 +346,7 @@ class Model:
|
|||||||
whisper_weight_type=config.WHISPER_WEIGHT_TYPE,
|
whisper_weight_type=config.WHISPER_WEIGHT_TYPE,
|
||||||
)
|
)
|
||||||
def sendMicTranscript():
|
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()
|
message = mic_transcriber.getTranscript()
|
||||||
try:
|
try:
|
||||||
fnc(message)
|
fnc(message)
|
||||||
@@ -449,7 +449,7 @@ class Model:
|
|||||||
whisper_weight_type=config.WHISPER_WEIGHT_TYPE,
|
whisper_weight_type=config.WHISPER_WEIGHT_TYPE,
|
||||||
)
|
)
|
||||||
def sendSpeakerTranscript():
|
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()
|
message = speaker_transcriber.getTranscript()
|
||||||
try:
|
try:
|
||||||
fnc(message)
|
fnc(message)
|
||||||
|
|||||||
@@ -37,21 +37,16 @@ class AudioTranscriber:
|
|||||||
self.whisper_model = getWhisperModel(root, whisper_weight_type)
|
self.whisper_model = getWhisperModel(root, whisper_weight_type)
|
||||||
self.transcription_engine = "Whisper"
|
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()
|
audio, time_spoken = audio_queue.get()
|
||||||
self.updateLastSampleAndPhraseStatus(audio, time_spoken)
|
self.updateLastSampleAndPhraseStatus(audio, time_spoken)
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
try:
|
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"]()
|
audio_data = self.audio_sources["process_data_func"]()
|
||||||
match transcription_engine:
|
match self.transcription_engine:
|
||||||
case "Google":
|
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":
|
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
|
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):
|
if isinstance(audio_data, torch.Tensor):
|
||||||
@@ -62,7 +57,7 @@ class AudioTranscriber:
|
|||||||
temperature=0.0,
|
temperature=0.0,
|
||||||
log_prob_threshold=-0.8,
|
log_prob_threshold=-0.8,
|
||||||
no_speech_threshold=0.6,
|
no_speech_threshold=0.6,
|
||||||
language=transcription_lang[language][country][transcription_engine],
|
language=transcription_lang[language][country][self.transcription_engine],
|
||||||
word_timestamps=False,
|
word_timestamps=False,
|
||||||
without_timestamps=True,
|
without_timestamps=True,
|
||||||
task="transcribe",
|
task="transcribe",
|
||||||
|
|||||||
Reference in New Issue
Block a user