use crate::download::{Download, get_cache_dir};
use std::{
ops::{Deref, DerefMut},
path::Path,
};
static CHECKPOINT_URL: &str =
"https://github.com/mzdk100/kokoro/releases/download/V1.1/kokoro-v1.1-zh.onnx";
static VOICES_URL: &str =
"https://github.com/mzdk100/kokoro/releases/download/V1.1/voices-v1.1-zh.bin";
#[derive(Debug, Clone)]
pub struct CheckpointModel(Download);
impl CheckpointModel {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self(Download::new(path, CHECKPOINT_URL))
}
}
impl Deref for CheckpointModel {
type Target = Download;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for CheckpointModel {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl Default for CheckpointModel {
fn default() -> Self {
let cache_dir = get_cache_dir().unwrap().join("kokoro");
let path = cache_dir.join("kokoro-v1.1-zh.onnx");
Self(Download::new(path, CHECKPOINT_URL))
}
}
#[derive(Debug, Clone)]
pub struct VoicesData(Download);
impl VoicesData {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self(Download::new(path, VOICES_URL))
}
}
impl Default for VoicesData {
fn default() -> Self {
let cache_dir = get_cache_dir().unwrap().join("kokoro");
let path = cache_dir.join("voices-v1.1-zh.bin");
Self(Download::new(path, VOICES_URL))
}
}
impl Deref for VoicesData {
type Target = Download;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for VoicesData {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}