package whisper import ( "fmt" "math" "go-whisper-api/config" pkg "github.com/ggerganov/whisper.cpp/bindings/go/pkg/whisper" ) func ApplyVAD(ctx pkg.Context, vad config.VAD) { if !vad.Enabled { return } vad = vad.WithDefaults() ctx.SetVAD(true) ctx.SetVADModelPath(vad.Model) ctx.SetVADThreshold(float32(vad.Threshold)) ctx.SetVADMinSpeechMs(vad.MinSpeechMs) ctx.SetVADMinSilenceMs(vad.MinSilenceMs) if vad.MaxSpeechSec > 0 { ctx.SetVADMaxSpeechSec(float32(vad.MaxSpeechSec)) } else { ctx.SetVADMaxSpeechSec(float32(math.MaxFloat32)) } ctx.SetVADSpeechPadMs(vad.SpeechPadMs) ctx.SetVADSamplesOverlap(float32(vad.SamplesOverlap)) } func prepareVAD(vad *config.VAD, modelsDir string) error { if vad == nil || !vad.Enabled { return nil } if modelsDir != "" { vad.Model = vad.ResolveModelPath(modelsDir) } *vad = vad.WithDefaults() if err := vad.Validate(); err != nil { return fmt.Errorf("vad: %w", err) } return nil }