From 53e675b9a01d8519b749b4ee85c04744d1551496 Mon Sep 17 00:00:00 2001 From: bel Date: Wed, 3 Jan 2024 17:09:27 -0700 Subject: [PATCH] no panic on unusable mic --- listen-lib/src/lib.rs | 6 +++++- rust-whisper-baked/src/main.rs | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/listen-lib/src/lib.rs b/listen-lib/src/lib.rs index cea4f3b..05ac1e2 100644 --- a/listen-lib/src/lib.rs +++ b/listen-lib/src/lib.rs @@ -25,7 +25,11 @@ pub fn devices() -> Vec { fn _devices() -> Result, String> { match cpal::default_host().devices() { Ok(devices) => Ok(devices.filter(|device| { - device.supported_input_configs().unwrap().count() > 0 + let input_configs = device.supported_input_configs(); + if !input_configs.is_ok() { + return false; + } + 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 87399ca..6d3bacd 100644 --- a/rust-whisper-baked/src/main.rs +++ b/rust-whisper-baked/src/main.rs @@ -68,10 +68,14 @@ fn channel(flags: rust_whisper_lib::Flags) { let flags = rust_whisper_lib::Flags::parse(); match flags.stream_device { Some(device_name) => { - if device_name == "" { + eprintln!("with device ({}) '{}'", device_name.len(), &device_name); + if device_name.len() == 0 { + let mut i = 0; for device in listen_lib::devices() { - eprintln!("{}", device); + eprintln!("[{}] {}", i, device); + i += 1; } + eprintln!("found {} devices", i); } else { listen_lib::main_with(|data| { send.send(data).unwrap(); @@ -79,6 +83,7 @@ fn channel(flags: rust_whisper_lib::Flags) { } }, None => { + eprintln!("without any device"); listen_lib::main(|data| { send.send(data).unwrap(); });