Skip to content
Closed
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
1 change: 1 addition & 0 deletions bindings/go/pkg/whisper/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Model interface {

// Return a new speech-to-text context.
NewContext() (Context, error)
NewContextWithStrategy(SamplingStrategy) (Context, error)

// Return true if the model is multilingual.
IsMultilingual() bool
Expand Down
14 changes: 13 additions & 1 deletion bindings/go/pkg/whisper/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ type model struct {
// Make sure model adheres to the interface
var _ Model = (*model)(nil)

type SamplingStrategy whisper.SamplingStrategy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having this and the globals might be a little confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the other option was to have clients import both versions, but figured that'd be more of a headache. Alright, no worries!


const (
SAMPLING_GREEDY SamplingStrategy = (SamplingStrategy)(whisper.SAMPLING_GREEDY)
SAMPLING_BEAM_SEARCH SamplingStrategy = (SamplingStrategy)(whisper.SAMPLING_BEAM_SEARCH)
)

///////////////////////////////////////////////////////////////////////////////
// LIFECYCLE

Expand Down Expand Up @@ -82,12 +89,17 @@ func (model *model) Languages() []string {
}

func (model *model) NewContext() (Context, error) {
// By default, specify the greedy strategy
return model.NewContextWithStrategy(SAMPLING_GREEDY)
}

func (model *model) NewContextWithStrategy(strategy SamplingStrategy) (Context, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps instead of passing in just the strategy to this function, it could accepts a parameter of type whisper.Params?

if model.ctx == nil {
return nil, ErrInternalAppError
}

// Create new context
params := model.ctx.Whisper_full_default_params(whisper.SAMPLING_GREEDY)
params := model.ctx.Whisper_full_default_params((whisper.SamplingStrategy)(strategy))
params.SetTranslate(false)
params.SetPrintSpecial(false)
params.SetPrintProgress(false)
Expand Down
Loading