video_translate/docs/plans/2026-03-19-tts-language-contract.md
Song367 04072dc94b
All checks were successful
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 1m6s
commit code
2026-03-19 20:13:24 +08:00

62 lines
2.6 KiB
Markdown

# TTS Language Contract Implementation Plan
> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Add `ttsText` and `ttsLanguage` to subtitle generation so English subtitles and TTS dubbing language are handled separately.
**Architecture:** Keep the current subtitle pipeline shape, but thread an optional `ttsLanguage` through request parsing, prompt creation, and subtitle normalization. Dubbing should use `ttsText` when available so later UI work can choose a TTS language without reworking the playback layer.
**Tech Stack:** TypeScript, Vitest, React client services, Node subtitle generation pipeline
---
### Task 1: Lock the new prompt and parsing contract with tests
**Files:**
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\server\videoSubtitleGeneration.test.ts`
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\services\subtitleService.test.ts`
**Step 1: Write the failing tests**
- Assert the user prompt mentions `Subtitle language: English` and `TTS language`.
- Assert the system prompt includes `ttsText` and `ttsLanguage`.
- Assert normalized subtitles preserve returned `ttsText` and `ttsLanguage`.
- Assert the client request forwards `ttsLanguage`.
**Step 2: Run tests to verify they fail**
Run:
`npm run test -- src/server/videoSubtitleGeneration.test.ts src/services/subtitleService.test.ts`
**Step 3: Commit**
Skip commit for now.
### Task 2: Implement the backend contract
**Files:**
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\server\videoSubtitleGeneration.ts`
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\server\subtitleGeneration.ts`
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\server\subtitleRequest.ts`
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\types.ts`
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\services\subtitleService.ts`
- Modify: `E:\Downloads\ai-video-dubbing-&-translation\src\components\EditorScreen.tsx`
**Step 1: Write the minimal implementation**
- Add optional `ttsText` and `ttsLanguage` to subtitle types.
- Accept optional `ttsLanguage` in request parsing and pipeline functions.
- Build prompts with English subtitle language plus requested TTS language.
- Normalize model output into subtitle objects with `ttsText` and `ttsLanguage`.
- Use `ttsText` for TTS generation when present.
**Step 2: Run tests to verify they pass**
Run:
`npm run test -- src/server/videoSubtitleGeneration.test.ts src/services/subtitleService.test.ts src/components/EditorScreen.test.tsx`
**Step 3: Commit**
Skip commit for now.