Documentation
¶
Overview ¶
Package noisereduce performs spectral-gating noise reduction on audio-rate signals. It is a pure-Go implementation with two algorithms:
- Stationary spectral gating (NStdThreshStationary, optional noise clip). Statistics are computed once over a noise sample (or the signal itself) and a fixed threshold is applied to the entire input.
- Non-stationary spectral gating, where the noise floor is estimated continuously from a time-smoothed magnitude spectrogram.
Index ¶
- func BandLimitedNoise(minFreq, maxFreq float64, samples, sampleRate int, r *rand.Rand) []float64
- func FFTNoise(f []float64, r *rand.Rand) []float64
- func ReadWAV(path string) (samples [][]float64, sampleRate int, err error)
- func ReadWAVBytes(data []byte) (samples [][]float64, sampleRate int, err error)
- func ReduceNoise(y [][]float64, sr int, opt Options) ([][]float64, error)
- func ReduceNoiseMono(y []float64, sr int, opt Options) ([]float64, error)
- func ReduceNoiseWAVBytes(data []byte, opt Options) ([]byte, error)
- func WriteWAVPCM16(path string, samples [][]float64, sampleRate int) error
- func WriteWAVPCM16Bytes(samples [][]float64, sampleRate int) ([]byte, error)
- type Algorithm
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BandLimitedNoise ¶
BandLimitedNoise generates a band-limited noise signal of the given length and sample rate.
minFreq and maxFreq are inclusive Hz bounds.
func FFTNoise ¶
FFTNoise randomises phases in a real-valued half-symmetric spectrum f and returns the inverse FFT real part.
f is a length-N real spectrum (typically a band-pass mask). The output is a length-N real time-domain signal.
func ReadWAV ¶
ReadWAV reads a WAVE file and returns samples shaped [channels][frames] as float64 in [-1, 1] (PCM normalised by 32768).
func ReadWAVBytes ¶
ReadWAVBytes reads WAVE data from memory and returns samples shaped [channels][frames] as float64 in [-1, 1] (PCM normalised by 32768).
func ReduceNoise ¶
ReduceNoise applies spectral-gating noise reduction to a multichannel signal shaped [channels][frames]. The output has the same shape.
func ReduceNoiseMono ¶
ReduceNoiseMono is a convenience wrapper for single-channel input.
func ReduceNoiseWAVBytes ¶
ReduceNoiseWAVBytes reads WAV data from memory, applies ReduceNoise, and returns a 16-bit PCM WAV byte slice.
func WriteWAVPCM16 ¶
WriteWAVPCM16 writes [channels][frames] float64 samples as 16-bit PCM. Samples are clamped to [-1, 1] and scaled by 32767.
Types ¶
type Algorithm ¶
type Algorithm int
Algorithm selects between stationary and non-stationary spectral gating.
type Options ¶
type Options struct {
Algorithm Algorithm
// YNoise is an optional noise reference for the stationary gate.
// Shape [channels][frames]. Channels are averaged before STFT.
// If nil, Y itself is used as the noise reference.
YNoise [][]float64
PropDecrease float64 // proportion to suppress (0..1); default 1.0
TimeConstantS float64 // IIR time constant in seconds; default 2.0
FreqMaskSmoothHz float64 // freq smoothing width (Hz); 0 disables; default 500
TimeMaskSmoothMs float64 // time smoothing width (ms); 0 disables; default 50
ThreshNMultNonstationary float64 // sigmoid shift; default 2
SigmoidSlopeNonstationary float64 // sigmoid slope; default 10
NStdThreshStationary float64 // stddev multiplier; default 1.5
ChunkSize int // frames per chunk; 0 disables chunking; default 600000
Padding int // pad applied around each chunk; default 30000
NFFT int // FFT length; default 1024
WinLength int // window length; 0 => NFFT
HopLength int // hop between frames; 0 => WinLength/4
ClipNoiseStationary bool // stationary: clip noise to ChunkSize. Default true.
NJobs int // parallel chunk workers; 0 => runtime.GOMAXPROCS(0)
}
Options controls ReduceNoise.
Start from DefaultOptions() to get the standard spectral-gating settings, then override the knobs you care about. A zero-valued Options{} is also valid: every field's zero value has a well-defined meaning (e.g. PropDecrease=0 disables suppression, ChunkSize=0 disables chunking, FreqMaskSmoothHz=0 disables freq smoothing). Only NFFT is auto-defaulted, since 0 makes the STFT undefined; pass DefaultOptions().NFFT (1024) explicitly if you prefer.
Field names use Go exported identifiers for the algorithm parameters.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the recommended option set for spectral gating.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
noisereduce
command
Command noisereduce applies spectral-gating noise reduction to a WAV file.
|
Command noisereduce applies spectral-gating noise reduction to a WAV file. |