Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
44 lines
1.0 KiB
Go
44 lines
1.0 KiB
Go
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
|
|
}
|