piper1-rs 0.1.0

Safe Rust bindings to Piper, the TTS library
Documentation
//! JSON model for a TTS model's attached JSON file.

use std::collections::HashMap;

use serde::{Deserialize, Serialize};

use super::{Language, ModelQuality, SpeakerIdMap};

/// The data model of a model's config JSON file.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModelConfig {
	/// Output audio parameters.
	pub audio:          Audio,
	/// ESpeak voice data.
	pub espeak:         Espeak,
	/// Default inference parameters to this model.
	#[serde(rename = "inference")]
	pub default_params: DefaultInferenceParameters,
	/// Unknown use.
	pub phoneme_type:   Option<String>,
	/// A map of phonemes to another different phoneme.
	pub phoneme_map:    HashMap<String, Vec<String>>,
	/// A map of phonemes to their IDs.
	pub phoneme_id_map: HashMap<String, Vec<u8>>,
	/// Unknown use.
	pub num_symbols:    u16,
	/// The number of unique speakers, or in other words, the length of speaker_id_map
	pub num_speakers:   u8,
	/// A map of speaker names to their model level IDs.
	pub speaker_id_map: SpeakerIdMap,
	/// The version of Piper this was built for.
	pub piper_version:  String,
	/// Language details for the model
	pub language:       Language,
	/// The origin dataset for this model.
	pub dataset:        String,
}

/// Output audio parameters.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Audio {
	/// The output sample rate for this model.
	pub sample_rate: u16,
	/// The quality of this model.
	pub quality:     ModelQuality,
}

/// ESpeak voice data.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Espeak {
	/// The voice name used as the base (?)
	voice: String,
}

/// Default inference parameters for this model
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DefaultInferenceParameters {
	/// Default amount of noise added for this model.
	noise_scale:  f32,
	/// Default length scale for this model.
	length_scale: f32,
	/// Default variation in phoneme length for this model.
	noise_w:      f32,
}