Skip to content

Commit

Permalink
go : added wrappers to reset and print timings (ggerganov#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
glaslos authored Jan 25, 2023
1 parent 411ea9b commit 02c7516
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.o
*.a
.cache/
.vs/
.vscode/
Expand Down
3 changes: 3 additions & 0 deletions bindings/go/examples/go-whisper/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ func Process(model whisper.Model, path string, flags *Flags) error {

// Process the data
fmt.Fprintf(flags.Output(), " ...processing %q\n", path)
context.ResetTimings()
if err := context.Process(data, cb); err != nil {
return err
}

context.PrintTimings()

// Print out the results
switch {
case flags.GetOut() == "srt":
Expand Down
10 changes: 10 additions & 0 deletions bindings/go/pkg/whisper/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ func (context *context) SetMaxTokensPerSegment(n uint) {
context.params.SetMaxTokensPerSegment(int(n))
}

// ResetTimings resets the mode timings. Should be called before processing
func (context *context) ResetTimings() {
context.model.ctx.Whisper_reset_timings()
}

// PrintTimings prints the model timings to stdout.
func (context *context) PrintTimings() {
context.model.ctx.Whisper_print_timings()
}

// Process new sample data and return any errors
func (context *context) Process(data []float32, cb SegmentCallback) error {
if context.model.ctx == 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 @@ -60,6 +60,9 @@ type Context interface {
IsNOT(Token) bool // Test for "No timestamps" token
IsLANG(Token, string) bool // Test for token associated with a specific language
IsText(Token) bool // Test for text token

PrintTimings()
ResetTimings()
}

// Segment is the text result of a speech recognition.
Expand Down

0 comments on commit 02c7516

Please sign in to comment.