filters

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package filters provides frame-filtering processors for the pipeline, ported from upstream processors/filters: frame_filter, function_filter, identity_filter, null_filter, stt_mute_filter, wake_check_filter, wake_notifier_filter. Use New* constructors for programmatic use, or register via pipeline and configure with plugin_options in config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrameFilter

type FrameFilter struct {
	*processors.BaseProcessor
	// contains filtered or unexported fields
}

FrameFilter allows only frames whose FrameType() is in the allowed set. Lifecycle frames (Start, End, Cancel, Stop, Error) always pass through.

func NewFrameFilter

func NewFrameFilter(name string, allowedTypes []string) *FrameFilter

NewFrameFilter returns a filter that forwards only frames with type in allowedTypes, plus lifecycle frames.

func NewFrameFilterFromOptions

func NewFrameFilterFromOptions(name string, opts json.RawMessage) *FrameFilter

NewFrameFilterFromOptions builds a FrameFilter from plugin_options JSON. If opts is nil or empty, allows no data frames (only lifecycle).

func (*FrameFilter) ProcessFrame

func (p *FrameFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame forwards the frame only if it is lifecycle or its type is in the allowed set.

type FrameFilterOptions

type FrameFilterOptions struct {
	AllowedTypes []string `json:"allowed_types"`
}

FrameFilterOptions is the JSON shape for plugin_options["frame_filter"].

type FunctionFilter

type FunctionFilter struct {
	*processors.BaseProcessor
	Filter             FunctionFilterPredicate
	Direction          processors.Direction // 0 = both
	FilterSystemFrames bool
}

FunctionFilter forwards frames based on a predicate. Lifecycle frames (Start, End, Cancel, Stop) always pass. Optionally restrict to one direction and optionally filter system frames (e.g. ErrorFrame).

func NewFunctionFilter

func NewFunctionFilter(name string, filter FunctionFilterPredicate, direction processors.Direction, filterSystemFrames bool) *FunctionFilter

NewFunctionFilter returns a filter that uses the given predicate. Lifecycle frames always pass. If direction is non-zero, only that direction is filtered; the opposite direction always forwards.

func NewFunctionFilterFromOptions

func NewFunctionFilterFromOptions(name string, opts json.RawMessage) *FunctionFilter

NewFunctionFilterFromOptions builds a FunctionFilter from plugin_options. Predicate is always all-pass when created from config.

func (*FunctionFilter) ProcessFrame

func (p *FunctionFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame forwards the frame if it is lifecycle, or (when direction matches) if the predicate returns true.

type FunctionFilterOptions

type FunctionFilterOptions struct {
	Direction          string `json:"direction"` // "downstream", "upstream", or "" for both
	FilterSystemFrames bool   `json:"filter_system_frames"`
}

FunctionFilterOptions is the JSON shape for plugin_options["function_filter"]. The actual filter predicate cannot be set via config; use NewFunctionFilter for that.

type FunctionFilterPredicate

type FunctionFilterPredicate func(f frames.Frame) bool

FunctionFilterPredicate returns true if the frame should pass. Used for programmatic FunctionFilter.

type IdentityFilter

type IdentityFilter struct {
	*processors.BaseProcessor
}

IdentityFilter forwards all frames unchanged (pass-through).

func NewIdentityFilter

func NewIdentityFilter(name string) *IdentityFilter

NewIdentityFilter returns a pass-through filter.

func (*IdentityFilter) ProcessFrame

func (p *IdentityFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame forwards the frame unchanged.

type NullFilter

type NullFilter struct {
	*processors.BaseProcessor
}

NullFilter blocks all frames except lifecycle frames (Start, End, Cancel, Stop, Error).

func NewNullFilter

func NewNullFilter(name string) *NullFilter

NewNullFilter returns a filter that only passes lifecycle frames.

func (*NullFilter) ProcessFrame

func (p *NullFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame forwards only lifecycle frames; drops all others.

type STTMuteConfig

type STTMuteConfig struct {
	Strategies         []STTMuteStrategy                                              `json:"strategies"`
	ShouldMuteCallback func(ctx context.Context, filter *STTMuteFilter) (bool, error) `json:"-"` // for Custom; set programmatically
}

STTMuteConfig configures STT muting. FirstSpeech and MuteUntilFirstBotComplete should not be used together.

type STTMuteFilter

type STTMuteFilter struct {
	*processors.BaseProcessor
	Config STTMuteConfig
	// contains filtered or unexported fields
}

STTMuteFilter suppresses VAD/STT-related frames when muted (e.g. during bot speech or until first bot complete). When muted, VAD, transcription, interruption, and input audio frames are dropped.

func NewSTTMuteFilter

func NewSTTMuteFilter(name string, config STTMuteConfig) *STTMuteFilter

NewSTTMuteFilter returns an STT mute filter with the given config.

func NewSTTMuteFilterFromOptions

func NewSTTMuteFilterFromOptions(name string, opts json.RawMessage) *STTMuteFilter

NewSTTMuteFilterFromOptions builds from plugin_options. Custom strategy and callback require programmatic setup.

func (*STTMuteFilter) ProcessFrame

func (p *STTMuteFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame updates mute state from bot/session frames and suppresses STT/VAD frames when muted.

type STTMuteFilterOptions

type STTMuteFilterOptions struct {
	Strategies []string `json:"strategies"` // e.g. ["first_speech", "always"]
}

STTMuteFilterOptions is the JSON shape for plugin_options["stt_mute_filter"].

type STTMuteStrategy

type STTMuteStrategy string

STTMuteStrategy determines when STT is muted.

const (
	STTMuteFirstSpeech           STTMuteStrategy = "first_speech"                  // mute until first bot speech detected
	STTMuteUntilFirstBotComplete STTMuteStrategy = "mute_until_first_bot_complete" // mute until first bot speech completes
	STTMuteAlways                STTMuteStrategy = "always"                        // mute whenever bot is speaking
	STTMuteCustom                STTMuteStrategy = "custom"                        // use ShouldMuteCallback
)

type WakeCheckFilter

type WakeCheckFilter struct {
	*processors.BaseProcessor
	// contains filtered or unexported fields
}

WakeCheckFilter passes TranscriptionFrames only after a wake phrase has been detected for that participant. Other frame types always pass. After wake, frames pass for keepaliveTimeout; then state resets to idle.

func NewWakeCheckFilter

func NewWakeCheckFilter(name string, wakePhrases []string, keepaliveTimeout time.Duration) *WakeCheckFilter

NewWakeCheckFilter returns a wake-phrase filter. wakePhrases are matched as word-boundary phrases (case-insensitive).

func NewWakeCheckFilterFromOptions

func NewWakeCheckFilterFromOptions(name string, opts json.RawMessage) *WakeCheckFilter

NewWakeCheckFilterFromOptions builds from plugin_options.

func (*WakeCheckFilter) ProcessFrame

func (p *WakeCheckFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame forwards non-TranscriptionFrame as-is. For TranscriptionFrame, forwards only after wake for that user_id, with keepalive.

type WakeCheckFilterOptions

type WakeCheckFilterOptions struct {
	WakePhrases   []string `json:"wake_phrases"`
	KeepaliveSecs float64  `json:"keepalive_secs"`
}

WakeCheckFilterOptions is the JSON shape for plugin_options["wake_check_filter"].

type WakeNotifierFilter

type WakeNotifierFilter struct {
	*processors.BaseProcessor
	// contains filtered or unexported fields
}

WakeNotifierFilter forwards all frames; when a frame's type is in the allowed set and the predicate returns true, it calls notifier.Notify().

func NewWakeNotifierFilter

func NewWakeNotifierFilter(name string, n *notifier.Notifier, types []string, predicate func(frames.Frame) bool) *WakeNotifierFilter

NewWakeNotifierFilter returns a filter that forwards every frame and optionally triggers n when frame type is in types and predicate(f) is true. If predicate is nil, any matching type triggers Notify. If notifier is nil, Notify is never called.

func NewWakeNotifierFilterFromOptions

func NewWakeNotifierFilterFromOptions(name string, opts json.RawMessage) *WakeNotifierFilter

NewWakeNotifierFilterFromOptions builds from plugin_options. Notifier is nil (Notify never called); set via programmatic constructor for real use.

func (*WakeNotifierFilter) ProcessFrame

func (p *WakeNotifierFilter) ProcessFrame(ctx context.Context, f frames.Frame, dir processors.Direction) error

ProcessFrame forwards the frame; if type matches and (predicate is nil or predicate(f)), calls notifier.Notify().

type WakeNotifierFilterOptions

type WakeNotifierFilterOptions struct {
	Types []string `json:"types"` // frame types that can trigger notification (e.g. ["TranscriptionFrame"])
}

WakeNotifierFilterOptions is the JSON shape for plugin_options["wake_notifier_filter"]. Notifier must be set programmatically via NewWakeNotifierFilter; when created from config with no notifier, Notify is never called.

Jump to

Keyboard shortcuts

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