BATCH11 0.1.1__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.
BATCH11/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .tts import generate, load_model
2
+
3
+ __all__ = ["generate", "load_model"]
BATCH11/tts.py ADDED
@@ -0,0 +1,100 @@
1
+ from pathlib import Path
2
+ from threading import Lock
3
+
4
+ _model = None
5
+ _model_device = None
6
+ _model_lock = Lock()
7
+
8
+
9
+ def _resolve_device(device):
10
+ import torch
11
+
12
+ if device == "auto":
13
+ return "cuda" if torch.cuda.is_available() else "cpu"
14
+
15
+ if device == "cuda" and not torch.cuda.is_available():
16
+ raise RuntimeError("CUDA was requested, but no CUDA GPU is available.")
17
+
18
+ if device not in ("cpu", "cuda"):
19
+ raise ValueError("device must be 'auto', 'cpu', or 'cuda'.")
20
+
21
+ return device
22
+
23
+
24
+ def load_model(device="auto"):
25
+ """Load the Chatterbox model once and reuse it."""
26
+
27
+ global _model, _model_device
28
+
29
+ resolved_device = _resolve_device(device)
30
+
31
+ with _model_lock:
32
+ if _model is None or _model_device != resolved_device:
33
+ from chatterbox.tts import ChatterboxTTS
34
+
35
+ _model = ChatterboxTTS.from_pretrained(
36
+ device=resolved_device
37
+ )
38
+ _model_device = resolved_device
39
+
40
+ return _model
41
+
42
+
43
+ def generate(
44
+ text,
45
+ output_path="output.wav",
46
+ audio_prompt_path=None,
47
+ device="auto",
48
+ **generation_kwargs
49
+ ):
50
+ """Generate speech using Chatterbox and save it as a WAV file."""
51
+
52
+ if not isinstance(text, str) or not text.strip():
53
+ raise ValueError("Text must be a non-empty string.")
54
+
55
+ output_path = Path(output_path)
56
+
57
+ if output_path.suffix.lower() != ".wav":
58
+ raise ValueError("Output file must have a .wav extension.")
59
+
60
+ if audio_prompt_path is not None:
61
+ audio_prompt_path = Path(audio_prompt_path)
62
+
63
+ if not audio_prompt_path.is_file():
64
+ raise FileNotFoundError(
65
+ f"Voice reference audio not found: {audio_prompt_path}"
66
+ )
67
+
68
+ model = load_model(device=device)
69
+
70
+ kwargs = dict(generation_kwargs)
71
+
72
+ if audio_prompt_path is not None:
73
+ kwargs["audio_prompt_path"] = str(audio_prompt_path)
74
+
75
+ audio = model.generate(
76
+ text=text.strip(),
77
+ **kwargs
78
+ )
79
+
80
+ import torch
81
+ import torchaudio
82
+
83
+ if not isinstance(audio, torch.Tensor):
84
+ raise TypeError("Chatterbox returned an unexpected audio format.")
85
+
86
+ if audio.ndim == 1:
87
+ audio = audio.unsqueeze(0)
88
+
89
+ if audio.ndim != 2:
90
+ raise ValueError("Generated audio must be a 1D or 2D tensor.")
91
+
92
+ output_path.parent.mkdir(parents=True, exist_ok=True)
93
+
94
+ torchaudio.save(
95
+ str(output_path),
96
+ audio.detach().cpu(),
97
+ model.sr
98
+ )
99
+
100
+ return output_path
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: BATCH11
3
+ Version: 0.1.1
4
+ Summary: Python Text-to-Speech toolkit powered by Chatterbox
5
+ Requires-Python: <3.14,>=3.10
6
+ Description-Content-Type: text/markdown
7
+ Requires-Dist: chatterbox-tts==0.1.7
8
+ Requires-Dist: torchvision==0.21.0
9
+
10
+ # BATCH11
11
+
12
+ A Python Text-to-Speech toolkit powered by the Chatterbox engine.
13
+
14
+ ## Installation
15
+
16
+ pip install BATCH11
17
+
18
+ ## Basic usage
19
+
20
+ import BATCH11
21
+
22
+ BATCH11.generate(
23
+ text="Hello from BATCH11!",
24
+ output_path="output.wav"
25
+ )
26
+
27
+ ## Voice cloning
28
+
29
+ BATCH11.generate(
30
+ text="Hello from my reference voice!",
31
+ audio_prompt_path="reference.wav",
32
+ output_path="cloned.wav"
33
+ )
@@ -0,0 +1,6 @@
1
+ BATCH11/__init__.py,sha256=hXN7AirSjhbmvaQwHO0zY-PBfrqoqgBnVqO_RpJG7Vc,76
2
+ BATCH11/tts.py,sha256=a4OJ_vukOglG6oYw-KSZjxnfxBvvZ6jy_W3s18ZrFY8,2471
3
+ batch11-0.1.1.dist-info/METADATA,sha256=ayc9IIxDnaU6xqHIhF0wb30zW9BQjU6AxwhW_lSFBfg,678
4
+ batch11-0.1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ batch11-0.1.1.dist-info/top_level.txt,sha256=V6izC4u8jX2xfamqYOTbuC-SZgYV3RDvN4bvbcoOcII,8
6
+ batch11-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ BATCH11