mod conformer;
mod cpu;
mod error;
mod fft;
mod gguf;
mod gigaam;
mod gpu;
mod parakeet;
mod whisper;
use std::path::Path;
use error::bail;
pub use error::{Error, Result};
pub struct Model(Family);
enum Family {
Gigaam(Box<gigaam::Gigaam>),
Parakeet(Box<parakeet::Parakeet>),
Whisper(Box<whisper::Whisper>),
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct Transcript {
pub text: String,
pub tokens: Vec<Token>,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Token {
pub id: u32,
pub piece: String,
pub start_ms: u32,
}
impl Model {
pub fn load(path: impl AsRef<Path>) -> Result<Self> {
let g = gguf::Gguf::open(path.as_ref())?;
Ok(Self(match g.get::<&str>("general.architecture")? {
"gigaam" => Family::Gigaam(Box::new(gigaam::Gigaam::load(&g)?)),
"parakeet" => Family::Parakeet(Box::new(parakeet::Parakeet::load(&g)?)),
"whisper" => Family::Whisper(Box::new(whisper::Whisper::load(&g)?)),
arch => {
bail!("general.architecture is {arch:?}, only gigaam, parakeet and whisper are supported")
}
}))
}
pub fn transcribe(&self, pcm: &[f32]) -> Result<Transcript> {
match &self.0 {
Family::Gigaam(m) => m.transcribe(pcm),
Family::Parakeet(m) => m.transcribe(pcm),
Family::Whisper(m) => m.transcribe(pcm),
}
}
pub fn max_audio_ms(&self) -> Option<u32> {
match &self.0 {
Family::Gigaam(_) => Some(25_000),
Family::Whisper(_) => Some(30_000),
Family::Parakeet(_) => None,
}
}
}