rust-whisper-baked can list input devices
parent
e27a8f8f56
commit
5c34112c0c
|
|
@ -24,7 +24,9 @@ pub fn devices() -> Vec<String> {
|
||||||
|
|
||||||
fn _devices() -> Result<Vec<cpal::Device>, String> {
|
fn _devices() -> Result<Vec<cpal::Device>, String> {
|
||||||
match cpal::default_host().devices() {
|
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)),
|
Err(msg) => Err(format!("failed to get devices: {}", msg)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ fn main() {
|
||||||
eprintln!("rust whisper baked lib channel...");
|
eprintln!("rust whisper baked lib channel...");
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
rust_whisper_baked_lib::channel(
|
rust_whisper_baked_lib::channel(
|
||||||
flags,
|
flags.clone(),
|
||||||
|result: Result<rust_whisper_lib::Transcribed, String>| {
|
|result: Result<rust_whisper_lib::Transcribed, String>| {
|
||||||
match result {
|
match result {
|
||||||
Ok(transcribed) => { println!("{}", transcribed.to_string()); },
|
Ok(transcribed) => { println!("{}", transcribed.to_string()); },
|
||||||
|
|
@ -23,8 +23,24 @@ fn main() {
|
||||||
});
|
});
|
||||||
|
|
||||||
eprintln!("listen lib main...");
|
eprintln!("listen lib main...");
|
||||||
|
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| {
|
listen_lib::main(|data| {
|
||||||
send.send(data).unwrap();
|
send.send(data).unwrap();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
eprintln!("/listen lib main...");
|
eprintln!("/listen lib main...");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ pub struct Flags {
|
||||||
|
|
||||||
#[arg(long, default_value = None)]
|
#[arg(long, default_value = None)]
|
||||||
pub wav: Option<String>,
|
pub wav: Option<String>,
|
||||||
|
#[arg(long, default_value = None)]
|
||||||
|
pub stream_device: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wav<F>(flags: Flags, handler_fn: F, wav_path: String) where F: FnMut(Result<Transcribed, String>) + Send + 'static {
|
pub fn wav<F>(flags: Flags, handler_fn: F, wav_path: String) where F: FnMut(Result<Transcribed, String>) + Send + 'static {
|
||||||
|
|
@ -334,6 +336,7 @@ mod tests {
|
||||||
stream_tail: 0.0,
|
stream_tail: 0.0,
|
||||||
wav: Some("../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string()),
|
wav: Some("../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string()),
|
||||||
debug: false,
|
debug: false,
|
||||||
|
stream_device: None,
|
||||||
},
|
},
|
||||||
| result | {
|
| result | {
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue