🎤 Micdrop

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:

Terminal window
npm install @micdrop/piper

Install the binary:

Terminal window
pip install piper-tts

Then download a voice, which comes as a pair of files that have to sit next to each other:

Terminal window
mkdir -p voices && cd voices
BASE=https://huggingface.co/rhasspy/piper-voices/resolve/main/fr/fr_FR/siwis/medium
curl -LO $BASE/fr_FR-siwis-medium.onnx
curl -LO $BASE/fr_FR-siwis-medium.onnx.json

Piper 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 MicdropServer
new MicdropServer(socket, {
tts,
// ... other options
})

Options

OptionTypeDefaultDescription
modelPathstringRequiredPath to the .onnx voice file
configPathstring<modelPath>.jsonVoice configuration
binaryPathstring'piper' in PATHPiper executable
speakernumberOptionalSpeaker index, for the voices holding several
lengthScalenumberOptionalDuration multiplier, above 1 to slow the voice down
noiseScalenumberOptionalVariability of the generated speech
noiseWidthnumberOptionalVariability of the phoneme durations
sentenceSilencenumberOptionalSilence 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.