Skip to content

Escape literal transcript text in WebVTT subtitles - #2890

Open
edawite wants to merge 1 commit into
openai:mainfrom
edawite:codex/vtt-escape-transcript-text
Open

edawite wants to merge 1 commit into
openai:mainfrom
edawite:codex/vtt-escape-transcript-text

Conversation

@edawite

@edawite edawite commented Oct 18, 2026

Copy link
Copy Markdown

Whisper writes transcript text directly into WebVTT cue payloads. A literal <name> is interpreted as a tag, and literal &lt; is interpreted as a character reference, changing what a player displays. Escape the transcript text before emitting VTT cues, following the WebVTT cue-text rules.

Escape words after line wrapping and before adding the writer's own <u> highlighting. This covers ordinary cues, highlighted cues, and gaps between words without double escaping. Segment text uses the same VTT-specific hook; SRT output remains unchanged.

Tests cover literal tags/entities, ampersands, ordinary text, highlighting and gaps, wrapping based on unescaped text, and unchanged input dictionaries. Against unchanged production code, seven new cases fail and five controls pass.

Validation on Windows CPU, Python 3.12.5, PyTorch 2.11.0+cpu:

  • python -m pytest -q tests --ignore=tests/test_transcribe.py -m 'not requires_cuda': 29 passed, 8 deselected.
  • Pinned Black 25.1.0, isort 6.0.0, flake8 7.1.1, and git diff --check pass. Black ran under Python 3.12.14.

Related: #2847 handles timestamp arrows. This change addresses literal markup/entity text; word-level --> also becomes --&gt; in VTT source, preserving its displayed arrow. Existing segment-level arrow replacement is retained.

Model-inference and CUDA tests were not run.

@AbarnaaSree

Copy link
Copy Markdown

Hi, I’d like to help validate this change. The escaping approach looks important for preserving literal transcript text in WebVTT without affecting highlighting, wrapping, or SRT output. Would it be helpful if I reviewed the diff and tested additional edge cases, particularly HTML entities, ampersands, and word-level timestamps, to ensure the output is escaped correctly without double escaping? I’ll coordinate with the existing contributor to avoid duplicating work.

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