Spaces:
Running
Running
adding what it translated to in output
Browse files
app.py
CHANGED
@@ -422,18 +422,24 @@ def tts_interface(selected_model, text, translate_enabled, status_output):
|
|
422 |
lang_code = get_language_code(model_info)
|
423 |
translate_code = get_translate_code(lang_code)
|
424 |
|
|
|
|
|
|
|
|
|
425 |
# For MMS models, we always need to translate
|
426 |
if is_mms:
|
427 |
if not translate_code:
|
428 |
return None, f"Cannot determine translation target language from code: {lang_code}"
|
429 |
print(f"MMS model detected, translating to {translate_code}")
|
430 |
-
|
|
|
431 |
# For other models, check if translation is enabled and needed
|
432 |
elif translate_enabled and translate_code and translate_code != "en":
|
433 |
if not translate_code:
|
434 |
return None, f"Cannot determine translation target language from code: {lang_code}"
|
435 |
print(f"Will translate to {translate_code} (from ISO code {lang_code})")
|
436 |
-
|
|
|
437 |
|
438 |
try:
|
439 |
# Update status with language info
|
@@ -445,7 +451,12 @@ def tts_interface(selected_model, text, translate_enabled, status_output):
|
|
445 |
# Generate audio
|
446 |
audio_data, sample_rate = generate_audio(text, model_info)
|
447 |
|
448 |
-
|
|
|
|
|
|
|
|
|
|
|
449 |
|
450 |
except ValueError as e:
|
451 |
# Handle known errors with user-friendly messages
|
|
|
422 |
lang_code = get_language_code(model_info)
|
423 |
translate_code = get_translate_code(lang_code)
|
424 |
|
425 |
+
# Store original text for status message
|
426 |
+
original_text = text
|
427 |
+
translated_text = None
|
428 |
+
|
429 |
# For MMS models, we always need to translate
|
430 |
if is_mms:
|
431 |
if not translate_code:
|
432 |
return None, f"Cannot determine translation target language from code: {lang_code}"
|
433 |
print(f"MMS model detected, translating to {translate_code}")
|
434 |
+
translated_text = translate_text(text, "en", translate_code)
|
435 |
+
text = translated_text
|
436 |
# For other models, check if translation is enabled and needed
|
437 |
elif translate_enabled and translate_code and translate_code != "en":
|
438 |
if not translate_code:
|
439 |
return None, f"Cannot determine translation target language from code: {lang_code}"
|
440 |
print(f"Will translate to {translate_code} (from ISO code {lang_code})")
|
441 |
+
translated_text = translate_text(text, "en", translate_code)
|
442 |
+
text = translated_text
|
443 |
|
444 |
try:
|
445 |
# Update status with language info
|
|
|
451 |
# Generate audio
|
452 |
audio_data, sample_rate = generate_audio(text, model_info)
|
453 |
|
454 |
+
# Include translation info in final status if text was translated
|
455 |
+
final_status = f"Generated speech using {voice_name} ({lang_name})"
|
456 |
+
if translated_text:
|
457 |
+
final_status += f"\nTranslated: '{original_text}' → '{translated_text}'"
|
458 |
+
|
459 |
+
return (sample_rate, audio_data), final_status
|
460 |
|
461 |
except ValueError as e:
|
462 |
# Handle known errors with user-friendly messages
|