mstar.model.kokoro.components#

class mstar.model.kokoro.components.KokoroTTS(config)[source]#

Bases: Module

Parameters:

config (KokoroModelConfig)

align(d, t_en, pred_dur, num_frames)[source]#

Expand phoneme features to num_frames frames.

Returns the frame-aligned prosody states [B, F, hidden + style], the aligned text features [B, hidden, F] and each row’s valid frame count.

Parameters:
Return type:

tuple[Tensor, Tensor, Tensor]

static alignment(pred_dur, num_frames)[source]#

Index of the phoneme that owns each frame, [B, num_frames].

Equal to the reference’s repeat_interleave + one-hot matmul on the valid frames; frames past a row’s total point at its last phoneme.

Parameters:
Return type:

Tensor

decode_frames(en, asr, frame_lengths, style)[source]#

Frame-aligned features -> waveform [B, F * samples_per_frame].

Parameters:
Return type:

Tensor

encode_text(input_ids, lengths, style, speed)[source]#

[B, T] ids -> prosody states [B, T, hidden + style], text features [B, hidden, T] and integer durations [B, T].

Parameters:
Return type:

tuple[Tensor, Tensor, Tensor]

forward(input_ids, lengths, style, speed)[source]#

Eager end-to-end synthesis: (waveform, frame lengths, durations).

Parameters:
Return type:

tuple[Tensor, Tensor, Tensor]

synthesize_frames(d, t_en, pred_dur, style, num_frames)[source]#

align then decode_frames: the waveform and each row’s frame count.

Parameters:
Return type:

tuple[Tensor, Tensor]

Modules

adain

Style-conditioned normalization blocks shared by the prosody predictor and the decoder (StyleTTS2's AdaIN1d / AdainResBlk1d).

albert

PL-BERT: the ALBERT phoneme encoder that conditions Kokoro's prosody.

decoder

iSTFTNet decoder: prosody-conditioned convolutional trunk, harmonic-plus-noise excitation, two upsampling stages with Snake residual blocks, and an inverse STFT head (StyleTTS2's Modules/istftnet.py as adapted by Kokoro).

lstm

Bidirectional LSTM over padded batches without packing.

masking

Length masks for padded batches.

prosody

Text encoder and prosody predictor (durations, F0 and energy) of Kokoro.

stft

Short-time Fourier analysis and synthesis over padded batches.

synthesizer

The whole Kokoro network: phonemes + style -> waveform, batched and masked.