Documentation ¶
Index ¶
- Variables
- func LinSpace(start, stop float32, num int) (res *tensor.Dense)
- type ActivationFunc
- type ExitFunc
- type Listener
- type Model
- type MuStd
- type Option
- type Params
- type PredictionFunc
- type Runner
- type TFLiteModel
- type ThresholdDecoder
- type ThresholdOptions
- type TriggerDetector
- type TriggerOption
Constants ¶
This section is empty.
Variables ¶
var DefaultThreshold = ThresholdOptions{
MinZ: -4.0,
MaxZ: 4.0,
Center: 0.5,
Resolution: 200,
}
DefaultThreshold is the default set of options for the decoder.
var (
ErrModelClosed = errors.New("model closed")
)
var (
ErrUnexpectedType = errors.New("unexpected tensor type")
)
Functions ¶
Types ¶
type ActivationFunc ¶
type ActivationFunc func()
type Model ¶
func NewTFLiteModel ¶
NewTFLiteModel creates a new tensorflow lite model
type MuStd ¶
type MuStd [][]float32
MuStd represents threshold configs with easy to use functions.
type Option ¶
type Option func(*Runner)
func WithActivationFunc ¶
func WithActivationFunc(f ActivationFunc) Option
WithActivationFunc sets the func called when activated
func WithDetectorOpts ¶
func WithDetectorOpts(opts ...TriggerOption) Option
WithDetectorOpts sets detector options
func WithExitFunc ¶
WithPredictionFunc sets the func called after prediction
func WithPredictionFunc ¶
func WithPredictionFunc(f PredictionFunc) Option
WithPredictionFunc sets the func called after prediction
type Params ¶
type Params struct { WindowT float32 `json:"window_t" default:"0.1"` HopT float32 `json:"hop_t" default:"0.05"` BufferT float32 `json:"buffer_t" default:"1.5"` SampleRate int `json:"sample_rate" default:"16000"` SampleDepth int `json:"sample_depth" default:"2"` NMFCC int `json:"n_mfcc" default:"13"` NFilt int `json:"n_filt" default:"20"` NFft int `json:"n_fft" default:"512"` UseDelta bool `json:"use_delta" default:"false"` ThresholdConfig MuStd `json:"threshold_config" default:"[[6,4]]"` ThresholdCenter float32 `json:"threshold_center" default:"0.2"` }
Params is the Precise model parameter list. This can be loaded from JSON, however for tflite models these are hardcoded. Defaults are set for these elsewhere via NewParams, not using the tags, but they are there for reference
func (Params) BufferSamples ¶
func (Params) HopSamples ¶
func (Params) WindowSamples ¶
type PredictionFunc ¶
type PredictionFunc func(prob float32)
type Runner ¶
type Runner struct { OnPrediction PredictionFunc OnActivation ActivationFunc OnExit ExitFunc // contains filtered or unexported fields }
type TFLiteModel ¶
type TFLiteModel struct {
// contains filtered or unexported fields
}
TFLiteModel represents a tensorflow lite model
type ThresholdDecoder ¶
type ThresholdDecoder struct { MinOut int MaxOut int OutRange int // contains filtered or unexported fields }
ThresholdDecoder decodes raw neural network output
func NewThresholdDecoder ¶
func NewThresholdDecoder(muStds MuStd, options ThresholdOptions) *ThresholdDecoder
NewThresholdDecoder creates a new ThresholdDecoder with calculated distributions.
func (*ThresholdDecoder) Decode ¶
func (t *ThresholdDecoder) Decode(rawOutput float32) float32
Decode takes raw neural network output and normalizes it using probability distribution
type ThresholdOptions ¶
type TriggerDetector ¶
type TriggerDetector struct {
// contains filtered or unexported fields
}
func NewTriggerDetector ¶
func NewTriggerDetector(chunkSize int, opts ...TriggerOption) *TriggerDetector
NewTriggerDetector creates a new TriggerDetector
func (*TriggerDetector) Update ¶
func (t *TriggerDetector) Update(prob float32) bool
Update adds the current probability to the detection history
type TriggerOption ¶
type TriggerOption func(*TriggerDetector)
func WithSensitivity ¶
func WithSensitivity(sensitivity float32) TriggerOption
WithSensitivity sets the detector sensitivity
func WithTriggerLevel ¶
func WithTriggerLevel(triggerLevel int) TriggerOption
WithTriggerLevel sets the number of triggers required to return a valid trigger