// Process new sample data and return any errors
func (context *context) Process(
data []float32,
+ callEncoderBegin EncoderBeginCallback,
callNewSegment SegmentCallback,
callProgress ProgressCallback,
) error {
// We don't do parallel processing at the moment
processors := 0
if processors > 1 {
- if err := context.model.ctx.Whisper_full_parallel(context.params, data, processors, nil, func(new int) {
+ if err := context.model.ctx.Whisper_full_parallel(context.params, data, processors, callEncoderBegin,
+ func(new int) {
+ if callNewSegment != nil {
+ num_segments := context.model.ctx.Whisper_full_n_segments()
+ s0 := num_segments - new
+ for i := s0; i < num_segments; i++ {
+ callNewSegment(toSegment(context.model.ctx, i))
+ }
+ }
+ }); err != nil {
+ return err
+ }
+ } else if err := context.model.ctx.Whisper_full(context.params, data, callEncoderBegin,
+ func(new int) {
if callNewSegment != nil {
num_segments := context.model.ctx.Whisper_full_n_segments()
s0 := num_segments - new
callNewSegment(toSegment(context.model.ctx, i))
}
}
- }); err != nil {
- return err
- }
- } else if err := context.model.ctx.Whisper_full(context.params, data, nil, func(new int) {
- if callNewSegment != nil {
- num_segments := context.model.ctx.Whisper_full_n_segments()
- s0 := num_segments - new
- for i := s0; i < num_segments; i++ {
- callNewSegment(toSegment(context.model.ctx, i))
+ }, func(progress int) {
+ if callProgress != nil {
+ callProgress(progress)
}
- }
- }, func(progress int) {
- if callProgress != nil {
- callProgress(progress)
- }
- }); err != nil {
+ }); err != nil {
return err
}
// processing. It is called during the Process function
type ProgressCallback func(int)
+// EncoderBeginCallback is the callback function for checking if we want to
+// continue processing. It is called during the Process function
+type EncoderBeginCallback func() bool
+
// Model is the interface to a whisper model. Create a new model with the
// function whisper.New(string)
type Model interface {
Languages() []string
}
-// Context is the speach recognition context.
+// Context is the speech recognition context.
type Context interface {
SetLanguage(string) error // Set the language to use for speech recognition, use "auto" for auto detect language.
SetTranslate(bool) // Set translate flag
// Process mono audio data and return any errors.
// If defined, newly generated segments are passed to the
// callback function during processing.
- Process([]float32, SegmentCallback, ProgressCallback) error
+ Process([]float32, EncoderBeginCallback, SegmentCallback, ProgressCallback) error
// After process is called, return segments until the end of the stream
// is reached, when io.EOF is returned.