2026-01-04 09:00:51 +05:00
|
|
|
#[cfg(feature = "vosk")]
|
2023-06-11 19:17:50 +05:00
|
|
|
mod vosk;
|
|
|
|
|
|
|
|
|
|
use crate::config;
|
2025-12-11 23:43:50 +05:00
|
|
|
use once_cell::sync::OnceCell;
|
2023-06-11 19:17:50 +05:00
|
|
|
|
|
|
|
|
use crate::config::structs::SpeechToTextEngine;
|
|
|
|
|
|
2026-01-05 03:38:04 +05:00
|
|
|
use crate::vosk_models;
|
|
|
|
|
// use vosk_models::{scan_vosk_models, get_model_path, VoskModelInfo};
|
2026-01-05 04:20:43 +05:00
|
|
|
pub use self::vosk::init_vosk;
|
|
|
|
|
pub use self::vosk::recognize_wake_word;
|
|
|
|
|
pub use self::vosk::recognize_speech;
|
|
|
|
|
pub use self::vosk::reset_speech_recognizer;
|
|
|
|
|
pub use self::vosk::reset_wake_recognizer;
|
2026-01-05 03:38:04 +05:00
|
|
|
|
2023-06-11 19:17:50 +05:00
|
|
|
static STT_TYPE: OnceCell<SpeechToTextEngine> = OnceCell::new();
|
|
|
|
|
|
|
|
|
|
pub fn init() -> Result<(), ()> {
|
2026-01-04 06:14:05 +05:00
|
|
|
if STT_TYPE.get().is_some() {
|
2025-12-11 23:43:50 +05:00
|
|
|
return Ok(());
|
|
|
|
|
} // already initialized
|
2023-06-11 19:17:50 +05:00
|
|
|
|
|
|
|
|
// set default stt type
|
|
|
|
|
// @TODO. Make it configurable?
|
|
|
|
|
STT_TYPE.set(config::DEFAULT_SPEECH_TO_TEXT_ENGINE).unwrap();
|
|
|
|
|
|
|
|
|
|
// load given recorder
|
|
|
|
|
match STT_TYPE.get().unwrap() {
|
|
|
|
|
SpeechToTextEngine::Vosk => {
|
|
|
|
|
// Init Vosk
|
|
|
|
|
info!("Initializing Vosk STT backend.");
|
|
|
|
|
vosk::init_vosk();
|
|
|
|
|
info!("STT backend initialized.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-05 04:20:43 +05:00
|
|
|
pub fn recognize(data: &[i16], include_partial: bool) -> Option<String> {
|
|
|
|
|
if include_partial {
|
|
|
|
|
vosk::recognize_wake_word(data).map(|(text, _)| text)
|
|
|
|
|
} else {
|
|
|
|
|
vosk::recognize_speech(data)
|
2023-06-11 19:17:50 +05:00
|
|
|
}
|
2025-12-11 23:43:50 +05:00
|
|
|
}
|
2026-01-05 04:20:43 +05:00
|
|
|
|
|
|
|
|
// pub fn recognize(data: &[i16], partial: bool) -> Option<String> {
|
|
|
|
|
// match STT_TYPE.get().unwrap() {
|
|
|
|
|
// SpeechToTextEngine::Vosk => vosk::recognize(data, partial),
|
|
|
|
|
// }
|
|
|
|
|
// }
|