grrrrr output

master
Bel LaPointe 2023-11-28 21:03:00 -07:00
parent 62e764436a
commit 54964ec59b
1 changed files with 26 additions and 2 deletions

View File

@ -25,6 +25,7 @@ fn main() {
Err(_) => { Err(_) => {
let host = cpal::default_host(); let host = cpal::default_host();
let device = host.default_input_device().unwrap(); let device = host.default_input_device().unwrap();
let output_device = host.default_output_device().unwrap();
let cfg = device.supported_input_configs() let cfg = device.supported_input_configs()
.unwrap() .unwrap()
@ -32,17 +33,39 @@ fn main() {
.nth(0) .nth(0)
.unwrap() .unwrap()
.with_max_sample_rate(); .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 buffer = vec![];
let mut last = Instant::now(); let mut last = Instant::now();
let five_seconds = Duration::new(15, 0); 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( let stream = device.build_input_stream(
&cfg.into(), &cfg.into(),
move |data: &[f32], _: &cpal::InputCallbackInfo| { move |data: &[f32], _: &cpal::InputCallbackInfo| {
data.iter() data.iter()
.map(|x| *x) .map(|x| *x)
.step_by(channels) .step_by(channels.into())
.for_each(|x| buffer.push(x)); .for_each(|x| buffer.push(x));
if Instant::now() - last > five_seconds { if Instant::now() - last > five_seconds {
let result = w.transcribe(&buffer).unwrap(); let result = w.transcribe(&buffer).unwrap();
@ -69,6 +92,7 @@ fn main() {
println!("sig {}", sig); println!("sig {}", sig);
break; break;
} }
stream.pause().unwrap();
}, },
}; };
} }