← Journal
Synthesize Speech Without the Cloud: Running Piper

Synthesize Speech Without the Cloud: Running Piper

A record of running Piper, a local neural text-to-speech engine, with the network disabled. It generated an audio file faster than real time.

Repository covered in this article

rhasspy/piper

A fast, local neural text to speech system

11.2k C++ MIT License

A cloud speech synthesis API sends an app's text to an external server. Piper is a local-only TTS (text-to-speech) engine that synthesizes speech from text with a lightweight neural network. I installed it and tested speech synthesis with the network disabled.

Piper uses a lightweight neural speech synthesis model designed to run faster than real time on small devices such as a Raspberry Pi. Piper uses the MIT License for its source code (*1).

1. Install Piper and download a voice model

Download the English voice model (en_US-lessac-medium) during the build while network access is available.

FROM docker.io/library/python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'piper-tts==1.4.2'
RUN python -m piper.download_voices en_US-lessac-medium --data-dir /opt/piper-voices
WORKDIR /work
podman build -t piper-sandbox .

2. Run speech synthesis with the network disabled

import time
import wave
from piper import PiperVoice

voice = PiperVoice.load(
    "/opt/piper-voices/en_US-lessac-medium.onnx",
    config_path="/opt/piper-voices/en_US-lessac-medium.onnx.json",
)

text = "Open source software lets anyone read, modify, and redistribute the code."

t0 = time.time()
with wave.open("/work/output.wav", "wb") as wav_file:
    voice.synthesize_wav(text, wav_file)
elapsed = time.time() - t0

with wave.open("/work/output.wav", "rb") as wav_file:
    duration = wav_file.getnframes() / wav_file.getframerate()

print(f"synthesis time: {elapsed:.2f}s")
print(f"audio duration: {duration:.2f}s")
podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work piper-sandbox \
  python tts_demo.py

The -v option makes the specified directory available for reads and writes inside the container. Run the command in an empty directory reserved for the experiment.

The command returned:

synthesis time: 1.51s
audio duration: 4.47s
sample rate: 22050 Hz

The program generated 4.47 seconds of speech in 1.51 seconds. The 1.51-second synthesis time is shorter than the 4.47-second audio duration, so Piper met its design goal of running faster than real time. I loaded the generated file, confirmed the format RIFF/WAVE, 16bit PCM, mono, 22050Hz, and found no corruption. I did not evaluate speech intelligibility as part of this record.

Synthesize speech without sending text outside your company

An app can send the text it converts to speech to an external service. Piper keeps the model on your system, so the app can synthesize speech without sending the text outside your company. I confirmed that Piper runs faster than real time, which makes it an option for applications that need real-time performance.

Sources

*1 Piper (GitHub), https://github.com/rhasspy/piper, MIT License