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> {
|
||||
if model_path.is_some() {
|
||||
let model_path = model_path.unwrap();
|
||||
return match WhisperContext::new(&model_path.clone()) {
|
||||
Ok(ctx) => Ok(Engine{ctx: ctx, threads: threads}),
|
||||
Err(msg) => Err(format!("failed to load {}: {}", model_path, msg)),
|
||||
};
|
||||
let whisper_context_result = match model_path {
|
||||
Some(model_path) => WhisperContext::new(&model_path),
|
||||
None => WhisperContext::new_from_buffer(&model_buffer.unwrap()),
|
||||
};
|
||||
match whisper_context_result {
|
||||
Ok(ctx) => Ok(Engine{ctx: ctx, threads: threads}),
|
||||
Err(msg) => Err(format!("failed to load model: {}", msg)),
|
||||
}
|
||||
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}),
|
||||
Err(msg) => Err(format!("failed to load buffer: {}", msg)),
|
||||
};
|
||||
}
|
||||
Err("neither model path nor buffer provided".to_string())
|
||||
}
|
||||
|
||||
impl Engine {
|
||||
|
|
|
|||
Loading…
Reference in New Issue