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 locallywithopen("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(self.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.
kokoro-base-onnx huggingface.co is an AI model on huggingface.co that provides kokoro-base-onnx's model effect (), which can be used instantly with this NeuML kokoro-base-onnx model. huggingface.co supports a free trial of the kokoro-base-onnx model, and also provides paid use of the kokoro-base-onnx. Support call kokoro-base-onnx model through api, including Node.js, Python, http.
kokoro-base-onnx huggingface.co is an online trial and call api platform, which integrates kokoro-base-onnx's modeling effects, including api services, and provides a free online trial of kokoro-base-onnx, you can try kokoro-base-onnx online for free by clicking the link below.
NeuML kokoro-base-onnx online free url in huggingface.co:
kokoro-base-onnx is an open source model from GitHub that offers a free installation service, and any user can find kokoro-base-onnx on GitHub to install. At the same time, huggingface.co provides the effect of kokoro-base-onnx install, users can directly use kokoro-base-onnx installed effect in huggingface.co for debugging and trial. It also supports api for free installation.