Back to Home

TTS on Repka-Pi: eSpeak NG and Piper

The article describes TTS implementation on Repka-Pi 4 with eSpeak NG and Piper TTS. Installation instructions, CLI/Python integration, and FastAPI server with queue are provided. Suitable for IoT and voice assistants.

Piper TTS speech synthesis on Repka-Pi 4
Advertisement 728x90

Speech Synthesis on Microcomputers: From eSpeak NG to Piper TTS

Microcomputers like Repka-Pi 4 can handle neural network-based speech synthesis. This article explores TTS systems eSpeak NG and Piper TTS: installation, CLI and Python execution, and building an asynchronous HTTP server using FastAPI. The approach is ideal for voice assistants, smart devices, and embedded projects.

Evolution of TTS Technologies

Speech synthesis has evolved from mechanical devices to neural network models. In the late 18th century, mechanical vocal tract analogs with diaphragms and bellows mimicked vocal tones—exemplified by the 1846 Euphonia with keys and acoustic components.

The electronic era began with Bell Labs' Voder (1930), where tone generators, noise sources, and filters were controlled via keyboard. Pattern Playback (1940s–1950s) reproduced spectrograms. In 1961, IBM 704 modeled a vocal tract to sing "Daisy Bell." Japan’s first formant-based TTS emerged in 1968. MUSA (1975–1978) delivered real-time Italian speech.

Google AdInline article slot

From the 1980s: formant synthesis with phonemes. From the 1990s: statistical methods. From the 2010s: end-to-end neural networks like VITS.

Lightweight eSpeak NG TTS

eSpeak NG is an open-source, formant-based TTS without real voice samples. Output sounds robotic but demands minimal resources—ideal for Repka-Pi 4 with 2 GB RAM. Perfect for alerts and prototypes.

Installation and CLI Usage

Update packages and install:

Google AdInline article slot
apt update
apt install espeak-ng

Check available voices:

espeak-ng --voices | grep Russian

Synthesize text:

espeak-ng "Hello Repka Pi" -v ru

Multi-line text via heredoc:

Google AdInline article slot
espeak-ng -v ru -s 150 << EOF
Hello world!
This very long text,
that takes several lines.
EOF

From file with female voice:

espeak-ng -v ru+f5 -s 150 -f hello-repka-pi.txt

Voices: ru, ru+m1..m7, ru+f1..f5.

Integration with Python

Function for subprocess execution:

import subprocess

def say(text, voice="ru", speed=150, pitch=50):
    """
    voice — language/voice (ru, en, de).
    speed — 80–200.
    pitch — 0–99.
    """
    try:
        subprocess.run([
            "espeak-ng",
            "-v", voice,
            "-s", str(speed),
            "-p", str(pitch),
            text
        ], check=True, capture_output=True)
    except FileNotFoundError:
        print("espeak-ng not found. Install: sudo apt install espeak-ng")
    except subprocess.CalledProcessError as e:
        print("Error:", e.stderr.decode())

if __name__ == "__main__":
    say("Hello! This test of a Russian voice.", voice="ru", speed=140)
    say("Hello, this is a test in English", voice="en-us", speed=160, pitch=60)
    say("Testing another Russian voice", voice="ru+f3", speed=135)

Run with: python3 espeak-ng-test.py.

Neural Network-Based Piper TTS

Piper TTS uses VITS (Variational Inference with adversarial learning for end-to-end TTS) and ONNX models to deliver natural-sounding, real-time speech on microcomputers. Performance exceeds eSpeak NG, with acceptable latency on Repka-Pi 4.

Installation and Model Setup

Virtual environment:

sudo apt update
sudo apt install python3-pip
python3 -m venv ~/piper_env
source ~/piper_env/bin/activate
pip install --upgrade pip
pip install piper-tts sounddevice numpy

Download the Russian model (denis-medium):

mkdir -p ~/piper-voices/ru
cd ~/piper-voices/ru
wget https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/ru/ru_RU/denis/medium/ru_RU-denis-medium.onnx?download=true -O ru_RU-denis-medium.onnx
wget https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/ru/ru_RU/denis/medium/ru_RU-denis-medium.onnx.json?download=true -O ru_RU-denis-medium.onnx.json

CLI and Python Execution

Synthesize to WAV:

piper --model ~/piper-voices/ru/ru_RU-irina-medium.onnx --output_file large_text.wav <<EOF
Hello world!
This very long text...
EOF
aplay large_text.wav

From file: piper --model model.onnx --output_file output.wav -f input.txt.

Python integration mirrors eSpeak NG—use piper via subprocess or native API.

FastAPI TTS Server

Build an async server to manage request queues. Run as a systemd service on Repka-Pi 4.

  • Benefits: Clients send HTTP POST requests without waiting; server queues tasks.
  • Stack: FastAPI, Piper TTS, task queue.

Server code example:

from fastapi import FastAPI

import queue
import threading
from piper import PiperVoice

app = FastAPI()
voice = PiperVoice.load("~/piper-voices/ru/ru_RU-denis-medium.onnx")
task_queue = queue.Queue()

def process_queue():
    while True:
        text = task_queue.get()
        wav = voice.synthesize(text)
        # Save or stream
        task_queue.task_done()

threading.Thread(target=process_queue, daemon=True).start()

@app.post("/synthesize")
async def synthesize(text: str):
    task_queue.put(text)
    return {"status": "queued"}

systemd unit file:

[Unit]
Description=Piper TTS Server
After=network.target

[Service]
ExecStart=/path/to/server.py
Restart=always

[Install]
WantedBy=multi-user.target

Client: curl -X POST http://repka-pi:8000/synthesize -d 'Text for synthesis'.

Key Takeaways

  • eSpeak NG: low footprint, formant synthesis, ideal for weak hardware.
  • Piper TTS: VITS/ONNX for natural speech, real-time on SBCs.
  • FastAPI server: async queue, systemd auto-start.
  • Use cases: voice assistants, IoT, robots on Repka-Pi 4/5.
  • Repka-Pi 5: up to 32 GB RAM, twice the performance vs Raspberry Pi 5 for TTS+ASR.

— Editorial Team

Advertisement 728x90

Read Next