Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Kokoro TTS JavaScript library #3

Merged
merged 14 commits into from
Jan 16, 2025
Merged

Create Kokoro TTS JavaScript library #3

merged 14 commits into from
Jan 16, 2025

Conversation

xenova
Copy link
Contributor

@xenova xenova commented Jan 15, 2025

This PR introduces kokoro-js, a JavaScript library for inference of Kokoro-82M (v0.19). It uses Transformers.js for ONNX inference and model caching.

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

Example JSFiddle.

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
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

@hexgrad
Copy link
Owner

hexgrad commented Jan 16, 2025

Thanks for the PR! @xenova Looks ready to merge after the rename to kokoro-js, correct?

@xenova
Copy link
Contributor Author

xenova commented Jan 16, 2025

Yep! Ready to merge! 🤗

I've been getting a few feature requests, like long-form generation, so I'll open a new PR for that later 🔥

@hexgrad hexgrad merged commit 0a1dc57 into hexgrad:main Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants