use super::BaseMetadata;
use serde::{Deserialize, Serialize};
#[derive(Debug)]
pub struct PiperMetadataBuilder {
metadata: PiperMetadata,
}
impl PiperMetadataBuilder {
pub fn new<S: Into<String>>(model_name: S, model_alias: S) -> Self {
let metadata = PiperMetadata {
model_name: model_name.into(),
model_alias: model_alias.into(),
..Default::default()
};
Self { metadata }
}
pub fn enable_debug(mut self, enable: bool) -> Self {
self.metadata.debug_log = enable;
self
}
pub fn with_speed(mut self, speed: f64) -> Self {
self.metadata.speed = speed;
self
}
pub fn with_speaker_id(mut self, speaker_id: u32) -> Self {
self.metadata.speaker_id = speaker_id;
self
}
pub fn with_noise_scale(mut self, noise_scale: f64) -> Self {
self.metadata.noise_scale = noise_scale;
self
}
pub fn with_length_scale(mut self, length_scale: f64) -> Self {
self.metadata.length_scale = length_scale;
self
}
pub fn with_noise_w(mut self, noise_w: f64) -> Self {
self.metadata.noise_w = noise_w;
self
}
pub fn with_sentence_silence(mut self, sentence_silence: f64) -> Self {
self.metadata.sentence_silence = sentence_silence;
self
}
pub fn with_phoneme_silence(mut self, phoneme_silence: f64) -> Self {
self.metadata.phoneme_silence = Some(phoneme_silence);
self
}
pub fn enable_json_input(mut self, flag: bool) -> Self {
self.metadata.json_input = Some(flag);
self
}
pub fn build(self) -> PiperMetadata {
self.metadata
}
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PiperMetadata {
#[serde(skip_serializing)]
pub model_name: String,
#[serde(skip_serializing)]
pub model_alias: String,
#[serde(rename = "enable-debug-log")]
pub debug_log: bool,
pub speed: f64,
pub speaker_id: u32,
pub noise_scale: f64,
length_scale: f64,
pub noise_w: f64,
pub sentence_silence: f64,
#[serde(skip_serializing_if = "Option::is_none")]
phoneme_silence: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub json_input: Option<bool>,
}
impl Default for PiperMetadata {
fn default() -> Self {
Self {
model_name: String::new(),
model_alias: String::new(),
debug_log: false,
speed: 1.0,
speaker_id: 0,
noise_scale: 0.667,
length_scale: 1.0,
noise_w: 0.8,
sentence_silence: 0.2,
phoneme_silence: None,
json_input: None,
}
}
}
impl BaseMetadata for PiperMetadata {
fn model_name(&self) -> &str {
&self.model_name
}
fn model_alias(&self) -> &str {
&self.model_alias
}
}