whisper.cpp/bindings/go/pkg/whisper/params_wrap.go

70 lines
2.4 KiB
Go

package whisper
import (
"time"
// Bindings
whisper "github.com/ggerganov/whisper.cpp/bindings/go"
)
// parameters is a high-level wrapper that implements the Parameters interface
// and delegates to the underlying low-level whisper.Params.
type parameters struct {
p *whisper.Params
}
func newParameters(p *whisper.Params) Parameters { return &parameters{p: p} }
func (w *parameters) SetTranslate(v bool) { w.p.SetTranslate(v) }
func (w *parameters) SetSplitOnWord(v bool) { w.p.SetSplitOnWord(v) }
func (w *parameters) SetThreads(v uint) { w.p.SetThreads(int(v)) }
func (w *parameters) SetOffset(d time.Duration) { w.p.SetOffset(int(d.Milliseconds())) }
func (w *parameters) SetDuration(d time.Duration) { w.p.SetDuration(int(d.Milliseconds())) }
func (w *parameters) SetTokenThreshold(t float32) { w.p.SetTokenThreshold(t) }
func (w *parameters) SetTokenSumThreshold(t float32) { w.p.SetTokenSumThreshold(t) }
func (w *parameters) SetMaxSegmentLength(n uint) { w.p.SetMaxSegmentLength(int(n)) }
func (w *parameters) SetTokenTimestamps(b bool) { w.p.SetTokenTimestamps(b) }
func (w *parameters) SetMaxTokensPerSegment(n uint) { w.p.SetMaxTokensPerSegment(int(n)) }
func (w *parameters) SetAudioCtx(n uint) { w.p.SetAudioCtx(int(n)) }
func (w *parameters) SetMaxContext(n int) { w.p.SetMaxContext(n) }
func (w *parameters) SetBeamSize(n int) { w.p.SetBeamSize(n) }
func (w *parameters) SetEntropyThold(t float32) { w.p.SetEntropyThold(t) }
func (w *parameters) SetInitialPrompt(prompt string) { w.p.SetInitialPrompt(prompt) }
func (w *parameters) SetTemperature(t float32) { w.p.SetTemperature(t) }
func (w *parameters) SetTemperatureFallback(t float32) { w.p.SetTemperatureFallback(t) }
func (w *parameters) SetLanguage(lang string) error {
if lang == "auto" {
return w.p.SetLanguage(-1)
}
id := whisper.Whisper_lang_id_str(lang)
if id < 0 {
return ErrUnsupportedLanguage
}
return w.p.SetLanguage(id)
}
func (w *parameters) SetSingleSegment(v bool) {
w.p.SetSingleSegment(v)
}
// Getter methods for Parameters interface
func (w *parameters) Language() string {
id := w.p.Language()
if id == -1 {
return "auto"
}
return whisper.Whisper_lang_str(id)
}
func (w *parameters) Threads() int {
return w.p.Threads()
}
func (w *parameters) WhisperParams() *whisper.Params {
return w.p
}
var _ Parameters = &parameters{}