use nihility_listener::input::{AudioInput, AudioInputConfig};
use tracing::info;

#[tokio::test]
async fn test_audio_input() {
    nihility_log::init().expect("Failed to initialize logger");
    let config = nihility_config::get_config::<AudioInputConfig>("nihility-audio-input")
        .expect("failed to get audio input config");
    let audio_input = AudioInput::init(config).expect("Initialization failed");
    let mut receiver = audio_input.get_sample_receiver();
    audio_input.run().await.expect("play failed");
    tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
    drop(audio_input);
    let mut buffer = Vec::with_capacity(16000);
    while let Ok(sample) = receiver.try_recv() {
        buffer.push(sample);
    }
    info!("record audio data len: {:?}", buffer.len());
}
