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
npm install @micdrop/kokoroUsage
import { KokoroTTS } from '@micdrop/kokoro'import { MicdropServer } from '@micdrop/server'
const tts = new KokoroTTS({ voice: 'britishFemale',})
// Use with MicdropServernew MicdropServer(socket, { tts, // ... other options})Options
| Option | Type | Default | Description |
|---|---|---|---|
model | string | 'onnx-community/Kokoro-82M-v1.0-ONNX' | Repository holding the ONNX export |
voice | string | 'americanFemale' | Shorthand or Kokoro voice id |
speed | number | 1 | Speech rate, above 1 to speak faster |
dtype | string | 'q8' | Weight precision |
device | string | 'cpu' | Execution provider passed to Transformers.js |
warmup | boolean | true | Synthesizes 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, and KOKORO_VOICE_IDS exports the full list.
import { KOKORO_VOICE_IDS, KokoroTTS } from '@micdrop/kokoro'
const tts = new KokoroTTS({ voice: 'am_michael' })Kokoro speaks English only in this integration. 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 a MacBook Pro M2, so a three second sentence takes about two seconds to generate and a short greeting comes back in about one second.
Micdrop cuts the answer into sentences and synthesizes each one as soon as it is complete, so the user hears the opening while the rest is still being written. Sentences go through one after the other rather than at once. The model is single threaded, so racing two sentences through it slows both down and the first word still arrives at the same moment.
Devices
cpu is the default and, on a Mac, the fastest option, 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 lists 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 runs one word through the model while the
call is being set up.
The fp32 precision loads several times slower for a nearly identical
synthesis speed, so q8 is the default.
Documentation
Read the guide on running Micdrop with local models to see how Kokoro fits with a local LLM and local speech to text.
License
Kokoro is released under the Apache 2.0 license, which covers commercial use.