Kokoro TTS Inference (tts/kokoro.rs)

kesha-voice-kit · rust/src/tts/kokoro.rs · rust · MIT
voice, lang:rust, tag:onnx

Performs text-to-speech inference using the Kokoro-82M ONNX model.

// Source: https://github.com/drakulavich/kesha-voice-kit | License: MIT | Copyright 2026 drakulavich
// Provided via justclaw.it.com; keep this notice with the code.
//! Kokoro-82M ONNX inference session.
//!
//! Inputs:  `tokens` (int64 [1,N]), `style` (f32 [1,256]), `speed` (f32 [1])
//! Output:  `audio` (f32 [T]) at 24 kHz
//!
//! Tensor names follow the kokoro-onnx official release. The earlier HF
//! onnx-community variant used `(input_ids, waveform)` and produced
//! unintelligible audio with `af_heart` — see #207.

use std::path::Path;

use ndarray::{Array1, Array2};
use ort::session::Session;
use ort::value::Value;

pub const SAMPLE_RATE: u32 = 24_000;

pub struct Kokoro {
    session: Session,
}

impl Kokoro {
    pub fn load(model_path: &Path) -> anyhow::Result<Self> {
        l

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key