Skip to content

Commit 2ce58b2

Browse files
authored
go : add wrapper for system info (ggml-org#456)
1 parent f8a85e2 commit 2ce58b2

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

bindings/go/examples/go-whisper/process.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ func Process(model whisper.Model, path string, flags *Flags) error {
2525
return err
2626
}
2727

28+
fmt.Printf("\n%s\n", context.SystemInfo())
29+
2830
// Open the file
2931
fmt.Fprintf(flags.Output(), "Loading %q\n", path)
3032
fh, err := os.Open(path)

bindings/go/params.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ func (p *Params) Language() int {
6666
return int(C.whisper_lang_id(p.language))
6767
}
6868

69+
// Threads available
70+
func (p *Params) Threads() int {
71+
return int(p.n_threads)
72+
}
73+
6974
// Set number of threads to use
7075
func (p *Params) SetThreads(threads int) {
7176
p.n_threads = C.int(threads)

bindings/go/pkg/whisper/context.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package whisper
22

33
import (
4+
"fmt"
45
"io"
6+
"runtime"
57
"strings"
68
"time"
79

@@ -117,13 +119,22 @@ func (context *context) PrintTimings() {
117119
context.model.ctx.Whisper_print_timings()
118120
}
119121

122+
// SystemInfo returns the system information
123+
func (context *context) SystemInfo() string {
124+
return fmt.Sprintf("system_info: n_threads = %d / %d | %s\n",
125+
context.params.Threads(),
126+
runtime.NumCPU(),
127+
whisper.Whisper_print_system_info(),
128+
)
129+
}
130+
120131
// Use mel data at offset_ms to try and auto-detect the spoken language
121132
// Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first.
122133
// Returns the probabilities of all languages.
123134
func (context *context) WhisperLangAutoDetect(offset_ms int, n_threads int) ([]float32, error) {
124135
langProbs, err := context.model.ctx.Whisper_lang_auto_detect(offset_ms, n_threads)
125136
if err != nil {
126-
return nil, err
137+
return nil, err
127138
}
128139
return langProbs, nil
129140
}

bindings/go/pkg/whisper/interface.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ type Context interface {
6161
IsLANG(Token, string) bool // Test for token associated with a specific language
6262
IsText(Token) bool // Test for text token
6363

64+
// Timings
6465
PrintTimings()
6566
ResetTimings()
67+
68+
SystemInfo() string
6669
}
6770

6871
// Segment is the text result of a speech recognition.

0 commit comments

Comments
 (0)