minor refactor
parent
589c6e65b8
commit
f97f746ab9
|
|
@ -199,21 +199,14 @@ struct Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_engine(model_path: Option<String>, model_buffer: Option<Vec<u8>>, threads: i32) -> Result<Engine, String> {
|
fn new_engine(model_path: Option<String>, model_buffer: Option<Vec<u8>>, threads: i32) -> Result<Engine, String> {
|
||||||
if model_path.is_some() {
|
let whisper_context_result = match model_path {
|
||||||
let model_path = model_path.unwrap();
|
Some(model_path) => WhisperContext::new(&model_path),
|
||||||
return match WhisperContext::new(&model_path.clone()) {
|
None => WhisperContext::new_from_buffer(&model_buffer.unwrap()),
|
||||||
Ok(ctx) => Ok(Engine{ctx: ctx, threads: threads}),
|
|
||||||
Err(msg) => Err(format!("failed to load {}: {}", model_path, msg)),
|
|
||||||
};
|
};
|
||||||
}
|
match whisper_context_result {
|
||||||
if model_buffer.is_some() {
|
|
||||||
let model_buffer = model_buffer.unwrap();
|
|
||||||
return match WhisperContext::new_from_buffer(&model_buffer) {
|
|
||||||
Ok(ctx) => Ok(Engine{ctx: ctx, threads: threads}),
|
Ok(ctx) => Ok(Engine{ctx: ctx, threads: threads}),
|
||||||
Err(msg) => Err(format!("failed to load buffer: {}", msg)),
|
Err(msg) => Err(format!("failed to load model: {}", msg)),
|
||||||
};
|
|
||||||
}
|
}
|
||||||
Err("neither model path nor buffer provided".to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Engine {
|
impl Engine {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue