Kokoro is a frontier TTS model for its size of 82 million parameters (text in/audio out). This JavaScript library allows the model to be run 100% locally in the browser thanks to 🤗 Transformers.js. Try it out using our online demo!
First, install the kokoro-js
library from NPM using:
npm i kokoro-js
You can then generate speech as follows:
import { KokoroTTS } from "kokoro-js";
const model_id = "onnx-community/Kokoro-82M-ONNX";
const tts = await KokoroTTS.from_pretrained(model_id, {
dtype: "q8", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
});
const text = "Life is like a box of chocolates. You never know what you're gonna get.";
const audio = await tts.generate(text, {
// Use `tts.list_voices()` to list all available voices
voice: "af_bella",
});
audio.save("audio.wav");
Life is like a box of chocolates. You never know what you're gonna get.
Voice | Nationality | Gender | Sample |
---|---|---|---|
Default (af ) |
American | Female | af.mp4 |
Bella (af_bella ) |
American | Female | af_bella.mp4 |
Nicole (af_nicole ) |
American | Female | af_nicole.mp4 |
Sarah (af_sarah ) |
American | Female | af_sarah.mp4 |
Sky (af_sky ) |
American | Female | af_sky.mp4 |
Adam (am_adam ) |
American | Male | am_adam.mp4 |
Michael (am_michael ) |
American | Male | am_michael.mp4 |
Emma (bf_emma ) |
British | Female | bf_emma.mp4 |
Isabella (bf_isabella ) |
British | Female | bf_isabella.mp4 |
George (bm_george ) |
British | Male | bm_george.mp4 |
Lewis (bm_lewis ) |
British | Male | bm_lewis.mp4 |