How to Install Piper TTS on Docker for Local, Offline Text-to-Speech



Picture a familiar annoyance: you need narration for a video or an internal announcement, so you paste a script into an online TTS service, wait in a queue, and download the result under some limit. If the script contains internal material, there is a second discomfort — the text just left your machine. Piper flips that around. Its synthesis engine runs on your own computer, and not a single sentence goes to an outside service.

Piper is a fast, local neural text-to-speech engine. It turns text into phonemes with espeak-ng, then synthesizes a waveform from those phonemes using a model exported to ONNX Runtime. In practice, you hand it text, pick a voice, and get a WAV file back. Because everything stays local, it fits narration work, scheduled announcements, voice-assistant prototypes, or turning a long article into audio you can listen to while doing something else.

One clarification belongs up front. The original Piper repository at rhasspy/piper is now archived, and development has moved to OHF-Voice/piper1-gpl. The Piper project itself does not publish an official Docker image you can simply pull for this purpose. So the Dockerfile in this guide is a generic container of my own making: its base is python:3.12-slim, and what gets installed inside is the official piper-tts package from Piper's own documentation. The Piper commands inside — the pip install, the voice downloader, the CLI, and the HTTP server — all come from that official documentation, not from an obscure third-party image.

What you need

The setup is short: a machine with Docker and Docker Compose, internet access only for the initial downloads, and a few hundred megabytes of free disk for the base image plus one voice. Piper runs on CPU, so no GPU is required. The documentation mentions a --cuda option, which needs the onnxruntime-gpu package — but this guide stays on CPU, so there is nothing GPU-related to configure.

Create a project folder and move into it:

mkdir piper-tts-docker
cd piper-tts-docker

This folder will hold three things: a Dockerfile, a docker-compose.yml, and two data folders — voices/ for voice models and output/ for synthesized WAV files. Keeping data in volumes outside the container means your voices survive when the container is removed and recreated.

Step 1: write the generic Dockerfile

Create a file named Dockerfile with this content:

FROM python:3.12-slim
WORKDIR /app
RUN pip install --no-cache-dir "piper-tts[http]"
CMD ["python3", "-m", "piper.http_server", "--host", "0.0.0.0", "--port", "5000", "-m", "en_US-lessac-medium", "--data-dir", "/app/voices"]

Line by line: FROM python:3.12-slim picks a lightweight Python base image; WORKDIR /app sets the working directory inside the container; the pip install line installs Piper with its HTTP dependencies, following the official install command (pip install piper-tts[http]); and CMD starts Piper's HTTP server on port 5000 with the en_US-lessac-medium voice, reading voice data from /app/voices.

An honest note here: this Dockerfile is your own recipe, not an official Piper artifact. The upside is that you know exactly what is inside the container, and you can swap the voice or the port without waiting for anyone else's image release. The trade-off is that keeping the base image and package versions current is on you.

Step 2: write docker-compose.yml

Create docker-compose.yml in the same folder:

services:
  piper:
    build: .
    container_name: piper-tts
    ports:
      - "5000:5000"
    volumes:
      - ./voices:/app/voices
      - ./output:/output
    restart: unless-stopped

The 5000:5000 port mapping exposes the server inside the container at localhost:5000 on the host. The ./voices:/app/voices volume holds voice models, while ./output:/output is ready for WAV files from the one-shot CLI mode covered in step 5. restart: unless-stopped brings the container back after a host reboot, unless you stopped it deliberately.

Build the image:

docker compose build

The expected result: the build finishes without errors, and docker images shows your project image. If the build fails at the pip install stage, the most common cause is a momentary network drop — just run it again, since there is no half-built state you need to clean up manually here.

Step 3: download one voice

Piper cannot speak without a voice model, and every voice always comes as a pair of files: an .onnx model file and an .onnx.json config file with the same name. The official documentation uses en_US-lessac-medium as its example voice, so use that for the first run. Download it into the volume with this one-shot command:

docker compose run --rm piper python3 -m piper.download_voices en_US-lessac-medium --data-dir /app/voices

This runs a temporary container, downloads the voice to /app/voices (mapped to the voices/ folder on the host), then removes the temporary container when it finishes. Check the result on the host:

ls -lh voices/

The expected result: en_US-lessac-medium.onnx and en_US-lessac-medium.onnx.json both sitting in that folder. If only one of them shows up, do not move on — download again, because Piper needs the complete pair.

To see the full list of available voices, the official documentation provides this command:

python3 -m piper.download_voices

Run it inside the container if you want to browse alternatives. Piper's official list covers many languages, including Indonesian under the code id_ID. Copy the voice name exactly as it appears in that list; do not guess a voice filename, because a single wrong letter is enough to make a download fail or a voice go unrecognized.



Step 4: start the HTTP server and synthesize your first audio

Now start the service in the background:

docker compose up -d
docker compose ps

The expected result: the piper-tts container shows as running. Check its logs if you want to confirm the server actually came up:

docker compose logs -f piper

