local

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 33 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package local is the built-in speech-to-text provider: it runs a whisper.cpp whisper-server child process on loopback and speaks its OpenAI-compatible transcription route, so audio never leaves the machine. It needs the whisper-server binary next to the executable or in a managed install location (no cgo; PATH is consulted only with SPEECHKIT_ALLOW_WHISPER_PATH=1) and a ggml-*.bin model file. The host owns the process lifecycle through Provider.StartServer and Provider.StopServer.

Stability: Beta — API-checked; may change with a changelog callout.

Index

Constants

View Source
const MinWhisperModelBytes = 50_000_000

MinWhisperModelBytes is the minimum file size we expect for a valid ggml model. ggml-base.bin is ~150 MB; anything under 50 MB is clearly corrupt/truncated.

Variables

View Source
var ErrAuthProxyUnavailable = errors.New("local whisper-server: authenticated loopback proxy unavailable")

ErrAuthProxyUnavailable is returned when the keyed loopback proxy in front of whisper-server cannot be set up, or is gone while the child still runs. The provider fails closed on it: whisper-server itself has no authentication and serves open CORS, so it is never reached directly.

Functions

func FindWhisperBinary

func FindWhisperBinary() (string, error)

FindWhisperBinary exposes the local whisper runtime lookup for callers that need to reflect runtime readiness without starting the subprocess.

func SetSubprocessPriorityLowered

func SetSubprocessPriorityLowered(lowered bool)

SetSubprocessPriorityLowered toggles the process-wide default for whether STT subprocesses are spawned at BELOW_NORMAL priority (default true). No-op on non-Windows. Providers with an explicit LowerSubprocessPriority ignore it. It forwards to procguard.SetSubprocessPriorityLowered, so the default is shared with every other SpeechKit subprocess.

func ValidateModelPath

func ValidateModelPath(path string) error

ValidateModelPath verifies that path points at a whisper.cpp ggml model file with a safe filename. It rejects path traversal, non-absolute paths, and filenames that don't match the ggml-*.bin pattern.

Types

type InstallStatus

type InstallStatus struct {
	BinaryFound bool     `json:"binaryFound"`
	BinaryPath  string   `json:"binaryPath"`
	ModelFound  bool     `json:"modelFound"`
	ModelPath   string   `json:"modelPath"`
	ModelBytes  int64    `json:"modelBytes"`
	ServerReady bool     `json:"serverReady"`
	Problems    []string `json:"problems,omitempty"`
}

InstallStatus describes what's present and what's missing for local STT.

type Options added in v0.74.0

type Options struct {
	// Port is the loopback port the whisper.cpp server listens on. 0 picks a
	// free ephemeral loopback port at every start, which another local
	// process cannot predict and bind first. A fixed port that is already in
	// use fails the start instead of trusting whatever listens there.
	Port int
	// ModelPath is the path to the whisper.cpp model file.
	ModelPath string
	// GPU selects the GPU backend passed to the server. Empty leaves it unset.
	GPU string
}

Options configures New.

type Provider

type Provider struct {
	BaseURL    string // e.g. "http://127.0.0.1:8080"
	Port       int
	ModelPath  string
	GPU        string
	Validation netsec.ValidationOptions
	// LowerSubprocessPriority overrides the process-wide default set via
	// SetSubprocessPriorityLowered for this provider only. nil keeps the
	// default (true on Windows). Ignored outside Windows.
	LowerSubprocessPriority *bool
	// Logger receives this provider's diagnostics. Nil falls back to
	// slog.Default() at log time.
	Logger *slog.Logger
	// contains filtered or unexported fields
}

Provider implements stt.STTProvider for Tier 1: localhost whisper.cpp server.

func New

func New(opts Options) *Provider

New creates the built-in whisper.cpp provider. The process is not started; lifecycle stays with the host.

func (*Provider) Capabilities added in v0.64.3

func (*Provider) Capabilities() []speechkit.Capability

Capabilities reports the speech-to-text baseline every provider satisfies.

func (*Provider) Health added in v0.64.3

func (p *Provider) Health(ctx context.Context) error

Health reports an error when no whisper-server child is running; otherwise it probes the child's /health endpoint and updates Provider.IsReady with the outcome, so a provider that lost readiness recovers on the next probe.

func (*Provider) IsReady added in v0.64.3

func (p *Provider) IsReady() bool

IsReady returns true if the whisper-server subprocess is running and responding.

func (*Provider) Name added in v0.64.3

func (p *Provider) Name() string

Name returns "local".

func (*Provider) RuntimeDone added in v0.64.3

func (p *Provider) RuntimeDone() <-chan struct{}

RuntimeDone closes whenever the owned whisper-server subprocess exits. RuntimeError then reports an unexpected exit and stays nil for an explicit StopServer call or process-context cancellation.

func (*Provider) RuntimeError added in v0.64.3

func (p *Provider) RuntimeError() error

RuntimeError returns why the current whisper-server child exited, once Provider.RuntimeDone has closed. It is nil while the child runs, after an explicit Provider.StopServer, when the process context was cancelled, or on a nil receiver.

func (*Provider) StartServer added in v0.64.3

func (p *Provider) StartServer(ctx context.Context) error

StartServer starts the whisper.cpp server subprocess. Blocks until ready or context cancelled.

func (*Provider) StopServer added in v0.64.3

func (p *Provider) StopServer()

StopServer terminates the whisper-server subprocess.

func (*Provider) Transcribe added in v0.64.3

func (p *Provider) Transcribe(ctx context.Context, audioData []byte, opts stt.TranscribeOpts) (*stt.Result, error)

Transcribe implements stt.STTProvider against the child's /v1/audio/transcriptions route. When a Provider.StartServer call is in progress it waits for it to finish, and it fails when the server is not ready. A multilanguage request is sent as whisper.cpp's explicit "auto", since the server would otherwise pin English. The request timeout grows with the audio length (20 s plus three times the clip, between 5 and 10 minutes) and the result Model is the model file's base name.

func (*Provider) VerifyInstallation added in v0.64.3

func (p *Provider) VerifyInstallation() InstallStatus

VerifyInstallation checks binary and model availability without starting the server.

Jump to

Keyboard shortcuts

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