kleintts 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.
kleintts/__init__.py ADDED
@@ -0,0 +1,35 @@
1
+ """kleintts: Klein-TTS text-to-speech models (Pro 13M, Flash 1.7M, Flash Lite 0.4M) in plain PyTorch."""
2
+
3
+ from .core import ( # noqa: F401
4
+ LANG_NAMES,
5
+ SAMPLE_RATE,
6
+ GConfig,
7
+ KleinG,
8
+ KleinTTS,
9
+ KleinTTSOutput,
10
+ Phonemizer,
11
+ list_voices,
12
+ save_wav,
13
+ synthesize,
14
+ )
15
+
16
+ __version__ = "0.1.0"
17
+ MODELS = { # short names -> Hugging Face repos (old names kept as aliases)
18
+ "pro": "klein-ml/Klein-TTS-X1.5-Pro",
19
+ "flash": "klein-ml/Klein-TTS-X1.5-Flash",
20
+ "flash-lite": "klein-ml/Klein-TTS-X1.5-Flash-Lite",
21
+ "small": "klein-ml/Klein-TTS-X1.5-Pro",
22
+ "tiny": "klein-ml/Klein-TTS-X1.5-Flash",
23
+ "micro": "klein-ml/Klein-TTS-X1.5-Flash-Lite",
24
+ }
25
+ DEFAULT_MODEL = "pro"
26
+
27
+ _from_pretrained = KleinTTS.from_pretrained.__func__
28
+
29
+
30
+ def _resolve(cls, path_or_repo: str = DEFAULT_MODEL, *args, **kwargs):
31
+ """KleinTTS.from_pretrained("pro" | "flash" | "flash-lite" | "<repo id>" | "<local folder>")"""
32
+ return _from_pretrained(cls, MODELS.get(path_or_repo.lower(), path_or_repo), *args, **kwargs)
33
+
34
+
35
+ KleinTTS.from_pretrained = classmethod(_resolve)
kleintts/cli.py ADDED
@@ -0,0 +1,39 @@
1
+ """Command line: kleintts "Hello there" -o hello.wav --voice af_heart"""
2
+ import argparse
3
+ import sys
4
+
5
+ from . import DEFAULT_MODEL, KleinTTS
6
+
7
+
8
+ def main(argv=None):
9
+ ap = argparse.ArgumentParser(prog="kleintts", description="Klein-TTS text to speech")
10
+ ap.add_argument("text", nargs="?", help="text to speak (or use --file)")
11
+ ap.add_argument("--file", help="read the text from a file")
12
+ ap.add_argument("-o", "--output", default="out.wav")
13
+ ap.add_argument("--model", default=DEFAULT_MODEL, help="pro, flash, flash-lite, a Hugging Face repo id or a local folder")
14
+ ap.add_argument("--voice")
15
+ ap.add_argument("--voice2", help="blend with a second voice of the same language")
16
+ ap.add_argument("--mix", type=float, default=0.5, help="blend weight of the second voice")
17
+ ap.add_argument("--speed", type=float, default=1.0)
18
+ ap.add_argument("--seed", type=int)
19
+ ap.add_argument("--device")
20
+ ap.add_argument("--list-voices", action="store_true")
21
+ a = ap.parse_args(argv)
22
+ tts = KleinTTS.from_pretrained(a.model, device=a.device)
23
+ if a.list_voices:
24
+ for lang in ("en-us", "en-gb", "es", "fr", "it"):
25
+ v = tts.voices(lang)
26
+ if v:
27
+ print(f"{lang}: {', '.join(v)}")
28
+ return 0
29
+ text = open(a.file, encoding="utf-8").read() if a.file else a.text
30
+ if not text:
31
+ ap.error("give some text, or --file")
32
+ out = tts.tts(text, voice=a.voice, voice2=a.voice2, mix=a.mix, speed=a.speed, seed=a.seed)
33
+ tts.save_wav(a.output, out.waveform, out.sample_rate)
34
+ print(f"wrote {a.output} ({out.waveform.numel() / out.sample_rate:.1f} s, voice {out.voice})")
35
+ return 0
36
+
37
+
38
+ if __name__ == "__main__":
39
+ sys.exit(main())