🎙️ Piper HTTP 🎙️
Dockerized HTTP service for Piper Text-to-Speech
Overview 📖
A Docker image that runs the Piper HTTP service from the Rhasspy project. This containerized solution provides a simple HTTP API for high-quality neural text-to-speech synthesis, with automatic voice model downloads and easy deployment. No complex setup required - just pull the Docker image and start converting text to speech.
Features 🚀
- • Fully containerized Piper TTS HTTP service
- • Automatic voice model downloads from Hugging Face
- • Simple REST API for text-to-speech conversion
- • Multi-language voice support
- • Available on Docker Hub for instant deployment
- • Includes Python client example for easy integration
Quick Start - Server Setup 🚀
Build from source:
Build from source
$ docker build -t piper .
$ docker run --name piper -p 5000:5000 piperOr use pre-built image from Docker Hub:
Docker Hub (pre-built image)
$ docker run -e MODEL_DOWNLOAD_LINK=https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/kusal/medium/en_US-kusal-medium.onnx?download=true --name piper -p 5000:5000 artibex/piper-httpQuick Start - Client Usage 🎯
Use the included Python client script to send text to the Piper service and play the generated audio:
Install dependencies:
Install Python dependencies
$ pip install requests playsoundPython client example (piper-tts.py):
piper-tts.py
import os
import sys
import requests
import random
from playsound import playsound
# Take textToSpeak as argument
if len(sys.argv) < 2:
print("Usage: python piper-tts.py \"Hello World!\"")
sys.exit(1)
textToSpeak = sys.argv[1]
urlPiper = "http://localhost:5000"
# Create random filename for output
outputFilename = "output" + str(random.randint(1,1000000)) + ".wav"
# Create the payload
payload = {'text': textToSpeak}
# Send request to piper
try:
r = requests.get(urlPiper, params=payload)
r.raise_for_status()
except requests.exceptions.RequestException as e:
print(f"Could not send request to piper: {e}")
sys.exit(1)
# Save the response to a file
with open(outputFilename, 'wb') as fd:
for chunk in r.iter_content(chunk_size=128):
fd.write(chunk)
# Play the audio
playsound(outputFilename)
# Clean up
os.remove(outputFilename)Usage examples:
Usage examples
$ python piper-tts.py "Hello World!"
$ python piper-tts.py "Welcome to Piper TTS"