From f38325b461f2070854c29cc86ea971cd060a2354 Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Thu, 7 May 2026 16:57:20 +0100 Subject: [PATCH] fix(tts): scope retranslation TTS to target language only When retranslate=True, _generate_tts_for_languages was receiving the full outputs dict (all 9 languages) and regenerating TTS + render for every language on every single-language retranslation task. That multiplied API calls by 8x and triggered unnecessary renders. Now passes only the target language outputs when retranslate=True. Co-Authored-By: Claude Sonnet 4.6 --- backend/app/tasks/translate_and_synthesize.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/app/tasks/translate_and_synthesize.py b/backend/app/tasks/translate_and_synthesize.py index 5d2ab7a..5f9be81 100644 --- a/backend/app/tasks/translate_and_synthesize.py +++ b/backend/app/tasks/translate_and_synthesize.py @@ -312,8 +312,15 @@ async def _async_translate_and_synthesize(job_id: str, languages: list[str] | No if job_doc["requested_outputs"]["audio_description_mp3"]: # Get TTS preferences from job tts_preferences = job_doc["requested_outputs"].get("tts_preferences", {}) + # For retranslation, only regenerate TTS for the specific target languages — + # not all languages. Regenerating all is wasteful and triggers unwanted renders. + tts_outputs = ( + {lang: updated_outputs[lang] for lang in target_languages if lang in updated_outputs} + if retranslate + else updated_outputs + ) await _generate_tts_for_languages( - job_id, updated_outputs, db, source_language, tts_preferences, accessible_video_requested, + job_id, tts_outputs, db, source_language, tts_preferences, accessible_video_requested, user_id=_cost_ctx["user_id"], cost_project_id=_cost_ctx["project_id"], )