feat(generation): parallelize within-scene TTS generation#696
Open
ly-wang19 wants to merge 1 commit into
Open
Conversation
Follow-up to THU-MAIC#660. generateTTSForScene rendered a scene's speech clips one at a time. Within a scene the speech actions are independent — each writes its own audio under its own audioId, no ordering/carry-over — so when the server opts into parallel generation (PARALLEL_SCENE_CONCURRENCY > 1, the THU-MAIC#660 knob) render them with bounded concurrency via mapWithConcurrency. Default (0/unset) is byte-for-byte the original serial loop; the bound respects TTS providers' 429 quotas. Per-clip failures are still counted (not thrown), so one bad clip never aborts the scene. Closes THU-MAIC#695
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Follow-up to #660 (just merged — opt-in parallel scene content). The remaining serial cost in classroom generation is TTS:
generateTTSForScenerendered a scene’s speech clips one at a time in afor … awaitloop.Why it’s safe: unlike cross-scene parallelism (ruled out in #572 because it breaks
previousSpeechesthreading), the speech actions within a scene are independent — each writes its own audio under its ownaudioId(tts_s<order>_<actionId>), stored separately, with no ordering/carry-over. Playback order comes from the action list, not generation order.Closes #695.
Change
When the server opts into parallel generation (
PARALLEL_SCENE_CONCURRENCY > 1, the #660 knob), render the scene’s speech clips with bounded concurrency via themapWithConcurrencyhelper #660 added; otherwise the original strictly-serialfor … awaitloop runs.0/unset) is byte-for-byte the original serial behaviour.Reuses the existing
parallelSceneConcurrencysetting (no new env var / plumbing). A dedicatedPARALLEL_TTS_CONCURRENCYcould be a later refinement if TTS vs LLM quota profiles need to diverge — noted in the issue.Test plan
npx vitest run— 94 files / 742 tests pass;tsc/prettier/eslintclean. The concurrency mechanism itself is already unit-tested (tests/utils/concurrency.test.ts, incl. the cap); the serial default path is unchanged. (The hook isn’t unit-tested — no DOM/hook harness in the repo — same as #660.)No user-facing strings (no i18n impact).