audio

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package audio defines the interfaces for pluggable audio processing a transport applies to the media it sends and receives. A Filter transforms incoming audio — for example noise reduction — before it enters the pipeline; a Mixer blends auxiliary audio — for example background music — into the outgoing audio. Concrete implementations live in the audio subpackages (rnnoise, noise, mixer).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain applies several Filters in sequence, composing multiple input-audio stages — noise reduction, gating, conditioning — into one Filter that a transport can use through Params.AudioInFilter.

func NewChain

func NewChain(filters ...Filter) *Chain

NewChain builds a Chain that applies filters in the given order.

func (*Chain) Filter

func (c *Chain) Filter(ctx context.Context, pcm []byte) ([]byte, error)

Filter runs pcm through each filter in order.

func (*Chain) Start

func (c *Chain) Start(ctx context.Context, sampleRate int) error

Start starts every filter in order, stopping at the first error.

func (*Chain) Stop

func (c *Chain) Stop(ctx context.Context) error

Stop stops every filter, returning the last error if any.

type Filter

type Filter interface {
	Start(ctx context.Context, sampleRate int) error
	Stop(ctx context.Context) error
	Filter(ctx context.Context, pcm []byte) ([]byte, error)
}

Filter transforms input audio before it enters the pipeline. Start is called with the input sample rate when the transport starts, Filter is called for each received chunk of 16-bit mono PCM, and Stop is called when the transport stops. Filter may buffer internally and return fewer (or more) samples than it was given; it returns an empty slice when it has nothing to emit yet.

type Mixer

type Mixer interface {
	Start(ctx context.Context, sampleRate int) error
	Stop(ctx context.Context) error
	Mix(ctx context.Context, pcm []byte) ([]byte, error)
	Control(ctx context.Context, settings map[string]any) error
}

Mixer mixes auxiliary audio — for example background music or sound effects — into a transport's outgoing audio. Start is called with the output sample rate when the transport starts; Mix blends the mixer's current audio into an outgoing chunk of bot audio and returns the result; Control applies a runtime settings update from a MixerControlFrame; Stop is called when the transport stops.

Directories

Path Synopsis
Package g711 implements the ITU-T G.711 μ-law companding codec used by telephony media streams (Twilio, Telnyx, Plivo and the wider PSTN).
Package g711 implements the ITU-T G.711 μ-law companding codec used by telephony media streams (Twilio, Telnyx, Plivo and the wider PSTN).
Package mixer mixes background audio into a transport's outgoing audio.
Package mixer mixes background audio into a transport's outgoing audio.
noise
gate
Package gate provides a noise gate: an audio.Filter that silences a chunk of audio whose RMS energy falls below a threshold, suppressing low-level background hum and hiss between speech.
Package gate provides a noise gate: an audio.Filter that silences a chunk of audio whose RMS energy falls below a threshold, suppressing low-level background hum and hiss between speech.
rnnoise
Package rnnoise is an input audio filter that suppresses background noise with RNNoise, Xiph's recurrent-network denoiser.
Package rnnoise is an input audio filter that suppresses background noise with RNNoise, Xiph's recurrent-network denoiser.
Package onset detects the first audible sample in a stream of PCM audio.
Package onset detects the first audible sample in a stream of PCM audio.
Package opus wraps the Opus codec for jargo's audio path: it decodes Opus packets to PCM on the way in and encodes PCM to Opus packets on the way out.
Package opus wraps the Opus codec for jargo's audio path: it decodes Opus packets to PCM on the way in and encodes PCM to Opus packets on the way out.
Package resample converts interleaved S16LE PCM audio between sample rates, preserving the channel count.
Package resample converts interleaved S16LE PCM audio between sample rates, preserving the channel count.
Package turn provides end-of-turn detection: it decides when a user has actually finished speaking, as opposed to merely pausing.
Package turn provides end-of-turn detection: it decides when a user has actually finished speaking, as opposed to merely pausing.
Package vad provides voice activity detection: it tells the pipeline when a user is speaking.
Package vad provides voice activity detection: it tells the pipeline when a user is speaking.

Jump to

Keyboard shortcuts

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