engine

package
v0.0.0-...-05fb7a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNativeEngineUnavailable = errors.New("engine: native backend unavailable")

ErrNativeEngineUnavailable indicates that a real native backend is not yet wired in.

Functions

func NativeAvailable

func NativeAvailable() bool

NativeAvailable reports whether the native whisper backend is compiled in.

Types

type Engine

type Engine interface {
	// TranscribeSegment processes a chunk of audio and may emit zero or more transcripts.
	TranscribeSegment(ctx context.Context, audio []byte, opts Options) ([]Result, error)
	// Flush finalises the transcription session and emits any buffered transcripts.
	Flush(ctx context.Context, opts Options) ([]Result, error)
	// Close releases underlying resources.
	Close() error
}

Engine exposes a streaming transcription interface backed by whisper.cpp or a stub implementation.

func New

func New(cfg config.Config, manager *models.Manager, logger *slog.Logger) (Engine, string, error)

New resolves the desired model and returns an Engine instance. Currently the implementation falls back to the stub engine when the native backend is unavailable or model artefacts cannot be ensured locally.

func NewNativeEngine

func NewNativeEngine(modelPath string, _ NativeOptions) (Engine, error)

NewNativeEngine returns an error when the native backend is not built.

type NativeEngine

type NativeEngine struct{}

NativeEngine is a stub that satisfies the Engine interface when the native backend is absent.

func (*NativeEngine) Close

func (e *NativeEngine) Close() error

func (*NativeEngine) Flush

func (e *NativeEngine) Flush(ctx context.Context, opts Options) ([]Result, error)

func (*NativeEngine) SetDefaultLanguage

func (e *NativeEngine) SetDefaultLanguage(string)

func (*NativeEngine) TranscribeSegment

func (e *NativeEngine) TranscribeSegment(ctx context.Context, audio []byte, opts Options) ([]Result, error)

type NativeOptions

type NativeOptions struct {
	UseGPU         *bool
	FlashAttention *bool
	Threads        *int
	// StepMs configures the hop size for sliding-window inference.
	StepMs *int
	// LengthMs is the total window size before Whisper is invoked (--length).
	LengthMs *int
	// KeepMs is the overlap kept from the previous window (--keep).
	KeepMs *int
	// Translate enables translation from source language to English
	Translate *bool
	// TemperatureInc controls temperature fallback during decoding (0.0 to disable)
	TemperatureInc *float32
	// DisableFallback mirrors --no-fallback; when true temperature fallback is disabled regardless of TemperatureInc.
	DisableFallback *bool
	// BeamSize sets beam search size (1 for greedy sampling, >1 for beam search)
	BeamSize *int
	// AudioCtx sets encoder context size (0 = all audio)
	AudioCtx *int
	// PrintTimestamps enables timestamp output in transcription
	PrintTimestamps *bool
	// PrintSpecial enables special token output
	PrintSpecial *bool
	// KeepContext mirrors --keep-context and toggles prompt reuse between iterations.
	KeepContext *bool
	// UseVAD enables the VAD-driven mode (step_ms <= 0).
	UseVAD *bool
	// VADThreshold configures vad_thold.
	VADThreshold *float32
	// FreqThreshold configures freq_thold.
	FreqThreshold *float32
	// MaxTokens mirrors --max-tokens.
	MaxTokens *int
	// TinyDiarize enables the experimental TinyDiARize feature (--tinydiarize).
	TinyDiarize *bool
}

NativeOptions configures the native Whisper backend. Fields are optional and fall back to environment variables or sensible defaults for auto-detection.

type Options

type Options struct {
	Language string
	// Final indicates whether the segment corresponds to the end of the stream.
	Final bool
	// Sequence carries the original sequence number from the segment, when available.
	Sequence uint64
}

Options configures decoding for a segment or flush call.

type Result

type Result struct {
	Text       string
	Confidence float32
	Final      bool
}

Result represents a transcript produced by the engine.

type StubEngine

type StubEngine struct {
	// contains filtered or unexported fields
}

StubEngine produces deterministic transcripts without invoking Whisper.

func NewStubEngine

func NewStubEngine(logger *slog.Logger, modelVariant string) *StubEngine

NewStubEngine returns an Engine that generates placeholder transcripts.

func (*StubEngine) Close

func (e *StubEngine) Close() error

Close implements the Engine interface.

func (*StubEngine) Flush

func (e *StubEngine) Flush(ctx context.Context, opts Options) ([]Result, error)

Flush implements the Engine interface.

func (*StubEngine) SetDefaultLanguage

func (e *StubEngine) SetDefaultLanguage(string)

SetDefaultLanguage satisfies the languageHintSetter interface; the stub ignores the hint.

func (*StubEngine) TranscribeSegment

func (e *StubEngine) TranscribeSegment(ctx context.Context, audio []byte, opts Options) ([]Result, error)

TranscribeSegment implements the Engine interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL