Documentation
¶
Overview ¶
Package speech binds the whole C API of speech.cpp's libspeech (speech.h of speech.cpp 0.11.3, C API 4.3) without cgo.
Load opens the library once per process; every other function needs it. Every object the library returns is a Go type with an explicit, idempotent Close; nothing is freed by a finalizer. The package keeps the set of loaded models, and FreeAll frees every one of them together with the requests and streaming objects made for it: on Metal a process that ends with a model loaded aborts, so a program calls FreeAll (or closes its models) before it exits.
Threads, as speech.h says: a model serves one request at a time; a Request, Detection, Diarization, Enhancement or Dialogue is used by one goroutine at a time, except Request.Cancel, which any goroutine may call; ModelInfo may be read from any goroutine. Close must not run while the object is in use. A callback (audio, frame, progress) runs on the goroutine that made the call and must not call into the library with the same model.
Index ¶
- Variables
- func APIVersion() (major, minor int, err error)
- func DeviceCount() int
- func DeviceDescription(index int) (string, bool)
- func DeviceMemory(index int) (total, free uint64, err error)
- func DeviceName(index int) (string, bool)
- func FreeAll()
- func LibraryPath() string
- func Load(path string) error
- func Loaded() bool
- func LoadedModels() int
- func MakeVoice(modelPath, referencePath, voicePath string, params *LoadParams) error
- func MakeVoiceFrom(modelPath string, voice *VoiceParams, voicePath string, params *LoadParams) error
- func OptionCount() int
- func Quantize(modelPath, typ, outPath string) error
- func SetLogHandler(fn LogFunc) error
- func StatusName(s Status) (string, bool)
- func Version() (string, error)
- type AudioFunc
- type Control
- type Detection
- func (d *Detection) Close()
- func (d *Detection) End() error
- func (d *Detection) Ending() (ending bool, end float64)
- func (d *Detection) Push(samples []float32) error
- func (d *Detection) Region(index int) (Region, error)
- func (d *Detection) RegionCount() int
- func (d *Detection) Regions() ([]Region, error)
- func (d *Detection) Speaking() (speaking bool, start float64, kept bool)
- type Device
- type DeviceKind
- type Dialogue
- type DialogueFunc
- type Diarization
- func (d *Diarization) Close()
- func (d *Diarization) End() error
- func (d *Diarization) Push(samples []float32) error
- func (d *Diarization) Segment(index int) (Segment, error)
- func (d *Diarization) SegmentCount() int
- func (d *Diarization) Segments() ([]Segment, error)
- func (d *Diarization) Settled() float64
- func (d *Diarization) Speaking(speaker int) (speaking bool, start float64)
- type Enhancement
- type Error
- type LoadParams
- type LogFunc
- type LogLevel
- type MetaEntry
- type Model
- type ModelInfo
- func (mi *ModelInfo) Architecture() string
- func (mi *ModelInfo) Basename() string
- func (mi *ModelInfo) Close()
- func (mi *ModelInfo) Device() (string, bool)
- func (mi *ModelInfo) FileBytes() uint64
- func (mi *ModelInfo) Finetune() (string, bool)
- func (mi *ModelInfo) FrameSamples() int
- func (mi *ModelInfo) Incremental() bool
- func (mi *ModelInfo) JSON() string
- func (mi *ModelInfo) Language(index int) (string, bool)
- func (mi *ModelInfo) LanguageCount() int
- func (mi *ModelInfo) Languages() []string
- func (mi *ModelInfo) Layout() uint32
- func (mi *ModelInfo) License() string
- func (mi *ModelInfo) MaxTextTokens() int
- func (mi *ModelInfo) Meta() []MetaEntry
- func (mi *ModelInfo) MetaCount() int
- func (mi *ModelInfo) MetaKey(index int) (string, bool)
- func (mi *ModelInfo) MetaValue(index int) (string, bool)
- func (mi *ModelInfo) Name() string
- func (mi *ModelInfo) OptionAt(index int) Option
- func (mi *ModelInfo) OptionChoice(o Option, index int) (string, bool)
- func (mi *ModelInfo) OptionChoiceCount(o Option) int
- func (mi *ModelInfo) OptionChoices(o Option) []string
- func (mi *ModelInfo) OptionCount() int
- func (mi *ModelInfo) OptionDefaultBool(o Option) (bool, error)
- func (mi *ModelInfo) OptionDefaultFloat(o Option) (float64, error)
- func (mi *ModelInfo) OptionDefaultInt(o Option) (int64, error)
- func (mi *ModelInfo) OptionDefaultString(o Option) (string, error)
- func (mi *ModelInfo) OptionHasDefault(o Option) bool
- func (mi *ModelInfo) OptionRange(o Option) (Range, error)
- func (mi *ModelInfo) OptionRequired(o Option) bool
- func (mi *ModelInfo) OptionSteers(o Option) bool
- func (mi *ModelInfo) Options() []Option
- func (mi *ModelInfo) Organization() string
- func (mi *ModelInfo) SampleRate() int
- func (mi *ModelInfo) SizeLabel() string
- func (mi *ModelInfo) Source() (repository, revision string, err error)
- func (mi *ModelInfo) Speakers() int
- func (mi *ModelInfo) Takes(o Option) bool
- func (mi *ModelInfo) Task() Task
- func (mi *ModelInfo) TextTokens(text string) (int, error)
- func (mi *ModelInfo) Threads() int
- func (mi *ModelInfo) Version() (string, bool)
- func (mi *ModelInfo) VoiceCodec() (string, bool)
- func (mi *ModelInfo) VoiceCount() int
- func (mi *ModelInfo) VoiceDescription(index int) (string, bool)
- func (mi *ModelInfo) VoiceFiles() bool
- func (mi *ModelInfo) VoiceGender(index int) (string, bool)
- func (mi *ModelInfo) VoiceLanguage(index int) (string, bool)
- func (mi *ModelInfo) VoiceName(index int) (string, bool)
- func (mi *ModelInfo) VoiceRecordings() bool
- func (mi *ModelInfo) Voices() []Voice
- func (mi *ModelInfo) WeightBytes() uint64
- func (mi *ModelInfo) WeightType() string
- type Option
- type ProgressFunc
- type Range
- type Region
- type Request
- func (r *Request) Cancel()
- func (r *Request) Close()
- func (r *Request) Detect() error
- func (r *Request) Diarize() error
- func (r *Request) Enhance(onAudio AudioFunc) error
- func (r *Request) Model() *Model
- func (r *Request) Result() (*Result, bool)
- func (r *Request) SetAudio(samples []float32, sampleRate int) error
- func (r *Request) SetBool(o Option, value bool) error
- func (r *Request) SetFloat(o Option, value float64) error
- func (r *Request) SetInt(o Option, value int64) error
- func (r *Request) SetProgress(fn ProgressFunc) error
- func (r *Request) SetString(o Option, value string) error
- func (r *Request) SetText(text string) error
- func (r *Request) StartDetection(sampleRate int) (*Detection, error)
- func (r *Request) StartDialogue(sampleRate int, onFrame DialogueFunc) (*Dialogue, error)
- func (r *Request) StartDiarization(sampleRate int) (*Diarization, error)
- func (r *Request) StartEnhancement(sampleRate int, onAudio AudioFunc) (*Enhancement, error)
- func (r *Request) Synthesize(onAudio AudioFunc) error
- func (r *Request) Transcribe() error
- type Result
- func (res *Result) Language(index int) (string, bool)
- func (res *Result) LanguageCount() int
- func (res *Result) Languages() []string
- func (res *Result) Samples() uint64
- func (res *Result) Seed() int64
- func (res *Result) Segment(index int) (Segment, error)
- func (res *Result) SegmentCount() int
- func (res *Result) SegmentSpeaker(index int) int
- func (res *Result) Segments() ([]Segment, error)
- func (res *Result) Stop() StopReason
- func (res *Result) Text() (string, bool)
- func (res *Result) Token(index int) (Token, error)
- func (res *Result) TokenCount() int
- func (res *Result) Tokens() ([]Token, error)
- func (res *Result) Untimed() (string, bool)
- type Segment
- type Status
- type StopReason
- type Task
- type Token
- type Type
- type Voice
- type VoiceParams
- func (vp *VoiceParams) AddReference(path string) error
- func (vp *VoiceParams) AddVoice(path string) error
- func (vp *VoiceParams) Close()
- func (vp *VoiceParams) KeepLoudness() error
- func (vp *VoiceParams) SetEmbedding(values []float32, tokens, dim int) error
- func (vp *VoiceParams) SetLoudness(lufs float64) error
- func (vp *VoiceParams) SetSpeaker(speaker int) error
- func (vp *VoiceParams) SetTranscript(text string) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrCancelled = errors.New("speech: cancelled") ErrInvalidArgument = errors.New("speech: invalid_argument") ErrUnsupported = errors.New("speech: unsupported") ErrOutOfRange = errors.New("speech: out_of_range") ErrModelFile = errors.New("speech: model_file") ErrDevice = errors.New("speech: device") ErrOutOfMemory = errors.New("speech: out_of_memory") ErrIO = errors.New("speech: io") ErrInternal = errors.New("speech: internal") )
One sentinel per status that is not StatusOK; every *Error matches the one of its status with errors.Is.
var ErrClosed = errors.New("speech: object is closed")
ErrClosed is returned by a method of an object whose Close has run.
var ErrNotLoaded = errors.New("speech: libspeech is not loaded (call speech.Load first)")
ErrNotLoaded is returned by a call made before Load succeeded.
Functions ¶
func APIVersion ¶
APIVersion is the C API version of the loaded library (speech_api_version_major and _minor).
func DeviceCount ¶
func DeviceCount() int
DeviceCount is speech_device_count. The first call that touches a device sets ggml up for the process, and must not run while another thread reads the environment (speech.h, Devices).
func DeviceDescription ¶
DeviceDescription is speech_device_description, with false past the last device.
func DeviceMemory ¶
DeviceMemory is speech_device_memory: the device's total memory and what is free now, in bytes.
func DeviceName ¶
DeviceName is speech_device_name, with false past the last device.
func FreeAll ¶
func FreeAll()
FreeAll closes every loaded model with the requests and streaming objects made for it, for a program's shutdown: on Metal a process that ends with a model loaded aborts. Nothing may be in use while it runs.
func LibraryPath ¶
func LibraryPath() string
LibraryPath is the file Load opened, or "" before Load.
func Load ¶
Load opens libspeech at path, a library file or a directory holding it, checks its C API version (see loader.Open) and binds every function of speech.h. It is done once per process: a later call with the same file returns nil, and one with another file returns an error, since a process cannot hold two of them.
func LoadedModels ¶
func LoadedModels() int
LoadedModels is the number of models loaded and not yet closed.
func MakeVoice ¶
func MakeVoice(modelPath, referencePath, voicePath string, params *LoadParams) error
MakeVoice is speech_voice_make: makes a voice file at voicePath from the WAVE recording at referencePath for the model file at modelPath, running the codec's encoder on the device params name (the defaults for nil).
func MakeVoiceFrom ¶
func MakeVoiceFrom(modelPath string, voice *VoiceParams, voicePath string, params *LoadParams) error
MakeVoiceFrom is speech_voice_make_from: makes a voice file at voicePath of voice for the model file at modelPath.
func OptionCount ¶
func OptionCount() int
OptionCount is speech_option_count: the options the loaded library knows, the values from 0 to one below it.
func Quantize ¶
Quantize is speech_quantize: writes the F32 model file at modelPath to outPath with its weights in typ ("F16", "Q8_0", "Q6_K", "Q5_K", "Q4_K" or "IQ4_NL").
func SetLogHandler ¶
SetLogHandler sends every later log message of the library and of ggml to fn (speech_log_set), or drops every message when fn is nil. Until it is called the library writes warnings and errors to stderr. It holds for the whole process. A panic in fn is recovered and written to stderr, since it cannot unwind through the library.
func StatusName ¶
StatusName is speech_status_name: the library's name of s, with false for a value the library does not know.
Types ¶
type AudioFunc ¶
AudioFunc receives audio of a synthesis or an enhancement. samples is a copy the function may keep.
type Control ¶
type Control int32
Control is what a callback returns: Continue, or Stop to stop the call it runs in, which then returns an error that matches ErrCancelled.
type Detection ¶
type Detection struct {
// contains filtered or unexported fields
}
Detection is speech_detection: a detection of audio that arrives a piece at a time. It is used by one goroutine at a time; its model's Close frees it if the caller has not.
func (*Detection) Close ¶
func (d *Detection) Close()
Close is speech_detection_free. It is idempotent.
func (*Detection) Ending ¶
Ending is speech_detection_ending: whether the speech of the region Speaking reports has stopped, with the end it is given with if no speech starts again.
func (*Detection) Push ¶
Push is speech_detection_push: the next mono samples at the detection's rate, copied.
func (*Detection) Region ¶
Region is speech_detection_region: the region at index in the order given. A region once given never changes.
func (*Detection) RegionCount ¶
RegionCount is speech_detection_region_count: the regions given so far.
type Device ¶
type Device struct {
Index int
Name string // as a load parameter gives it, such as "MTL0" or "CPU"
Description string
Kind DeviceKind
TotalMemory uint64 // bytes
FreeMemory uint64 // bytes, when Devices was called
}
Device is one device the library can run a model on.
type DeviceKind ¶
type DeviceKind int32
DeviceKind is speech_device_kind.
const ( DeviceCPU DeviceKind = 0 DeviceGPU DeviceKind = 1 // a GPU with memory of its own DeviceIGPU DeviceKind = 2 // a GPU that shares the CPU's memory )
The device kinds of speech.h.
func DeviceKindOf ¶
func DeviceKindOf(index int) (DeviceKind, error)
DeviceKindOf is speech_device_get_kind.
func (DeviceKind) String ¶
func (k DeviceKind) String() string
type Dialogue ¶
type Dialogue struct {
// contains filtered or unexported fields
}
Dialogue is speech_dialogue: a conversation with a dialogue model, which passes a frame of its audio and text to its callback for each frame of audio it hears. It is used by one goroutine at a time; its model's Close frees it if the caller has not.
func (*Dialogue) Close ¶
func (d *Dialogue) Close()
Close is speech_dialogue_free. It is idempotent.
type DialogueFunc ¶
DialogueFunc receives a frame of a conversation: the model's audio (a copy the function may keep) and the text it began to say in the frame, often "", a space where it fell silent.
type Diarization ¶
type Diarization struct {
// contains filtered or unexported fields
}
Diarization is speech_diarization: a diarization of audio that arrives a piece at a time. It is used by one goroutine at a time; its model's Close frees it if the caller has not.
func (*Diarization) Close ¶
func (d *Diarization) Close()
Close is speech_diarization_free. It is idempotent.
func (*Diarization) End ¶
func (d *Diarization) End() error
End is speech_diarization_end: ends the audio and gives every segment left.
func (*Diarization) Push ¶
func (d *Diarization) Push(samples []float32) error
Push is speech_diarization_push: the next mono samples at the diarization's rate, copied.
func (*Diarization) Segment ¶
func (d *Diarization) Segment(index int) (Segment, error)
Segment is speech_diarization_segment: the segment at index in the order given (Text "").
func (*Diarization) SegmentCount ¶
func (d *Diarization) SegmentCount() int
SegmentCount is speech_diarization_segment_count: the segments given so far.
func (*Diarization) Segments ¶
func (d *Diarization) Segments() ([]Segment, error)
Segments lists the segments given so far.
func (*Diarization) Settled ¶
func (d *Diarization) Settled() float64
Settled is speech_diarization_settled: the time before which the diarization is final; +Inf once the audio ended.
type Enhancement ¶
type Enhancement struct {
// contains filtered or unexported fields
}
Enhancement is speech_enhancement: an enhancement of audio that arrives a piece at a time, passing the enhanced audio to its callback during Push and End. It is used by one goroutine at a time; its model's Close frees it if the caller has not.
func (*Enhancement) Close ¶
func (e *Enhancement) Close()
Close is speech_enhancement_free. It is idempotent.
func (*Enhancement) End ¶
func (e *Enhancement) End() error
End is speech_enhancement_end: ends the audio and passes every sample not yet passed.
func (*Enhancement) Push ¶
func (e *Enhancement) Push(samples []float32) error
Push is speech_enhancement_push: the next mono samples; the enhanced samples they settle reach the callback before it returns. After Stop from the callback it returns an error matching ErrCancelled and takes no more audio.
type Error ¶
type Error struct {
Op string // the C function that failed, such as "speech_transcribe"
Status Status
Name string // the status' name, as speech_status_name gives it
Message string // speech_last_error of the call
Option string // speech_last_error_option of the call: an option's name or an input ("audio", "path", ...), or ""
}
Error is a failed call: its status, the status' name, the library's message and the input it concerns. SPEECH_CANCELLED is an *Error too, matching ErrCancelled.
type LoadParams ¶
type LoadParams struct {
// Device is "auto" (the default when empty), "gpu", "cpu" or a device's name as DeviceName gives it.
Device string
// Threads the CPU computes with, 1 or more; 0 leaves the library's default.
Threads int
// Warmup runs a short request of the model's task while loading, so that a GPU's kernels compile before the first
// request.
Warmup bool
}
LoadParams are what LoadModel, MakeVoice and MakeVoiceFrom take besides the path (speech_load_params). The zero value, like a nil *LoadParams, is the library's defaults: device "auto", the library's threads, no warm-up.
type LogFunc ¶
LogFunc receives the library's log messages and ggml's: text is one line or a piece of one, as ggml writes it. It is called on whichever thread is inside the library, so it must be safe for concurrent use.
type LogLevel ¶
type LogLevel int32
LogLevel is speech_log_level: how much a log message matters.
The log levels of speech.h.
type MetaEntry ¶
MetaEntry is one metadata entry of the model file: its key and its value as JSON text.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is speech_model: a loaded model on its device, with its voices. A model serves one request at a time.
The model keeps the requests and streaming objects made for it; Close frees them before the model, as speech.h requires, and FreeAll does so for every loaded model.
func LoadModel ¶
func LoadModel(path string, params *LoadParams) (*Model, error)
LoadModel is speech_model_load: loads the model file at path on the device params name (the defaults for nil).
func (*Model) AddVoice ¶
AddVoice is speech_voice_add: adds a voice named name from a voice file or a WAVE recording at path.
func (*Model) Close ¶
func (m *Model) Close()
Close frees every request and streaming object made for the model and still open, then the model (speech_model_free). None of them may be in use. A Close that comes while another goroutine makes a request or a streaming object, reads the model's Info or adds a voice waits for that call, then frees what it made; those calls return ErrClosed once Close has begun. A callback must not close its own model. It is idempotent.
func (*Model) Info ¶
Info is speech_model_get_info: the model's information now, with its device and the voices added so far. The caller closes it.
func (*Model) NewRequest ¶
NewRequest is speech_request_new: a request for the model with no input and no option set. Model.Close frees it if the caller has not.
type ModelInfo ¶
type ModelInfo struct {
// contains filtered or unexported fields
}
ModelInfo is speech_model_info: what a model file says about its model, read without the weights (OpenModelInfo), or taken from a loaded model (Model.Info). It never changes once made and any goroutine may read it. Its methods return zero values once it is closed.
func OpenModelInfo ¶
OpenModelInfo is speech_model_info_open: the information of the model file at path, checked as loading checks it short of the weights, without touching a device.
func (*ModelInfo) Architecture ¶
Architecture is general.architecture, the family, such as "fastconformer".
func (*ModelInfo) Close ¶
func (mi *ModelInfo) Close()
Close is speech_model_info_free. It is idempotent.
func (*ModelInfo) Device ¶
Device is the device a loaded model runs on, with false for information read from a file.
func (*ModelInfo) FrameSamples ¶
FrameSamples is the samples of a dialogue model's frame; 0 for other tasks.
func (*ModelInfo) Incremental ¶
Incremental reports whether a synthesis model passes audio while it still generates the rest.
func (*ModelInfo) JSON ¶
JSON is all of the information as one JSON object, as `speech info --json` writes it.
func (*ModelInfo) Language ¶
Language is the language at index as a BCP 47 tag, with false past the end.
func (*ModelInfo) LanguageCount ¶
LanguageCount is speech_model_info_language_count.
func (*ModelInfo) MaxTextTokens ¶
MaxTextTokens is the most tokens of text a synthesis request may have; 0 for other tasks.
func (*ModelInfo) MetaKey ¶
MetaKey is the key of the metadata entry at index, with false past the end.
func (*ModelInfo) MetaValue ¶
MetaValue is the value of the metadata entry at index as JSON text, with false past the end.
func (*ModelInfo) OptionAt ¶
OptionAt is the option at index of those the model takes, in the vocabulary's order.
func (*ModelInfo) OptionChoice ¶
OptionChoice is the value at index of those a string option takes, with false past the end.
func (*ModelInfo) OptionChoiceCount ¶
OptionChoiceCount is the number of values a string option takes; 0 for free text and other types.
func (*ModelInfo) OptionChoices ¶
OptionChoices lists the values a string option takes.
func (*ModelInfo) OptionCount ¶
OptionCount is the number of options the model takes.
func (*ModelInfo) OptionDefaultBool ¶
OptionDefaultBool is the default of a boolean option.
func (*ModelInfo) OptionDefaultFloat ¶
OptionDefaultFloat is the default of a number option.
func (*ModelInfo) OptionDefaultInt ¶
OptionDefaultInt is the default of an integer option.
func (*ModelInfo) OptionDefaultString ¶
OptionDefaultString is the default of a string option.
func (*ModelInfo) OptionHasDefault ¶
OptionHasDefault reports whether o has a default the model uses when a request does not set it.
func (*ModelInfo) OptionRange ¶
OptionRange is speech_model_info_option_range.
func (*ModelInfo) OptionRequired ¶
OptionRequired reports whether a request to the model must set o.
func (*ModelInfo) OptionSteers ¶
OptionSteers reports whether o's value steers the model, rather than only being checked.
func (*ModelInfo) Organization ¶
Organization is general.organization, such as "nvidia".
func (*ModelInfo) SampleRate ¶
SampleRate in Hz of the audio the model makes or takes; 0 for an enhancement model.
func (*ModelInfo) Source ¶
Source is speech_model_info_source: the repository URL the file was converted from and the revision converted.
func (*ModelInfo) Speakers ¶
Speakers is the most speakers a diarization model tells apart; 0 for other tasks.
func (*ModelInfo) TextTokens ¶
TextTokens is speech_model_info_text_tokens: the model's tokens text takes, as a synthesis request counts them.
func (*ModelInfo) Threads ¶
Threads is the threads the CPU computes a loaded model's graphs with; 0 for information read from a file and for a model none of whose graphs runs on the CPU.
func (*ModelInfo) Version ¶
Version is general.version, such as "v3", with false for a model whose name has none.
func (*ModelInfo) VoiceCodec ¶
VoiceCodec is the hash a voice file must carry for the model, with false for a model that takes no voice files.
func (*ModelInfo) VoiceCount ¶
VoiceCount is speech_model_info_voice_count: the model's own voices, then those added with Model.AddVoice.
func (*ModelInfo) VoiceDescription ¶
VoiceDescription is the model's English description of the voice at index, "" when there is none.
func (*ModelInfo) VoiceFiles ¶
VoiceFiles reports whether the model takes voices made from reference recordings.
func (*ModelInfo) VoiceGender ¶
VoiceGender is "female" or "male" for the voice at index, "" when the file does not say.
func (*ModelInfo) VoiceLanguage ¶
VoiceLanguage is the language the voice at index was recorded in, "" when the file does not say.
func (*ModelInfo) VoiceName ¶
VoiceName is the name of the voice at index, which OptionVoice takes; false past the end.
func (*ModelInfo) VoiceRecordings ¶
VoiceRecordings reports whether Model.AddVoice takes a WAVE recording as well as a voice file.
func (*ModelInfo) WeightBytes ¶
WeightBytes is what the model's weights take on a device.
func (*ModelInfo) WeightType ¶
WeightType is general.file_type as ggml names it, such as "Q4_K".
type Option ¶
type Option int32
Option is speech_option: one name of the vocabulary of what a request may ask. A later minor version of the C API only appends values; OptionCount gives the number the loaded library knows.
const ( OptionVoice Option = 0 // "voice" OptionLanguage Option = 1 // "language" OptionSeed Option = 2 // "seed" OptionSpeed Option = 3 // "speed" OptionSeconds Option = 4 // "seconds" OptionDurationScale Option = 5 // "duration_scale" OptionSteps Option = 6 // "steps" OptionMaxSeconds Option = 7 // "max_seconds" OptionTimestamps Option = 8 // "timestamps" OptionPrompt Option = 9 // "prompt" OptionDecoding Option = 10 // "decoding" OptionDoSample Option = 11 // "do_sample" OptionTopK Option = 12 // "top_k" OptionTopP Option = 13 // "top_p" OptionTemperature Option = 14 // "temperature" OptionRepetitionPenalty Option = 15 // "repetition_penalty" OptionCodePredictorDoSample Option = 16 // "code_predictor_do_sample" OptionCodePredictorTopK Option = 17 // "code_predictor_top_k" OptionCodePredictorTopP Option = 18 // "code_predictor_top_p" OptionCodePredictorTemperature Option = 19 // "code_predictor_temperature" OptionInstructions Option = 20 // "instructions" OptionCfgScaleText Option = 21 // "cfg_scale_text" OptionCfgScaleSpeaker Option = 22 // "cfg_scale_speaker" OptionCfgGuidanceMode Option = 23 // "cfg_guidance_mode" OptionCfgMinT Option = 24 // "cfg_min_t" OptionCfgMaxT Option = 25 // "cfg_max_t" OptionTruncationFactor Option = 26 // "truncation_factor" OptionRescaleK Option = 27 // "rescale_k" OptionRescaleSigma Option = 28 // "rescale_sigma" OptionSpeakerUncondMode Option = 29 // "speaker_uncond_mode" OptionSwayCoeff Option = 30 // "sway_coeff" OptionKeepTail Option = 31 // "keep_tail" OptionTailWindowSize Option = 32 // "tail_window_size" OptionTailStdThreshold Option = 33 // "tail_std_threshold" OptionTailMeanThreshold Option = 34 // "tail_mean_threshold" OptionSpeakerKvScale Option = 35 // "speaker_kv_scale" OptionSpeakerKvMinT Option = 36 // "speaker_kv_min_t" OptionSpeakerKvMaxLayers Option = 37 // "speaker_kv_max_layers" OptionCfgScaleInstructions Option = 38 // "cfg_scale_instructions" OptionThreshold Option = 39 // "threshold" OptionMinSpeechDurationMs Option = 40 // "min_speech_duration_ms" OptionMinSilenceDurationMs Option = 41 // "min_silence_duration_ms" OptionSpeechPadMs Option = 42 // "speech_pad_ms" OptionMaxSpeechDurationS Option = 43 // "max_speech_duration_s" OptionDecodeOnCpu Option = 44 // "decode_on_cpu" OptionDraft Option = 45 // "draft" OptionExpertsOnCpu Option = 46 // "experts_on_cpu" OptionStreamingMode Option = 47 // "streaming_mode" OptionSpkcacheLen Option = 48 // "spkcache_len" OptionFifoLen Option = 49 // "fifo_len" OptionChunkLen Option = 50 // "chunk_len" OptionChunkRightContext Option = 51 // "chunk_right_context" OptionSpkcacheUpdatePeriod Option = 52 // "spkcache_update_period" OptionOnset Option = 53 // "onset" OptionOffset Option = 54 // "offset" OptionPadOnset Option = 55 // "pad_onset" OptionPadOffset Option = 56 // "pad_offset" OptionMinDurationOn Option = 57 // "min_duration_on" OptionMinDurationOff Option = 58 // "min_duration_off" OptionSpeakers Option = 59 // "speakers" OptionKeywords Option = 60 // "keywords" OptionKeywordsAlpha Option = 61 // "keywords_alpha" OptionKeywordsGuard Option = 62 // "keywords_guard" OptionChunkSizeInSeconds Option = 63 // "chunk_size_in_seconds" OptionHopLengthPortion Option = 64 // "hop_length_portion" OptionBwe Option = 65 // "bwe" OptionPersona Option = 66 // "persona" OptionName Option = 67 // "name" OptionGender Option = 68 // "gender" OptionBackchannel Option = 69 // "backchannel" OptionOtherName Option = 70 // "other_name" OptionRelationship Option = 71 // "relationship" OptionSituation Option = 72 // "situation" OptionGuidanceScale Option = 73 // "guidance_scale" OptionEopBias Option = 74 // "eop_bias" OptionSpeakFirst Option = 75 // "speak_first" )
The options of speech.h (C API 4.3), with their fixed names.
func OptionFromName ¶
OptionFromName is speech_option_from_name: the option named name in snake_case.
func (Option) Name ¶
Name is speech_option_name: the option's fixed name in snake_case, with false for a value the library does not know or before Load.
type ProgressFunc ¶
ProgressFunc receives how far a request has come, from 0 to 1.
type Range ¶
type Range struct {
Min float64
Max float64
MinExclusive bool // the minimum itself lies outside the range
}
Range is the range of an integer or number option; Min and Max are infinite where the option has no bound.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request is speech_request: the input and options of one run of a model's task, and its result. It checks every value as it is set against what its model declares. A request is used by one goroutine at a time, except Cancel, which any goroutine may call. A request that has started its work runs once.
func (*Request) Cancel ¶
func (r *Request) Cancel()
Cancel is speech_request_cancel: stops the request at the next point where its work can stop, after which the run returns an error matching ErrCancelled; one cancelled before it runs does no work. Any goroutine may call it; on a closed request it does nothing.
func (*Request) Close ¶
func (r *Request) Close()
Close is speech_request_free: frees the request and its result. It must not be running. It is idempotent.
func (*Request) Detect ¶
Detect is speech_detect: finds the regions of the request's audio where someone speaks (Result segments).
func (*Request) Diarize ¶
Diarize is speech_diarize: finds who speaks where in the request's audio (Result segments with speakers).
func (*Request) Enhance ¶
Enhance is speech_enhance: enhances the request's audio, passing it to onAudio as each piece settles.
func (*Request) Result ¶
Result is speech_request_result: the result of a request that ran to SPEECH_OK or SPEECH_CANCELLED, with false before it has run, after it failed and once it is closed. It lives until the request is closed.
func (*Request) SetAudio ¶
SetAudio is speech_request_set_audio: mono samples, nominally within [-1, 1], at sampleRate Hz, copied.
func (*Request) SetFloat ¶
SetFloat is speech_request_set_float. NaN and the infinities are refused.
func (*Request) SetProgress ¶
func (r *Request) SetProgress(fn ProgressFunc) error
SetProgress is speech_request_set_progress: fn receives how far the request has come while it does work that passes no audio, on the goroutine that runs the request; returning Stop stops it. nil removes the callback.
func (*Request) StartDetection ¶
StartDetection is speech_detection_start: a detection of audio at sampleRate Hz with the request's options. The request must have no audio; it is left as it was.
func (*Request) StartDialogue ¶
func (r *Request) StartDialogue(sampleRate int, onFrame DialogueFunc) (*Dialogue, error)
StartDialogue is speech_dialogue_start: a conversation hearing audio at sampleRate Hz with the request's options. It runs the prompt and passes the model's first frame to onFrame before it returns. If onFrame asks to stop there, the conversation is freed and the error matches ErrCancelled.
func (*Request) StartDiarization ¶
func (r *Request) StartDiarization(sampleRate int) (*Diarization, error)
StartDiarization is speech_diarization_start: a diarization of audio at sampleRate Hz with the request's options.
func (*Request) StartEnhancement ¶
func (r *Request) StartEnhancement(sampleRate int, onAudio AudioFunc) (*Enhancement, error)
StartEnhancement is speech_enhancement_start: an enhancement of audio at sampleRate Hz with the request's options, passing the enhanced audio to onAudio. The request must have no audio; it may be closed afterwards.
func (*Request) Synthesize ¶
Synthesize is speech_synthesize: speaks the request, passing its audio to onAudio as it is made, at the model's sample rate. Returning Stop from onAudio ends it with an error matching ErrCancelled.
func (*Request) Transcribe ¶
Transcribe is speech_transcribe: recognizes the speech in the request's audio, whole.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result is speech_result: what a request did. It lives as long as its request; its methods return zero values once the request is closed.
func (*Result) Language ¶
Language is the language at index as a BCP 47 tag, with false past the end.
func (*Result) LanguageCount ¶
LanguageCount is the number of languages a recognition heard.
func (*Result) Samples ¶
Samples is the number of samples a synthesis or an enhancement passed to its callback.
func (*Result) Seed ¶
Seed is the seed a synthesis used; -1 for other tasks, and 0 (like every method) once the request is closed.
func (*Result) Segment ¶
Segment is the segment at index with its speaker (speech_result_segment and speech_result_segment_speaker).
func (*Result) SegmentCount ¶
SegmentCount is speech_result_segment_count.
func (*Result) SegmentSpeaker ¶
SegmentSpeaker is speech_result_segment_speaker: the speaker of the segment at index, or -1.
func (*Result) TokenCount ¶
TokenCount is speech_result_token_count.
type Segment ¶
Segment is a segment of a recognition (with timestamps or speakers), a region of a detection (Text "") or a segment of a diarization (Text ""), in seconds from the start of the audio. Speaker is -1 where there is none.
type Status ¶
type Status int32
Status is speech_status: what a call that can fail returns. A negative value is an error.
const ( StatusOK Status = 0 StatusCancelled Status = 1 StatusInvalidArgument Status = -1 StatusUnsupported Status = -2 StatusOutOfRange Status = -3 StatusModelFile Status = -4 StatusDevice Status = -5 StatusOutOfMemory Status = -6 StatusIO Status = -7 StatusInternal Status = -8 )
The statuses of speech.h.
type StopReason ¶
type StopReason int32
StopReason is speech_stop: why a request ended.
const ( StopComplete StopReason = 0 StopMaxSeconds StopReason = 1 StopModelLimit StopReason = 2 StopCancelled StopReason = 3 )
The stop reasons of speech.h.
func (StopReason) Name ¶
func (s StopReason) Name() (string, bool)
Name is speech_stop_name, with false for a value the library does not know or before Load.
func (StopReason) String ¶
func (s StopReason) String() string
String is the stop reason's name, or "stop(N)" where the library gives none.
type Task ¶
type Task int32
Task is speech_task: what a model does.
type Type ¶
type Type int32
Type is speech_type: the type of an option's values, which names the setter that takes them.
The option types of speech.h.
type Voice ¶
type Voice struct {
Name string
Language string // BCP 47 tag, or "" when the file does not say
Gender string // "female", "male" or ""
Description string // in English, or ""
}
Voice describes one voice of a model.
type VoiceParams ¶
type VoiceParams struct {
// contains filtered or unexported fields
}
VoiceParams is speech_voice_params: what MakeVoiceFrom makes a voice file of (several references and their loudness, an embedding, or recordings with transcripts and speakers). It is used by one goroutine at a time.
func NewVoiceParams ¶
func NewVoiceParams() (*VoiceParams, error)
NewVoiceParams is speech_voice_params_new: parameters without a reference, at the model's loudness.
func (*VoiceParams) AddReference ¶
func (vp *VoiceParams) AddReference(path string) error
AddReference is speech_voice_params_add_reference: adds the WAVE recording at path.
func (*VoiceParams) AddVoice ¶
func (vp *VoiceParams) AddVoice(path string) error
AddVoice is speech_voice_params_add_voice: adds the references of the voice file at path as they are.
func (*VoiceParams) Close ¶
func (vp *VoiceParams) Close()
Close is speech_voice_params_free. It is idempotent.
func (*VoiceParams) KeepLoudness ¶
func (vp *VoiceParams) KeepLoudness() error
KeepLoudness is speech_voice_params_keep_loudness: keeps each reference's loudness as recorded.
func (*VoiceParams) SetEmbedding ¶
func (vp *VoiceParams) SetEmbedding(values []float32, tokens, dim int) error
SetEmbedding is speech_voice_params_set_embedding: a speaker-inversion embedding of tokens vectors of dim values, row by row, in place of references. len(values) must be tokens*dim.
func (*VoiceParams) SetLoudness ¶
func (vp *VoiceParams) SetLoudness(lufs float64) error
SetLoudness is speech_voice_params_set_loudness: brings each reference to lufs before it is encoded.
func (*VoiceParams) SetSpeaker ¶
func (vp *VoiceParams) SetSpeaker(speaker int) error
SetSpeaker is speech_voice_params_set_speaker: the speaker, from 0, of what was added last.
func (*VoiceParams) SetTranscript ¶
func (vp *VoiceParams) SetTranscript(text string) error
SetTranscript is speech_voice_params_set_transcript: the words of the reference added last.