Skip to content

Translate: timed subtitles from video files - #19029

Merged
danielhanchen merged 2 commits into
mainfrom
translate-av-subtitles
Nov 23, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
translate-av-subtitles

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Related to #18666

Summary

A video file dropped on the Translate page now becomes a timed subtitle file when the Voice settings speech model reports segment timings. The transcript is turned into an SRT, which then goes through the subtitle path from #18992, so every cue keeps its timing and the Download subtitles action appears (trip.mp4 translated into French saves as trip.fr.srt). Audio files and every other flow are unchanged.

Backend (opt-in, default byte-identical)

  • POST /api/inference/audio/transcribe/raw takes a new optional timestamps query flag (default false).
  • With the flag, the whisper.cpp engine asks whisper-server for response_format=verbose_json (plus no_language_probabilities=true, so it does not run a second language detection pass) and the result gains segments: [{start, end, text}] in seconds. The text field is built exactly as before.
  • Without the flag the request to whisper-server and the JSON response are unchanged.
  • The flag is ignored by the other engines. audio.cpp models that always time their text (Parakeet-TDT and the like) already return segments on this route today.

Frontend

  • transcribeAudioBlob gets an optional onSegments callback. Only when it is passed does the request carry timestamps=true, and the callback only fires when the engine actually returned segments.
  • Translate passes it for video files only. With segments, segmentsToSrt builds an SRT (dictation dictionary applied per cue) and the page loads it with the file name, so the existing subtitle detection, batching and download take over. With no segments the plain transcript loads, as today.
  • subtitleFileName also strips video extensions.

Scoped out, and why

  • Transformers engine (custom HF repos, and the fallback when whisper-server is missing): Studio does not use the pipeline. It calls model.generate in a worker subprocess, and the worker sends back {"type": "text", "text", "consumed"} per 30 s window (stt_transformers_worker.py transcribe_window, decoded with skip_special_tokens=True). Returning segments would mean changing that worker protocol for the subprocess, in-process and MLX engines, which is more than a small opt-in change. These models keep today's plain transcript.
  • llama.cpp (mtmd) Qwen3-ASR, the default Voice model: the runtime returns text only, so there are no timings to read. A video falls back to the plain transcript.
  • audio.cpp Qwen3-ASR: it times text only with a separate 1.1 GB forced aligner (ON_REQUEST_TIMESTAMPS). This change does not start that download for a Translate drop.
  • Audio files keep producing a plain transcript, as asked, so nothing changes for people already using audio on Translate.
  • The Audio page's capability table (stt_capabilities) still reports whisper.cpp as having no timestamps, so the Transcribe page is unchanged.

Tests

  • Backend (CPU, a fake whisper-server over HTTP, no model downloads):
    • tests/test_stt_ggml_sidecar.py: the flag sends verbose_json + no_language_probabilities, segments are normalised (blank and untimed ones dropped), and the default request sends json and returns the same four keys as before.
    • tests/test_stt_raw_timestamps.py: the route passes timestamps=True only to whisper.cpp; the default response is unchanged for gguf, mtmd, transformers and audiocpp.
    • With the functional hunks reverted, the 3 new timestamp tests fail and the default-shape tests pass.
    • pytest tests/test_stt_raw_timestamps.py tests/test_stt_ggml_sidecar.py tests/test_stt_context_settings.py tests/test_stt_transcription_cancellation.py tests/test_stt_broken_runtime_falls_back.py tests/test_stt_ggml_request_path.py: 128 passed.
  • Frontend: segmentsToSrt output parses as SRT with the expected cues, timings, rounding past one hour and empty-input handling; video naming; the page asks for timings only for video files. Translate tests 88/88, full npm test 17057 passed, 0 failed. npm run typecheck clean; eslint on the touched files reports the same findings as main, nothing new.

Not verified here

  • An end-to-end run against a real whisper-server binary and a Whisper model (this host has no GPU and the check would need a model download). The verbose_json response shape follows examples/server/server.cpp in unslothai/whisper.cpp (segments carry start/end in seconds when timestamps are on, which Studio never turns off).

Before / after

A 23 second MP4 of speech dropped on Translate in a real Studio (CPU), with Whisper tiny on whisper.cpp as the Voice model, translated into French with Hy-MT2 1.8B. Before, the video becomes one plain paragraph; after, it becomes 8 timed cues, translated with every timing kept, and the result has a Download subtitles action:

before and after

Also checked the backend change directly against a real whisper-server with ggml base.en on WAV and MP4 input: the default response is unchanged and timestamps=true adds segments with real timings.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T08:53:46.999327Z 1b7db26 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen danielhanchen self-assigned this Nov 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: 1b7db262ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Nov 23, 2026
# Conflicts:
#	studio/frontend/src/features/translate/translate-subtitles.ts
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.

1 participant