ONNX Model Zoo

NeuML/kokoro-base-onnx

By NeuML · ↓ 0 · ♥ 3 · Updated 2025-03-21

What's in this repo

This page lists the files in NeuML/kokoro-base-onnx, including model.onnx.

  • 1 ONNX models (.onnx files)
  • 15 files, including 11 .mp3, 1 .md, 1 .onnx, 1 .json
  • Last updated 2025-03-21

ONNX files

File Size Download
model.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

Kokoro Base (82M) Model for ONNX

Kokoro 82M export to ONNX. This model is the same ONNX file that's in the base repository. The voices file is from this repository.

Usage with txtai

txtai has a built in Text to Speech (TTS) pipeline that makes using this model easy.

Note: This requires txtai >= 8.3.0. Install from GitHub until that release.

import soundfile as sf

from txtai.pipeline import TextToSpeech

# Build pipeline
tts = TextToSpeech("NeuML/kokoro-base-onnx")

# Generate speech
speech, rate = tts("Say something here")

# Write to file
sf.write("out.wav", speech, rate)

Usage with ONNX

This model can also be run directly with ONNX provided the input text is tokenized. Tokenization can be done with ttstokenizer. ttstokenizer is a permissively licensed library with no external dependencies (such as espeak).

Note that the txtai pipeline has additional functionality such as batching large inputs together that would need to be duplicated with this method.

import json
import numpy as np
import onnxruntime
import soundfile as sf

from ttstokenizer import IPATokenizer

# This example assumes the files have been downloaded locally
with open("kokoro-base-onnx/voices.json", "r", encoding="utf-8") as f:
    voices = json.load(f)

# Create model
model = onnxruntime.InferenceSession(
    "kokoro-base-onnx/model.onnx",
    providers=["CPUExecutionProvider"]
)

# Create tokenizer
tokenizer = IPATokenizer()

# Tokenize inputs
inputs = tokenizer("Say something here")

# Get speaker array
speaker = np.array(voices["af"], dtype=np.float32)

# Generate speech
outputs = model.run(None, {
    "tokens": [[0, *inputs, 0]],
    "style": speaker[len(inputs)],
    "speed": np.ones(1, dtype=np.float32) * 1.0
})

# Write to file
sf.write("out.wav", outputs[0], 24000)

Speaker reference

The Kokoro model has a number of built-in speakers.

When using this model, set a speaker id from the reference table below.

SPEAKER GENDER NATIONALITY EXAMPLE
af F American
af_bella F American
af_nicole F American
af_sarah F American
af_sky F American
am_adam M American
af_michael M American
bf_emma F British
bf_isabella F British
bm_george M British
bm_lewis M British

The following shows an example on how to set a speaker id when using txtai

speech, rate = tts("Say something here", speaker="af_sky")

Model info

txtai onnx audio text-to-speech en base_model:hexgrad/Kokoro-82M base_model:quantized:hexgrad/Kokoro-82M license:apache-2.0 region:us
↓ 0 ♥ 3

Created: 2025-01-16

Updated: 2025-03-21

View on Hugging Face

Files (15)

.gitattributes
README.md
examples/af.mp3
examples/af_bella.mp3
examples/af_nicole.mp3
examples/af_sarah.mp3
examples/af_sky.mp3
examples/am_adam.mp3
examples/am_michael.mp3
examples/bf_emma.mp3
examples/bf_isabella.mp3
examples/bm_george.mp3
examples/bm_lewis.mp3
model.onnx ONNX
voices.json

Related models