4 Commits

Author SHA1 Message Date
Bel LaPointe
f326f077ce no more rwhisper 2023-12-21 15:07:05 -05:00
Bel LaPointe
3b79024bdd confirmed rwhisper aint gonna cut it seemingly because candle doesnt cut it 2023-12-21 14:40:17 -05:00
Bel LaPointe
de099d9917 but it is soooo sloooow 2023-12-21 14:34:22 -05:00
Bel LaPointe
0d8315550a IT RUNS WITH RWHISPER WOO 2023-12-21 14:20:19 -05:00

View File

@@ -41,15 +41,29 @@ pub fn wav<F>(flags: Flags, handler_fn: F, wav_path: String) where F: FnMut(Resu
flags.stream_tail, flags.stream_tail,
handler_fn, handler_fn,
).unwrap(); ).unwrap();
let (header, data) = wav::read( w.transcribe(&f32_from_wav_file(&wav_path).unwrap())
&mut std::fs::File::open(wav_path).expect("failed to open $WAV"), }
).expect("failed to decode $WAV");
assert!(header.channel_count == 1);
assert!(header.sampling_rate == 16_000);
let data16 = data.as_sixteen().expect("wav is not 32bit floats");
let audio_data = &whisper_rs::convert_integer_to_float_audio(&data16);
w.transcribe(&audio_data); fn f32_from_wav_file(path: &String) -> Result<Vec<f32>, String> {
let f = std::fs::File::open(path);
if let Some(err) = f.as_ref().err() {
return Err(format!("failed to open wav file: {}", err));
}
let wav_read = wav::read(&mut f.unwrap());
if let Some(err) = wav_read.as_ref().err() {
return Err(format!("failed to parse wav file: {}", err));
}
let (header, data) = wav_read.unwrap();
if header.channel_count != 1 {
return Err("!= 1 channel".to_string());
}
if header.sampling_rate != 16_000 {
return Err("!= 16_000 hz".to_string());
}
match data.as_sixteen() {
Some(data16) => Ok(whisper_rs::convert_integer_to_float_audio(&data16)),
None => Err(format!("couldnt translate wav to 16s")),
}
} }
pub fn channel<F>(flags: Flags, handler_fn: F, stream: std::sync::mpsc::Receiver<Vec<f32>>) where F: FnMut(Result<Transcribed, String>) + Send + 'static { pub fn channel<F>(flags: Flags, handler_fn: F, stream: std::sync::mpsc::Receiver<Vec<f32>>) where F: FnMut(Result<Transcribed, String>) + Send + 'static {
@@ -320,7 +334,7 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_transcribe_tiny_jfk_wav() { fn test_transcribe_tiny_jfk_wav_whisper_rs() {
wav( wav(
Flags { Flags {
model_path: None, model_path: None,