This commit is contained in:
Gabriel LT 2026-04-23 10:45:40 +03:00 committed by GitHub
commit 25de2e4e7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -728,6 +728,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

View File

@ -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;
@ -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;
}
@ -5476,6 +5477,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
//////////////////////////////////