Documentation
¶
Overview ¶
Package apm provides a Go wrapper for WebRTC's AudioProcessing module.
This package enables high-quality audio processing including echo cancellation, noise suppression, automatic gain control, and voice activity detection.
Example usage:
processor, err := apm.New(apm.Config{
SampleRateHz: 48000,
NumChannels: 1,
EchoCancellation: &apm.EchoCancellationConfig{
Enabled: true,
SuppressionLevel: apm.SuppressionHigh,
},
NoiseSuppression: &apm.NoiseSuppressionConfig{
Enabled: true,
Level: apm.NoiseSuppressionHigh,
},
})
if err != nil {
log.Fatal(err)
}
defer processor.Close()
// Process audio frames...
cleanSamples, hasVoice, err := processor.ProcessCapture(micSamples)
Package cgo provides low-level CGO bindings to the WebRTC AudioProcessing module.
Index ¶
- Constants
- func GetNumSamplesPerFrame() int
- func GetSampleRateHz() int
- type AnalogMicGainEmulationConfig
- type CaptureLevelAdjustmentConfig
- type Config
- type EchoCancellationConfig
- type GainControlConfig
- type Handle
- func (h *Handle) ApplyConfig(config Config)
- func (h *Handle) Destroy()
- func (h *Handle) GetStats() Stats
- func (h *Handle) Initialize()
- func (h *Handle) ProcessCaptureFrame(samples []float32, numChannels int) error
- func (h *Handle) ProcessCaptureIntFrame(samples []int16, numChannels int) error
- func (h *Handle) ProcessRenderFrame(samples []float32, numChannels int) error
- func (h *Handle) ProcessRenderIntFrame(samples []int16, numChannels int) error
- func (h *Handle) RecommendedStreamAnalogLevel() int
- func (h *Handle) SetOutputWillBeMuted(muted bool)
- func (h *Handle) SetStreamAnalogLevel(level int)
- func (h *Handle) SetStreamDelayMs(delayMs int)
- func (h *Handle) SetStreamKeyPressed(pressed bool)
- func (h *Handle) StreamDelayMs() int
- type NoiseSuppressionConfig
- type NsLevel
- type Processor
- func (p *Processor) Close() error
- func (p *Processor) GetStats() Stats
- func (p *Processor) Initialize()
- func (p *Processor) ProcessCapture(samples []float32) error
- func (p *Processor) ProcessCaptureInt16(samples []int16) error
- func (p *Processor) ProcessRender(samples []float32) error
- func (p *Processor) ProcessRenderInt16(samples []int16) error
- func (p *Processor) RecommendedStreamAnalogLevel() int
- func (p *Processor) SetKeyPressed(pressed bool)
- func (p *Processor) SetOutputMuted(muted bool)
- func (p *Processor) SetStreamAnalogLevel(level int)
- func (p *Processor) SetStreamDelay(delayMs int)
- func (p *Processor) StreamDelay() int
- type Stats
Constants ¶
const ( SampleRateHz = C.APM_SAMPLE_RATE_HZ FrameMs = C.APM_FRAME_MS NumSamplesPerFrame = C.APM_NUM_SAMPLES_PER_FRAME )
Constants exported from the C library
Variables ¶
This section is empty.
Functions ¶
func GetNumSamplesPerFrame ¶
func GetNumSamplesPerFrame() int
GetNumSamplesPerFrame returns the number of samples per frame
Types ¶
type AnalogMicGainEmulationConfig ¶ added in v0.1.1
type CaptureLevelAdjustmentConfig ¶ added in v0.1.1
type CaptureLevelAdjustmentConfig struct {
Enabled bool
PreGainFactor float32
PostGainFactor float32
AnalogMicGainEmulation AnalogMicGainEmulationConfig
}
type Config ¶
type Config struct {
CaptureLevelAdjustment CaptureLevelAdjustmentConfig
EchoCancellation EchoCancellationConfig
GainControl GainControlConfig
NoiseSuppression NoiseSuppressionConfig
HighPassFilterEnabled bool
CaptureChannels int
RenderChannels int
}
Config holds all runtime configuration options
type EchoCancellationConfig ¶
type EchoCancellationConfig struct {
Enabled bool
MobileMode bool
StreamDelayMs int // nil means use delay-agnostic mode
}
EchoCancellationConfig holds echo cancellation settings
type GainControlConfig ¶
type GainControlConfig struct {
Enabled bool
InputVolumeControllerEnabled bool
HeadroomDB float32
MaxGainDB float32
GainDB float32
}
GainControlConfig holds automatic gain control settings
type Handle ¶
type Handle struct {
// contains filtered or unexported fields
}
Handle represents an opaque handle to the audio processor
func (*Handle) ApplyConfig ¶
ApplyConfig updates the runtime configuration
func (*Handle) Initialize ¶
func (h *Handle) Initialize()
func (*Handle) ProcessCaptureFrame ¶
ProcessCaptureFrame processes a capture (microphone) frame samples should be interleaved float32 samples with length = numChannels * NumSamplesPerFrame
func (*Handle) ProcessCaptureIntFrame ¶ added in v0.1.0
func (*Handle) ProcessRenderFrame ¶
ProcessRenderFrame processes a render (speaker) frame for echo cancellation samples should be interleaved float32 samples with length = numChannels * NumSamplesPerFrame
func (*Handle) ProcessRenderIntFrame ¶ added in v0.1.0
func (*Handle) RecommendedStreamAnalogLevel ¶ added in v0.1.1
func (*Handle) SetOutputWillBeMuted ¶
SetOutputWillBeMuted signals that output will be muted (hint for AEC/AGC)
func (*Handle) SetStreamAnalogLevel ¶ added in v0.1.1
func (*Handle) SetStreamDelayMs ¶
SetStreamDelayMs sets the delay between render and capture streams
func (*Handle) SetStreamKeyPressed ¶
SetStreamKeyPressed signals that a key is being pressed (hint for AEC)
func (*Handle) StreamDelayMs ¶
type NoiseSuppressionConfig ¶
NoiseSuppressionConfig holds noise suppression settings
type NsLevel ¶
type NsLevel int
NsLevel represents noise suppression levels
const ( NsLevelLow NsLevel = C.NS_LEVEL_LOW NsLevelModerate NsLevel = C.NS_LEVEL_MODERATE NsLevelHigh NsLevel = C.NS_LEVEL_HIGH NsLevelVeryHigh NsLevel = C.NS_LEVEL_VERY_HIGH )
type Processor ¶
type Processor struct {
// contains filtered or unexported fields
}
Processor is the main APM instance
func (*Processor) Initialize ¶ added in v0.0.2
func (p *Processor) Initialize()
func (*Processor) ProcessCapture ¶
ProcessCapture processes microphone input (near-end signal) Returns processed audio and voice activity detection result Input samples should be float32 in range [-1.0, 1.0]
func (*Processor) ProcessCaptureInt16 ¶
ProcessCaptureInt16 processes microphone input with int16 samples
func (*Processor) ProcessRender ¶
ProcessRender provides speaker output (far-end signal) for echo cancellation Must be called with speaker audio BEFORE ProcessCapture for the corresponding frame
func (*Processor) ProcessRenderInt16 ¶
ProcessRenderInt16 provides speaker output with int16 samples
func (*Processor) RecommendedStreamAnalogLevel ¶ added in v0.1.1
func (*Processor) SetKeyPressed ¶
SetKeyPressed signals that a key is being pressed (hint for AEC)
func (*Processor) SetOutputMuted ¶
SetOutputMuted signals that output will be muted (hint for AEC/AGC)
func (*Processor) SetStreamAnalogLevel ¶ added in v0.1.1
func (*Processor) SetStreamDelay ¶
SetStreamDelay updates the estimated delay between render and capture
func (*Processor) StreamDelay ¶ added in v0.0.2
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
echo_cancellation
command
Example: Echo cancellation
|
Example: Echo cancellation |
|
full_pipeline
command
Example: Full audio processing pipeline
|
Example: Full audio processing pipeline |
|
noise_suppression
command
Example: Noise suppression
|
Example: Noise suppression |
|
google.com
|
|