Comparar idiomas por codigo para que auto funcione con el subtitulado
Browse files- app.py +17 -2
- transcribe.py +4 -0
app.py
CHANGED
|
@@ -408,10 +408,25 @@ def subtitle_video(original_video_path, source_languaje, target_languaje):
|
|
| 408 |
print('*'*NUMBER)
|
| 409 |
print("Subtitle video")
|
| 410 |
|
| 411 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
return [
|
| 413 |
gr.update(value=None, visible=False),
|
| 414 |
-
gr.update(value="Translation pipeline not implemented yet"
|
|
|
|
| 415 |
]
|
| 416 |
|
| 417 |
merged_path = "merged_transcription_diarization/merged.json"
|
|
|
|
| 408 |
print('*'*NUMBER)
|
| 409 |
print("Subtitle video")
|
| 410 |
|
| 411 |
+
# Con "auto" el idioma no se conoce hasta haber transcrito, así que se lee
|
| 412 |
+
# el que quedó guardado en la transcripción
|
| 413 |
+
language_dict = get_language_dict()
|
| 414 |
+
source_code = None
|
| 415 |
+
if source_languaje == AUTO_LANGUAGE:
|
| 416 |
+
transcription_file = f"transcriptions/transcription_{source_languaje}.json"
|
| 417 |
+
if os.path.exists(transcription_file):
|
| 418 |
+
with open(transcription_file, encoding="utf-8") as f:
|
| 419 |
+
source_code = json.load(f).get("language")
|
| 420 |
+
elif source_languaje in language_dict:
|
| 421 |
+
source_code = language_dict[source_languaje]["transcriber"]
|
| 422 |
+
|
| 423 |
+
target_code = language_dict.get(target_languaje, {}).get("transcriber")
|
| 424 |
+
|
| 425 |
+
if source_code != target_code:
|
| 426 |
return [
|
| 427 |
gr.update(value=None, visible=False),
|
| 428 |
+
gr.update(value=f"Translation pipeline not implemented yet "
|
| 429 |
+
f"({source_code} -> {target_code})")
|
| 430 |
]
|
| 431 |
|
| 432 |
merged_path = "merged_transcription_diarization/merged.json"
|
transcribe.py
CHANGED
|
@@ -124,6 +124,10 @@ def transcribe(audio_file, language, device, chunk_length_s=30, stride_length_s=
|
|
| 124 |
|
| 125 |
print(f"Time to transcribe: {time() - t0:.2f} seconds")
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
# Both engines already return the normalised shape, so the second value is
|
| 128 |
# kept for the callers that expect the old two-value contract
|
| 129 |
return result, result
|
|
|
|
| 124 |
|
| 125 |
print(f"Time to transcribe: {time() - t0:.2f} seconds")
|
| 126 |
|
| 127 |
+
# Se guarda el idioma realmente usado: con autodetección es el único sitio
|
| 128 |
+
# donde se sabe, y hace falta después para decidir si hay que traducir
|
| 129 |
+
result["language"] = language
|
| 130 |
+
|
| 131 |
# Both engines already return the normalised shape, so the second value is
|
| 132 |
# kept for the callers that expect the old two-value contract
|
| 133 |
return result, result
|