🎤Micdrop

Piper TTS in Node.js

Piper TTS is an open source text to speech engine that runs offline on a CPU. Each voice is a small VITS model of a few dozen megabytes, for one language and one speaker. The project lists 178 voices in 53 languages, French, German and Spanish among them. @micdrop/piper drives the Piper binary as a subprocess of @micdrop/server, so a Node voice agent speaks any of these languages with no API key.

Piper starts speaking about 390 ms after it receives a sentence and generates much faster than real time, even on a modest CPU. With its 53 languages, it is the local voice to pick for a language beyond the five of Phonon, and for a commercial product in a language other than English, since the Phonon models for those languages are free for non-commercial use only. Kokoro sounds better in English, the only language it speaks in Micdrop. Piper only reads text aloud, so pair it with Whisper to transcribe the user’s speech locally as well.

Installation

Install the package:

Terminal window
npm install @micdrop/piper

Install the binary, which needs Python. In a container, add a Python interpreter to the image and run the same command:

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 with MicdropServer

If you have no Micdrop server yet, set up a first voice call and come back to swap its voice for Piper.

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
})

Usage without MicdropServer

import { PiperTTS } from '@micdrop/piper'
import { Readable } from 'stream'
const tts = new PiperTTS({
modelPath: './voices/fr_FR-siwis-medium.onnx',
})
// Audio is raw PCM, 16 bits, 16 kHz, mono
tts.on('Audio', (chunk) => console.log('Audio:', chunk.length, 'bytes'))
tts.on('Failed', (texts) => console.error('Failed:', texts))
tts.speak(Readable.from(['Hello! ', 'What can I do for you?']))

Events

EventPayloadDescription
AudioBufferA chunk of audio, PCM 16 bits, 16 kHz, mono, ready to be played.
Failedstring[]The Piper process exited with an error, or the binary cannot be run (reported once). The payload stays empty.

See the TTS interface for the full contract.

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
volumenumberOptionalVolume multiplier, 1 keeps the voice’s own level

Piper TTS voices

Voices are named after their language, their speaker and their quality, such as fr_FR-siwis-medium or en_GB-alba-medium. You can listen to every Piper voice before downloading it.

Piper has five French voices, siwis, upmc, tom, mls and gilles, each under its own license. We compared those licenses and Piper’s latency with Gradium’s Phonon and the hosted APIs to see which French text to speech engine suits a voice agent.

Every voice lives in the rhasspy/piper-voices repository on Hugging Face, under a path built from the same parts as its name:

<language>/<locale>/<speaker>/<quality>/<locale>-<speaker>-<quality>.onnx

So the British voice en_GB-alba-medium sits at en/en_GB/alba/medium/en_GB-alba-medium.onnx, and its configuration at the same path with .json appended. To download it, point the BASE line of the installation commands at that folder.

PiperTTS needs both <name>.onnx and <name>.onnx.json. The JSON file gives the sample rate the model generates at, 16 kHz for the low voices and 22.05 kHz for the others, along with the number of speakers. Micdrop reads that file at startup and resamples the audio to the 16 kHz the client plays. For a voice with several speakers, pick one with the speaker option.

What Piper TTS costs to run

Piper costs nothing per minute, since it runs on your own machine. It uses time and memory instead, measured here on the CPU of a MacBook Pro M2:

MeasurePiper
First sound, voice loaded~390 ms
Loading the voice~1 s
Three sentences in one processAbout the same time as one sentence
MemoryAbout the size of the voice file

Three sentences take about as long as one because loading the voice takes up almost all of that time. The Piper process holds about as much memory as its voice file, a few dozen megabytes for a medium voice, outside the Node process. With the transcription and the first tokens of a local LLM added, a fully local call with Piper answers in about a second.

One process for the whole call

Loading a voice takes about a second, while synthesizing a sentence adds almost nothing on top of it. PiperTTS starts the process as soon as you construct it and keeps it alive across sentences, so the voice loads once per call.

When the user interrupts while Piper is still writing audio, PiperTTS kills the process to cut that audio at once, then starts a new one right away. The new process loads its voice while the user is still speaking and is ready by the time the next answer begins. A process that has finished writing, quiet for a second, holds nothing back and stays as it is.

When the binary cannot be found or run, PiperTTS emits Failed once and leaves the process stopped for the rest of the call.

The whole answer is usually ready before the user has finished hearing its first sentence.

Piper TTS vs the hosted providers

Piper starts speaking about as fast as the hosted voices. ElevenLabs takes around 400 ms and Gradium around 300 ms. Only Cartesia answers clearly sooner, around 150 ms. Piper is free, while their entry prices run from $1.80 to $3.60 per hour of audio.

Piper’s VITS models sound flatter than the hosted voices. Pick Piper when the audio has to stay on your machine, when the call runs offline, or when the volume makes an hourly bill add up. Pick a hosted voice when its quality matters more to your users than the cost. You can compare Piper with every text to speech provider Micdrop supports on latency, voices and price.

Documentation

Piper also works in a voice agent that runs entirely on local models, next to a local LLM and local speech to text. For local text to speech in Node, Piper, Kokoro and Pocket TTS differ on latency, memory and languages.

License

The Piper engine is released under GPL-3.0 since it embedded espeak-ng. The archived rhasspy/piper repository was MIT. Micdrop drives the binary as a separate process. If you redistribute that binary yourself, its GPL terms come with it. Each voice carries its own license, some of them restrictive, so read the model card of the voice you pick.