Press Ctrl+C to stop watching the logs; the container keeps running, since logs -f only follows output rather than stopping the service.

Test the server with its info endpoint:

curl localhost:5000/info

The expected result: a JSON response naming the voice, its language, and its speaker count. If curl cannot connect, check two things: whether the container is actually running (docker compose ps), and whether port 5000 on the host is already taken by another application. If the port clashes, change the mapping in docker-compose.yml to something like "5001:5000", run docker compose up -d again, and reach the server on port 5001 instead.

Your first synthesis over HTTP, following the official documentation:

curl -X POST -H 'Content-Type: application/json' -d '{ "text": "This is a test." }' -o test.wav localhost:5000/synthesize

This posts text to the /synthesize endpoint and saves the result as test.wav in your working folder. Inspect the file:

ls -lh test.wav
file test.wav

The expected result: a file tens to hundreds of kilobytes in size (depending on text length), which file identifies as RIFF/WAVE audio data. Play it with any audio player on your machine. If the file is suspiciously tiny or will not play, check the container logs — the usual cause is an incompletely downloaded voice, or a voice name in CMD that does not match what is in /app/voices.

You can also open the web interface at http://localhost:5000 in a browser: type some text, press Speak, and listen right away. That page also shows voice information and the synthesis time of the most recent utterance, which is handy when comparing speeds across voices.

Step 5: one-shot CLI mode for batch scripts

The HTTP server suits repeated use, because the model loads once and stays warm. For turning a single long script into one file, though, the one-shot CLI mode is more direct. The official documentation gives this pattern:

python3 -m piper -m en_US-lessac-medium -f test.wav -- 'This is a test.'

Inside the Docker container, the same pattern runs through docker compose run, with the output folder mapped to the host:

mkdir -p output
docker compose run --rm piper python3 -m piper -m en_US-lessac-medium --data-dir /app/voices -f /output/narration.wav -- 'Welcome to this guide. All audio here is generated locally, with no cloud service involved.'

The expected result: output/narration.wav appears on the host and plays normally. For longer scripts, save the text to a file and use the --input-file option mentioned in the documentation, or split the script into paragraphs and join the WAV files later with an audio tool like FFmpeg. Other useful options from the documentation: --sentence-silence to add pauses between sentences, --volume to set a volume multiplier (default 1.0), and --speaker to pick a speaker on a multi-speaker voice.

Common problems and how to fix them

A few snags come up again and again on a first Piper-in-Docker run. First, the server runs but produces no speech: almost always, the .onnx and .onnx.json pair in the voice folder is incomplete. Second, the container exits immediately: read its logs with docker compose logs piper — often the voice name in CMD is not found in --data-dir. Third, curl refuses to connect while the container is running: check the port mapping and make sure you are hitting the host port, not the wrong in-container port. Fourth, the speech sounds right but the pacing feels off: look at the length_scale setting (via JSON in HTTP mode, or the matching CLI option) before blaming the model, since defaults can feel quite different from voice to voice.

One limitation is worth noting: because the HTTP server loads a single voice through the -m option, switching voices means changing the CMD or server command and restarting the container. For multi-voice work that changes often, the one-shot CLI mode per voice is usually simpler than maintaining several server containers.

Summary

PartDetail
TTS enginePiper, official piper-tts package from the project's documentation
ContainerGeneric, self-written Dockerfile on python:3.12-slim — not an official Piper Docker image
Example voiceen_US-lessac-medium, two files: .onnx and .onnx.json
HTTP serverpython3 -m piper.http_server, port 5000, /synthesize and /info endpoints
CLI modepython3 -m piper -m <voice> -f <file.wav> -- '<text>'
Data folders./voices for models, ./output for WAV files
HardwareCPU is enough; GPU is optional via --cuda and onnxruntime-gpu

Final checklist

  • docker compose build finishes without errors.
  • The voices/ folder holds the .onnx and .onnx.json pair for your chosen voice.
  • docker compose ps shows the piper-tts container running.
  • curl localhost:5000/info returns voice JSON.
  • A curl call to /synthesize produces a playable WAV file.
  • The one-shot CLI mode produces a file in output/.
  • The container is stopped with docker compose down when not in use, freeing port 5000.

Once every box is ticked, you have a local TTS service other applications can call over HTTP, or use occasionally through the CLI, with no script ever leaving your machine. A sensible next step: try an Indonesian voice from the official list, then run a longer script to judge the pauses between sentences.

Which voice would you try first — an English voice like en_US-lessac-medium, or an Indonesian voice from Piper's official list? Tell us in the comments, including what you plan to use the audio for.

Read also: Faster-Whisper on Docker: Local Audio and Video Transcription Without Sending Files to the Cloud, and the companion article in this batch at https://blog.rnevio.com/2026/10/how-to-install-comfyui-in-docker-with.html.

Diskusi

Ada pertanyaan atau pengalaman yang ingin dibagikan?

0komentar

Komentar ditinjau sebelum ditampilkan. Mari berdiskusi dengan sopan dan sesuai topik.