Skip to main content

NoiseReductionConfig

Struct NoiseReductionConfig 

Source
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: u32

Sample rate in Hz.

Default: 16000 Range: 8000-48000

§window_ms: f32

STFT 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: f32

STFT 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: f32

Oversubtraction 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: f32

Spectral 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: f32

Noise 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: bool

Enable noise reduction.

Default: true

Effect: When false, audio passes through unmodified (bypass mode).

Implementations§

Source§

impl NoiseReductionConfig

Source

pub fn validate(&self) -> Result<()>

Validate configuration parameters.

§Errors

Returns Error::Configuration if:

  • sample_rate_hz not in 8000-48000 Hz
  • window_ms not in 10.0-50.0 ms
  • hop_ms >= window_ms (overlap required)
  • oversubtraction_factor not in 1.0-3.0
  • spectral_floor not in 0.001-0.1
  • noise_smoothing not in 0.9-0.999
Source

pub fn frame_length(&self) -> usize

Calculate frame length in samples.

Source

pub fn hop_length(&self) -> usize

Calculate hop length in samples.

Source

pub fn fft_size(&self) -> usize

Calculate FFT size (next power of 2 >= frame length).

Trait Implementations§

Source§

impl Clone for NoiseReductionConfig

Source§

fn clone(&self) -> NoiseReductionConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NoiseReductionConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NoiseReductionConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more