From 54c978c3a31dac51bb6fab06d5ac5b11b336ae30 Mon Sep 17 00:00:00 2001 From: Johan Date: Sun, 15 Oct 2023 05:35:06 -0700 Subject: [PATCH] binding : Expose the audio_ctx param through the Go binding (#1368) * expose the audio_ctx param through the go binding * expose the audio_ctx param to the go binding context --- bindings/go/params.go | 6 ++++++ bindings/go/pkg/whisper/context.go | 7 ++++++- bindings/go/pkg/whisper/interface.go | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bindings/go/params.go b/bindings/go/params.go index b480ccf84e5..3c9dd5ce8ec 100644 --- a/bindings/go/params.go +++ b/bindings/go/params.go @@ -118,6 +118,11 @@ func (p *Params) SetMaxTokensPerSegment(n int) { p.max_tokens = C.int(n) } +// Set audio encoder context +func (p *Params) SetAudioCtx(n int) { + p.audio_ctx = C.int(n) +} + /////////////////////////////////////////////////////////////////////////////// // PRIVATE METHODS @@ -141,6 +146,7 @@ func (p *Params) String() string { str += fmt.Sprintf(" n_max_text_ctx=%d", p.n_max_text_ctx) str += fmt.Sprintf(" offset_ms=%d", p.offset_ms) str += fmt.Sprintf(" duration_ms=%d", p.duration_ms) + str += fmt.Sprintf(" audio_ctx=%d", p.audio_ctx) if p.translate { str += " translate" } diff --git a/bindings/go/pkg/whisper/context.go b/bindings/go/pkg/whisper/context.go index 6f3c2c747a0..f51d4f89ac0 100644 --- a/bindings/go/pkg/whisper/context.go +++ b/bindings/go/pkg/whisper/context.go @@ -82,7 +82,7 @@ func (context *context) SetSpeedup(v bool) { } func (context *context) SetSplitOnWord(v bool) { - context.params.SetSplitOnWord(v) + context.params.SetSplitOnWord(v) } // Set number of threads to use @@ -125,6 +125,11 @@ func (context *context) SetMaxTokensPerSegment(n uint) { context.params.SetMaxTokensPerSegment(int(n)) } +// Set audio encoder context +func (context *context) SetAudioCtx(n uint) { + context.params.SetAudioCtx(int(n)) +} + // ResetTimings resets the mode timings. Should be called before processing func (context *context) ResetTimings() { context.model.ctx.Whisper_reset_timings() diff --git a/bindings/go/pkg/whisper/interface.go b/bindings/go/pkg/whisper/interface.go index 771961abf5b..4744271d21f 100644 --- a/bindings/go/pkg/whisper/interface.go +++ b/bindings/go/pkg/whisper/interface.go @@ -48,6 +48,7 @@ type Context interface { SetMaxSegmentLength(uint) // Set max segment length in characters SetTokenTimestamps(bool) // Set token timestamps flag SetMaxTokensPerSegment(uint) // Set max tokens per segment (0 = no limit) + SetAudioCtx(uint) // Set audio encoder context // Process mono audio data and return any errors. // If defined, newly generated segments are passed to the