Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: add wrapper for system info #456

Merged
merged 1 commit into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bindings/go/examples/go-whisper/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions bindings/go/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion bindings/go/pkg/whisper/context.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package whisper

import (
"fmt"
"io"
"runtime"
"strings"
"time"

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions bindings/go/pkg/whisper/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down