pub struct NoiseReductionConfig {
pub sample_rate_hz: u32,
pub window_ms: f32,
pub hop_ms: f32,
pub oversubtraction_factor: f32,
pub spectral_floor: f32,
pub noise_smoothing: f32,
pub enable: bool,
}Expand description
Configuration for noise reduction via spectral subtraction.
§Examples
use speech_prep::preprocessing::NoiseReductionConfig;
// Default: 25ms window, 10ms hop, α=2.0, β=0.02
let config = NoiseReductionConfig::default();
// Aggressive noise removal for noisy environment
let config = NoiseReductionConfig {
oversubtraction_factor: 2.5,
spectral_floor: 0.01,
..Default::default()
};Fields§
§sample_rate_hz: u32Sample rate in Hz.
Default: 16000 Range: 8000-48000
window_ms: f32STFT window duration in milliseconds.
Default: 25.0 Range: 10.0-50.0
Effect: Longer windows improve frequency resolution but reduce time resolution. 25ms captures 1-3 pitch periods for typical speech.
hop_ms: f32STFT hop duration in milliseconds.
Default: 10.0 Range: 5.0-25.0
Effect: Smaller hops increase overlap (smoother reconstruction) but require more computation. 10ms hop = 60% overlap with 25ms window.
oversubtraction_factor: f32Oversubtraction factor (α).
Default: 2.0 Range: 1.0-3.0
Effect: Multiplier for noise estimate in spectral subtraction.
- Higher: More aggressive noise removal, more artifacts
- Lower: Conservative removal, less SNR gain
spectral_floor: f32Spectral floor (β) as fraction of noise estimate.
Default: 0.02 (2% of noise estimate) Range: 0.001-0.1
Effect: Minimum magnitude after subtraction to prevent musical noise. Acts as a noise gate.
noise_smoothing: f32Noise profile smoothing factor (α_noise).
Default: 0.98 Range: 0.9-0.999
Effect: Exponential moving average smoothing for noise profile. Higher values = slower adaptation, more stable estimate.
enable: boolEnable noise reduction.
Default: true
Effect: When false, audio passes through unmodified (bypass mode).
Implementations§
Source§impl NoiseReductionConfig
impl NoiseReductionConfig
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate configuration parameters.
§Errors
Returns Error::Configuration if:
sample_rate_hznot in 8000-48000 Hzwindow_msnot in 10.0-50.0 mshop_ms>=window_ms(overlap required)oversubtraction_factornot in 1.0-3.0spectral_floornot in 0.001-0.1noise_smoothingnot in 0.9-0.999
Sourcepub fn frame_length(&self) -> usize
pub fn frame_length(&self) -> usize
Calculate frame length in samples.
Sourcepub fn hop_length(&self) -> usize
pub fn hop_length(&self) -> usize
Calculate hop length in samples.
Trait Implementations§
Source§impl Clone for NoiseReductionConfig
impl Clone for NoiseReductionConfig
Source§fn clone(&self) -> NoiseReductionConfig
fn clone(&self) -> NoiseReductionConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more