mirror of
https://github.com/ggerganov/whisper.cpp.git
synced 2025-06-23 19:21:39 +02:00
Adding in NewContextWithStrategy for go binding
Adding in NewContextWithStrategy, a function to allow you to specify the strategy when initializing the context. NewContext will use this "helper" function so that users don't need to think about what strategy they're specifying by default. I'm also doing it this way (instead of a function that sets the strategy) because the basis of what parameters we populate the context with is determined by the strategy we are using, so it needs to be done in the beginning of creating the context.
This commit is contained in:
parent
996581c5e2
commit
97707fb370
@ -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
|
||||
|
@ -20,6 +20,13 @@ type model struct {
|
||||
// Make sure model adheres to the interface
|
||||
var _ Model = (*model)(nil)
|
||||
|
||||
type SamplingStrategy whisper.SamplingStrategy
|
||||
|
||||
const (
|
||||
SAMPLING_GREEDY SamplingStrategy = (SamplingStrategy)(whisper.SAMPLING_GREEDY)
|
||||
SAMPLING_BEAM_SEARCH SamplingStrategy = (SamplingStrategy)(whisper.SAMPLING_BEAM_SEARCH)
|
||||
)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// LIFECYCLE
|
||||
|
||||
@ -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) {
|
||||
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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user