+ let samples =
+ m17codec2::decode_codec2(&codec2_data, "../../Data/speech_out.raw");
+ let host = cpal::default_host();
+ let def = host.default_output_device().unwrap();
+ let mut configs = def.supported_output_configs().unwrap();
+ let config = configs
+ .find(|c| c.channels() == 1 && c.sample_format() == SampleFormat::I16)
+ .unwrap()
+ .with_sample_rate(SampleRate(8000));
+ let mut counter = 0;
+ let mut index = 0;
+ let stream = def
+ .build_output_stream(
+ &config.into(),
+ move |data: &mut [i16], _: &cpal::OutputCallbackInfo| {
+ println!(
+ "iteration {counter} asked for {} samples at time {}",
+ data.len(),
+ std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap()
+ .as_millis()
+ );
+ counter += 1;
+ let qty = data.len().min(samples.len() - index);
+ println!("providing {qty} samples");
+ data[0..qty].copy_from_slice(&samples[index..(index + qty)]);
+ index += qty;
+ },
+ move |e| {
+ println!("error occurred");
+ },
+ None,
+ )
+ .unwrap();
+ stream.play().unwrap();
+
+ std::thread::sleep(std::time::Duration::from_secs(10));