File size: 4,937 Bytes
50962bd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | #!/usr/bin/env python3
"""Regenerate ``manifest.json`` and ``SHA256SUMS`` from the package tree.
python scripts/build_manifest.py --version 1.1.0
The manifest is the machine-readable description of the bundle; SHA256SUMS is
the flat file ``sha256sum -c`` can verify. Both are derived from what is on
disk, so run this last, after building presets and samples.
"""
from __future__ import annotations
import argparse
import hashlib
import json
from datetime import datetime, timezone
from pathlib import Path
SKIP_DIRS = {"__pycache__", ".pytest_cache", ".git", "dist", "build"}
SKIP_SUFFIXES = {".pyc", ".part", ".log"}
# Derived from the tree, so hashing them would be circular.
SKIP_FILES = {"manifest.json", "SHA256SUMS"}
PRESETS = {
"jarvis-prime": {
"file": "voices/jarvis-prime.npy",
"recipe": {"bm_lewis": 0.55, "bm_daniel": 0.30, "bm_george": 0.15},
"median_f0_hz": 105.3,
"character": "default; lowest register with crisp consonants",
},
"jarvis-classic": {
"file": "voices/jarvis-classic.npy",
"recipe": {"bm_george": 0.25, "bm_daniel": 0.35, "bm_lewis": 0.40},
"median_f0_hz": 114.0,
"median_f1_hz": 589,
"median_f2_hz": 1928,
"character": "brighter, precise, unforced",
},
"jarvis-deep": {
"file": "voices/jarvis-deep.npy",
"recipe": {"bm_lewis": 0.50, "bm_daniel": 0.50},
"median_f0_hz": 104.8,
"median_f1_hz": 589,
"median_f2_hz": 1810,
"character": "heaviest; slower-feeling",
},
}
def digest(path: Path) -> tuple[int, str]:
sha = hashlib.sha256()
size = 0
with path.open("rb") as handle:
for block in iter(lambda: handle.read(1024 * 1024), b""):
sha.update(block)
size += len(block)
return size, sha.hexdigest()
def iter_files(root: Path):
for path in sorted(root.rglob("*")):
if not path.is_file():
continue
relative = path.relative_to(root)
if relative.as_posix() in SKIP_FILES:
continue
if any(part in SKIP_DIRS for part in relative.parts[:-1]):
continue
if path.suffix.lower() in SKIP_SUFFIXES:
continue
yield relative
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--version", default="1.1.0")
parser.add_argument(
"--created-at",
default=datetime.now(timezone.utc).isoformat(timespec="seconds"),
)
args = parser.parse_args()
root = Path(__file__).resolve().parent.parent
files: dict[str, dict[str, object]] = {}
sums: list[str] = []
for relative in iter_files(root):
size, sha = digest(root / relative)
key = relative.as_posix()
files[key] = {"bytes": size, "sha256": sha}
sums.append(f"{sha} *{key}")
(root / "SHA256SUMS").write_text(
"\n".join(sums) + "\n", encoding="utf-8", newline="\n"
)
manifest = {
"schema_version": 1,
"name": "Jarvis LVM",
"version": args.version,
"description": (
"Local, CPU-first JARVIS-inspired British butler voice built on "
"Kokoro-82M, with a measured delivery planner."
),
"license": "Apache-2.0",
"created_at": args.created_at,
"engine": {
"package": "kokoro-onnx",
"package_version": "0.6.1",
"runtime": "onnxruntime",
"provider": "CPUExecutionProvider",
"model_format": "onnx-int8",
"language": "en-gb",
"sample_rate": 24000,
},
"defaults": {
"voice": "jarvis-prime",
"speed": 0.95,
"lang": "en-gb",
"style": "jarvis",
},
"delivery": {
"style": "jarvis",
"description": (
"Splits a reply at sentence and clause boundaries, inserts a "
"measured pause (130 ms clause, 240 ms sentence), and slows "
"the terminal clause. Set style='off' for plain delivery."
),
"clause_gap_ms": 130,
"sentence_gap_ms": 240,
"segment_speeds": {"first": 0.99, "middle": 1.0, "last": 0.96},
},
"presets": PRESETS,
"assets": {
"model": "models/kokoro-v1.0.int8.onnx",
"voices": "voices/voices-v1.0.bin",
},
"performance": {
"host": "Windows 11, 6 physical CPU cores, ONNX Runtime 1.32",
"load_seconds": 0.77,
"real_time_factor": 0.50,
"rss_mib": 574,
"intra_threads": 6,
},
"files": files,
}
(root / "manifest.json").write_text(
json.dumps(manifest, indent=2) + "\n", encoding="utf-8"
)
print(f"wrote manifest.json and SHA256SUMS for {len(files)} files")
if __name__ == "__main__":
main()
|