kokoro-pi 1.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. kokoro_pi-1.2.0/CHANGELOG.md +121 -0
  2. kokoro_pi-1.2.0/LICENSE +21 -0
  3. kokoro_pi-1.2.0/MANIFEST.in +10 -0
  4. kokoro_pi-1.2.0/Makefile +66 -0
  5. kokoro_pi-1.2.0/NOTICE +30 -0
  6. kokoro_pi-1.2.0/PKG-INFO +527 -0
  7. kokoro_pi-1.2.0/README.md +495 -0
  8. kokoro_pi-1.2.0/corpus/english.json +49 -0
  9. kokoro_pi-1.2.0/corpus/heldout.json +34 -0
  10. kokoro_pi-1.2.0/install.sh +182 -0
  11. kokoro_pi-1.2.0/native/build.sh +36 -0
  12. kokoro_pi-1.2.0/native/include/README.md +12 -0
  13. kokoro_pi-1.2.0/native/include/onnxruntime_c_api.h +7429 -0
  14. kokoro_pi-1.2.0/native/include/onnxruntime_cxx_api.h +3210 -0
  15. kokoro_pi-1.2.0/native/include/onnxruntime_cxx_inline.h +3540 -0
  16. kokoro_pi-1.2.0/native/include/onnxruntime_ep_c_api.h +988 -0
  17. kokoro_pi-1.2.0/native/include/onnxruntime_float16.h +535 -0
  18. kokoro_pi-1.2.0/native/ops.h +14 -0
  19. kokoro_pi-1.2.0/native/quant_conv_op.cpp +289 -0
  20. kokoro_pi-1.2.0/native/register.cpp +22 -0
  21. kokoro_pi-1.2.0/native/snake_op.cpp +70 -0
  22. kokoro_pi-1.2.0/pyproject.toml +57 -0
  23. kokoro_pi-1.2.0/setup.cfg +4 -0
  24. kokoro_pi-1.2.0/setup.py +116 -0
  25. kokoro_pi-1.2.0/src/kokoro_pi/__init__.py +29 -0
  26. kokoro_pi-1.2.0/src/kokoro_pi/__main__.py +139 -0
  27. kokoro_pi-1.2.0/src/kokoro_pi/assets.py +64 -0
  28. kokoro_pi-1.2.0/src/kokoro_pi/build.py +287 -0
  29. kokoro_pi-1.2.0/src/kokoro_pi/compat.py +124 -0
  30. kokoro_pi-1.2.0/src/kokoro_pi/config.py +294 -0
  31. kokoro_pi-1.2.0/src/kokoro_pi/graph.py +187 -0
  32. kokoro_pi-1.2.0/src/kokoro_pi/openai.py +105 -0
  33. kokoro_pi-1.2.0/src/kokoro_pi/paths.py +73 -0
  34. kokoro_pi-1.2.0/src/kokoro_pi/quantise.py +232 -0
  35. kokoro_pi-1.2.0/src/kokoro_pi/server.py +495 -0
  36. kokoro_pi-1.2.0/src/kokoro_pi/validate.py +178 -0
  37. kokoro_pi-1.2.0/src/kokoro_pi/wyoming.py +193 -0
  38. kokoro_pi-1.2.0/src/kokoro_pi.egg-info/PKG-INFO +527 -0
  39. kokoro_pi-1.2.0/src/kokoro_pi.egg-info/SOURCES.txt +45 -0
  40. kokoro_pi-1.2.0/src/kokoro_pi.egg-info/dependency_links.txt +1 -0
  41. kokoro_pi-1.2.0/src/kokoro_pi.egg-info/entry_points.txt +2 -0
  42. kokoro_pi-1.2.0/src/kokoro_pi.egg-info/requires.txt +6 -0
  43. kokoro_pi-1.2.0/src/kokoro_pi.egg-info/top_level.txt +1 -0
  44. kokoro_pi-1.2.0/systemd/kokoro-pi.service +24 -0
  45. kokoro_pi-1.2.0/tools/bench_http.py +95 -0
  46. kokoro_pi-1.2.0/tools/check_protocols.py +240 -0
  47. kokoro_pi-1.2.0/tools/compare.py +213 -0
