Expand description
Turn whisper.cpp output into clean, caption-ready segments.
whisper.cpp can emit a JSON file (-oj / -ojf) or plain stdout lines like
[00:00:01.000 --> 00:00:03.500] Hello there. This crate normalizes both
into Segments with millisecond timestamps and, when token-level data is
present, whole-word Word timings.
whisper.cpp’s special tokens ([_BEG_], [_TT_150], <|endoftext|>, …)
are dropped, and to_srt / to_vtt turn segments into subtitle files.
No whisper dependency: it works on output files from any whisper.cpp
version, and merge_bpe_tokens also accepts tokens from whisper-rs.
let stdout = "[00:00:01.000 --> 00:00:02.500] Hello world\n";
let segments = whisper_captions::parse_whisper_stdout(stdout);
assert_eq!(segments[0].text, "Hello world");
assert_eq!(segments[0].start_ms, 1000);
assert_eq!(segments[0].duration_ms, 1500);
let srt = whisper_captions::to_srt(&segments);
assert!(srt.starts_with("1\n00:00:01,000 --> 00:00:02,500\nHello world\n"));Structs§
- RawToken
- A raw whisper token before BPE merging. The text is kept untouched so the leading-space “starts a new word” signal survives until merging.
- Segment
- One caption-ready transcript segment.
- Word
- A whole word with its timing, reassembled from whisper’s BPE tokens.
Functions§
- is_
special_ token - Is this a whisper control token rather than speech?
- merge_
bpe_ tokens - Reassemble whisper’s BPE tokens into whole words.
- normalize_
raw_ token - Normalize one raw whisper word/token, keeping its text untouched.
- parse_
timestamp_ ms - Parse a whisper timestamp into milliseconds.
- parse_
transcript - Prefer JSON segments; fall back to stdout when JSON is missing or empty.
- parse_
whisper_ json - Parse a whisper.cpp JSON result (any of the known layouts).
- parse_
whisper_ json_ str - Parse a whisper.cpp JSON string. Invalid JSON yields an error.
- parse_
whisper_ stdout - Parse whisper.cpp’s human-readable stdout (
[start --> end] textlines). - to_srt
- Render segments as SubRip (
.srt). - to_vtt
- Render segments as WebVTT (
.vtt).