From 2bee2650c66497b8804e3c82426373703c6d97a1 Mon Sep 17 00:00:00 2001 From: Lukas Rist Date: Sat, 28 Jan 2023 17:44:56 +0100 Subject: [PATCH] go : add wrapper for system info (#456) --- bindings/go/examples/go-whisper/process.go | 2 ++ bindings/go/params.go | 5 +++++ bindings/go/pkg/whisper/context.go | 13 ++++++++++++- bindings/go/pkg/whisper/interface.go | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bindings/go/examples/go-whisper/process.go b/bindings/go/examples/go-whisper/process.go index d4913be4..d25fcd14 100644 --- a/bindings/go/examples/go-whisper/process.go +++ b/bindings/go/examples/go-whisper/process.go @@ -25,6 +25,8 @@ func Process(model whisper.Model, path string, flags *Flags) error { return err } + fmt.Printf("\n%s\n", context.SystemInfo()) + // Open the file fmt.Fprintf(flags.Output(), "Loading %q\n", path) fh, err := os.Open(path) diff --git a/bindings/go/params.go b/bindings/go/params.go index d7dc238f..08757d7b 100644 --- a/bindings/go/params.go +++ b/bindings/go/params.go @@ -66,6 +66,11 @@ func (p *Params) Language() int { return int(C.whisper_lang_id(p.language)) } +// Threads available +func (p *Params) Threads() int { + return int(p.n_threads) +} + // Set number of threads to use func (p *Params) SetThreads(threads int) { p.n_threads = C.int(threads) diff --git a/bindings/go/pkg/whisper/context.go b/bindings/go/pkg/whisper/context.go index b26a4b73..a4fe5134 100644 --- a/bindings/go/pkg/whisper/context.go +++ b/bindings/go/pkg/whisper/context.go @@ -1,7 +1,9 @@ package whisper import ( + "fmt" "io" + "runtime" "strings" "time" @@ -117,13 +119,22 @@ func (context *context) PrintTimings() { context.model.ctx.Whisper_print_timings() } +// SystemInfo returns the system information +func (context *context) SystemInfo() string { + return fmt.Sprintf("system_info: n_threads = %d / %d | %s\n", + context.params.Threads(), + runtime.NumCPU(), + whisper.Whisper_print_system_info(), + ) +} + // Use mel data at offset_ms to try and auto-detect the spoken language // Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first. // Returns the probabilities of all languages. func (context *context) WhisperLangAutoDetect(offset_ms int, n_threads int) ([]float32, error) { langProbs, err := context.model.ctx.Whisper_lang_auto_detect(offset_ms, n_threads) if err != nil { - return nil, err + return nil, err } return langProbs, nil } diff --git a/bindings/go/pkg/whisper/interface.go b/bindings/go/pkg/whisper/interface.go index c587df93..4242963f 100644 --- a/bindings/go/pkg/whisper/interface.go +++ b/bindings/go/pkg/whisper/interface.go @@ -61,8 +61,11 @@ type Context interface { IsLANG(Token, string) bool // Test for token associated with a specific language IsText(Token) bool // Test for text token + // Timings PrintTimings() ResetTimings() + + SystemInfo() string } // Segment is the text result of a speech recognition.