Skip to content

fix(subtitle_gen): accept Doubao timestamps and join Chinese tokens - #828

Open
henry56714 wants to merge 3 commits into
OpenMontageInc:mainfrom
henry56714:codex/fix-doubao-subtitle-timestamps
Open

henry56714 wants to merge 3 commits into
OpenMontageInc:mainfrom
henry56714:codex/fix-doubao-subtitle-timestamps

Conversation

@henry56714

Copy link
Copy Markdown

Summary

Doubao TTS returns sentence and word timings as startTime/endTime in seconds. Passing its sentences output directly to subtitle_gen fails because the subtitle generator expects start/end. Chinese character tokens also acquire unwanted spaces when joined into captions.

Related issue

No linked issue; reproduced with Doubao-shaped timestamp input.

Changes

  • Normalize complete start/end or startTime/endTime pairs without mutating caller input. Preserve seconds and prefer canonical timestamps when both pairs exist.
  • Return an actionable error for missing, non-finite, negative, or reversed timings before writing subtitles.
  • Join Chinese tokens without extra spaces while retaining Latin word spacing, including karaoke output and corrected transcript text.
  • Update the input schema description and add focused regression coverage.

Testing

python -m pytest tests/tools/test_subtitle_doubao.py tests/tools/test_subtitle_timestamps.py -q — 21 passed.

Coverage includes SRT/VTT/JSON, sentence-only timing, input preservation, invalid timing, canonical English output, mixed Chinese/English text, karaoke highlighting, and cue length boundaries.

Tests are offline. This PR does not change the Doubao API transport; no new live TTS request was made for this submission.

Checklist

  • The change is focused on a single logical concern.
  • Relevant subtitle tests passed locally (command above).
  • The input schema description documents the accepted timestamp fields and units.
  • No unrelated files, build artifacts, or local configuration are included in the diff.

@henry56714
henry56714 requested a review from calesthio as a code owner October 20, 2026 09:18

@calesthio calesthio left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed against docs/PR_REVIEW_GUIDE.md at 910fa851293f9cc1efb849e1dce598f0600c0433 in an isolated worktree.

[P2] Preserve word boundaries around curly quotes in non-Chinese captions.

The Doubao timestamp defect is real and the 17 new tests pass, but the new _join_tokens treats curly quotes as Chinese boundaries for every language. Running execute with timed English tokens ["He", "said", "“hello", "world”", "today."] now writes "He said“hello world”today."; clean main writes "He said “hello world” today.". This affects ordinary SRT output as well as the shared correction/karaoke joining path.

This was reproduced entirely locally with canonical numeric timestamps, so it is independent of Doubao credentials, transport, SDK versions or fonts. Korean spacing still passes a separate control. Please make spacing suppression depend on the surrounding script/language rather than curly punctuation alone, and add English curly-quote and mixed-language regression cases while retaining the Chinese behavior. The existing timestamp suite also passes (4 tests).

Validation command: py -m pytest tests/tools/test_subtitle_doubao.py -q --tb=short -p no:cacheprovider. Clean-main comparison used c8066452 with the PR regression tests copied in; production code and dependencies were otherwise unchanged. Initial baseline: 16 failed, 1 passed in 0.42s.

SanHsien added a commit to SanHsien/OpenMontage that referenced this pull request Oct 24, 2026
…lack-frame check

Ports the approach (not the diff) of upstream PRs still unmerged or closed:
- piper_tts: feed narration to Piper as UTF-8 (OpenMontageInc#842); the Windows ANSI code
  page garbled CJK and accented text.
- video_compose: decode ffprobe/ffmpeg text output as UTF-8 with errors=replace
  (part of OpenMontageInc#696) so a cp950/GBK console cannot kill the pipe reader.
- subtitle_gen: no space between adjacent CJK tokens, karaoke markup aware
  (OpenMontageInc#828, defect 1 of OpenMontageInc#725).
- video_compose final_review: judge black frames by mean luminance; the old
  "PNG < 2000 bytes" test never fired (a black 1280x720 PNG is 4349 bytes).
  Closed-unmerged OpenMontageInc#679, defect still present on upstream main.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@henry56714

Copy link
Copy Markdown
Author

Thanks for catching the spacing regression. I fixed it in 8e25752. Curly quotes now preserve outer word boundaries in English and keep Chinese spacing, including when the quotes arrive as separate tokens. The new regression cases cover English, Chinese, and mixed captions in plain SRT and SRT/WebVTT karaoke.

I also merged upstream main and preserved WebVTT escaping. On the updated head 762ed0f, python -m pytest tests/tools/test_subtitle_*.py tests/tools/test_azure_stt.py -q --tb=short -p no:cacheprovider passed all 65 tests.

@henry56714
henry56714 requested a review from calesthio November 26, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants