grrrrr output
parent
62e764436a
commit
54964ec59b
|
|
@ -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();
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue