Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/whisper.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,12 @@ extern "C" {
WHISPER_API void whisper_vad_free_segments(struct whisper_vad_segments * segments);
WHISPER_API void whisper_vad_free (struct whisper_vad_context * ctx);

// Inject external VAD context for use with params.vad = true.
// The caller retains ownership - whisper will not free this context.
// Frees any previously set internal VAD context.
WHISPER_API void whisper_state_set_vad(struct whisper_state * state, struct whisper_vad_context * vctx);
WHISPER_API void whisper_set_vad (struct whisper_context * ctx, struct whisper_vad_context * vctx);

////////////////////////////////////////////////////////////////////////////

// Temporary helpers needed for exposing ggml interface
Expand Down
19 changes: 18 additions & 1 deletion src/whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ struct whisper_state {
int32_t exp_n_audio_ctx = 0; // 0 - use default

whisper_vad_context * vad_context = nullptr;
bool vad_external = false;

struct vad_segment_info {
int64_t orig_start;
Expand Down Expand Up @@ -3835,7 +3836,7 @@ void whisper_free_state(struct whisper_state * state) {
// [EXPERIMENTAL] Token-level timestamps with DTW
aheads_masks_free(state->aheads_masks);

if (state->vad_context != nullptr) {
if (state->vad_context != nullptr && !state->vad_external) {
whisper_vad_free(state->vad_context);
state->vad_context = nullptr;
}
Expand Down Expand Up @@ -5467,6 +5468,22 @@ void whisper_vad_free_segments(whisper_vad_segments * segments) {
}
}

void whisper_state_set_vad(
struct whisper_state * state,
struct whisper_vad_context * vctx) {
if (state->vad_context != nullptr && !state->vad_external) {
whisper_vad_free(state->vad_context);
}
state->vad_context = vctx;
state->vad_external = (vctx != nullptr);
}

void whisper_set_vad(
struct whisper_context * ctx,
struct whisper_vad_context * vctx) {
whisper_state_set_vad(ctx->state, vctx);
}

//////////////////////////////////
// Grammar - ported from llama.cpp
//////////////////////////////////
Expand Down
Loading