Update modules/whisper/whisper_base.py
Browse files
modules/whisper/whisper_base.py
CHANGED
|
@@ -269,27 +269,33 @@ class WhisperBase(ABC):
|
|
| 269 |
#)
|
| 270 |
#files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language, "lang_prob": file_lang_probs, "input_source_file": (file_name+file_ext)}
|
| 271 |
|
|
|
|
|
|
|
|
|
|
| 272 |
# Translate to English using Whisper built-in functionality
|
| 273 |
transcription_note = ""
|
| 274 |
if params.is_translate:
|
| 275 |
transcription_note = "Translated to English"
|
| 276 |
-
|
| 277 |
|
| 278 |
# Translate the transcribed segments
|
| 279 |
translation_note = ""
|
| 280 |
if translate_output:
|
| 281 |
self.nllb_inf = NLLBInference()
|
| 282 |
-
if
|
| 283 |
transcribed_segments = self.nllb_inf.translate_text(
|
| 284 |
input_list_dict=transcribed_segments,
|
| 285 |
model_size=translate_model,
|
| 286 |
-
src_lang=
|
| 287 |
tgt_lang=target_lang,
|
| 288 |
speaker_diarization=params.is_diarize
|
| 289 |
)
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
| 291 |
else:
|
| 292 |
-
translation_note =
|
| 293 |
|
| 294 |
## Get preview as txt
|
| 295 |
file_name, file_ext = os.path.splitext(os.path.basename(file))
|
|
@@ -338,7 +344,7 @@ class WhisperBase(ABC):
|
|
| 338 |
total_info += f'Input file: {info["input_source_file"]}\nLanguage: {info["lang"]} with probability {info["lang_prob"]}%\n'
|
| 339 |
|
| 340 |
if params.is_translate:
|
| 341 |
-
total_info += f'
|
| 342 |
|
| 343 |
if translate_output:
|
| 344 |
total_info += f'Translation: {info["translation"]}\n'
|
|
|
|
| 269 |
#)
|
| 270 |
#files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language, "lang_prob": file_lang_probs, "input_source_file": (file_name+file_ext)}
|
| 271 |
|
| 272 |
+
# Define source language
|
| 273 |
+
source_lang = file_language
|
| 274 |
+
|
| 275 |
# Translate to English using Whisper built-in functionality
|
| 276 |
transcription_note = ""
|
| 277 |
if params.is_translate:
|
| 278 |
transcription_note = "Translated to English"
|
| 279 |
+
source_lang = "English"
|
| 280 |
|
| 281 |
# Translate the transcribed segments
|
| 282 |
translation_note = ""
|
| 283 |
if translate_output:
|
| 284 |
self.nllb_inf = NLLBInference()
|
| 285 |
+
if source_lang in NLLB_AVAILABLE_LANGS.keys():
|
| 286 |
transcribed_segments = self.nllb_inf.translate_text(
|
| 287 |
input_list_dict=transcribed_segments,
|
| 288 |
model_size=translate_model,
|
| 289 |
+
src_lang=source_lang,
|
| 290 |
tgt_lang=target_lang,
|
| 291 |
speaker_diarization=params.is_diarize
|
| 292 |
)
|
| 293 |
+
if source_lang != target_lang:
|
| 294 |
+
translation_note = source_lang + " to " + target_lang
|
| 295 |
+
else:
|
| 296 |
+
translation_note = source_lang + " equal to " + target_lang
|
| 297 |
else:
|
| 298 |
+
translation_note = source_lang + " not supported"
|
| 299 |
|
| 300 |
## Get preview as txt
|
| 301 |
file_name, file_ext = os.path.splitext(os.path.basename(file))
|
|
|
|
| 344 |
total_info += f'Input file: {info["input_source_file"]}\nLanguage: {info["lang"]} with probability {info["lang_prob"]}%\n'
|
| 345 |
|
| 346 |
if params.is_translate:
|
| 347 |
+
total_info += f'Transcription: {info["transcription"]}\n'
|
| 348 |
|
| 349 |
if translate_output:
|
| 350 |
total_info += f'Translation: {info["translation"]}\n'
|