🎤 Micdrop

Kokoro

Local text to speech for @micdrop/server, running Kokoro in your Node process through Transformers.js and ONNX Runtime.

Kokoro is an 82 million parameter model, small enough to download in seconds and to sit next to an LLM in memory, with a quality well above what its size suggests.

Installation

Terminal window
npm install @micdrop/kokoro

Usage

import { KokoroTTS } from '@micdrop/kokoro'
import { MicdropServer } from '@micdrop/server'
const tts = new KokoroTTS({
voice: 'britishFemale',
})
// Use with MicdropServer
new MicdropServer(socket, {
tts,
// ... other options
})

Options

OptionTypeDefaultDescription
modelstring'onnx-community/Kokoro-82M-v1.0-ONNX'Repository holding the ONNX export
voicestring'americanFemale'Shorthand or Kokoro voice id
speednumber1Speech rate, above 1 to speak faster
dtypestring'q8'Weight precision
devicestring'cpu'Execution provider passed to Transformers.js
warmupbooleantrueSynthesizes one word at startup

Voices

Shorthands cover the accents and the genders: americanFemale, americanMale, britishFemale and britishMale. Every voice id the model holds works too, exported as KOKORO_VOICE_IDS.

import { KOKORO_VOICE_IDS, KokoroTTS } from '@micdrop/kokoro'
const tts = new KokoroTTS({ voice: 'am_michael' })

Kokoro only speaks English here. The upstream model also holds French, Italian, Japanese, Portuguese and Chinese voices, but the kokoro-js library phonemizes every input with the English rules, so those voices read foreign words with an English pronunciation. Use Piper for the other languages.

Latency

Synthesis runs at roughly half to three quarters of real time on an Apple M3, so a three second sentence takes about two seconds to generate and a short greeting comes back in about one second.

The answer is cut into sentences and each one is synthesized as soon as it is complete, so the user hears the opening while the rest is still being written. Sentences are generated one after the other rather than at once: the model is single threaded, and racing two sentences through it slows both down without bringing the first word any closer.

Devices

cpu is the default and, on a Mac, the fastest option available, since Transformers.js exposes no GPU device on macOS. On Windows dml uses DirectML, and on Linux with an NVIDIA card cuda is worth trying. The local models guide carries the measurements.

Memory and startup

The model is loaded once per configuration and shared by every call. Loading takes about a second and a half in q8, and the first synthesis pays for the graph warm-up, which is why warmup speaks one word while the call is being set up.

The fp32 precision loads several times slower for a synthesis speed that is close to identical, so q8 is the default.

Documentation

Read the guide on running Micdrop with local models to see how this fits with a local LLM and a local transcription.

License

Kokoro is released under the Apache 2.0 license, which covers commercial use.