🎤 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. In English itself, Kokoro sounds better, and English is all it speaks in Micdrop.

Installation

Install the package:

Terminal window
npm install @micdrop/piper

Install the binary:

Terminal window
pip install piper-tts

Then download a voice. It 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 gives the same result.

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 voices with several speakers
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. The JSON file gives the sample rate the model generates at, and Micdrop reads that file at startup so the audio reaches the client at the rate it expects.

One process per sentence

The exit of each Piper process marks the end of a sentence’s audio, and killing it makes an interruption immediate. Loading a voice costs on the order of a hundred milliseconds, paid while the client is still playing the previous sentence.

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 Piper fits with a local LLM and local speech to text.

License

Piper is released under the MIT license, and each voice under its own permissive license.