@@ -0,0 +1,121 @@
1
+ # Changelog
2
+
3
+ Dates are when the work landed on `main`. Versions follow
4
+ [semantic versioning](https://semver.org): the HTTP API and the config file keys
5
+ are the public surface.
6
+
7
+ ## 1.2.0 — 2026-09-18
8
+
9
+ Installable from PyPI, and usable as a library in place of kokoro-onnx.
10
+
11
+ ### Added
12
+
13
+ - **`pip install kokoro-pi`.** Binary wheels for `manylinux_2_28` on aarch64 and
14
+ x86_64 carry a **pre-compiled kernel**, so nothing needs a compiler; anywhere
15
+ else pip falls back to the source distribution and `kokoro-pi build` compiles
16
+ the operators there. The wheel is tagged `py3-none`, not per-Python, because
17
+ the library is loaded by ONNX Runtime rather than imported by CPython.
18
+ Published by GitHub Actions through PyPI trusted publishing — no API token
19
+ exists to leak.
20
+ - **`from kokoro_pi import Kokoro`** — kokoro-onnx's API over these kernels.
21
+ `create`, `create_stream` and `get_voices` take the same arguments and return
22
+ the same things, delegated to kokoro-onnx itself so nothing about
23
+ phonemisation or voices is reimplemented. The constructor takes a models
24
+ *directory* rather than model files, because these models are derived rather
25
+ than downloaded.
26
+ - `kokoro_pi.paths`, which finds `native/` and `corpus/` whether the package was
27
+ cloned or installed, and reports a pre-compiled kernel when a wheel shipped one.
28
+
29
+ ### Changed
30
+
31
+ - **Calibration reduces inside the graph.** Instrumentation used to mark each
32
+ target's input tensor as a graph output, so every pass copied out 36
33
+ activation tensors — 313 MB per utterance, measured. It now adds `Abs` and
34
+ `ReduceMax` and returns one vector per target: **0.5 MB**, with identical
35
+ ranges (worst difference 0.0).
36
+ - `--corpus` and `--heldout` default to the packaged corpora rather than to
37
+ paths relative to a repository that may not exist.
38
+ - `Engine(..., warm=False)` skips the warm-up synthesis, for library callers who
39
+ only want the object.
40
+
41
+ ### Fixed
42
+
43
+ - **Builds were being killed by the kernel.** A full build peaked at 3.1 GB
44
+ because nothing was released between stages, and an out-of-memory kill is a
45
+ `SIGKILL` — no traceback, the log simply stops mid-stage. Every stage now
46
+ frees what it is finished with before the next allocates, the parity check
47
+ keeps its six reference waveforms instead of the session that made them, and
48
+ the build warns up front when `MemAvailable` is below what it needs. The
49
+ documented 2.5 GB was disk; the memory figure was written down nowhere.
50
+ - Both ARM kernels now round identically (`std::fma` in the portable path,
51
+ matching `vfmaq_f32`), so a Pi 4 and a Pi 5 produce the same audio rather than
52
+ differing by the half-ULP this vocoder amplifies to its phase-chaos floor.
53
+
54
+ ## 1.1.0 — 2026-09-18
55
+
56
+ Speaks other people's protocols, and can be configured without editing a
57
+ systemd unit.
58
+
59
+ ### Added
60
+
61
+ - **`POST /v1/audio/speech`**, the OpenAI speech API, so Open WebUI, LibreChat,
62
+ SillyTavern and the OpenAI SDKs work against this service with a base URL
63
+ change and nothing else. OpenAI's voice names map onto Kokoro's, `mp3`/`opus`/
64
+ `aac`/`flac` are produced with ffmpeg when it is installed, and `GET
65
+ /v1/models` answers for clients that ask first.
66
+ - **The Wyoming protocol**, which is how Home Assistant talks to a voice
67
+ service — `wyoming = true`, and every voice appears in Home Assistant tagged
68
+ with its language. It advertises `supports_synthesize_streaming` and
69
+ implements the streaming events, so a sentence from a conversation agent
70
+ starts playing at its first clause.
71
+ - **Configuration from a file, the environment or a flag**, resolved in that
72
+ reverse order, with `kokoro-pi config` to print what is in force and where
73
+ each value came from. `install.sh` writes
74
+ `~/.config/kokoro-pi/config.toml` and points the unit at it.
75
+ - **`voices`**, an allowlist, so `/v1/voices` is an honest menu of what a
76
+ service will speak and a typo is a 400 rather than a surprise accent.
77
+ - **`api_key`** (constant-time, on `/v1` and `/readyz`; `/healthz` stays open
78
+ and says only `{"ready": true}`) and **`allow_origin`** with `OPTIONS`
79
+ preflight, so a browser page can call a Pi.
80
+ - **`speed`, `stream`, `stream_limit`, `log_requests`** as service-wide
81
+ defaults. Request logging is off by default and never includes the text.
82
+ - **[A page you can hear it on](https://zreecespieces.github.io/kokoro-pi/)**,
83
+ and `tools/compare.py` for measuring this against Piper, Kokoro-FastAPI or
84
+ anything else that speaks the OpenAI API, on your own hardware.
85
+ - `tools/check_protocols.py`, which exercises every protocol a running service
86
+ speaks and says what broke.
87
+
88
+ ### Changed
89
+
90
+ - **`lang` defaults to `auto`, which reads the language from the voice's name.**
91
+ Kokoro names voices `<language><gender>_<name>`, and `bf_emma` was being given
92
+ American phonemes — a British voice pronouncing an American's vowels. If you
93
+ were relying on everything being read as `en-us`, set `lang = "en-us"`.
94
+ Only `en-us` and `en-gb` are tested; espeak's Japanese and Chinese phonemes
95
+ are not the ones Kokoro was trained on.
96
+ - `/readyz` reports more: voice count, language mode, format, streaming and
97
+ `wait_seconds`.
98
+
99
+ ### Fixed
100
+
101
+ - **Re-running `install.sh` to upgrade left the old code running.**
102
+ `systemctl --user enable --now` does nothing to a unit that is already active,
103
+ so the installer rewrote the unit, printed "ready", and the previous process
104
+ kept serving.
105
+
106
+ ## 1.0.0 — 2026-09-17
107
+
108
+ First public release: the speech engine from a personal assistant, packaged.
109
+
110
+ - Four algebra-preserving graph rewrites and a fused native Snake activation:
111
+ 1.35× with the waveform preserved to 115 dB.
112
+ - A hand-written fused int8 convolution kernel using ARM's `SDOT`: **451 GOP/s**,
113
+ faster than ONNX Runtime's own int8 path (336 GOP/s) and 4.4× its float
114
+ kernel, with per-input-channel activation scales folded into the weights.
115
+ - Clause-level streaming, so first audio arrives after the first clause instead
116
+ of after the whole passage.
117
+ - **2.0–2.2× over the upstream ONNX export end to end**, about 3× over a
118
+ PyTorch install, and first audio 6.6× sooner.
119
+ - One-command install, a resident systemd service, 54 voices, three variants
120
+ side by side, checksum-verified assets, disjoint calibration and held-out
121
+ corpora, and quality gated on log-spectral distance rather than waveform SNR.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zachary Reece
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,10 @@
1
+ # The sdist must be able to build the kernel, so it carries the sources the
2
+ # wheel compiles and the corpora the build calibrates and checks against.
3
+ graft native
4
+ graft corpus
5
+ include LICENSE NOTICE CHANGELOG.md Makefile install.sh
6
+ recursive-include systemd *.service
7
+ recursive-include tools *.py
8
+ prune docs/audio
9
+ prune samples
10
+ prune .github
@@ -0,0 +1,66 @@
1
+ # Convenience targets. The installer does all of this for you; these are for hacking.
2
+ PREFIX ?= $(HOME)/.kokoro-pi
3
+ MODELS ?= $(PREFIX)/models
4
+ VENV ?= $(PREFIX)/venv
5
+ PYTHON ?= $(VENV)/bin/python
6
+ PORT ?= 8080
7
+ THREADS ?= 4
8
+ export PYTHONPATH = $(CURDIR)/src
9
+
10
+ .PHONY: help venv native build serve validate samples check compare audio clean distclean
11
+
12
+ help:
13
+ @echo "make venv create the virtual environment and install dependencies"
14
+ @echo "make native compile the operator library into $(MODELS)"
15
+ @echo "make build download the upstream model and derive the optimised ones"
16
+ @echo "make serve run the service in the foreground on port $(PORT)"
17
+ @echo "make validate measure quality and speed across variants"
18
+ @echo "make samples write a WAV per held-out utterance per variant into samples/"
19
+ @echo "make audio convert samples/ to the MP3s the web page plays (needs ffmpeg)"
20
+ @echo "make check exercise every protocol against a running service on $(PORT)"
21
+ @echo "make compare measure against another engine; see tools/compare.py --help"
22
+ @echo "make clean remove derived models, keeping the upstream download"
23
+
24
+ venv:
25
+ $(PYTHON) -c '' 2>/dev/null || python3 -m venv $(VENV)
26
+ $(VENV)/bin/pip install --quiet --upgrade pip wheel
27
+ $(VENV)/bin/pip install --quiet -r requirements.txt
28
+
29
+ native:
30
+ mkdir -p $(MODELS)
31
+ bash native/build.sh $(MODELS)/libkokoro_pi_ops.so
32
+
33
+ build: venv
34
+ $(PYTHON) -m kokoro_pi build --models $(MODELS) --threads $(THREADS)
35
+
36
+ serve:
37
+ $(PYTHON) -m kokoro_pi serve --models $(MODELS) --port $(PORT) --threads $(THREADS)
38
+
39
+ validate:
40
+ $(PYTHON) -m kokoro_pi validate --models $(MODELS) --variants upstream float int8 \
41
+ --reference upstream --threads $(THREADS)
42
+
43
+ samples:
44
+ $(PYTHON) -m kokoro_pi validate --models $(MODELS) --variants upstream float int8 \
45
+ --reference upstream --audio-dir samples --repeats 1 --threads $(THREADS)
46
+
47
+ check:
48
+ python3 tools/check_protocols.py --url http://127.0.0.1:$(PORT)
49
+
50
+ compare:
51
+ python3 tools/compare.py --kokoro-pi http://127.0.0.1:$(PORT)
52
+
53
+ # The page plays 64 kbit MP3s so it loads on a phone; the WAVs stay authoritative.
54
+ audio: samples
55
+ mkdir -p docs/audio
56
+ for f in samples/*.wav; do \
57
+ ffmpeg -hide_banner -loglevel error -y -i "$$f" -c:a libmp3lame -b:a 64k \
58
+ "docs/audio/$$(basename $$f .wav).mp3"; \
59
+ done
60
+
61
+ clean:
62
+ rm -f $(MODELS)/kokoro-fused.onnx $(MODELS)/kokoro-int8.onnx \
63
+ $(MODELS)/kokoro-calibration.onnx $(MODELS)/calibration.npz $(MODELS)/models.json
64
+
65
+ distclean:
66
+ rm -rf $(PREFIX)
kokoro_pi-1.2.0/NOTICE ADDED
@@ -0,0 +1,30 @@
1
+ kokoro-pi
2
+ Copyright (c) 2026 Zachary Reece
3
+ Licensed under the MIT License (see LICENSE).
4
+
5
+ This project optimises and serves models it does not ship. It builds on:
6
+
7
+ Kokoro-82M
8
+ https://huggingface.co/hexgrad/Kokoro-82M
9
+ Copyright (c) hexgrad. Licensed under the Apache License, Version 2.0.
10
+ The speech model itself. kokoro-pi downloads the ONNX export at install time and
11
+ rewrites it; the weights are unchanged apart from the documented int8 quantisation
12
+ of the vocoder's convolutions.
13
+
14
+ kokoro-onnx
15
+ https://github.com/thewh1teagle/kokoro-onnx
16
+ Copyright (c) thewh1teagle. Licensed under the MIT License.
17
+ Provides the ONNX export, the voice pack, and the tokenisation and phonemisation
18
+ front end this service calls. Model files are downloaded from its releases.
19
+
20
+ ONNX Runtime
21
+ https://github.com/microsoft/onnxruntime
22
+ Copyright (c) Microsoft Corporation. Licensed under the MIT License.
23
+ The inference engine. The five public C and C++ API headers under native/include are
24
+ vendored unmodified from release 1.23 (API version 23) so the custom operators can be
25
+ compiled without a source checkout or a matching pip package layout.
26
+
27
+ espeak-ng, via espeakng-loader and phonemizer-fork
28
+ https://github.com/espeak-ng/espeak-ng (GPLv3)
29
+ Used at runtime for phonemisation, through the dependencies above. It is invoked as
30
+ a separate library and is not linked into or redistributed by this project.