Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -491,21 +491,20 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
| 491 |
logger.info("Generando audio de voz...")
|
| 492 |
voz_path = os.path.join(temp_dir_intermediate, "voz.mp3")
|
| 493 |
|
| 494 |
-
tts_voices_to_try = [selected_voice]
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
if "es-ES-JuanNeural" not in tts_voices_to_try and "es-ES-JuanNeural" is not None: tts_voices_to_try.append("es-ES-JuanNeural")
|
| 498 |
-
if "es-ES-ElviraNeural" not in tts_voices_to_try and "es-ES-ElviraNeural" is not None: tts_voices_to_try.append("es-ES-ElviraNeural")
|
| 499 |
-
# Si la lista de voces disponibles es fiable, podrías usar un subconjunto ordenado para reintentos más amplios
|
| 500 |
-
# Opcional: si AVAILABLE_VOICES es fiable, podrías usar un subconjunto ordenado para reintentos
|
| 501 |
-
# Ejemplo: for voice_id in [selected_voice] + sorted([v[1] for v in AVAILABLE_VOICES if v[1].startswith('es-') and v[1] != selected_voice]) + sorted([v[1] for v in AVAILABLE_VOICES if not v[1].startswith('es-') and v[1] != selected_voice]):
|
| 502 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 503 |
|
| 504 |
tts_success = False
|
| 505 |
-
tried_voices = set()
|
| 506 |
|
| 507 |
for current_voice in tts_voices_to_try:
|
| 508 |
-
if not current_voice or current_voice in tried_voices: continue
|
| 509 |
tried_voices.add(current_voice)
|
| 510 |
|
| 511 |
logger.info(f"Intentando TTS con voz: {current_voice}...")
|
|
@@ -513,12 +512,11 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
| 513 |
tts_success = asyncio.run(text_to_speech(guion, voz_path, voice=current_voice))
|
| 514 |
if tts_success:
|
| 515 |
logger.info(f"TTS exitoso con voz '{current_voice}'.")
|
| 516 |
-
break
|
| 517 |
except Exception as e:
|
| 518 |
logger.warning(f"Fallo al generar TTS con voz '{current_voice}': {str(e)}", exc_info=True)
|
| 519 |
-
pass
|
| 520 |
|
| 521 |
-
# Verificar si el archivo fue creado después de todos los intentos
|
| 522 |
if not tts_success or not os.path.exists(voz_path) or os.path.getsize(voz_path) <= 100:
|
| 523 |
logger.error("Fallo en la generación de voz después de todos los intentos. Archivo de audio no creado o es muy pequeño.")
|
| 524 |
raise ValueError("Error generando voz a partir del guion (fallo de TTS).")
|
|
@@ -532,6 +530,12 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
| 532 |
try: audio_tts_original.close()
|
| 533 |
except: pass
|
| 534 |
audio_tts_original = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
raise ValueError("Audio de voz generado es inválido después de procesamiento inicial.")
|
| 536 |
|
| 537 |
audio_tts = audio_tts_original
|
|
@@ -541,7 +545,6 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
| 541 |
if audio_duration < 1.0:
|
| 542 |
logger.error(f"Duración audio voz ({audio_duration:.2f}s) es muy corta.")
|
| 543 |
raise ValueError("Generated voice audio is too short (min 1 second required).")
|
| 544 |
-
|
| 545 |
# 3. Extraer palabras clave
|
| 546 |
logger.info("Extrayendo palabras clave...")
|
| 547 |
try:
|
|
|
|
| 491 |
logger.info("Generando audio de voz...")
|
| 492 |
voz_path = os.path.join(temp_dir_intermediate, "voz.mp3")
|
| 493 |
|
| 494 |
+
tts_voices_to_try = [selected_voice]
|
| 495 |
+
fallback_juan = "es-ES-JuanNeural"
|
| 496 |
+
fallback_elvira = "es-ES-ElviraNeural"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
|
| 498 |
+
if fallback_juan and fallback_juan != selected_voice and fallback_juan not in tts_voices_to_try:
|
| 499 |
+
tts_voices_to_try.append(fallback_juan)
|
| 500 |
+
if fallback_elvira and fallback_elvira != selected_voice and fallback_elvira not in tts_voices_to_try:
|
| 501 |
+
tts_voices_to_try.append(fallback_elvira)
|
| 502 |
|
| 503 |
tts_success = False
|
| 504 |
+
tried_voices = set()
|
| 505 |
|
| 506 |
for current_voice in tts_voices_to_try:
|
| 507 |
+
if not current_voice or current_voice in tried_voices: continue
|
| 508 |
tried_voices.add(current_voice)
|
| 509 |
|
| 510 |
logger.info(f"Intentando TTS con voz: {current_voice}...")
|
|
|
|
| 512 |
tts_success = asyncio.run(text_to_speech(guion, voz_path, voice=current_voice))
|
| 513 |
if tts_success:
|
| 514 |
logger.info(f"TTS exitoso con voz '{current_voice}'.")
|
| 515 |
+
break
|
| 516 |
except Exception as e:
|
| 517 |
logger.warning(f"Fallo al generar TTS con voz '{current_voice}': {str(e)}", exc_info=True)
|
| 518 |
+
pass
|
| 519 |
|
|
|
|
| 520 |
if not tts_success or not os.path.exists(voz_path) or os.path.getsize(voz_path) <= 100:
|
| 521 |
logger.error("Fallo en la generación de voz después de todos los intentos. Archivo de audio no creado o es muy pequeño.")
|
| 522 |
raise ValueError("Error generando voz a partir del guion (fallo de TTS).")
|
|
|
|
| 530 |
try: audio_tts_original.close()
|
| 531 |
except: pass
|
| 532 |
audio_tts_original = None
|
| 533 |
+
if os.path.exists(voz_path):
|
| 534 |
+
try: os.remove(voz_path)
|
| 535 |
+
except: pass
|
| 536 |
+
if voz_path in temp_intermediate_files:
|
| 537 |
+
temp_intermediate_files.remove(voz_path)
|
| 538 |
+
|
| 539 |
raise ValueError("Audio de voz generado es inválido después de procesamiento inicial.")
|
| 540 |
|
| 541 |
audio_tts = audio_tts_original
|
|
|
|
| 545 |
if audio_duration < 1.0:
|
| 546 |
logger.error(f"Duración audio voz ({audio_duration:.2f}s) es muy corta.")
|
| 547 |
raise ValueError("Generated voice audio is too short (min 1 second required).")
|
|
|
|
| 548 |
# 3. Extraer palabras clave
|
| 549 |
logger.info("Extrayendo palabras clave...")
|
| 550 |
try:
|