kittensynth 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,24 @@
1
+ """KittenTTS synthesis frontend backed by kitteng2p + OnnxVoice."""
2
+
3
+ from importlib.metadata import PackageNotFoundError
4
+ from importlib.metadata import version as _distribution_version
5
+
6
+ from .config import SynthesisConfig
7
+ from .types import SynthesisResult, VoiceInfo
8
+ from .voice import KittenVoice
9
+ from .voice_bank import DEFAULT_VOICE_ALIASES, VoiceBank
10
+
11
+ try:
12
+ __version__ = _distribution_version("kittensynth")
13
+ except PackageNotFoundError:
14
+ __version__ = "0+unknown"
15
+
16
+ __all__ = [
17
+ "__version__",
18
+ "DEFAULT_VOICE_ALIASES",
19
+ "KittenVoice",
20
+ "SynthesisConfig",
21
+ "SynthesisResult",
22
+ "VoiceBank",
23
+ "VoiceInfo",
24
+ ]
@@ -0,0 +1,33 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+
5
+ from .voice import KittenVoice
6
+
7
+
8
+ def main() -> int:
9
+ parser = argparse.ArgumentParser(description="Synthesize one prepared KittenTTS request")
10
+ parser.add_argument("text")
11
+ parser.add_argument("--model", default="nano-0.8-int8")
12
+ parser.add_argument("--voice", default="Jasper")
13
+ parser.add_argument("--speed", type=float, default=1.0)
14
+ parser.add_argument("-o", "--output", default="kitten.wav")
15
+ parser.add_argument("--cache-dir")
16
+ parser.add_argument("--catalog-url")
17
+ parser.add_argument("--offline", action="store_true")
18
+ args = parser.parse_args()
19
+
20
+ with KittenVoice.from_pretrained(
21
+ args.model,
22
+ cache_dir=args.cache_dir,
23
+ catalog_url=args.catalog_url,
24
+ offline=args.offline,
25
+ ) as model:
26
+ result = model.synthesize_prepared(args.text, voice=args.voice, speed=args.speed)
27
+ result.save_wav(args.output)
28
+ print(args.output)
29
+ return 0
30
+
31
+
32
+ if __name__ == "__main__":
33
+ raise SystemExit(main())
@@ -0,0 +1,195 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import os
5
+ from collections.abc import Mapping, Sequence
6
+ from dataclasses import dataclass
7
+ from pathlib import Path
8
+ from typing import Any
9
+
10
+ from .errors import OnnxVoiceContractError, UnsupportedModelError
11
+ from .voice_bank import DEFAULT_VOICE_ALIASES
12
+
13
+ DEFAULT_CATALOG_URL = (
14
+ "https://raw.githubusercontent.com/buchwandler/kitten-onnx-bundles/main/catalog/models.json"
15
+ )
16
+
17
+
18
+ @dataclass(frozen=True, slots=True)
19
+ class ResolvedKittenModel:
20
+ ref: str
21
+ model_id: str
22
+ model_path: Path
23
+ voices_path: Path
24
+ sample_rate: int
25
+ metadata: dict[str, Any]
26
+ installation: Any
27
+
28
+
29
+ def _module() -> Any:
30
+ try:
31
+ import onnxvoice
32
+ except ModuleNotFoundError as exc:
33
+ raise OnnxVoiceContractError("OnnxVoice is required for Kitten synthesis") from exc
34
+ return onnxvoice
35
+
36
+
37
+ def normalize_ref(value: str) -> str:
38
+ value = str(value).strip()
39
+ if not value:
40
+ raise ValueError("model reference cannot be empty")
41
+ return value if ":" in value else f"kitten:{value}"
42
+
43
+
44
+ def _manager(
45
+ *,
46
+ cache_dir: str | Path | None,
47
+ offline: bool,
48
+ catalog_url: str | None,
49
+ ) -> Any:
50
+ module = _module()
51
+ source = catalog_url or os.getenv("KITTENSYNTH_CATALOG_URL") or DEFAULT_CATALOG_URL
52
+ try:
53
+ return module.OnnxVoice(
54
+ cache_dir=cache_dir,
55
+ catalog_sources={"kitten": source},
56
+ offline=offline,
57
+ )
58
+ except TypeError as exc:
59
+ raise OnnxVoiceContractError(
60
+ "Installed OnnxVoice does not expose the expected manager constructor"
61
+ ) from exc
62
+
63
+
64
+ def installation_to_model(installation: Any) -> ResolvedKittenModel:
65
+ if str(getattr(installation, "system", "")) != "kitten":
66
+ raise UnsupportedModelError("expected an OnnxVoice Kitten installation")
67
+ try:
68
+ model_path = Path(installation.artifact("model").path)
69
+ voices_path = Path(installation.artifact("voices").path)
70
+ except (KeyError, AttributeError) as exc:
71
+ raise UnsupportedModelError(
72
+ "Kitten installation must contain model and voices artifacts"
73
+ ) from exc
74
+
75
+ metadata = dict(getattr(installation, "metadata", {}) or {})
76
+ metadata.setdefault("voice_aliases", dict(DEFAULT_VOICE_ALIASES))
77
+ metadata.setdefault("speed_priors", {})
78
+ sample_rate = int(
79
+ getattr(installation, "sample_rate", None) or metadata.get("sample_rate") or 24000
80
+ )
81
+ return ResolvedKittenModel(
82
+ ref=str(getattr(installation, "ref", f"kitten:{getattr(installation, 'id', 'unknown')}")),
83
+ model_id=str(getattr(installation, "id", "unknown")),
84
+ model_path=model_path,
85
+ voices_path=voices_path,
86
+ sample_rate=sample_rate,
87
+ metadata=metadata,
88
+ installation=installation,
89
+ )
90
+
91
+
92
+ def install_pretrained_model(
93
+ ref: str,
94
+ *,
95
+ quality: str | None = None,
96
+ cache_dir: str | Path | None = None,
97
+ offline: bool = False,
98
+ refresh_catalog: bool = False,
99
+ force_download: bool = False,
100
+ catalog_url: str | None = None,
101
+ progress: Any | None = None,
102
+ ) -> ResolvedKittenModel:
103
+ manager = _manager(cache_dir=cache_dir, offline=offline, catalog_url=catalog_url)
104
+ installation = manager.install(
105
+ normalize_ref(ref),
106
+ quality=quality,
107
+ refresh=refresh_catalog,
108
+ force=force_download,
109
+ progress=progress,
110
+ )
111
+ return installation_to_model(installation)
112
+
113
+
114
+ def open_installed_model(
115
+ resolved: ResolvedKittenModel,
116
+ *,
117
+ providers: Sequence[Any] | str | None = None,
118
+ provider_options: Mapping[str, Any] | None = None,
119
+ session_options: Any | None = None,
120
+ cache_dir: str | Path | None = None,
121
+ offline: bool = False,
122
+ catalog_url: str | None = None,
123
+ ) -> Any:
124
+ manager = _manager(cache_dir=cache_dir, offline=offline, catalog_url=catalog_url)
125
+ try:
126
+ return manager.open(
127
+ resolved.installation,
128
+ providers=providers,
129
+ provider_options=provider_options,
130
+ session_options=session_options,
131
+ )
132
+ except Exception as exc:
133
+ if "kitten" in str(exc).lower() or "unsupported system" in str(exc).lower():
134
+ raise OnnxVoiceContractError(
135
+ "OnnxVoice must register a 'kitten' adapter before kittensynth can infer"
136
+ ) from exc
137
+ raise
138
+
139
+
140
+ def open_local_model(
141
+ *,
142
+ model_path: str | Path,
143
+ voices_path: str | Path,
144
+ metadata: Mapping[str, Any],
145
+ providers: Sequence[Any] | str | None = None,
146
+ provider_options: Mapping[str, Any] | None = None,
147
+ session_options: Any | None = None,
148
+ ) -> Any:
149
+ module = _module()
150
+ try:
151
+ return module.OnnxVoice.open_local(
152
+ system="kitten",
153
+ model=model_path,
154
+ voices=voices_path,
155
+ metadata=dict(metadata),
156
+ sample_rate=int(metadata.get("sample_rate") or 24000),
157
+ providers=providers,
158
+ provider_options=provider_options,
159
+ session_options=session_options,
160
+ )
161
+ except Exception as exc:
162
+ if "kitten" in str(exc).lower() or "unsupported system" in str(exc).lower():
163
+ raise OnnxVoiceContractError(
164
+ "OnnxVoice must register a 'kitten' adapter before local inference works"
165
+ ) from exc
166
+ raise
167
+
168
+
169
+ def load_local_config(path: str | Path | None) -> dict[str, Any]:
170
+ metadata: dict[str, Any] = {
171
+ "sample_rate": 24000,
172
+ "voice_aliases": dict(DEFAULT_VOICE_ALIASES),
173
+ "speed_priors": {},
174
+ "runtime": {"profile": "ONNX2"},
175
+ }
176
+ if path is None:
177
+ return metadata
178
+
179
+ raw = json.loads(Path(path).read_text(encoding="utf-8"))
180
+ if not isinstance(raw, dict):
181
+ raise UnsupportedModelError("Kitten config.json must contain an object")
182
+ profile = raw.get("type")
183
+ if profile not in {"ONNX1", "ONNX2", None}:
184
+ raise UnsupportedModelError(f"unsupported Kitten runtime profile: {profile!r}")
185
+ if isinstance(raw.get("voice_aliases"), dict):
186
+ metadata["voice_aliases"] = {
187
+ str(key): str(value) for key, value in raw["voice_aliases"].items()
188
+ }
189
+ if isinstance(raw.get("speed_priors"), dict):
190
+ metadata["speed_priors"] = {
191
+ str(key): float(value) for key, value in raw["speed_priors"].items()
192
+ }
193
+ metadata["runtime"] = {"profile": profile or "ONNX2"}
194
+ metadata["upstream_config"] = raw
195
+ return metadata
kittensynth/config.py ADDED
@@ -0,0 +1,17 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ from dataclasses import dataclass
5
+
6
+ from .errors import InvalidSpeedError
7
+
8
+
9
+ @dataclass(frozen=True, slots=True)
10
+ class SynthesisConfig:
11
+ speed: float = 1.0
12
+
13
+ def validated(self) -> SynthesisConfig:
14
+ value = float(self.speed)
15
+ if not math.isfinite(value) or value <= 0:
16
+ raise InvalidSpeedError("speed must be a finite positive number")
17
+ return self
kittensynth/errors.py ADDED
@@ -0,0 +1,22 @@
1
+ class KittenSynthError(Exception):
2
+ """Base error for kittensynth."""
3
+
4
+
5
+ class EmptyTextError(KittenSynthError, ValueError):
6
+ """Raised when a synthesis request is empty."""
7
+
8
+
9
+ class InvalidSpeedError(KittenSynthError, ValueError):
10
+ """Raised when speed is invalid."""
11
+
12
+
13
+ class InvalidVoiceError(KittenSynthError, ValueError):
14
+ """Raised when a voice is not in the active voice archive."""
15
+
16
+
17
+ class UnsupportedModelError(KittenSynthError, RuntimeError):
18
+ """Raised when an installation does not satisfy the Kitten contract."""
19
+
20
+
21
+ class OnnxVoiceContractError(KittenSynthError, RuntimeError):
22
+ """Raised when the installed OnnxVoice lacks Kitten support."""
kittensynth/py.typed ADDED
File without changes
kittensynth/types.py ADDED
@@ -0,0 +1,47 @@
1
+ from __future__ import annotations
2
+
3
+ import wave
4
+ from dataclasses import dataclass
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import numpy as np
9
+
10
+
11
+ @dataclass(frozen=True, slots=True)
12
+ class VoiceInfo:
13
+ name: str
14
+ internal_id: str
15
+
16
+
17
+ @dataclass(frozen=True, slots=True)
18
+ class SynthesisResult:
19
+ audio: np.ndarray
20
+ sample_rate: int
21
+ voice: str
22
+ model_ref: str | None
23
+ speed: float
24
+ metadata: dict[str, Any] | None = None
25
+
26
+ def __post_init__(self) -> None:
27
+ audio = np.asarray(self.audio, dtype=np.float32).reshape(-1)
28
+ if not np.all(np.isfinite(audio)):
29
+ raise ValueError("audio must be finite")
30
+ if int(self.sample_rate) <= 0:
31
+ raise ValueError("sample_rate must be positive")
32
+ object.__setattr__(self, "audio", audio)
33
+ object.__setattr__(self, "sample_rate", int(self.sample_rate))
34
+
35
+ @property
36
+ def duration_seconds(self) -> float:
37
+ return float(self.audio.size) / float(self.sample_rate)
38
+
39
+ def save_wav(self, path: str | Path) -> None:
40
+ target = Path(path)
41
+ target.parent.mkdir(parents=True, exist_ok=True)
42
+ pcm = (np.clip(self.audio, -1.0, 1.0) * 32767.0).astype("<i2", copy=False)
43
+ with wave.open(str(target), "wb") as handle:
44
+ handle.setnchannels(1)
45
+ handle.setsampwidth(2)
46
+ handle.setframerate(self.sample_rate)
47
+ handle.writeframes(pcm.tobytes())
kittensynth/voice.py ADDED
@@ -0,0 +1,199 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Mapping, Sequence
4
+ from pathlib import Path
5
+ from typing import Any
6
+
7
+ import numpy as np
8
+ from kitteng2p import KittenG2P
9
+
10
+ from ._onnxvoice import (
11
+ install_pretrained_model,
12
+ load_local_config,
13
+ open_installed_model,
14
+ open_local_model,
15
+ )
16
+ from .config import SynthesisConfig
17
+ from .errors import EmptyTextError
18
+ from .types import SynthesisResult, VoiceInfo
19
+ from .voice_bank import VoiceBank
20
+
21
+
22
+ class KittenVoice:
23
+ def __init__(
24
+ self,
25
+ *,
26
+ runtime: Any,
27
+ voices_path: str | Path,
28
+ metadata: Mapping[str, Any],
29
+ model_ref: str | None,
30
+ g2p: KittenG2P | None = None,
31
+ sample_rate: int = 24000,
32
+ ) -> None:
33
+ self.runtime = runtime
34
+ self.model_ref = model_ref
35
+ self.metadata = dict(metadata)
36
+ self.sample_rate = int(sample_rate)
37
+ self._owns_g2p = g2p is None
38
+ self.g2p = g2p or KittenG2P()
39
+ self.voice_bank = VoiceBank(
40
+ voices_path,
41
+ voice_aliases=self.metadata.get("voice_aliases"),
42
+ speed_priors=self.metadata.get("speed_priors"),
43
+ )
44
+ self._closed = False
45
+
46
+ @classmethod
47
+ def from_pretrained(
48
+ cls,
49
+ model: str = "nano-0.8-int8",
50
+ *,
51
+ quality: str | None = None,
52
+ cache_dir: str | Path | None = None,
53
+ offline: bool = False,
54
+ refresh_catalog: bool = False,
55
+ force_download: bool = False,
56
+ catalog_url: str | None = None,
57
+ providers: Sequence[Any] | str | None = None,
58
+ provider_options: Mapping[str, Any] | None = None,
59
+ session_options: Any | None = None,
60
+ progress: Any | None = None,
61
+ g2p: KittenG2P | None = None,
62
+ ) -> KittenVoice:
63
+ resolved = install_pretrained_model(
64
+ model,
65
+ quality=quality,
66
+ cache_dir=cache_dir,
67
+ offline=offline,
68
+ refresh_catalog=refresh_catalog,
69
+ force_download=force_download,
70
+ catalog_url=catalog_url,
71
+ progress=progress,
72
+ )
73
+ runtime = open_installed_model(
74
+ resolved,
75
+ providers=providers,
76
+ provider_options=provider_options,
77
+ session_options=session_options,
78
+ cache_dir=cache_dir,
79
+ offline=offline,
80
+ catalog_url=catalog_url,
81
+ )
82
+ return cls(
83
+ runtime=runtime,
84
+ voices_path=resolved.voices_path,
85
+ metadata=resolved.metadata,
86
+ model_ref=resolved.ref,
87
+ g2p=g2p,
88
+ sample_rate=resolved.sample_rate,
89
+ )
90
+
91
+ @classmethod
92
+ def from_local(
93
+ cls,
94
+ *,
95
+ model_path: str | Path,
96
+ voices_path: str | Path,
97
+ config_path: str | Path | None = None,
98
+ providers: Sequence[Any] | str | None = None,
99
+ provider_options: Mapping[str, Any] | None = None,
100
+ session_options: Any | None = None,
101
+ g2p: KittenG2P | None = None,
102
+ ) -> KittenVoice:
103
+ metadata = load_local_config(config_path)
104
+ runtime = open_local_model(
105
+ model_path=model_path,
106
+ voices_path=voices_path,
107
+ metadata=metadata,
108
+ providers=providers,
109
+ provider_options=provider_options,
110
+ session_options=session_options,
111
+ )
112
+ return cls(
113
+ runtime=runtime,
114
+ voices_path=voices_path,
115
+ metadata=metadata,
116
+ model_ref=None,
117
+ g2p=g2p,
118
+ sample_rate=int(metadata.get("sample_rate") or 24000),
119
+ )
120
+
121
+ @property
122
+ def available_voices(self) -> tuple[str, ...]:
123
+ return self.voice_bank.available_voices
124
+
125
+ @property
126
+ def voices(self) -> tuple[VoiceInfo, ...]:
127
+ return tuple(
128
+ VoiceInfo(name=name, internal_id=self.voice_bank.resolve(name))
129
+ for name in self.available_voices
130
+ )
131
+
132
+ def synthesize_prepared(
133
+ self,
134
+ text: str,
135
+ *,
136
+ voice: str = "Jasper",
137
+ speed: float = 1.0,
138
+ config: SynthesisConfig | None = None,
139
+ ) -> SynthesisResult:
140
+ if self._closed:
141
+ raise RuntimeError("KittenVoice is closed")
142
+ if not isinstance(text, str) or not text.strip():
143
+ raise EmptyTextError("text must contain speakable content")
144
+ if config is not None:
145
+ speed = config.validated().speed
146
+
147
+ frontend = self.g2p.phonemize_prepared(text)
148
+ style = self.voice_bank.style_for(voice, text_length=len(text))
149
+ effective_speed = self.voice_bank.effective_speed(voice, speed)
150
+
151
+ result = self.runtime.infer(
152
+ frontend.token_ids,
153
+ style=style,
154
+ speed=effective_speed,
155
+ )
156
+ audio = np.asarray(result.audio, dtype=np.float32).reshape(-1)
157
+ sample_rate = int(getattr(result, "sample_rate", 0) or self.sample_rate)
158
+ return SynthesisResult(
159
+ audio=audio,
160
+ sample_rate=sample_rate,
161
+ voice=voice,
162
+ model_ref=self.model_ref,
163
+ speed=effective_speed,
164
+ metadata={
165
+ "phonemes": frontend.phonemes,
166
+ "token_count": len(frontend.token_ids),
167
+ "dropped_symbols": frontend.dropped_symbols,
168
+ "internal_voice": self.voice_bank.resolve(voice),
169
+ },
170
+ )
171
+
172
+ # Small compatibility alias for callers migrating from the first MVP.
173
+ synthesize_text = synthesize_prepared
174
+
175
+ def diagnostics(self) -> dict[str, object]:
176
+ runtime_diagnostics = getattr(self.runtime, "diagnostics", None)
177
+ g2p_diagnostics = getattr(getattr(self.g2p, "backend", None), "diagnostics", None)
178
+ return {
179
+ "runtime": runtime_diagnostics()
180
+ if callable(runtime_diagnostics)
181
+ else runtime_diagnostics,
182
+ "g2p": g2p_diagnostics,
183
+ }
184
+
185
+ def close(self) -> None:
186
+ if self._closed:
187
+ return
188
+ close = getattr(self.runtime, "close", None)
189
+ if callable(close):
190
+ close()
191
+ if self._owns_g2p:
192
+ self.g2p.close()
193
+ self._closed = True
194
+
195
+ def __enter__(self) -> KittenVoice:
196
+ return self
197
+
198
+ def __exit__(self, *_: object) -> None:
199
+ self.close()
@@ -0,0 +1,70 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+ from collections.abc import Mapping
5
+ from pathlib import Path
6
+
7
+ import numpy as np
8
+
9
+ from .errors import InvalidSpeedError, InvalidVoiceError
10
+
11
+ DEFAULT_VOICE_ALIASES: dict[str, str] = {
12
+ "Bella": "expr-voice-2-f",
13
+ "Jasper": "expr-voice-2-m",
14
+ "Luna": "expr-voice-3-f",
15
+ "Bruno": "expr-voice-3-m",
16
+ "Rosie": "expr-voice-4-f",
17
+ "Hugo": "expr-voice-4-m",
18
+ "Kiki": "expr-voice-5-f",
19
+ "Leo": "expr-voice-5-m",
20
+ }
21
+
22
+
23
+ class VoiceBank:
24
+ def __init__(
25
+ self,
26
+ path: str | Path,
27
+ *,
28
+ voice_aliases: Mapping[str, str] | None = None,
29
+ speed_priors: Mapping[str, float] | None = None,
30
+ ) -> None:
31
+ self.path = Path(path)
32
+ aliases = dict(DEFAULT_VOICE_ALIASES if voice_aliases is None else voice_aliases)
33
+ self.voice_aliases = {str(key): str(value) for key, value in aliases.items()}
34
+ self.speed_priors = {str(key): float(value) for key, value in (speed_priors or {}).items()}
35
+ with np.load(self.path, allow_pickle=False) as archive:
36
+ self._styles = {str(name): np.asarray(archive[name]) for name in archive.files}
37
+ if not self._styles:
38
+ raise ValueError("voices.npz is empty")
39
+
40
+ @property
41
+ def available_voices(self) -> tuple[str, ...]:
42
+ aliases = [
43
+ alias for alias, internal in self.voice_aliases.items() if internal in self._styles
44
+ ]
45
+ return tuple(aliases)
46
+
47
+ def resolve(self, voice: str) -> str:
48
+ internal = self.voice_aliases.get(voice, voice)
49
+ if internal not in self._styles:
50
+ choices = ", ".join(self.available_voices)
51
+ raise InvalidVoiceError(f"Voice {voice!r} is unavailable; choose from {choices}")
52
+ return internal
53
+
54
+ def style_for(self, voice: str, *, text_length: int) -> np.ndarray:
55
+ internal = self.resolve(voice)
56
+ styles = np.asarray(self._styles[internal])
57
+ if styles.ndim < 2 or styles.shape[0] < 1:
58
+ raise ValueError(f"invalid style shape for {internal}: {styles.shape}")
59
+ index = min(max(int(text_length), 0), styles.shape[0] - 1)
60
+ return np.asarray(styles[index : index + 1])
61
+
62
+ def effective_speed(self, voice: str, requested: float) -> float:
63
+ speed = float(requested)
64
+ if not math.isfinite(speed) or speed <= 0:
65
+ raise InvalidSpeedError("speed must be a finite positive number")
66
+ internal = self.resolve(voice)
67
+ effective = speed * self.speed_priors.get(internal, 1.0)
68
+ if not math.isfinite(effective) or effective <= 0:
69
+ raise InvalidSpeedError("effective speed must be finite and positive")
70
+ return effective
@@ -0,0 +1,189 @@
1
+ Metadata-Version: 2.4
2
+ Name: kittensynth
3
+ Version: 0.1.0
4
+ Summary: KittenTTS synthesis frontend backed by kitteng2p and OnnxVoice
5
+ Author: kittensynth contributors
6
+ License: Apache-2.0
7
+ Project-URL: Repository, https://github.com/buchwandler/kittensynth
8
+ Project-URL: Homepage, https://github.com/buchwandler/kittensynth
9
+ Keywords: tts,kitten,kittentts,onnx,onnxruntime,speech
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: NOTICE
22
+ Requires-Dist: numpy>=1.23
23
+ Requires-Dist: kitteng2p<0.2,>=0.0
24
+ Requires-Dist: onnxvoice<0.3,>=0.2
25
+ Provides-Extra: cpu
26
+ Requires-Dist: onnxvoice[cpu]<0.3,>=0.2; extra == "cpu"
27
+ Provides-Extra: gpu
28
+ Requires-Dist: onnxvoice[gpu]<0.3,>=0.2; extra == "gpu"
29
+ Provides-Extra: bundled-g2p
30
+ Requires-Dist: kitteng2p[bundled]<0.2,>=0.1; extra == "bundled-g2p"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8; extra == "dev"
33
+ Requires-Dist: pytest-cov>=5; extra == "dev"
34
+ Requires-Dist: ruff<0.17,>=0.16; extra == "dev"
35
+ Requires-Dist: mypy>=1.11; extra == "dev"
36
+ Requires-Dist: build>=1; extra == "dev"
37
+ Requires-Dist: twine>=5; extra == "dev"
38
+ Requires-Dist: packaging>=24; extra == "dev"
39
+ Requires-Dist: tomli>=2; python_version < "3.11" and extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # kittensynth
43
+
44
+ KittenTTS synthesis layer built on **kitteng2p + OnnxVoice**.
45
+
46
+ This MVP follows the same repository/package shape as PiperSynth/PiperG2P:
47
+
48
+ ```text
49
+ pyproject.toml
50
+ kittensynth/
51
+ tests/
52
+ docs/
53
+ ```
54
+
55
+ There is **no `src/` layer** and no hard-coded package version.
56
+
57
+ ## Architecture
58
+
59
+ ```text
60
+ prepared speakable English
61
+ |
62
+ v
63
+ kitteng2p
64
+ - eSpeak
65
+ - Kitten phoneme tokenization
66
+ - Kitten v0.8 token IDs
67
+ |
68
+ v
69
+ kittensynth
70
+ - voice alias/style row
71
+ - speed-prior policy
72
+ |
73
+ v
74
+ onnxvoice
75
+ - catalogs/install/cache/integrity
76
+ - ORT providers/sessions
77
+ - Kitten graph ABI
78
+ |
79
+ v
80
+ float32 waveform
81
+ ```
82
+
83
+ `kittensynth` has **no direct eSpeak or phonemizer dependency**. That is now entirely owned by
84
+ `kitteng2p`.
85
+
86
+ ## Required OnnxVoice contract
87
+
88
+ A future/updated OnnxVoice release must register:
89
+
90
+ ```text
91
+ system = kitten
92
+ ```
93
+
94
+ and expose:
95
+
96
+ ```python
97
+ runtime.infer(token_ids, style=style, speed=effective_speed)
98
+ ```
99
+
100
+ The installation contains at least:
101
+
102
+ ```text
103
+ role=model
104
+ role=voices
105
+ ```
106
+
107
+ with 24 kHz metadata and Kitten voice aliases/speed priors.
108
+
109
+ ## Managed model
110
+
111
+ ```python
112
+ from kittensynth import KittenVoice
113
+
114
+ with KittenVoice.from_pretrained("nano-0.8-int8") as model:
115
+ result = model.synthesize_prepared(
116
+ "Hello from KittenSynth.",
117
+ voice="Jasper",
118
+ )
119
+ result.save_wav("hello.wav")
120
+ ```
121
+
122
+ ## Local model
123
+
124
+ ```python
125
+ from kittensynth import KittenVoice
126
+
127
+ with KittenVoice.from_local(
128
+ model_path="kitten_tts_nano_v0_8.onnx",
129
+ voices_path="voices.npz",
130
+ config_path="config.json",
131
+ ) as model:
132
+ result = model.synthesize_prepared("Local synthesis.", voice="Bella")
133
+ result.save_wav("local.wav")
134
+ ```
135
+
136
+ ## Prepared-text boundary
137
+
138
+ Like PiperG2P/PiperSynth, this MVP expects prepared speakable text. Written-form semantic expansion
139
+ (numbers, currencies, dates, URLs, abbreviations) stays outside the engine.
140
+
141
+ That keeps these packages independent:
142
+
143
+ ```text
144
+ semantic preparation -> kitteng2p -> kittensynth -> onnxvoice
145
+ ```
146
+
147
+ ## Voice selection
148
+
149
+ The current v0.8 aliases are:
150
+
151
+ ```text
152
+ Bella -> expr-voice-2-f
153
+ Jasper -> expr-voice-2-m
154
+ Luna -> expr-voice-3-f
155
+ Bruno -> expr-voice-3-m
156
+ Rosie -> expr-voice-4-f
157
+ Hugo -> expr-voice-4-m
158
+ Kiki -> expr-voice-5-f
159
+ Leo -> expr-voice-5-m
160
+ ```
161
+
162
+ The style row is selected exactly as upstream v0.8:
163
+
164
+ ```python
165
+ min(len(text), style_rows - 1)
166
+ ```
167
+
168
+ ## Dynamic versioning
169
+
170
+ Both `kitteng2p` and `kittensynth` use the same Git-tag-driven `setuptools-scm` pattern:
171
+
172
+ ```bash
173
+ git tag v0.1.0
174
+ python -m build
175
+ ```
176
+
177
+ The source-ZIP fallback is `0.1.dev0`; installed `__version__` comes from distribution metadata.
178
+
179
+ ## Development
180
+
181
+ For sibling checkout development:
182
+
183
+ ```bash
184
+ python -m pip install -e ../kitteng2p
185
+ python -m pip install -e ".[dev]"
186
+ python -m pytest
187
+ ```
188
+
189
+ Real synthesis remains blocked until OnnxVoice contains the Kitten adapter/catalog parser.
@@ -0,0 +1,16 @@
1
+ kittensynth/__init__.py,sha256=6tWjOyjwEoCANVOW1wchGMk51s_74VfYSNklPP3Jj38,638
2
+ kittensynth/__main__.py,sha256=eiWur15DGR7hUGQkT5idIEgiJxnFD9Mbsx2DxApAVmQ,1035
3
+ kittensynth/_onnxvoice.py,sha256=23Klr4VoQL5FjVDp812E0hhoP3GcwqmKoCHFXcDKs3w,6417
4
+ kittensynth/config.py,sha256=HFeq-bZj87-iKvp0W0bPMxpsRr21S6NZExERV3G3eCk,433
5
+ kittensynth/errors.py,sha256=TnX3jJpcXU771snSYv8fWdk3CDI4QJz625-RgdXMndE,670
6
+ kittensynth/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ kittensynth/types.py,sha256=M-L8gx0OS3DXGuiT37_5DpL_MpkKkzJ1O-FlRP-rLH0,1426
8
+ kittensynth/voice.py,sha256=3hTS0vfsYYeM1oC6K02nBz2EAO-0dN19S1MuDBKVo9o,6285
9
+ kittensynth/voice_bank.py,sha256=5F_lY0SWLzaAfD9cfaJaGLGzytHpzht3E19BF2ARqG8,2694
10
+ kittensynth-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
+ kittensynth-0.1.0.dist-info/licenses/NOTICE,sha256=zPSBCaahN3SRvMo60dyYJNx6zklDr02Nb_3ZNx0v8gc,210
12
+ kittensynth-0.1.0.dist-info/METADATA,sha256=ERLp05TiPEGPgjwiT5uQGSiPHXjRltzV5ZmVxARsQNQ,4533
13
+ kittensynth-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
14
+ kittensynth-0.1.0.dist-info/entry_points.txt,sha256=yASb7Z8dBFsXLB63Xb7RNxO6LnvUzra_Qrk_k6maTx0,58
15
+ kittensynth-0.1.0.dist-info/top_level.txt,sha256=aOF0JPP8MnfyShiLlAOaFfpdCnXayeCiYWS2RAWghMk,12
16
+ kittensynth-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kittensynth = kittensynth.__main__:main
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,4 @@
1
+ kittensynth
2
+
3
+ This repository contains independently authored integration/frontend code. It does not include or
4
+ relicense KittenTTS model weights or voice-style assets. Runtime assets retain upstream licensing.
@@ -0,0 +1 @@
1
+ kittensynth