rustpotter detections optimization + few code improvements

This commit is contained in:
Priler 2026-01-04 06:14:05 +05:00
parent 612ed2f1b0
commit a425d8f834
12 changed files with 64 additions and 58 deletions

View file

@ -9,7 +9,7 @@ static MODEL: OnceCell<Model> = OnceCell::new();
static RECOGNIZER: OnceCell<Mutex<Recognizer>> = OnceCell::new();
pub fn init_vosk() {
if !RECOGNIZER.get().is_none() {
if RECOGNIZER.get().is_some() {
return;
} // already initialized
@ -53,21 +53,14 @@ pub fn recognize(data: &[i16], include_partial: bool) -> Option<String> {
}
DecodingState::Finalized => {
// Result will always be multiple because we called set_max_alternatives
Some(
RECOGNIZER
.get()
.unwrap()
.lock()
.unwrap()
.result()
.multiple()
.unwrap()
.alternatives
.first()
.unwrap()
.text
.into(),
)
RECOGNIZER
.get()
.unwrap()
.lock()
.unwrap()
.result()
.multiple()
.and_then(|m| m.alternatives.first().map(|a| a.text.to_string()))
}
DecodingState::Failed => None,
}