diff --git a/src/main.rs b/src/main.rs index fdfa757..f240653 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use audiopus::{Application, Channels, SampleRate}; use clap::Parser; use cpal::traits::{DeviceTrait, HostTrait, StreamTrait}; use cpal::{FromSample, Sample, StreamConfig}; -use log::{LevelFilter, info}; +use log::{LevelFilter, info, error}; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; @@ -68,11 +68,8 @@ fn main() -> Result<(), anyhow::Error> { udp_connection, ))); - // A flag to indicate that recording is in progress. - println!("Begin recording..."); - let err_fn = move |err| { - eprintln!("an error occurred on stream: {err}"); + error!("an error occurred on stream: {err}"); }; let sound_buffer2 = sound_buffer.clone(); @@ -108,13 +105,12 @@ fn main() -> Result<(), anyhow::Error> { } }; + info!("Running tap..."); stream.play()?; - // Let recording go for roughly three seconds. - std::thread::sleep(std::time::Duration::from_secs(3)); - drop(stream); - drop(sound_buffer); + std::thread::park(); + info!("Exiting..."); Ok(()) } @@ -128,6 +124,8 @@ fn write_input_data( if let Ok(mut ctx) = ctx.try_lock() { let sample: Vec = input.iter().map(|s| f32::from_sample(*s)).collect(); - ctx.write_data(&sample).unwrap(); + if let Err(err) = ctx.write_data(&sample) { + error!("Got error when writing data to sound buffer: {err}") + } } }