baked streams even wav files

This commit is contained in:
bel
2024-01-01 20:56:53 -07:00
parent 97c025f04d
commit 393100973c
4 changed files with 47 additions and 303 deletions

View File

@@ -7,11 +7,45 @@ use std::thread;
fn main() {
let flags = rust_whisper_lib::Flags::parse();
match flags.wav.clone() {
Some(path) => wav(flags, path),
Some(path) => wav_ch(flags, path),
None => channel(flags),
};
}
fn wav_ch(flags: rust_whisper_lib::Flags, path: String) {
let mut audio = rust_whisper_baked_lib::f32_from_wav_file(&path).unwrap();
let (send, recv) = std::sync::mpsc::sync_channel(100);
let n = audio.len() / match audio.len() % 100 {
0 => 100,
_ => 99,
};
for _ in 0..100 {
send.send(audio.drain(0..n).collect()).unwrap();
}
let (fin_send, fin_recv) = std::sync::mpsc::sync_channel::<Option<i32>>(1);
thread::spawn(move || {
let mut i = 0;
rust_whisper_baked_lib::channel(
flags.clone(),
move |result: Result<rust_whisper_lib::Transcribed, String>| {
match result {
Ok(transcribed) => { println!("{}", transcribed.to_string()); },
Err(msg) => { eprintln!("error: {}", msg); },
};
i += 1;
if i == 100 {
fin_send.send(None).unwrap();
}
},
recv,
);
});
let _ = fin_recv.recv();
}
fn wav(flags: rust_whisper_lib::Flags, _path: String) {
rust_whisper_baked_lib::wav(flags,
|result: Result<rust_whisper_lib::Transcribed, String>| {