Repository navigation
Home
Tonic is an early-alpha, patent-free, from-scratch speech synthesis (TTS), finite-grammar speech recognition (ASR), and Windows SAPI 5 (sapi.dll) engine written entirely in pure Zig (0.17.1+) under the Apache License 2.0 for Pisco and Vodka.
Every subsystem — English text normalization, rule-based grapheme-to-phoneme conversion, 22050 Hz Klatt-style formant synthesis, W3C SSML and SAPI 5 XML prosody parsing, 512-point Radix-2 FFT, 26-band Mel filterbank, 26-dimensional CMVN + Delta MFCC feature extraction, adaptive noise-floor VAD, W3C SRGS and SAPI 5 XML grammar parsing, multi-rate Sakoe-Chiba banded DTW command recognition, optional runtime Linux libspeechd.so.2 bridging, dynamic Windows winmm.dll audio plumbing, and Windows COM SAPI 5 vtables — is original pure-Zig code with zero GPLv3 dependencies and zero prebuilt binary blobs.
The repository produces a native Linux CLI (tonic), a native Linux shared library (libtonic.so), and freestanding multi-architecture Windows PE sapi.dll binaries (x86_64-windows, i386-windows, and aarch64-windows) from a single zig build invocation.
Important
Early-Alpha Status (0.1.0-dev):
Active development takes place on the unstable branch, while stable is tracked by Pisco.
-
Intelligible, Lightweight Formant TTS: Tonic's built-in Klatt-style synthesizer is compact, deterministic, and dependency-free, producing classic robotic formant speech suitable for accessibility prompts, HUD callouts, and headless testing. On Linux hosts with
speech-dispatcher(libspeechd.so.2) installed, Tonic can optionally delegate plain-text playback to host voices at runtime without bundling any copyleft code. -
Finite-Grammar Voice Commands (Not Open Dictation):
GrammarRecognizeris engineered for closed-vocabulary command grammars typical of Windows games usingISpRecoGrammar(such as tactical squad or cockpit voice commands). Multi-rate synthetic templates, 26-dim CMVN + Delta MFCCs, and adaptive noise-floor VAD improve robustness across speaking speed, pitch, and ambient noise, though Tonic does not attempt unconstrained continuous dictation or large neural acoustic models. -
Remaining SAPI 5 Gaps: Compiled binary SAPI CFG rule-graph deserialization (
SPBINARYGRAMMAR), live recognition audio retention/serialization (ISpRecoResult::GetAudio,Serialize,SpeakAudio,ScaleAudio,ISpPhrase::GetSerializedPhrase,ISpRecoContext::DeserializeResult), andISpRecoGrammar::SaveCmdare not yet implemented.
-
From-Scratch Klatt Formant TTS (
src/tts/): 42 ARPAbet-style phonemes (PHONEME_COUNT = 42), English text normalizer (0..999integers, digit-by-digit larger numbers, common abbreviations, punctuation pauses), high-frequency exception lexicon + rule-based English G2P, Rosenberg-style glottal pulse with declination and question-rise pitch contours, 32-bit Galois LFSR fricative noise source, 3-stage cascaded biquad resonators (F1,F2,F3) with smooth boundary interpolation, SAPI rate (-10..+10), volume (0..100), and pitch controls, plus a standard 44-byte RIFF WAV writer. -
W3C SSML & SAPI 5 XML Prosody (
src/tts/ssml.zig): Segment parser supporting<rate>,<volume>,<pitch>,<prosody>,<break>, and<silence>tags (up to 32 nesting levels and 10,000 ms silence durations) with XML entity decoding and exact per-segment prosody application. -
Pure-Zig Finite-Grammar ASR (
src/asr/): 512-point iterative Radix-2 Cooley-Tukey FFT, 0.97 pre-emphasis, 25 ms Hamming window with 10 ms hop, 26-band triangular Mel filterbank, DCT-II, per-utterance CMVN (C1..C12), first-order regression Delta MFCCs (26-dim feature frames), adaptive 20th-percentile noise-floor VAD with stationary-noise rejection, and Sakoe-Chiba banded DTW across multi-rate (-2,0,+2) synthetic or caller-supplied acoustic templates. -
W3C SRGS, SAPI 5 XML & Phrase-List Grammars (
src/asr/srgs.zig): Bounded grammar expander supporting<grammar>,<rule>,<one-of>,<item>,<ruleref>(W3C SRGS) and<GRAMMAR>,<RULE>,<L>,<P>,<O>,<RULEREF>(SAPI 5 XML), UTF-8 and UTF-16LE encodings, plain newline-separated phrase lists, cyclic<ruleref>guards, and safe non-crashing handling of compiled binary SAPI CFG blobs. -
Multi-Arch Windows PE
sapi.dll(src/sapi/,src/com/): Cross-compiled freestanding (link_libc = false) tox86_64-windows,i386-windows, andaarch64-windowswith comptime-verified COM vtable slot offsets. ImplementsIClassFactory,ISpVoice(withSPF_ASYNC,WaitUntilDone,SPF_PURGEBEFORESPEAK,SPEI_WORD_BOUNDARY, SSML,SpeakStream, and dynamicwinmm.dllwaveOutplayback),ISpRecognizer(with live 16 kHzwinmm.dllwaveIncapture + streaming VAD andEmulateRecognition),ISpRecoContext,ISpRecoGrammar,ISpRecoResult,ISpPhrase, all 5ISpNotifySourcedelivery mechanisms, and built-in object token enumeration (Tonic English). -
Optional Runtime Linux Host Speech Bridge (
src/host/bridge.zig): Dynamically probeslibspeechd.so.2(speech-dispatcher) viadlopenwhenTONIC_NO_HOST_SPEECHis unset, mapping SAPI rate and volume cleanly and falling back to the built-in formant synthesizer wheneverspeech-dispatcheris absent or disabled. -
Native Linux CLI & C ABI Shared Library: Ships
tonic(info,speak,recognize) andlibtonic.so(tonic_version,tonic_sample_rate,tonic_synthesize_pcm16,tonic_free_pcm16) for standalone scripting, diagnostics, and host runtime integration.
Requires Linux and Zig 0.17.1+:
git clone https://github.com/buntatoes/tonic.git
cd tonic
# Run the full unit test suite across all modules
zig build test --summary all
# Build native Linux CLI, libtonic.so, and multi-arch Windows PE sapi.dll
zig build -Doptimize=ReleaseSafe
# Inspect engine capabilities and host speech-dispatcher bridge status
./zig-out/bin/tonic info
# Synthesize plain text or SSML to a 22050 Hz 16-bit mono WAV file
./zig-out/bin/tonic speak "Systems online. All 42 sensors ready." --wav output.wav
./zig-out/bin/tonic speak '<speak>Shields <break time="200ms"/> <prosody pitch="high">online</prosody></speak>' --wav ssml.wav
# Recognize a WAV recording against an SRGS XML, SAPI 5 XML, or phrase-list grammar
./zig-out/bin/tonic recognize command.wav --grammar commands.xml
# Force the built-in formant synthesizer (skip host speech-dispatcher probe)
TONIC_NO_HOST_SPEECH=1 ./zig-out/bin/tonic speak "Hello from Tonic." --rate 2 --volume 90| Project | Role | License | Links |
|---|---|---|---|
| Tonic | Standalone SAPI 5 (sapi.dll) speech synthesis (Klatt formant TTS, SSML, optional host libspeechd bridge) & finite-grammar MFCC/DTW voice-command engine written from scratch in Zig |
Apache-2.0 | Repository |
| Pisco | Steam Play compatibility tool, zero-Python native Zig launcher, build/deploy tooling, and code generators | Apache-2.0 (original Zig code) + upstream Proton/submodule licenses | Repository · Wiki |
| Vodka | Standalone Windows compatibility runtime (0.1) built from scratch in Zig & inline assembly (vodkaserver, PE loader, Wayland, audio, Win32 DLLs) |
Apache-2.0 | Repository · Wiki |
| Bitters | Standalone Direct3D 8–12 & DXGI to Vulkan 1.4 graphics translation layer written from scratch in Zig (early alpha) | Apache-2.0 | Repository |
| Coupe, Potato, & Tumbler | Companion Zig SIMD math (libgraphene-1.0), XR 1.1 loader/bridge, and AV1 decoder (libdav1d C-ABI) libraries |
Apache-2.0 (PATENTS.AV1 for Tumbler) |
Coupe · Potato · Tumbler |
If you encounter a speech synthesis, voice-command recognition, or SAPI 5 compatibility issue in a game or standalone workload, please open a GitHub issue on buntatoes/tonic (or buntatoes/pisco for Steam Play / Pisco launch issues) and include:
-
Game or application title — full name, Steam AppID (if applicable), and any launch options or
TONIC_*environment variables used. - Steps to replicate — clear steps to reproduce the issue, along with expected vs. actual behavior (including whether the title uses TTS, voice commands, SSML, or binary CFG grammars).
-
Hardware & OS details — CPU, Linux distro, kernel version, audio stack (PipeWire vs. ALSA, plus whether
speech-dispatcheris installed), and microphone setup if reporting ASR issues. - Tonic & Pisco version — the exact Tonic branch/commit (and Pisco/Vodka version if running through Steam Play).
-
Logs (optional, helpful) —
tonic infooutput,zig build testoutput, or relevantPROTON_LOG=1/PISCO_LOG=1excerpts (scrubbed of any personal paths or credentials).
| Page | Description |
|---|---|
| Architecture | End-to-end TTS, SSML, MFCC/DTW ASR, SRGS grammar, WinMM audio, host bridge, and per-game fix registry internals |
| SAPI 5 Compatibility | Exported DLL entry points, CLSIDs/IIDs, comptime-verified COM vtables, interface behavior, notification modes, and current limitations |
| Building and Testing | Prerequisites, zig build options (-Dpe-dlls, -Dpe-archs), zig-out/ artifact layout, and unit test coverage |
| CLI and Runtime Usage | Complete tonic CLI command reference, libtonic.so C ABI, environment variables, and Linux libspeechd.so.2 bridge behavior |
| Pisco and Vodka Integration | How Pisco builds, symlinks, and routes Tonic via VODKADLLPATH and sapi=n, plus standalone Vodka usage |
| Troubleshooting and Reporting Issues | Diagnostics, audio/mic troubleshooting, per-game fix policy, tested hardware matrix, and issue reporting checklist |
Copyright (c) 2026 buntatoes. Tonic is a 100% standalone speech engine built from scratch and licensed under the Apache License 2.0. The Tonic, Pisco, Vodka, and Bitters names, wordmarks, and logos are All Rights Reserved.
Trademarks & Non-Affiliation: Windows and SAPI are trademarks or registered trademarks of Microsoft Corporation. Steam, Steam Play, and Proton are trademarks or registered trademarks of Valve Corporation. Linux, AMD, NVIDIA, Intel, and other third-party trademarks belong to their respective owners; Tonic is an independent open-source project and is not affiliated with, endorsed by, or sponsored by any of them.
Design & Engine
Build & Usage
Support
Links
-
Tonic Repository (
unstable/stable) - Pisco · Pisco Wiki
- Vodka · Vodka Wiki
- Bitters
- Apache-2.0 License