dictation

package
v0.81.14 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 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 dictation provides an embeddable strict Dictation runtime.

Dictation is the most boundary-strict of the three SpeechKit modes: STT turns speech into text and the pipeline stops there. No LLM rewriting, no codewords, no tool invocation. Host apps integrate this when they want a transcript surface they can route into their own editor, command dispatcher, or downstream processor.

Use NewService (or its original name NewRuntime) to construct an instance; pass a recorder, a speechkit.Transcriber — typically stt.AsTranscriber wrapped around any stt.STTProvider — and the speechkit.RuntimePolicy from the host config.

Stability: Stable — no breaking change without a minor version bump and a changelog callout.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingRecorder    = errors.New("speechkit dictation: recorder is required")
	ErrMissingTranscriber = errors.New("speechkit dictation: transcriber is required")
	ErrAlreadyRecording   = errors.New("speechkit dictation: already recording")
	ErrNotRecording       = errors.New("speechkit dictation: not recording")
	ErrAudioTooShort      = errors.New("speechkit dictation: audio too short")
)

Errors of the Dictation runtime. NewRuntime rejects a missing Recorder or Transcriber; Runtime.Start returns ErrAlreadyRecording while a recording is active; Runtime.Stop returns ErrNotRecording without an active recording and ErrAudioTooShort when the capture is shorter than Options.MinPCMBytes, in which case nothing is transcribed.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Recorder supplies the PCM audio for one dictation. audio/capture.Session
	// satisfies it; tests use any in-memory AudioRecorder.
	Recorder speechkit.AudioRecorder
	// Transcriber turns the recorded WAV into a Transcript. Wrap an
	// stt.STTProvider or stt.Router with stt.AsTranscriber.
	Transcriber speechkit.Transcriber
	// Output receives the final transcript. Nil means the transcript is only
	// returned from Stop / stored; the runtime does not inject text anywhere.
	Output speechkit.TranscriptOutput
	// Store optionally persists every completed dictation.
	Store speechkit.Persistence
	// Observer can retain recognized text before output or slow history I/O.
	Observer speechkit.TranscriptionFinalizationObserver
	// Policy is the host's runtime policy (local-only, allowed providers, ...).
	// It is validated against Profiles at construction time.
	Policy speechkit.RuntimePolicy
	// Profiles is the provider catalog the Policy is checked against. Empty
	// means catalog.DefaultProviderProfiles().
	Profiles []speechkit.ProviderProfile
	// Language is the BCP-47 hint passed to the transcriber; "" means "auto".
	Language string
	// Target is an opaque, host-defined value handed unchanged to
	// Output.Deliver as its target argument. The runtime never inspects it; it
	// exists so a host can route one Output to several destinations (an editor
	// handle, a window id, a "clipboard" marker) without a per-target Output.
	// Nil is valid and means "the Output's default destination". Pass a value
	// implementing [speechkit.OutputTarget] (for example
	// speechkit.TargetRef{Kind: speechkit.TargetKindEditor, ID: "notes"});
	// untyped values are accepted until the field becomes OutputTarget in
	// v0.69.0.
	Target any
	// MinPCMBytes is the shortest recording that is transcribed; shorter
	// recordings fail Stop with ErrAudioTooShort. <= 0 means
	// speechkit.DefaultMinPCMBytes.
	MinPCMBytes int
}

Options configures a Dictation Runtime. Recorder and Transcriber are required; NewRuntime returns ErrMissingRecorder / ErrMissingTranscriber otherwise. Everything else has a documented default.

type Runtime

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

Runtime is an embeddable Dictation-only service. It keeps the mode boundary strict: audio in, final text out, no tool calls or LLM rewriting.

func NewRuntime

func NewRuntime(opts Options) (*Runtime, error)

NewRuntime validates opts and builds the runtime. It returns ErrMissingRecorder or ErrMissingTranscriber when those options are nil, and an error when opts.Policy enables or pins a non-dictation mode, fails speechkit.ValidateRuntimePolicy against opts.Profiles, or leaves no usable dictation profile. Defaults: Language "auto", MinPCMBytes speechkit.DefaultMinPCMBytes, Profiles catalog.DefaultProviderProfiles().

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context) error

Start opens the recorder and begins capturing; with Stop it implements speechkit.DictationService. It returns ErrAlreadyRecording while a recording is active, ctx.Err() when ctx is already done, and the recorder's error (leaving the runtime idle) when the device fails to open.

func (*Runtime) Stop

Stop ends the capture and transcribes it; without an active recording it returns ErrNotRecording. The returned speechkit.DictationRun always carries timing and a speechkit.TranscriptionFinalization; a recorder, ErrAudioTooShort or transcriber failure marks recognition failed and returns that error. After recognition the transcript goes to Options.Output (with Options.Target) and to Options.Store, which gets its own 15-second budget; their errors are joined into the returned error while the run keeps the recognized text. Options.Observer is notified after every finalization step.

type Service added in v0.67.14

type Service = Runtime

Service is the mode-service name for the Dictation runtime, matching assist.Service, tts.Service and voiceagent.Service so hosts wire the three modes with one vocabulary. Runtime and Service are the same type.

func NewService added in v0.67.14

func NewService(opts Options) (*Service, error)

NewService constructs a Dictation service; it is NewRuntime under the name the other mode packages use.

Jump to

Keyboard shortcuts

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