Spaces:
Sleeping
Sleeping
Lukas Rist
commited on
go : add wrapper for system info (#456)
Browse files
bindings/go/examples/go-whisper/process.go
CHANGED
|
@@ -25,6 +25,8 @@ func Process(model whisper.Model, path string, flags *Flags) error {
|
|
| 25 |
return err
|
| 26 |
}
|
| 27 |
|
|
|
|
|
|
|
| 28 |
// Open the file
|
| 29 |
fmt.Fprintf(flags.Output(), "Loading %q\n", path)
|
| 30 |
fh, err := os.Open(path)
|
|
|
|
| 25 |
return err
|
| 26 |
}
|
| 27 |
|
| 28 |
+
fmt.Printf("\n%s\n", context.SystemInfo())
|
| 29 |
+
|
| 30 |
// Open the file
|
| 31 |
fmt.Fprintf(flags.Output(), "Loading %q\n", path)
|
| 32 |
fh, err := os.Open(path)
|
bindings/go/params.go
CHANGED
|
@@ -66,6 +66,11 @@ func (p *Params) Language() int {
|
|
| 66 |
return int(C.whisper_lang_id(p.language))
|
| 67 |
}
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
// Set number of threads to use
|
| 70 |
func (p *Params) SetThreads(threads int) {
|
| 71 |
p.n_threads = C.int(threads)
|
|
|
|
| 66 |
return int(C.whisper_lang_id(p.language))
|
| 67 |
}
|
| 68 |
|
| 69 |
+
// Threads available
|
| 70 |
+
func (p *Params) Threads() int {
|
| 71 |
+
return int(p.n_threads)
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
// Set number of threads to use
|
| 75 |
func (p *Params) SetThreads(threads int) {
|
| 76 |
p.n_threads = C.int(threads)
|
bindings/go/pkg/whisper/context.go
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
package whisper
|
| 2 |
|
| 3 |
import (
|
|
|
|
| 4 |
"io"
|
|
|
|
| 5 |
"strings"
|
| 6 |
"time"
|
| 7 |
|
|
@@ -117,13 +119,22 @@ func (context *context) PrintTimings() {
|
|
| 117 |
context.model.ctx.Whisper_print_timings()
|
| 118 |
}
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
// Use mel data at offset_ms to try and auto-detect the spoken language
|
| 121 |
// Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first.
|
| 122 |
// Returns the probabilities of all languages.
|
| 123 |
func (context *context) WhisperLangAutoDetect(offset_ms int, n_threads int) ([]float32, error) {
|
| 124 |
langProbs, err := context.model.ctx.Whisper_lang_auto_detect(offset_ms, n_threads)
|
| 125 |
if err != nil {
|
| 126 |
-
|
| 127 |
}
|
| 128 |
return langProbs, nil
|
| 129 |
}
|
|
|
|
| 1 |
package whisper
|
| 2 |
|
| 3 |
import (
|
| 4 |
+
"fmt"
|
| 5 |
"io"
|
| 6 |
+
"runtime"
|
| 7 |
"strings"
|
| 8 |
"time"
|
| 9 |
|
|
|
|
| 119 |
context.model.ctx.Whisper_print_timings()
|
| 120 |
}
|
| 121 |
|
| 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 |
+
|
| 131 |
// Use mel data at offset_ms to try and auto-detect the spoken language
|
| 132 |
// Make sure to call whisper_pcm_to_mel() or whisper_set_mel() first.
|
| 133 |
// Returns the probabilities of all languages.
|
| 134 |
func (context *context) WhisperLangAutoDetect(offset_ms int, n_threads int) ([]float32, error) {
|
| 135 |
langProbs, err := context.model.ctx.Whisper_lang_auto_detect(offset_ms, n_threads)
|
| 136 |
if err != nil {
|
| 137 |
+
return nil, err
|
| 138 |
}
|
| 139 |
return langProbs, nil
|
| 140 |
}
|
bindings/go/pkg/whisper/interface.go
CHANGED
|
@@ -61,8 +61,11 @@ type Context interface {
|
|
| 61 |
IsLANG(Token, string) bool // Test for token associated with a specific language
|
| 62 |
IsText(Token) bool // Test for text token
|
| 63 |
|
|
|
|
| 64 |
PrintTimings()
|
| 65 |
ResetTimings()
|
|
|
|
|
|
|
| 66 |
}
|
| 67 |
|
| 68 |
// Segment is the text result of a speech recognition.
|
|
|
|
| 61 |
IsLANG(Token, string) bool // Test for token associated with a specific language
|
| 62 |
IsText(Token) bool // Test for text token
|
| 63 |
|
| 64 |
+
// Timings
|
| 65 |
PrintTimings()
|
| 66 |
ResetTimings()
|
| 67 |
+
|
| 68 |
+
SystemInfo() string
|
| 69 |
}
|
| 70 |
|
| 71 |
// Segment is the text result of a speech recognition.
|