Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 2.77 KB

File metadata and controls

56 lines (40 loc) · 2.77 KB

API 参考

只列出公开接口。所有函数都可从顶层 denoiselab 直接导入。

顶层门面

denoise(signal, sample_rate, method="logmmse", **kwargs) -> np.ndarray

按名字调用降噪方法。method 取自 available_methods()**kwargs 透传给具体方法。

evaluate(reference, estimate, sample_rate) -> dict[str, float]

一次算出全部指标,返回 {"snr", "segmental_snr", "si_sdr", "lsd", "stoi_proxy", "pesq_proxy"}

available_methods() -> list[str]

返回所有可用降噪方法名(已排序)。

降噪方法(denoiselab.methods

函数 主要参数
spectral_subtraction(signal, sr, n_noise_frames=6, over_subtraction=1.5, spectral_floor=0.02, power=2.0) 过减因子、谱下限、幅度/功率域
wiener_filter(signal, sr, n_noise_frames=6, alpha=0.98, xi_min_db=-25.0) 判决引导平滑、先验 SNR 下限
logmmse(signal, sr, n_noise_frames=6, alpha=0.98, noise_update=0.98, vad_threshold=0.15) 自适应噪声更新、似然比 VAD
spectral_gate(signal, sr, n_noise_frames=6, n_std_thresh=1.5, prop_decrease=1.0, smooth_freq=3, smooth_time=3) 阈值倍数、衰减比例、掩码平滑

NMF(监督式)

  • train_bases(signal, n_components=16, n_iter=100) -> np.ndarray:学出 (n_freq, k) 的非负基。
  • nmf_denoise(signal, sr, w_speech, w_noise, n_iter=50) -> np.ndarray:用语音/噪声基做软掩码降噪。

指标(denoiselab.metrics

函数 返回 说明
snr(reference, estimate) dB 全局信噪比
segmental_snr(reference, estimate, frame_length=256, hop_length=128) dB 分段信噪比(裁剪到 [-10, 35] dB)
si_sdr(reference, estimate) dB 尺度不变 SDR
log_spectral_distance(reference, estimate) dB 对数谱距离,越小越好
stoi_proxy(reference, estimate, sample_rate) 0~1 可懂度近似
pesq_proxy(reference, estimate, sample_rate) 1.0~4.5 PESQ 风格综合分

STFT(denoiselab.stft

  • stft(x, n_fft=512, hop_length=128, win_length=512) -> np.ndarray(n_freq, n_frames) 复数谱。
  • istft(spectrum, hop_length=128, win_length=512, length=None) -> np.ndarray:WOLA 逆变换。
  • magphase(spectrum) -> (magnitude, phase):拆分幅度与单位相位。
  • StftConfig(n_fft, hop_length, win_length):打包一套参数,带 .stft() / .istft() 方法。

合成数据(denoiselab.mixing

  • synth_vowel(duration=1.0, sample_rate=16000, f0=120.0, n_harmonics=6, seed=0)
  • white_noise(n_samples, seed=1)
  • add_noise(clean, noise, snr_db)

I/O(denoiselab.io

  • read_wav(path) -> (signal, sample_rate):读成 [-1,1] 的单声道 float64。
  • write_wav(path, signal, sample_rate):写成 16-bit PCM。