antocorr/kokoro.js

1

stars

3

commits

JavaScript

primary language

Jul 29, 2026

updated

README

Kokoro TTS

NPM NPM Downloads jsDelivr Hits License Demo

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!

Usage

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-v1.0-ONNX";
const tts = await KokoroTTS.from_pretrained(model_id, {
  dtype: "q8", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
  device: "wasm", // Options: "wasm", "webgpu" (web) or "cpu" (node). If using "webgpu", we recommend using dtype="fp32".
});

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_heart",
});
audio.save("audio.wav");

Or if you'd prefer to stream the output, you can do that with:

import { KokoroTTS, TextSplitterStream } from "kokoro-js";

const model_id = "onnx-community/Kokoro-82M-v1.0-ONNX";
const tts = await KokoroTTS.from_pretrained(model_id, {
  dtype: "fp32", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
  // device: "webgpu", // Options: "wasm", "webgpu" (web) or "cpu" (node).
});

// First, set up the stream
const splitter = new TextSplitterStream();
const stream = tts.stream(splitter);
(async () => {
  let i = 0;
  for await (const { text, phonemes, audio } of stream) {
    console.log({ text, phonemes });
    audio.save(`audio-${i++}.wav`);
  }
})();

// Next, add text to the stream. Note that the text can be added at different times.
// For this example, let's pretend we're consuming text from an LLM, one word at a time.
const text = "Kokoro is an open-weight TTS model with 82 million parameters. Despite its lightweight architecture, it delivers comparable quality to larger models while being significantly faster and more cost-efficient. With Apache-licensed weights, Kokoro can be deployed anywhere from production environments to personal projects. It can even run 100% locally in your browser, powered by Transformers.js!";
const tokens = text.match(/\s*\S+/g);
for (const token of tokens) {
  splitter.push(token);
  await new Promise((resolve) => setTimeout(resolve, 10));
}

// Finally, close the stream to signal that no more text will be added.
splitter.close();

// Alternatively, if you'd like to keep the stream open, but flush any remaining text, you can use the `flush` method.
// splitter.flush();

Voices/Samples

[!TIP] You can find samples for each of the voices in the model card on Hugging Face.

American English

NameTraitsTarget QualityTraining DurationOverall Grade
af_heart๐Ÿšบโค๏ธA
af_alloy๐ŸšบBMM minutesC
af_aoede๐ŸšบBH hoursC+
af_bella๐Ÿšบ๐Ÿ”ฅAHH hoursA-
af_jessica๐ŸšบCMM minutesD
af_kore๐ŸšบBH hoursC+
af_nicole๐Ÿšบ๐ŸŽงBHH hoursB-
af_nova๐ŸšบBMM minutesC
af_river๐ŸšบCMM minutesD
af_sarah๐ŸšบBH hoursC+
af_sky๐ŸšบBM minutes ๐ŸคC-
am_adam๐ŸšนDH hoursF+
am_echo๐ŸšนCMM minutesD
am_eric๐ŸšนCMM minutesD
am_fenrir๐ŸšนBH hoursC+
am_liam๐ŸšนCMM minutesD
am_michael๐ŸšนBH hoursC+
am_onyx๐ŸšนCMM minutesD
am_puck๐ŸšนBH hoursC+
am_santa๐ŸšนCM minutes ๐ŸคD-

British English

NameTraitsTarget QualityTraining DurationOverall Grade
bf_alice๐ŸšบCMM minutesD
bf_emma๐ŸšบBHH hoursB-
bf_isabella๐ŸšบBMM minutesC
bf_lily๐ŸšบCMM minutesD
bm_daniel๐ŸšนCMM minutesD
bm_fable๐ŸšนBMM minutesC
bm_george๐ŸšนBMM minutesC
bm_lewis๐ŸšนCH hoursD+

Spanish

NameTraitsTarget QualityTraining DurationOverall Grade
ef_dora๐ŸšบCMM minutesD
em_alex๐ŸšนCMM minutesD
em_santa๐ŸšนCMM minutesD

French

NameTraitsTarget QualityTraining DurationOverall Grade
ff_siwis๐ŸšบBH hoursB-

Hindi

NameTraitsTarget QualityTraining DurationOverall Grade
hf_alpha๐ŸšบBH hoursC
hf_beta๐ŸšบBH hoursC
hm_omega๐ŸšนBH hoursC
hm_psi๐ŸšนBH hoursC

Italian

NameTraitsTarget QualityTraining DurationOverall Grade
if_sara๐ŸšบBH hoursC
im_nicola๐ŸšนBH hoursC

Brazilian Portuguese

NameTraitsTarget QualityTraining DurationOverall Grade
pf_dora๐ŸšบCMM minutesD
pm_alex๐ŸšนCMM minutesD
pm_santa๐ŸšนCMM minutesD

Contributors

antocorr

3 commits

antocorr/kokoro.js

