use std::sync::Arc;
use burn::tensor::Device;
use crate::{
data::pretrained::{
Construct,
LoadedResources,
PretrainedRef,
ResourceMap,
},
errors::BunsenResult,
kits::speech::silero_vad::{
SileroVadCollection,
pretrained::{
BURNPACK,
SILERO_KIT,
},
},
};
#[derive(Clone, Debug, Default)]
pub struct SileroConstruct;
impl SileroConstruct {
pub fn new() -> Self {
Self
}
}
impl Construct for SileroConstruct {
type Built = SileroVadCollection;
const KIT: &'static str = SILERO_KIT;
fn for_map(_map: &ResourceMap) -> BunsenResult<Self> {
Ok(Self)
}
fn construct(
&self,
_model: &PretrainedRef,
loaded: &LoadedResources,
device: &Device,
) -> BunsenResult<Arc<SileroVadCollection>> {
Ok(Arc::new(SileroVadCollection::load_from_burnpack_file(
loaded.expect(BURNPACK)?,
device,
)?))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_the_hook_names_its_kit() {
assert_eq!(<SileroConstruct as Construct>::KIT, "silero_vad");
assert!(format!("{:?}", SileroConstruct::new()).contains("SileroConstruct"));
}
}