- Go 75%
- Python 13%
- Shell 8%
- TypeScript 4%
- Makefile <1%
zegff #
zegff reads text aloud with Piper — but
not blindly. The text is analysed first (language, tone, subject, code), and
based on that it picks one voice, translates if needed, and cleans up the text
so it is speakable.
Requirements #
- Go to build
piper-ttswith at least one voice model- an OpenAI-compatible LLM endpoint: OpenRouter, OpenAI, Groq, … (key in the environment), or a local Ollama — this does the translation and rewriting
- analysis (jev): TypeSafe SystemOne with a key in the environment
(
TYPESAFE_AI_API_KEY), or run it locally through the same LLM as above ([jev] provider = "llm"), or skip it (provider = "off") - an audio player:
ffplay,pw-play,paplayoraplay - optional: the zegd broker for queued, one-by-one playback — the default route when its socket is reachable; without it zegff warns once and synthesizes locally (see below)
Installation #
On Arch: build and install the package:
cd packaging
makepkg -si # builds the CLI from the local checkout, installs to /usr
The package ships the CLI (zegff), the zegd broker with a user unit,
say and inflect-tts, plus example configs and docs. It also carries the
agent integration files — skill/zegff/SKILL.md,
skill/zegff-voice/SKILL.md (spoken-output shaping: no markup, numbered
summaries) and extensions/zegff-voice.ts
— under /usr/share/zegff/agent/; enable them per user by pointing pi at those
paths in ~/.pi/agent/settings.json (skills/extensions accept absolute
paths), or by copying them into ~/.agents/skills/ and ~/.pi/agent/extensions/
(see the post-install hint for the exact lines).
From a git checkout (with Go installed):
git clone <repo-url> zegff && cd zegff
./install.sh # builds into ~/.local/bin (or a prefix you pick), writes an example config, checks requirements
The installer asks two things (skipped when non-interactive, e.g. curl | bash):
where to put the binaries (default ~/.local/bin, or pass it directly:
./install.sh /usr/local), and whether to also install the agent skills
(skill/zegff/SKILL.md → ~/.agents/skills/, so coding agents know how to
use zegff).
Manual install also works:
go build -o ~/.local/bin/zegff .
mkdir -p ~/.config/zegff
cp config.example.toml ~/.config/zegff/config.toml
Requirements per component #
| component | Arch | other systems |
|---|---|---|
piper-tts |
pacman -S piper-tts |
piper releases |
| voices | pacman -S piper-voices-common piper-voices-nl-be piper-voices-en-us |
download from HuggingFace and adjust the model paths in the config |
| LLM endpoint | OpenRouter/OpenAI/Groq: API key in the env · Ollama: pacman -S ollama |
any OpenAI-compatible /v1 |
| analysis | typesafe key (TYPESAFE_AI_API_KEY=…), or [jev] provider = "llm" (same LLM as [generate]), or "off" |
— |
| player | ffplay (ffmpeg), pw-play, paplay or aplay |
Without a voices package you download a voice yourself, for example:
base=https://huggingface.co/rhasspy/piper-voices/resolve/main
d=~/.local/share/piper-voices/nl/nl_BE/nathalie/medium
mkdir -p "$d"
curl -L "$base/nl/nl_BE/nathalie/medium/nl_BE-nathalie-medium.onnx" -o "$d/nl_BE-nathalie-medium.onnx"
curl -L "$base/nl/nl_BE/nathalie/medium/nl_BE-nathalie-medium.onnx.json" -o "$d/nl_BE-nathalie-medium.onnx.json"
and put that path in model = "…" of the [[voices]] block in your config.
mand #
The companion tool mand — runs a shell command (or reads piped output)
and reduces it to at most six words, with a --hint to steer what to extract
— lives in its own repo; see the tangled mand repository.
Building #
go build -o zegff .
Usage #
zegff "Hello world" # plays right away
zegff --file note.md # text from a file
echo "Hello there" | zegff # via stdin
zegff --out reading.wav --no-play "…" # just write a WAV
zegff --voice amy --verbose "…" # force a voice, show the analysis
| flag | meaning |
|---|---|
--file <path> |
text from a file |
--out <wav> |
write the WAV to this path |
--no-play |
don't play (requires --out) |
--voice <name> |
force a voice; skips the jev voice choice |
--prioritize-speed |
pick the fastest-engine voice (inflect < piper < kokoro) matching the detected language, instead of the jev choice; when the language is unknown (mixed/uncertain input), the jev choice is used |
--session-id <id> |
one sticky voice per session: zegd assigns distinct voices to active sessions and expires them after 30 idle minutes |
--session-topic <text> |
spoken as a preamble — "done" becomes "the pi-background extension reports: done"; sticky per session, also works without --session-id |
--zegd |
speak via the zegd broker even when disabled in config |
--no-zegd |
synthesize and play locally, skip the zegd broker |
--config <path> |
alternative config file (default ~/.config/zegff/config.toml) |
--strict |
fail instead of falling back when jev or the LLM step fails |
--verbose |
show analysis and choices on stderr |
-h, --help |
help |
Speaking via zegd (default on) #
With zegd reachable, zegff hands synthesis and playback to the broker by
default: analysis, rewriting and voice selection stay in zegff, zegd queues
the job and plays every clip strictly one by one — several zegff runs (or
say calls) never overlap. If the broker is unreachable, zegff warns and
synthesizes locally.
zegff "Morning brief, read this at breakfast" # via zegd, returns once queued
zegff --no-zegd "…" # force local synth+play
zegff --zegd "…" # demand zegd: fail instead of falling back
say --status # zegd shows what is queued/playing
Voice names must exist in zegd's config as well: zegff sends its
already-resolved voice and the broker treats a named voice as exact-or-error
(it verifies, never re-picks). Limitations: no prosody passthrough, and
--out/--no-play imply local synthesis — the WAV never reaches zegff in
zegd mode. See ADR 0007; [zegd] config keys: enabled (default true),
socket (default $XDG_RUNTIME_DIR/zegd.sock) and timeout (default
30s — it only bounds the enqueue exchange; zegd speaks at its own pace).
The broker itself lives in this repo under zegd/ (Python): install with
./zegd/install.sh (user-unit, recommended) or sudo ./zegd/install.sh --system (system-unit, headless); see zegd/README.md. On Arch the package
already includes zegd and its user unit — just systemctl --user enable --now zegd and copy the example config from /usr/share/zegd/.
Sessions (background jobs that announce themselves) #
Long-running helpers can own a voice: --session-id mike makes zegd bind
the session to one voice — every active session gets a different one
(fastest engine first, restricted to the detected language), and idle
sessions expire after [sessions].idle_timeout (default 30 min) so the
voice is freed. --session-topic "the pi-background extension" makes the
broker speak a preamble, so a bare notification becomes self-describing:
zegff --session-id mike --session-topic "the pi-background extension" "done"
# spoken as: "the pi-background extension reports: done" — in mike's voice
zegff --session-id mike "finished" # same voice, same preamble
say -s ci --topic "the CI pipeline" "still running"
Both flags are optional and independent; a topic without a session is a
one-shot preamble. --voice still wins over a session assignment. Without
the broker, sessions are ignored with a warning (same fallback as always).
Voicing pi itself (extension) #
extensions/zegff-voice.ts is a pi
extension: every pi session becomes a zegd session — it keeps a distinct
sticky voice — and when the toggle is on, each settled turn is spoken as
"<session topic> reports: done". The topic follows pi's session name
(/name pi-background → "the pi-background reports: done").
mkdir -p ~/.pi/agent/extensions && cp extensions/zegff-voice.ts ~/.pi/agent/extensions/
Toggle: /voice on|off inside pi, or the same state file the agent skill
uses — ~/.local/state/zegff/agent-voice (exists = on; default off). At
most two clips queue up, so a fast agent never leaves a stale backlog.
Configuration #
# The voices determine the target language: text is translated into the
# language of the voice that will speak it. Detection itself is not
# limited to the installed voices' languages.
[[voices]]
name = "nathalie"
lang = "nl"
model = "/usr/share/piper-voices/nl/nl_BE/nathalie/medium/nl_BE-nathalie-medium.onnx"
[[voices]]
name = "amy"
lang = "en"
model = "/usr/share/piper-voices/en/en_US/amy/medium/en_US-amy-medium.onnx"
[jev]
provider = "typesafe" # typesafe | llm | off
endpoint = "https://api.typesafe.ai/v1/systemone"
model = "jev-latest"
timeout = "15s"
# Analysis with an LLM instead of SystemOne — [jev.llm] picks its own
# provider/model independently of [generate] (tested with gemma3:1b on
# Ollama). Empty fields inherit [generate], but only when both run on the
# same provider:
#
# [jev.llm]
# provider = "ollama"
# model = "gemma3:1b"
#
# Or skip analysis entirely (first voice, neutral tone):
# provider = "off"
[generate]
provider = "openai" # openai | ollama — both OpenAI-compatible
model = "openai/gpt-oss-120b"
base_url = "https://openrouter.ai/api/v1"
api_key_env = "OPENROUTER_API_KEY" # default: OPENAI_API_KEY
timeout = "90s"
# ollama instead (local, no key):
# provider = "ollama"
# model = "gpt-oss:20b"
# base_url = "http://127.0.0.1:11434/v1" # default
[output]
player = "ffplay" # ffplay | pw-play | paplay | aplay
# log = "off" # or a custom run-log path (default ~/.local/state/zegff/log.jsonl)
[zegd]
# enabled = false # opt out: always synthesize and play locally
# socket = "" # "" = $XDG_RUNTIME_DIR/zegd.sock
# timeout = "30s" # bounds the enqueue exchange; zegd speaks at its own pace
Without a config file, zegff uses nathalie (nl) and amy (en). Add a
[[voices]] block per additional language for which you have downloaded a
Piper voice.
Analysis (jev) #
The analysis step classifies the text before it is spoken: language, best voice, tone, topic, and two probabilities (contains code, needs phonetic cleanup). Three providers:
| provider | what it does | needs |
|---|---|---|
typesafe (default) |
TypeSafe SystemOne structured-classification API | TYPESAFE_AI_API_KEY in the env; without a key the analysis is skipped |
llm |
one chat completion through the same library as [generate] — any OpenAI-compatible endpoint or local Ollama |
a model; configure via [jev.llm] |
off |
skip analysis: first voice, neutral tone, cleanup forced on | nothing |
With [jev.llm] you can run the analysis on a different provider than the
rewriting — for example a local gemma3:1b on Ollama for analysis while
[generate] stays on OpenRouter:
[jev]
provider = "llm"
timeout = "60s" # local CPU models need more than the 15 s default
[jev.llm]
provider = "ollama" # omit to inherit the [generate] provider
model = "gemma3:1b"
Empty [jev.llm] fields inherit [generate], but only when both run on the
same provider (a cross-provider inherit would send an Ollama call to the
OpenRouter endpoint). Small local models classify well but detect the input
language less reliably than SystemOne.
Language and voice selection #
- One voice configured → all text is translated into that voice's language.
- Multiple voices → the language of the text determines the voice; if it doesn't fit, jev picks the best match and translation happens.
--voiceoverrides the choice; translation then still happens into the language of that voice.- Detection is independent of the installed voices: a Dutch text with only English voices installed is still detected as Dutch and translated. A low-confidence detection (< 0.6, SystemOne only) is treated as unknown and spoken as-is — acting on a guess risks translating into the wrong target or feeding the rewriter the wrong language.
- If the text contains code blocks, the model replaces them with a short description that fits the running text; abbreviations and difficult names are spelled out phonetically.
Kokoro voices (engine = "kokoro") #
Piper is fast, but the 82M Kokoro model sounds clearly better for English. Kokoro has no Dutch — keep nathalie (piper) for that. Voices run via sherpa-onnx:
# 1. the runner (Arch: paru -S sherpa-onnx, or grab a prebuilt binary from
# the sherpa-onnx releases and put it in ~/.local/bin)
# 2. the model (~350 MB):
mkdir -p ~/.local/share/zegff && cd ~/.local/share/zegff
curl -LO https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/kokoro-multi-lang-v1_0.tar.bz2
tar xjf kokoro-multi-lang-v1_0.tar.bz2
Then add a kokoro voice next to your piper ones:
[[voices]]
name = "heart" # kokoro speaker af_heart
lang = "en"
engine = "kokoro"
model = "~/.local/share/zegff/kokoro-multi-lang-v1_0/model.onnx"
bank = "~/.local/share/zegff/kokoro-multi-lang-v1_0"
sid = 3 # 0 af_alloy, 2 af_bella, 3 af_heart, 21 bf_emma, 25 bm_fable, …
Pick it with --voice heart. Tone controls the speaking rate via kokoro's
--speed (inverse of piper's length scale); all kokoro speakers are listed in
the sherpa kokoro docs.
Tone variants #
Each [[voices]] block may carry [voices.variants.<tone>] sub-tables that
override model, bank and sid per tone — name, lang and engine
always inherit from the parent voice. Tones are neutraal (the parent voice
itself), vrolijk, serieus, verdrietig, boos, enthousiast; jev picks
the tone per message automatically and zegd merges the variant over its own
config copy (unknown variant = enqueue error). When speaking via the
broker, the variants table must live in zegd's config too — the
broker merges its own copy and errors on a variant it cannot see. See
ADR 0008.
Inflect voices (engine = "inflect") #
Inflect-Nano-v2 is a 4M-parameter VITS model — 16 MB, English only, one fixed male voice, Apache-2.0. On an i5-8250U it measured RTF ≈ 0.3 (faster than realtime), about 3× faster than kokoro, and each seed synthesises bit-identical audio. Quality is below kokoro; use it when speed or footprint matters more than the voice. Setup:
# 1. model (~36 MB with code, via huggingface_hub):
python3 -c "from huggingface_hub import snapshot_download; snapshot_download('owensong/Inflect-Nano-v2', local_dir='$HOME/.local/share/zegff/inflect-nano-v2', allow_patterns=['*.py','*.json','*.pth','runtime/**'])"
# 2. a venv with CPU torch next to the model (the wrapper expects venv/bin/python):
python3 -m venv ~/.local/share/zegff/inflect-nano-v2/venv
~/.local/share/zegff/inflect-nano-v2/venv/bin/pip install --index-url https://download.pytorch.org/whl/cpu torch
~/.local/share/zegff/inflect-nano-v2/venv/bin/pip install num2words unidecode phonemizer espeakng-loader soundfile numpy scipy huggingface-hub
# 3. the wrapper:
cp scripts/inflect-tts ~/.local/bin/
Then add the voice:
[[voices]]
name = "nano"
lang = "en"
engine = "inflect"
model = "~/.local/share/zegff/inflect-nano-v2"
The first run starts a warm daemon (<model>/serve.py on a unix socket) that
keeps the model loaded, so follow-up runs skip the ~10 s torch/model startup
and synthesize faster than realtime (measured RTF 0.5–1 vs ~3 cold). The
daemon exits after 30 idle minutes (tune with INFLECT_IDLE_SECS) and the
wrapper falls back to one-shot synthesis if it cannot run. Budget ~1 GB RAM
while it is resident.
Using zegff/voice as a library #
The voice system — declarative [[voices]] config, piper/kokoro/inflect engines,
language/name selection, tone-based prosody — is a public package, so other
programs can reuse it without any of zegff's analysis code:
import "zegff/voice"
voices, _ := voice.LoadVoices("/etc/myapp/voices.toml") // full zegff config works
if len(voices) == 0 {
voices = voice.Defaults()
}
v, err := voice.Select(voices, "en", "", "") // by language; (voices, lang, preferred, forced)
err = voice.Runner{}.Synthesize(ctx, v, "/tmp/out.wav", "hello", voice.ProsodyForTone("vrolijk"))
// engine binaries default from PATH; override Runner fields only for stubs or non-PATH installs
The module is named zegff; import it with a replace directive or a go work
entry until it is published under a fetchable path.
Tone → prosody #
Piper has no emotion tags; tone only controls the speaking rate:
| tone (config value) | length_scale |
|---|---|
enthousiast (enthusiastic) |
0.98 |
boos (angry) |
0.98 |
vrolijk (cheerful) |
1.00 |
neutraal (neutral, default) |
1.08 |
serieus (serious) |
1.13 |
verdrietig (sad) |
1.23 |
Run log #
Every run appends one JSON line to ~/.local/state/zegff/log.jsonl
(override with [output] log = "path", disable with log = "off"): input
chars/words, voice + engine (zegd when the broker played it), detected vs
target language, tone, per-stage timings (analysis, rewrite, synthesis,
total; in zegd mode synth_ms is the whole round trip including playback)
and the produced audio duration (empty in zegd mode — the WAV never reaches
zegff). Failed syntheses are logged with an error field. Handy for
watching what the LLM stages cost you versus the synth itself:
tail -1 ~/.local/state/zegff/log.jsonl | jq .
Development #
go test ./...
go vet ./...
Architecture decisions are recorded as ADRs in docs/adr/
(one file per decision, oldest first); research notes live in
docs/research/.