Skip to content

Commit

Permalink
binding : Expose the audio_ctx param through the Go binding (#1368)
Browse files Browse the repository at this point in the history
* expose the audio_ctx param through the go binding

* expose the audio_ctx param to the go binding context
  • Loading branch information
JohanRaffin authored Oct 15, 2023
1 parent 9a7074d commit 54c978c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions bindings/go/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
}
Expand Down
7 changes: 6 additions & 1 deletion bindings/go/pkg/whisper/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions bindings/go/pkg/whisper/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54c978c

Please sign in to comment.