Documentation
¶
Overview ¶
Package voice provides continuous, local speech transcription.
The package feeds microphone audio to a sherpa-onnx streaming recognizer. It prints finalized utterances itself and also exposes those utterances to the importing application. It never interprets spoken text as a command.
Index ¶
- Variables
- type Config
- type ModelConfig
- type Partial
- type Recognizer
- type Session
- func (s *Session) Done() <-chan struct{}
- func (s *Session) Errors() <-chan error
- func (s *Session) Finals() <-chan Utterance
- func (s *Session) Partials() <-chan Partial
- func (s *Session) Ready() <-chan struct{}
- func (s *Session) Stop() error
- func (s *Session) Wait() error
- func (s *Session) WaitReady() error
- type Utterance
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidConfiguration indicates invalid library configuration. ErrInvalidConfiguration = errors.New("voice: invalid configuration") // ErrMissingModel indicates that a configured model file is missing or not a regular file. ErrMissingModel = errors.New("voice: missing model file") // ErrUnsupported indicates that the current platform or build cannot capture audio. ErrUnsupported = errors.New("voice: speech recognition is unsupported") // ErrNoMicrophone indicates that no capture device is available. ErrNoMicrophone = errors.New("voice: no microphone is available") ErrDeviceUnavailable = errors.New("voice: requested microphone is unavailable") // ErrMicrophonePermission indicates that the audio backend could not open the microphone. ErrMicrophonePermission = errors.New("voice: microphone permission or device-open failure") // ErrMicrophoneDisconnected indicates that the active microphone stopped unexpectedly. ErrMicrophoneDisconnected = errors.New("voice: microphone disconnected") // ErrRecognizerInit indicates that sherpa-onnx could not create its native recognizer. ErrRecognizerInit = errors.New("voice: recognizer initialization failed") // ErrRecognition indicates a failure while processing audio. ErrRecognition = errors.New("voice: recognition failed") // ErrAudioOverload indicates that the bounded audio queue overflowed. ErrAudioOverload = errors.New("voice: audio processing queue overflowed") // ErrOutput indicates that the configured output writer failed. ErrOutput = errors.New("voice: output writer failed") // ErrSessionActive indicates that a recognizer already has a listening session. ErrSessionActive = errors.New("voice: a listening session is already active") // ErrStopped indicates that a session was explicitly stopped. ErrStopped = errors.New("voice: listening session stopped") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Model ModelConfig
// Language is descriptive metadata for the selected model. Model.Language
// is used when Language is empty.
Language string
// Microphone selects a device by malgo ID or device name. Empty selects the
// operating system's default capture device.
Microphone string
// Output receives exactly one newline-terminated line per finalized
// utterance. Nil uses os.Stdout. The library never opens a transcript file.
Output io.Writer
// OnFinal receives finalized utterances after the library writes them.
OnFinal func(Utterance)
// OnPartial receives changing partial recognition text. Partials are never
// written to Output and are never delivered through Finals.
OnPartial func(Partial)
// SampleRate and FeatureDim default to 16000 and 80, respectively.
SampleRate int
FeatureDim int
// AudioQueueSize bounds microphone audio retained in memory. When full,
// the session stops with ErrAudioOverload rather than growing memory.
AudioQueueSize int
// EventQueueSize bounds the exported final and partial event channels.
EventQueueSize int
}
Config controls a Recognizer.
type ModelConfig ¶
type ModelConfig struct {
Encoder string
Decoder string
Joiner string
Tokens string
// ModelType is optional for most models. It defaults to zipformer2, which
// is the type used by the documented English Zipformer example.
ModelType string
// Provider is a sherpa-onnx provider such as cpu. It defaults to cpu.
Provider string
// NumThreads controls native model computation and defaults to one.
NumThreads int
// Language is descriptive metadata for the selected model (for example,
// en-US). The online transducer API infers language from the model files.
Language string
}
ModelConfig identifies one sherpa-onnx online transducer model.
A general-purpose streaming Zipformer model needs encoder, decoder, joiner, and tokens files. The files are read by the native runtime; this library never downloads or copies them.
type Recognizer ¶
type Recognizer struct {
// contains filtered or unexported fields
}
Recognizer owns one local model configuration and permits one session at a time.
func New ¶
func New(config Config) (*Recognizer, error)
New validates model paths and creates a local recognizer configuration. It does not access the microphone or initialize the native model.
func (*Recognizer) Language ¶
func (r *Recognizer) Language() string
Language returns the descriptive language metadata configured for the model.
func (*Recognizer) Start ¶
func (r *Recognizer) Start(ctx context.Context) (*Session, error)
Start begins microphone capture and continues until Stop, context cancellation, a microphone failure, or a recognition failure. Setup errors are reported by Session.WaitReady and Session.Errors.
func (*Recognizer) Stop ¶
func (r *Recognizer) Stop() error
Stop stops the active session and waits for its workers and native resources to be released. It is safe to call repeatedly.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done returns a channel closed only after all native resources and workers have been released.
func (*Session) Errors ¶
Errors returns zero or one terminal error and is closed when the session ends.
func (*Session) Finals ¶
Finals returns a bounded stream of finalized utterances. It is closed when the session ends.
func (*Session) Partials ¶
Partials returns a bounded, informational stream of changing partial text. A slow partial consumer may cause partials to be dropped; finalized text is never replaced by a partial.
func (*Session) Ready ¶
func (s *Session) Ready() <-chan struct{}
Ready returns a channel closed after native setup succeeds or fails.
func (*Session) Stop ¶
Stop requests cancellation, waits for cleanup, and returns the session's terminal error. It is safe to call repeatedly.