From 54964ec59b4a966a82f5ca16630138681f0e0e29 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Tue, 28 Nov 2023 21:03:00 -0700 Subject: [PATCH] grrrrr output --- rust-whisper.d/src/main.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/rust-whisper.d/src/main.rs b/rust-whisper.d/src/main.rs index eb3b7aa..72d5dd2 100644 --- a/rust-whisper.d/src/main.rs +++ b/rust-whisper.d/src/main.rs @@ -25,6 +25,7 @@ fn main() { Err(_) => { let host = cpal::default_host(); let device = host.default_input_device().unwrap(); + let output_device = host.default_output_device().unwrap(); let cfg = device.supported_input_configs() .unwrap() @@ -32,17 +33,39 @@ fn main() { .nth(0) .unwrap() .with_max_sample_rate(); - let channels = cfg.channels().into(); + let channels = cfg.channels(); + + let output_cfg = output_device.supported_output_configs() + .unwrap() + .filter(|x| x.sample_format() == cpal::SampleFormat::F32) + .filter(|x| x.channels() == 2) + .nth(0) + .unwrap() + .with_max_sample_rate(); + eprintln!("trying output with {} / {:?}", output_device.name().unwrap(), output_cfg); let mut buffer = vec![]; let mut last = Instant::now(); let five_seconds = Duration::new(15, 0); + device.build_output_stream( + &output_cfg.into(), + move |data: &mut [f32], _: &cpal::OutputCallbackInfo| { + for i in data.iter_mut() { + *i = cpal::Sample::EQUILIBRIUM; + } + // TODO + }, + move |err| { + eprintln!("output error: {}", err) + }, + None, + ).unwrap().play().unwrap(); let stream = device.build_input_stream( &cfg.into(), move |data: &[f32], _: &cpal::InputCallbackInfo| { data.iter() .map(|x| *x) - .step_by(channels) + .step_by(channels.into()) .for_each(|x| buffer.push(x)); if Instant::now() - last > five_seconds { let result = w.transcribe(&buffer).unwrap(); @@ -69,6 +92,7 @@ fn main() { println!("sig {}", sig); break; } + stream.pause().unwrap(); }, }; }