From 02c7516c575de5bf999c306e855bdfda120b01ff Mon Sep 17 00:00:00 2001 From: Lukas Rist Date: Wed, 25 Jan 2023 17:57:30 +0100 Subject: [PATCH] go : added wrappers to reset and print timings (#436) --- .gitignore | 1 + bindings/go/examples/go-whisper/process.go | 3 +++ bindings/go/pkg/whisper/context.go | 10 ++++++++++ bindings/go/pkg/whisper/interface.go | 3 +++ 4 files changed, 17 insertions(+) diff --git a/.gitignore b/.gitignore index 2f998a6..f9a1278 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.a .cache/ .vs/ .vscode/ diff --git a/bindings/go/examples/go-whisper/process.go b/bindings/go/examples/go-whisper/process.go index aacdc69..d4913be 100644 --- a/bindings/go/examples/go-whisper/process.go +++ b/bindings/go/examples/go-whisper/process.go @@ -64,10 +64,13 @@ func Process(model whisper.Model, path string, flags *Flags) error { // Process the data fmt.Fprintf(flags.Output(), " ...processing %q\n", path) + context.ResetTimings() if err := context.Process(data, cb); err != nil { return err } + context.PrintTimings() + // Print out the results switch { case flags.GetOut() == "srt": diff --git a/bindings/go/pkg/whisper/context.go b/bindings/go/pkg/whisper/context.go index 5dda57e..a4496b8 100644 --- a/bindings/go/pkg/whisper/context.go +++ b/bindings/go/pkg/whisper/context.go @@ -107,6 +107,16 @@ func (context *context) SetMaxTokensPerSegment(n uint) { context.params.SetMaxTokensPerSegment(int(n)) } +// ResetTimings resets the mode timings. Should be called before processing +func (context *context) ResetTimings() { + context.model.ctx.Whisper_reset_timings() +} + +// PrintTimings prints the model timings to stdout. +func (context *context) PrintTimings() { + context.model.ctx.Whisper_print_timings() +} + // Process new sample data and return any errors func (context *context) Process(data []float32, cb SegmentCallback) error { if context.model.ctx == nil { diff --git a/bindings/go/pkg/whisper/interface.go b/bindings/go/pkg/whisper/interface.go index 5ca913a..c587df9 100644 --- a/bindings/go/pkg/whisper/interface.go +++ b/bindings/go/pkg/whisper/interface.go @@ -60,6 +60,9 @@ type Context interface { IsNOT(Token) bool // Test for "No timestamps" token IsLANG(Token, string) bool // Test for token associated with a specific language IsText(Token) bool // Test for text token + + PrintTimings() + ResetTimings() } // Segment is the text result of a speech recognition.