Piper
Local text to speech for @micdrop/server, driving the Piper binary as a subprocess.
Piper voices are small VITS models, a few dozen megabytes each, covering around forty languages including French. They generate much faster than real time even on a modest CPU, which makes Piper the option to reach for outside English, where Kokoro sounds better but only speaks English.
Installation
Install the package:
npm install @micdrop/piperInstall the binary:
pip install piper-ttsThen download a voice, which comes as a pair of files that have to sit next to each other:
mkdir -p voices && cd voicesBASE=https://huggingface.co/rhasspy/piper-voices/resolve/main/fr/fr_FR/siwis/mediumcurl -LO $BASE/fr_FR-siwis-medium.onnxcurl -LO $BASE/fr_FR-siwis-medium.onnx.jsonPiper ships a download_voices module, but calling it means finding the exact
interpreter pip installed it under, which is rarely the python3 in your
path. Downloading the two files is shorter and works the same.
Usage
import { PiperTTS } from '@micdrop/piper'import { MicdropServer } from '@micdrop/server'
const tts = new PiperTTS({ modelPath: './voices/fr_FR-siwis-medium.onnx',})
// Use with MicdropServernew MicdropServer(socket, { tts, // ... other options})Options
| Option | Type | Default | Description |
|---|---|---|---|
modelPath | string | Required | Path to the .onnx voice file |
configPath | string | <modelPath>.json | Voice configuration |
binaryPath | string | 'piper' in PATH | Piper executable |
speaker | number | Optional | Speaker index, for the voices holding several |
lengthScale | number | Optional | Duration multiplier, above 1 to slow the voice down |
noiseScale | number | Optional | Variability of the generated speech |
noiseWidth | number | Optional | Variability of the phoneme durations |
sentenceSilence | number | Optional | Silence added after each sentence, in seconds |
Voices
Voices are named after their language, their speaker and their quality, such as
fr_FR-siwis-medium or en_GB-alba-medium. The
voice samples page lets you listen
to them before downloading.
Each voice ships as <name>.onnx and <name>.onnx.json, which have to sit next
to each other. The JSON file carries the sample rate the model generates at,
read at startup so the audio reaches the client at the rate it expects.
How the process is driven
One process is spawned per sentence: its exit is what marks the end of that sentence’s audio, and killing it is what makes an interruption immediate. Loading a voice costs on the order of a hundred milliseconds, paid while the previous sentence is still being played by the client.
Piper generates much faster than real time, so the whole answer is usually ready before the user has finished hearing its first sentence.
Documentation
Read the guide on running Micdrop with local models to see how this fits with a local LLM and a local transcription.
License
Piper is released under the MIT license, and its voices under permissive licenses that vary by voice.