Speech in one pass
Kokoro turns text into speech without generating it token by token. It is the inference half of StyleTTS 2 with an iSTFTNet vocoder, released by hexgrad with Apache-licensed weights: 81.8 M parameters on this page's checkpoint. A text-to-speech model has to decide things the text does not say: how long each sound lasts, where the pitch rises and falls, how loud it is, and what the voice sounds like. Kokoro predicts each of these explicitly, then renders the sound.
The page follows the pipeline left to right. Text → phonemes turns the line into phoneme symbols and a phoneme-level BERT reads them in context. Style → durations and prosody takes a 256-number style vector for the voice and predicts the frames each phoneme lasts, the pitch and the energy. Decoder → iSTFT turns those into the magnitude and phase of a short-time Fourier transform, and the inverse transform gives 24 kHz samples. The Voices strip plays the same phonemes in three voices.
From letters to phonemes
Spelling is a poor guide to English sound, so Kokoro never reads letters. hexgrad's misaki looks each word up in a gold dictionary, then a larger silver one, and falls back to espeak-ng for words in neither; the dot after each word's tag says which one answered, and all 13 words of this line are in the gold dictionary. Some words depend on context, which misaki resolves with spaCy's part-of-speech tags and the next word: the is ðə before a consonant and ði before a vowel, and read depends on its tense. Diphthongs are single symbols (O for oʊ, W for aʊ, I for aɪ), and stress marks ˈ and ˌ sit before stressed syllables.
This line becomes 57 symbols, each mapped to one of 178 ids, with id 0 at both ends. PL-BERT then reads the ids: an ALBERT network pre-trained on phonemes from a large text corpus, by predicting masked phonemes and the graphemes they came from, so that it learns which words a phoneme sequence spells. ALBERT shares one layer's weights across all of its depth; here a 768-wide layer is applied 12 times, and its output is projected to 512 numbers per phoneme, the columns of the PL-BERT heatmap. Prosody depends on meaning, which is why the duration and pitch predictors read these features rather than the raw ids.
A voice is a vector
Each voice is a style vector: the first 128 numbers condition the decoder and set the timbre, the last 128 condition the predictors and set the prosody. In StyleTTS 2 the style is either encoded from a reference recording or sampled by a small diffusion model conditioned on the text. Kokoro ships the result as voice packs of 510 precomputed vectors, one per utterance length, and takes the row for the number of phonemes; the Style vectors strips show the rows for this line in the three voices.
The style enters through adaptive instance normalisation (AdaIN), borrowed from image style transfer. Each channel is normalised over time and then scaled and shifted by amounts a linear layer reads from the style :
Every residual block of the decoder and of the pitch and energy predictors uses it, so the same phoneme features produce a different voice when the style changes, which the voice buttons show.
How long, how high, how loud
The duration predictor reads PL-BERT's features with the prosody half of the style through three bidirectional LSTMs, each followed by a layer norm modulated by the style. For each phoneme it outputs 50 logits ; their sigmoids add up to a duration, and the frames are that duration rounded:
The lasts panel draws the sigmoids of the selected phoneme. A frame is 25 ms (600 samples), so af_heart says this line in 142 frames, 3.55 s. Each phoneme's features are then repeated for its frames by a 0/1 alignment matrix, and a second predictor turns the stretched features into pitch (F0, in Hz) and energy, two values per frame. The Frames, pitch and energy panel draws them on one time axis, with another voice's pitch dashed: af_heart's voiced frames average 195 Hz and am_michael's 113 Hz, from the same phonemes and different style vectors. Because duration, pitch and energy are explicit numbers, they can be edited before decoding; the speed argument divides every duration.
The decoder and the inverse STFT
The decoder concatenates the text encoder's phoneme features (stretched to frames), pitch and energy, and passes them through AdaIN residual blocks to 512 channels at 80 Hz. A classic vocoder would now upsample by 300 to reach audio samples. iSTFTNet stops early: two transposed convolutions upsample by 10 and 6, and a last convolution writes 22 channels per step, the log-magnitude and phase of an 11-bin, 20-point STFT with a hop of 5 samples. The inverse STFT does the rest:
so the phase is confined to ±1 radian, as the Magnitude and phase heatmaps show. Letting a fixed transform produce the fine time structure makes the network lighter and faster. Pitch also enters the vocoder directly, as in neural source-filter models: a source of sines at F0 and its first 8 overtones, silent where the frame is unvoiced and with a little noise, is analysed with the same STFT and added at both upsampling scales. Its overtones start at random phases, so the recorder fixes the seed; the harmonic source card plays it.
Where it came from
StyleTTS (2022) introduced the style vector and AdaIN conditioning with explicit durations; StyleTTS 2 (2023) added a diffusion model that samples styles, PL-BERT, and adversarial training against a large speech language model, and reported human-level naturalness on LJSpeech. Kokoro keeps StyleTTS 2's inference path with fixed voice packs, and was trained on permissively licensed audio. It differs from the CSM tab's approach, which writes speech as codec tokens one frame at a time with a large language model and conditions on the conversation; on this explainer CSM answers this very line, using Kokoro's af_heart recording as its context.
Papers
- StyleTTS 2: Towards Human-Level Text-to-Speech through Style Diffusion and Adversarial Training with Large Speech Language Models The architecture Kokoro runs: PL-BERT features, style-conditioned duration, pitch and energy predictors, and the AdaIN decoder with an iSTFTNet vocoder.
- iSTFTNet: Fast and Lightweight Mel-Spectrogram Vocoder Incorporating Inverse Short-Time Fourier Transform Replaces a vocoder's last upsampling layers with a predicted magnitude and phase and an inverse STFT, the step the Magnitude and phase panel shows.
- Phoneme-Level BERT for Enhanced Prosody of Text-to-Speech with Grapheme Predictions PL-BERT, the phoneme encoder pre-trained with masked phoneme and grapheme prediction that Kokoro's predictors read.
- StyleTTS: A Style-Based Generative Model for Natural and Diverse Text-to-Speech Synthesis Introduces the style vector, AdaIN conditioning and the explicit duration, pitch and energy predictors.
- Neural source-filter waveform models for statistical parametric speech synthesis The harmonic source: sines at F0 and its overtones, with noise where unvoiced, that the vocoder filters.
- Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization Adaptive instance normalisation, the way the style vector enters every block.
- ALBERT: A Lite BERT for Self-supervised Learning of Language Representations The factorised embedding and cross-layer weight sharing of the network PL-BERT is built on.