Add new crate denoise required by audio (#38217)

The audio crate will use the denoise crate to remove background noises
from microphone input.

We intent to contribute this to rodio. Before that can happen a PR needs
to land in candle. Until then this lives here.

Uses a candle fork which removes the dependency on `protoc` and has the PR's mentioned above already applied.

Release Notes:

- N/A

---------

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
David Kleingeld
2025-09-16 21:49:26 +00:00
committed by GitHub
co-authored by Mikayla
parent 26202e5af2
commit 0343b5ff06
12 changed files with 1156 additions and 38 deletions
+23
View File
@@ -0,0 +1,23 @@
use std::time::Duration;
use rodio::Source;
use rodio::wav_to_file;
use rodio::{nz, source::UniformSourceIterator};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = std::fs::File::open("clips_airconditioning.wav")?;
let decoder = rodio::Decoder::try_from(file)?;
let resampled = UniformSourceIterator::new(decoder, nz!(1), nz!(16_000));
let mut enabled = true;
let denoised = denoise::Denoiser::try_new(resampled)?.periodic_access(
Duration::from_secs(2),
|denoised| {
enabled = !enabled;
denoised.set_enabled(enabled);
},
);
wav_to_file(denoised, "processed.wav")?;
Ok(())
}