diff --git a/listen-lib/src/lib.rs b/listen-lib/src/lib.rs index 562fce6..82ef807 100644 --- a/listen-lib/src/lib.rs +++ b/listen-lib/src/lib.rs @@ -24,7 +24,9 @@ pub fn devices() -> Vec { fn _devices() -> Result, String> { match cpal::default_host().devices() { - Ok(devices) => Ok(devices.collect()), + Ok(devices) => Ok(devices.filter(|device| { + device.supported_input_configs().unwrap().count() > 0 + }).collect()), Err(msg) => Err(format!("failed to get devices: {}", msg)), } } diff --git a/rust-whisper-baked/src/main.rs b/rust-whisper-baked/src/main.rs index 7306e9a..e5c7d2e 100644 --- a/rust-whisper-baked/src/main.rs +++ b/rust-whisper-baked/src/main.rs @@ -11,7 +11,7 @@ fn main() { eprintln!("rust whisper baked lib channel..."); thread::spawn(move || { rust_whisper_baked_lib::channel( - flags, + flags.clone(), |result: Result| { match result { Ok(transcribed) => { println!("{}", transcribed.to_string()); }, @@ -23,8 +23,24 @@ fn main() { }); eprintln!("listen lib main..."); - listen_lib::main(|data| { - send.send(data).unwrap(); - }); + let flags = rust_whisper_lib::Flags::parse(); + match flags.stream_device { + Some(device_name) => { + if device_name == "" { + for device in listen_lib::devices() { + eprintln!("{}", device); + } + } else { + listen_lib::main_with(|data| { + send.send(data).unwrap(); + }, device_name); + } + }, + None => { + listen_lib::main(|data| { + send.send(data).unwrap(); + }); + } + } eprintln!("/listen lib main..."); } diff --git a/rust-whisper-lib/src/lib.rs b/rust-whisper-lib/src/lib.rs index 5b4d99f..bc415f5 100644 --- a/rust-whisper-lib/src/lib.rs +++ b/rust-whisper-lib/src/lib.rs @@ -29,6 +29,8 @@ pub struct Flags { #[arg(long, default_value = None)] pub wav: Option, + #[arg(long, default_value = None)] + pub stream_device: Option, } pub fn wav(flags: Flags, handler_fn: F, wav_path: String) where F: FnMut(Result) + Send + 'static { @@ -334,6 +336,7 @@ mod tests { stream_tail: 0.0, wav: Some("../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string()), debug: false, + stream_device: None, }, | result | { assert!(result.is_ok());