no panic on unusable mic

master
bel 2024-01-03 17:09:27 -07:00
parent 9780c6f2ef
commit 53e675b9a0
2 changed files with 12 additions and 3 deletions

View File

@ -25,7 +25,11 @@ pub fn devices() -> Vec<String> {
fn _devices() -> Result<Vec<cpal::Device>, 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)),
}

View File

@ -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();
});