use std::path::{Path, PathBuf};
#[cfg(test)]
mod tests;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, derive_more::Display, derive_more::IsVariant)]
#[display("{}", self.as_str())]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
pub enum CedModel {
Tiny,
Mini,
Small,
Base,
}
impl CedModel {
pub const ALL: [CedModel; 4] = [Self::Tiny, Self::Mini, Self::Small, Self::Base];
#[inline(always)]
pub const fn as_str(&self) -> &'static str {
match self {
Self::Tiny => "tiny",
Self::Mini => "mini",
Self::Small => "small",
Self::Base => "base",
}
}
#[inline(always)]
pub const fn hf_repo(&self) -> &'static str {
match self {
Self::Tiny => "mispeech/ced-tiny",
Self::Mini => "mispeech/ced-mini",
Self::Small => "mispeech/ced-small",
Self::Base => "mispeech/ced-base",
}
}
#[inline(always)]
pub const fn dir_name(&self) -> &'static str {
match self {
Self::Tiny => "ced-tiny",
Self::Mini => "ced-mini",
Self::Small => "ced-small",
Self::Base => "ced-base",
}
}
#[inline(always)]
pub const fn mlmodelc_name(&self) -> &'static str {
match self {
Self::Tiny => "ced_tiny.mlmodelc",
Self::Mini => "ced_mini.mlmodelc",
Self::Small => "ced_small.mlmodelc",
Self::Base => "ced_base.mlmodelc",
}
}
pub fn mlmodelc_path(&self, models_root: impl AsRef<Path>) -> PathBuf {
models_root
.as_ref()
.join(self.dir_name())
.join(self.mlmodelc_name())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[error("unknown CED model name")]
pub struct ParseCedModelError(());
impl core::str::FromStr for CedModel {
type Err = ParseCedModelError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"tiny" => Self::Tiny,
"mini" => Self::Mini,
"small" => Self::Small,
"base" => Self::Base,
_ => return Err(ParseCedModelError(())),
})
}
}