whisper : expose internal VAD speech segments (#3916)

When transcribing with params.vad = true, whisper already computes the speech
segments and keeps them in the state. Expose them so callers can reuse those
boundaries (for example to align or clip subtitles to speech) instead of running
a second, separate VAD pass.

Times are on the original audio timeline in centiseconds; the count is 0 when VAD
was not used. test-vad-full.cpp checks the segments are ordered and non-empty.
This commit is contained in:
Lin Xiaodong
2026-07-01 19:10:16 +08:00
committed by GitHub
parent 167d225f3a
commit 6fc7c33b4c
3 changed files with 47 additions and 0 deletions

View File

@@ -681,6 +681,17 @@ extern "C" {
WHISPER_API float whisper_full_get_token_p (struct whisper_context * ctx, int i_segment, int i_token);
WHISPER_API float whisper_full_get_token_p_from_state(struct whisper_state * state, int i_segment, int i_token);
// Access the speech segments detected by the internal VAD (only when params.vad = true).
// Times are on the original audio timeline, in centiseconds. The count is 0 when VAD was
// not used, so callers can reuse whisper's own speech boundaries instead of running a
// separate VAD pass.
WHISPER_API int whisper_full_n_vad_segments (struct whisper_context * ctx);
WHISPER_API int whisper_full_n_vad_segments_from_state (struct whisper_state * state);
WHISPER_API int64_t whisper_full_get_vad_segment_t0 (struct whisper_context * ctx, int i);
WHISPER_API int64_t whisper_full_get_vad_segment_t0_from_state(struct whisper_state * state, int i);
WHISPER_API int64_t whisper_full_get_vad_segment_t1 (struct whisper_context * ctx, int i);
WHISPER_API int64_t whisper_full_get_vad_segment_t1_from_state(struct whisper_state * state, int i);
//
// Voice Activity Detection (VAD)
//