feat: subtitle/caption export (SRT + WebVTT)#184
Open
seonghobae wants to merge 1 commit into
Open
Conversation
Add a self-contained, stdlib-only subtitles.py that converts timestamped transcript segments into SubRip (.srt) and WebVTT (.vtt) captions. - Segment dataclass as a tiny input contract (also accepts duck-typed objects with .start/.end/.text), independent of transcribe.py - to_srt / to_vtt render formatted text; write_srt / write_vtt write files - Correct timestamp formatting: SRT HH:MM:SS,mmm, VTT HH:MM:SS.mmm, sequential SRT indices, WEBVTT header, hours>0, sub-second, multi-line - Edge cases: empty input, negative-time clamp, millisecond rounding, CRLF normalization - 21 unit tests in tests/test_subtitles.py; interrogate 100% Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJRVbDrp1vGYkJgNHMGPpG
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.
Why
Captions/subtitles are a high-value output for recorded audio/video — searchable, accessible, embeddable. This adds a self-contained module to turn timestamped transcript segments into
.srtand.vttfiles.What
subtitles.py(stdlib-only, no new dependency; independent — does not import the transcription module).Segmentdataclass input contract (also accepts duck-typed objects with.start/.end/.text).to_srt/to_vtt(return text) andwrite_srt/write_vtt(write files). SRTHH:MM:SS,mmm+ 1-based indices; VTTHH:MM:SS.mmm+WEBVTTheader. Handles empty input, sub-second, hours>0, multi-line, negative clamp, ms rounding.Tests
tests/test_subtitles.py— 21 tests (formats, indices, headers, empty, hour-plus, rounding, duck-typing, file roundtrips).interrogate100%; full suite no new failures.🤖 Generated with Claude Code