1

stars

3

commits

JavaScript

primary language

Jul 29, 2026

updated

README

Kokoro TTS

NPM NPM Downloads jsDelivr Hits License Demo

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!

Usage

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-v1.0-ONNX";
const tts = await KokoroTTS.from_pretrained(model_id, {
  dtype: "q8", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
  device: "wasm", // Options: "wasm", "webgpu" (web) or "cpu" (node). If using "webgpu", we recommend using dtype="fp32".
});

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_heart",
});
audio.save("audio.wav");

Or if you'd prefer to stream the output, you can do that with:

import { KokoroTTS, TextSplitterStream } from "kokoro-js";

const model_id = "onnx-community/Kokoro-82M-v1.0-ONNX";
const tts = await KokoroTTS.from_pretrained(model_id, {
  dtype: "fp32", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
  // device: "webgpu", // Options: "wasm", "webgpu" (web) or "cpu" (node).
});

// First, set up the stream
const splitter = new TextSplitterStream();
const stream = tts.stream(splitter);
(async () => {
  let i = 0;
  for await (const { text, phonemes, audio } of stream) {
    console.log({ text, phonemes });
    audio.save(`audio-${i++}.wav`);
  }
})();

// Next, add text to the stream. Note that the text can be added at different times.
// For this example, let's pretend we're consuming text from an LLM, one word at a time.
const text = "Kokoro is an open-weight TTS model with 82 million parameters. Despite its lightweight architecture, it delivers comparable quality to larger models while being significantly faster and more cost-efficient. With Apache-licensed weights, Kokoro can be deployed anywhere from production environments to personal projects. It can even run 100% locally in your browser, powered by Transformers.js!";
const tokens = text.match(/\s*\S+/g);
for (const token of tokens) {
  splitter.push(token);
  await new Promise((resolve) => setTimeout(resolve, 10));
}

// Finally, close the stream to signal that no more text will be added.
splitter.close();

// Alternatively, if you'd like to keep the stream open, but flush any remaining text, you can use the `flush` method.
// splitter.flush();

Voices/Samples

[!TIP] You can find samples for each of the voices in the model card on Hugging Face.

American English

NameTraitsTarget QualityTraining DurationOverall Grade
af_heart๐Ÿšบโค๏ธA
af_alloy๐ŸšบBMM minutesC
af_aoede๐ŸšบBH hoursC+
af_bella๐Ÿšบ๐Ÿ”ฅAHH hoursA-
af_jessica๐ŸšบCMM minutesD
af_kore๐ŸšบBH hoursC+
af_nicole๐Ÿšบ๐ŸŽงBHH hoursB-
af_nova๐ŸšบBMM minutesC
af_river๐ŸšบCMM minutesD
af_sarah๐ŸšบBH hoursC+
af_sky๐ŸšบBM minutes ๐ŸคC-
am_adam๐ŸšนDH hoursF+
am_echo๐ŸšนCMM minutesD
am_eric๐ŸšนCMM minutesD
am_fenrir๐ŸšนBH hoursC+
am_liam๐ŸšนCMM minutesD
am_michael๐ŸšนBH hoursC+
am_onyx๐ŸšนCMM minutesD
am_puck๐ŸšนBH hoursC+
am_santa๐ŸšนCM minutes ๐ŸคD-

British English

NameTraitsTarget QualityTraining DurationOverall Grade
bf_alice๐ŸšบCMM minutesD
bf_emma๐ŸšบBHH hoursB-
bf_isabella๐ŸšบBMM minutesC
bf_lily๐ŸšบCMM minutesD
bm_daniel๐ŸšนCMM minutesD
bm_fable๐ŸšนBMM minutesC
bm_george๐ŸšนBMM minutesC
bm_lewis๐ŸšนCH hoursD+

Spanish

NameTraitsTarget QualityTraining DurationOverall Grade
ef_dora๐ŸšบCMM minutesD
em_alex๐ŸšนCMM minutesD
em_santa๐ŸšนCMM minutesD

French

NameTraitsTarget QualityTraining DurationOverall Grade
ff_siwis๐ŸšบBH hoursB-

Hindi

NameTraitsTarget QualityTraining DurationOverall Grade
hf_alpha๐ŸšบBH hoursC
hf_beta๐ŸšบBH hoursC
hm_omega๐ŸšนBH hoursC
hm_psi๐ŸšนBH hoursC

Italian

NameTraitsTarget QualityTraining DurationOverall Grade
if_sara๐ŸšบBH hoursC
im_nicola๐ŸšนBH hoursC

Brazilian Portuguese

NameTraitsTarget QualityTraining DurationOverall Grade
pf_dora๐ŸšบCMM minutesD
pm_alex๐ŸšนCMM minutesD
pm_santa๐ŸšนCMM minutesD

Contributors

antocorr

3 commits

Languages

JavaScript

73.6%

HTML

26.4%