Views
No views yet
Life is like a box of chocolates. You never know what you're gonna get.
| Voice | Nationality | Gender | Sample |
|---|---|---|---|
Default (af) | American | Female | |
Bella (af_bella) | American | Female | |
Nicole (af_nicole) | American | Female | |
Sarah (af_sarah) | American | Female | |
Sky (af_sky) | American | Female | |
Adam (am_adam) | American | Male | |
Michael (am_michael) | American | Male | |
Emma (bf_emma) | British | Female | |
Isabella (bf_isabella) | British | Female | |
George (bm_george) | British | Male | |
Lewis (bm_lewis) | British | Male |
kokoro-js library from NPM using:npm i kokoro-js1import { KokoroTTS } from "kokoro-js";
2
3const model_id = "onnx-community/Kokoro-82M-ONNX";
4const tts = await KokoroTTS.from_pretrained(model_id, {
5 dtype: "q8", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
6});
7
8const text = "Life is like a box of chocolates. You never know what you're gonna get.";
9const audio = await tts.generate(text, {
10 // Use `tts.list_voices()` to list all available voices
11 voice: "af_bella",
12});
13audio.save("audio.wav");1import os
2import numpy as np
3from onnxruntime import InferenceSession
4
5# Tokens produced by phonemize() and tokenize() in kokoro.py
6tokens = [50, 157, 43, 135, 16, 53, 135, 46, 16, 43, 102, 16, 56, 156, 57, 135, 6, 16, 102, 62, 61, 16, 70, 56, 16, 138, 56, 156, 72, 56, 61, 85, 123, 83, 44, 83, 54, 16, 53, 65, 156, 86, 61, 62, 131, 83, 56, 4, 16, 54, 156, 43, 102, 53, 16, 156, 72, 61, 53, 102, 112, 16, 70, 56, 16, 138, 56, 44, 156, 76, 158, 123, 56, 16, 62, 131, 156, 43, 102, 54, 46, 16, 102, 48, 16, 81, 47, 102, 54, 16, 54, 156, 51, 158, 46, 16, 70, 16, 92, 156, 135, 46, 16, 54, 156, 43, 102, 48, 4, 16, 81, 47, 102, 16, 50, 156, 72, 64, 83, 56, 62, 16, 156, 51, 158, 64, 83, 56, 16, 44, 157, 102, 56, 16, 44, 156, 76, 158, 123, 56, 4]
7
8# Context length is 512, but leave room for the pad token 0 at the start & end
9assert len(tokens) <= 510, len(tokens)
10
11# Style vector based on len(tokens), ref_s has shape (1, 256)
12voices = np.fromfile('./voices/af.bin', dtype=np.float32).reshape(-1, 1, 256)
13ref_s = voices[len(tokens)]
14
15# Add the pad ids, and reshape tokens, should now have shape (1, <=512)
16tokens = [[0, *tokens, 0]]
17
18model_name = 'model.onnx' # Options: model.onnx, model_fp16.onnx, model_quantized.onnx, model_q8f16.onnx, model_uint8.onnx, model_uint8f16.onnx, model_q4.onnx, model_q4f16.onnx
19sess = InferenceSession(os.path.join('onnx', model_name))
20
21audio = sess.run(None, dict(
22 input_ids=tokens,
23 style=ref_s,
24 speed=np.ones(1, dtype=np.float32),
25))[0]1import scipy.io.wavfile as wavfile
2wavfile.write('audio.wav', 24000, audio[0])How could I know? It's an unanswerable question. Like asking an unborn child if they'll lead a good life. They haven't even been born.
| Model | Size (MB) | Sample |
|---|---|---|
| model.onnx (fp32) | 326 | |
| model_fp16.onnx (fp16) | 163 | |
| model_quantized.onnx (8-bit) | 92.4 | |
| model_q8f16.onnx (Mixed precision) | 86 | |
| model_uint8.onnx (8-bit & mixed precision) | 177 | |
| model_uint8f16.onnx (Mixed precision) | 114 | |
| model_q4.onnx (4-bit matmul) | 305 | |
| model_q4f16.onnx (4-bit matmul & fp16 weights) | 154 |