purge non callback handling
parent
1b96b132e1
commit
ec6a71d38c
33
src/main.rs
33
src/main.rs
|
|
@ -39,10 +39,12 @@ fn main() {
|
||||||
flags.threads,
|
flags.threads,
|
||||||
flags.stream_head,
|
flags.stream_head,
|
||||||
flags.stream_tail,
|
flags.stream_tail,
|
||||||
new_handler(),
|
|
||||||
|result| {
|
|result| {
|
||||||
match result {
|
match result {
|
||||||
Ok(whispered) => { println!("{}", whispered.to_string()); },
|
Ok(whispered) => {
|
||||||
|
eprintln!("{}: {:?}", chrono::Local::now(), whispered);
|
||||||
|
println!("{}", whispered.to_string());
|
||||||
|
},
|
||||||
Err(msg) => { eprintln!("Error whispering: {}", msg); },
|
Err(msg) => { eprintln!("Error whispering: {}", msg); },
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
@ -102,10 +104,10 @@ struct WhisperService {
|
||||||
jobs: std::sync::mpsc::SyncSender<AWhisper>,
|
jobs: std::sync::mpsc::SyncSender<AWhisper>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_whisper_service(model_path: String, threads: i32, stream_head: f32, stream_tail: f32, handler: Handler, handler_fn: fn(Result<&Whispered, String>)) -> Result<WhisperService, String> {
|
fn new_whisper_service(model_path: String, threads: i32, stream_head: f32, stream_tail: f32, handler_fn: fn(Result<&Whispered, String>)) -> Result<WhisperService, String> {
|
||||||
match new_whisper_engine(model_path, threads) {
|
match new_whisper_engine(model_path, threads) {
|
||||||
Ok(engine) => {
|
Ok(engine) => {
|
||||||
let whisper = new_whisper_impl(engine, stream_head, stream_tail, handler, handler_fn);
|
let whisper = new_whisper_impl(engine, stream_head, stream_tail, handler_fn);
|
||||||
let (send, recv) = std::sync::mpsc::sync_channel(100);
|
let (send, recv) = std::sync::mpsc::sync_channel(100);
|
||||||
thread::spawn(move || { whisper.transcribe_asyncs(recv); });
|
thread::spawn(move || { whisper.transcribe_asyncs(recv); });
|
||||||
Ok(WhisperService{jobs: send})
|
Ok(WhisperService{jobs: send})
|
||||||
|
|
@ -140,16 +142,14 @@ struct WhisperImpl {
|
||||||
engine: WhisperEngine,
|
engine: WhisperEngine,
|
||||||
stream_head: f32,
|
stream_head: f32,
|
||||||
stream_tail: f32,
|
stream_tail: f32,
|
||||||
handler: Handler,
|
|
||||||
handler_fn: fn(Result<&Whispered, String>),
|
handler_fn: fn(Result<&Whispered, String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_whisper_impl(engine: WhisperEngine, stream_head: f32, stream_tail: f32, handler: Handler, handler_fn: fn(Result<&Whispered, String>)) -> WhisperImpl {
|
fn new_whisper_impl(engine: WhisperEngine, stream_head: f32, stream_tail: f32, handler_fn: fn(Result<&Whispered, String>)) -> WhisperImpl {
|
||||||
WhisperImpl {
|
WhisperImpl {
|
||||||
engine: engine,
|
engine: engine,
|
||||||
stream_head: stream_head,
|
stream_head: stream_head,
|
||||||
stream_tail: stream_tail,
|
stream_tail: stream_tail,
|
||||||
handler: handler,
|
|
||||||
handler_fn: handler_fn,
|
handler_fn: handler_fn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -190,11 +190,9 @@ impl WhisperImpl {
|
||||||
.after(&(self.stream_head * 100.0))
|
.after(&(self.stream_head * 100.0))
|
||||||
.before(&(self.stream_tail * 100.0));
|
.before(&(self.stream_tail * 100.0));
|
||||||
(self.handler_fn)(Ok(&result));
|
(self.handler_fn)(Ok(&result));
|
||||||
self.handler.on_success(&result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_error(&self, msg: String) {
|
fn on_error(&self, msg: String) {
|
||||||
self.handler.on_error(format!("failed to transcribe: {}", &msg));
|
|
||||||
(self.handler_fn)(Err(format!("failed to transcribe: {}", &msg)));
|
(self.handler_fn)(Err(format!("failed to transcribe: {}", &msg)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -312,23 +310,6 @@ impl Whispered {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
struct Handler {}
|
|
||||||
|
|
||||||
const fn new_handler() -> Handler {
|
|
||||||
Handler{}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Handler {
|
|
||||||
fn on_success(&self, result: &Whispered) {
|
|
||||||
eprintln!("{}: {:?}", chrono::Local::now(), result);
|
|
||||||
println!("{}", result.to_string());
|
|
||||||
}
|
|
||||||
fn on_error(&self, msg: String) {
|
|
||||||
eprintln!("error: {}", msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Listener {
|
struct Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue