wake

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package wake slides a fixed window over 16 kHz audio, scores it every hop and debounces accepted windows into wake-word detections.

It is phonmatchnet-run's internal/listen, made push-driven: the caller writes audio frames of any size as they arrive, instead of the listener reading a stream on its own goroutine. Window placement and debouncing are unchanged.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Window int // samples scored per window
	Hop    int // samples between window ends
	// Confirm is how many consecutive accepted windows make a detection.
	Confirm int
	// Refractory is how long after a detection, measured from its window's
	// end, no window counts toward another one. A refractory period of at
	// least Window keeps one utterance from firing twice.
	Refractory int
}

Config sets the window geometry and debouncing, in samples.

func (Config) Validate

func (c Config) Validate() error

Validate checks the geometry.

type Event

type Event[T any] struct {
	Window   Window
	Result   T
	Accepted bool
	Detected bool
}

Event reports one scored window. Detected marks the window that completed a detection.

type Listener

type Listener[T any] struct {
	// contains filtered or unexported fields
}

Listener holds the most recent Window samples and the debounce state. It is not safe for concurrent use.

func New

func New[T any](c Config, score Score[T]) (*Listener[T], error)

New returns a listener at stream offset zero.

func (*Listener[T]) Position

func (l *Listener[T]) Position() int64

Position returns how many samples have been written.

func (*Listener[T]) Write

func (l *Listener[T]) Write(ctx context.Context, samples []float32, emit func(Event[T]) error) error

Write appends samples, which continue the stream, and scores a window at every hop boundary once Window samples have arrived, calling emit for each. A frame that crosses several boundaries scores several windows. Errors from score or emit stop Write; the samples up to that window have been consumed.

type Score

type Score[T any] func(context.Context, Window) (T, bool, error)

Score scores one window and reports whether it is accepted.

func PhonMatchNet

func PhonMatchNet(engine *phonmatchnet.Engine, keyword phonmatchnet.Keyword, far float64) Score[phonmatchnet.Result]

PhonMatchNet scores each window against keyword with engine at the calibrated operating point far (zero selects phonmatchnet.DefaultFAR). Window must be 0.5 to 2 seconds of 16 kHz audio.

type Window

type Window struct {
	Start, End int64
	Samples    []float32
}

Window is one scored span of the stream. Start and End are sample offsets from the start of the stream, End exclusive. Samples is reused by the next window; copy it to keep it.

Jump to

Keyboard shortcuts

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