Kokoro<T>
Models & Types · AiDotNet.TextToSpeech.EndToEnd
Kokoro: lightweight end-to-end TTS with a StyleTTS2-inspired architecture using style tokens and ISTFTNet decoder.
Inheritance: NeuralNetworkBase<T> → TtsModelBase<T> → Kokoro<T>
Implements: IEndToEndTts<T>
For Beginners
Kokoro is a remarkably small but high-quality TTS model with only 82 million parameters (compared to billions in larger models). It is inspired by StyleTTS2’s architecture and uses several clever techniques to achieve quality speech from a compact model: (1) A BERT-style phoneme encoder processes text into hidden states, (2) A released voice bank supplies acoustic and prosodic style vectors, (3) A duration predictor determines how long each sound should last, (4) An ISTFTNet decoder converts features into audio by predicting STFT magnitude and phase and applying inverse STFT, which is faster than traditional waveform generation. The neural graph reads phonemes; text frontend and voice-bank selection are configured separately.
How It Works
References:
- Project: “Kokoro: A frontier TTS model for its size of 82M params” (Hexgrad, 2024)
Constructors
| Constructor | Summary |
|---|---|
Kokoro(NeuralNetworkArchitecture<T> architecture, KokoroOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
Initializes a new instance of the Kokoro class in native training/inference mode. |
Kokoro(NeuralNetworkArchitecture<T> architecture, string modelPath, KokoroOptions options) |
Initializes a new instance of the Kokoro class in native training/inference mode. |
Properties
| Property | Summary |
|---|---|
Func<string, string> TextPhonemizer { get; set; } |
Text frontend for raw text, normally the official Misaki phonemizer. |
int HiddenDim { get; } |
Gets the hidden dimension size. |
int MaxTextLength { get; } |
|
int NumFlowSteps { get; } |
Gets the number of normalizing flow steps used in the decoder. |
Methods
| Method | Summary |
|---|---|
LayerInputDomain GetInputDomain(int[] inputShape) |
|
ModelMetadata<T> GetModelMetadata() |
|
Tensor<T> ForwardForTraining(Tensor<T> input) |
|
Tensor<T> Synthesize(string text) |
Synthesizes speech using Kokoro’s StyleTTS2-inspired pipeline with ISTFTNet decoder. |
Tensor<T> SynthesizePhonemes(string phonemes, Tensor<T> voiceStyle, double speed) |
Runs the actual language-independent KModel graph with explicit phonemes and a 256-value voice style. |
int[] EncodePhonemes(string phonemes) |
Maps the exact configured phoneme symbols to IDs, dropping unknown symbols and adding both pad IDs. |
void LoadAuthorConfiguration(string configuration) |
Loads the original Kokoro-82M configuration and phoneme vocabulary, independently of its weights. |
void LoadAuthorWeights(string checkpoint, string configuration) |
Loads the original Kokoro-82M component checkpoint and its exact phoneme vocabulary. |
void LoadVoice(string path) |
Loads an original voice .pt bank [phoneme length, 1, 256]. |