rlx_kittentts/config.rs
1// RLX — versatile ML compiler + runtime.
2// Copyright (C) 2026 Eugene Hauptmann, Nataliya Kosmyna.
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16//! `config.json` schema from KittenTTS Hugging Face repos.
17
18use std::{collections::HashMap, path::Path};
19
20use anyhow::{Context, Result};
21use serde::Deserialize;
22
23/// Default mini model on Hugging Face.
24pub const DEFAULT_HF_REPO: &str = "KittenML/kitten-tts-mini-0.8";
25
26/// Deserialised `config.json` from a KittenTTS repository.
27#[derive(Debug, Clone, Deserialize)]
28pub struct ModelConfig {
29 #[serde(rename = "type")]
30 pub model_type: String,
31 pub model_file: String,
32 pub voices: String,
33 #[serde(default)]
34 pub speed_priors: HashMap<String, f32>,
35 #[serde(default)]
36 pub voice_aliases: HashMap<String, String>,
37}
38
39impl ModelConfig {
40 pub fn load_from_dir(model_dir: &Path) -> Result<Self> {
41 let path = model_dir.join("config.json");
42 let bytes = std::fs::read(&path)
43 .with_context(|| format!("read config.json in {}", model_dir.display()))?;
44 let config: Self =
45 serde_json::from_slice(&bytes).with_context(|| format!("parse {}", path.display()))?;
46 if !matches!(config.model_type.as_str(), "ONNX1" | "ONNX2") {
47 anyhow::bail!(
48 "unsupported model type '{}' in {} (expected ONNX1 or ONNX2)",
49 config.model_type,
50 path.display()
51 );
52 }
53 Ok(config)
54 }
55}