Documentation
¶
Overview ¶
Package speech is offline speech recognition on the controller: the sherpa-onnx C API bound through purego, a SenseVoice recognizer and the resampler that brings recorder audio to the model's rate. It has no Node, transport or UI dependency, and audio never leaves the process.
Index ¶
Constants ¶
const ( // SampleRate is the rate the recognizer decodes, in Hz. SampleRate = 16_000 // MaxSamples bounds one recording to five minutes. MaxSamples = SampleRate * 300 )
const Version = "1.13.8"
Version is the only sherpa-onnx release this binding accepts.
Variables ¶
var ( // is not the pinned build. ErrUnavailable = errors.New("speech runtime is unavailable") // ErrInvalidModel reports model files the recognizer cannot load. ErrInvalidModel = errors.New("speech model validation failed") // ErrRecognition reports a failed decode. ErrRecognition = errors.New("speech recognition failed") // ErrInvalidAudio reports audio outside the accepted bounds. ErrInvalidAudio = errors.New("invalid speech audio") )
var Languages = [...]string{"auto", "chinese", "english"}
Languages are the values of the dictation.language preference, in the order of the constants.
Functions ¶
func Initialize ¶
func Initialize() error
Initialize loads the runtime packaged beside the executable, the only place it is loaded from.
func Load ¶
Load opens the pinned sherpa-onnx C API library in directory. The pinned onnxruntime of the same directory is opened first, so that sherpa-onnx binds to the image every other consumer uses. The process keeps one runtime: a second directory is refused.
Types ¶
type Language ¶
type Language int
Language is the language the recognizer assumes.
func ParseLanguage ¶
ParseLanguage maps a dictation.language preference; anything else is Auto.
type Recognizer ¶
type Recognizer struct {
// contains filtered or unexported fields
}
Recognizer is one loaded SenseVoice model, reused for the successive decodes of a recording. It is not safe for concurrent use.
func NewRecognizer ¶
func NewRecognizer(model, tokens string, language Language) (*Recognizer, error)
NewRecognizer loads a SenseVoice graph and its vocabulary after Load. A path that cannot be a C string, or files sherpa-onnx rejects, are ErrInvalidModel.
func (*Recognizer) Close ¶
func (r *Recognizer) Close()
Close releases the model. The recognizer must not be used afterwards.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package capture records a microphone through a purego binding of the miniaudio shim built from native/capture.
|
Package capture records a microphone through a purego binding of the miniaudio shim built from native/capture. |
|
Package models is the controller's own speech-model installations: the recommended SenseVoice model and the models registered in the index models/speech.json of the desktop data directory, with their files under models/speech/<id>.
|
Package models is the controller's own speech-model installations: the recommended SenseVoice model and the models registered in the index models/speech.json of the desktop data directory, with their files under models/speech/<id>. |