parent
3b79024bdd
commit
f326f077ce
File diff suppressed because it is too large
Load Diff
|
|
@ -12,6 +12,3 @@ tokio = "1.27"
|
|||
byteorder = "1.5.0"
|
||||
chrono = "0.4.31"
|
||||
clap = { version = "4.4.10", features = ["derive"] }
|
||||
rwhisper = "0.1.2"
|
||||
rodio = "0.17.3"
|
||||
futures = "0.3.29"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ use clap::Parser;
|
|||
use std::thread;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use rwhisper;
|
||||
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
pub struct Flags {
|
||||
|
|
@ -258,54 +257,6 @@ impl Engine {
|
|||
}
|
||||
}
|
||||
|
||||
struct Engine2 {
|
||||
model: rwhisper::Whisper,
|
||||
}
|
||||
|
||||
fn new_engine2(model_path: Option<String>, model_buffer: Option<Vec<u8>>, threads: i32) -> Result<Engine2, String> {
|
||||
match rwhisper::WhisperBuilder::default()
|
||||
.with_cpu(true)
|
||||
.with_language(Some(rwhisper::WhisperLanguage::English))
|
||||
.with_source(rwhisper::WhisperSource::TinyEn)
|
||||
.build() {
|
||||
Ok(model) => Ok(Engine2{model: model}),
|
||||
Err(msg) => Err(format!("failed to create model: {}", msg)),
|
||||
}
|
||||
}
|
||||
|
||||
impl Engine2 {
|
||||
fn transcribe(&self, data: &Vec<f32>) -> Result<Transcribed, String> {
|
||||
self._transcribe(data)
|
||||
}
|
||||
|
||||
fn _transcribe(&self, data: &Vec<f32>) -> Result<Transcribed, String> {
|
||||
let buffer = rodio::buffer::SamplesBuffer::new(1, 16_000, data.clone());
|
||||
let stream = self.model.transcribe(buffer);
|
||||
if stream.as_ref().is_err() {
|
||||
return Err(format!("failed to start transcribing: {}", stream.err().unwrap()));
|
||||
}
|
||||
let stream = stream.unwrap();
|
||||
|
||||
let future = async {
|
||||
let mut w: Vec<u8> = vec![];
|
||||
stream.write_to(&mut w).await.unwrap();
|
||||
w
|
||||
};
|
||||
let w = futures::executor::block_on(future);
|
||||
let mut result = new_whispered();
|
||||
result.push(String::from_utf8(w).unwrap(), 0, (100 * data.len() / 16_000) as i64);
|
||||
Ok(result)
|
||||
|
||||
/*
|
||||
let mut w: Vec<u8> = vec![];
|
||||
stream.write_to(&mut w).await.unwrap();
|
||||
let mut result = new_whispered();
|
||||
result.push(String::from_utf8(w).unwrap(), 0, (100 * data.len() / 16_000) as i64);
|
||||
Ok(result)
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
struct ATranscribe {
|
||||
data: Vec<f32>,
|
||||
ack: Option<std::sync::mpsc::SyncSender<bool>>,
|
||||
|
|
@ -404,20 +355,4 @@ mod tests {
|
|||
"../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transcribe_tiny_jfk_wav_rwhisper() {
|
||||
let engine_2 = new_engine2(
|
||||
Some("../models/ggml-tiny.en.bin".to_string()),
|
||||
None,
|
||||
4,
|
||||
).expect("failed to make new engine2");
|
||||
let data = f32_from_wav_file(&"../gitea-whisper-rs/sys/whisper.cpp/bindings/go/samples/jfk.wav".to_string()).expect("failed to read jfk.wav");
|
||||
let start = std::time::Instant::now();
|
||||
for i in 0..2 {
|
||||
let result = engine_2.transcribe(&data).expect("failed to transcribe");
|
||||
println!("rwhisper = {}s", start.elapsed().as_secs_f32());
|
||||
assert_eq!(" And so my fellow American asked not what your country can do for you, ask what you can do for your country.".to_string(), result.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue