]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
go : add wrapper for system info (#456)
authorLukas Rist <redacted>
Sat, 28 Jan 2023 16:44:56 +0000 (17:44 +0100)
committerGitHub <redacted>
Sat, 28 Jan 2023 16:44:56 +0000 (18:44 +0200)
bindings/go/examples/go-whisper/process.go
bindings/go/params.go
bindings/go/pkg/whisper/context.go
bindings/go/pkg/whisper/interface.go

index d4913be447dea836134f1693a54e47cd66ad1f45..d25fcd149ea8cb726ea622aa5fe28949398bc1d3 100644 (file)
@@ -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)
index d7dc238f5ad03f2026ae639a1ed2b4917ed5eb47..08757d7b2333b48d60382495397fb9f2ff2c1b76 100644 (file)
@@ -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)
index b26a4b73180798ceb2187b6b57d4792217fa083c..a4fe5134cf7f6b6add01e5fe5e5074ea0da9fc33 100644 (file)
@@ -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
 }
index c587df936731f1afd0b4858792766820e401fd67..4242963fb804205e31f5cba929cb24eeefa2ea1c 100644 (file)
@@ -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.