Files
kokoro/kokoro.js/README.md
Joshua Lochner 0a1dc5750c Create Kokoro TTS JavaScript library (#3)
* Set up JS project

* Finalise JS library

* Update README

* Fix package.json repository url

* Rename package -> `kokoro-js`

* Fix samples in README

* Cleanup README

* Bump `phonemizer` version

* Create web demo

* Run prettier

* Link to model used in demo

* Enable multithreading in HF space demo (~40% faster)

* Add link to demo in README

* Bump to v1.0.1
2025-01-16 09:50:34 -08:00

3.8 KiB

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-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");

Voices/Samples

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