windextts 0.1.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 (42) hide show
  1. windextts-0.1.0/LICENSE +202 -0
  2. windextts-0.1.0/PKG-INFO +218 -0
  3. windextts-0.1.0/README.md +169 -0
  4. windextts-0.1.0/pyproject.toml +70 -0
  5. windextts-0.1.0/setup.cfg +4 -0
  6. windextts-0.1.0/windextts/__init__.py +3 -0
  7. windextts-0.1.0/windextts/__main__.py +5 -0
  8. windextts-0.1.0/windextts/attention.py +154 -0
  9. windextts-0.1.0/windextts/cli.py +188 -0
  10. windextts-0.1.0/windextts/config.py +326 -0
  11. windextts-0.1.0/windextts/data/mel_basis_hifigan.pt +0 -0
  12. windextts-0.1.0/windextts/data/seamless_frontend.npz +0 -0
  13. windextts-0.1.0/windextts/download.py +199 -0
  14. windextts-0.1.0/windextts/frontend/__init__.py +1 -0
  15. windextts-0.1.0/windextts/frontend/audio_utils.py +236 -0
  16. windextts-0.1.0/windextts/frontend/mel.py +158 -0
  17. windextts-0.1.0/windextts/frontend/normalizer.py +417 -0
  18. windextts-0.1.0/windextts/frontend/segmenter.py +158 -0
  19. windextts-0.1.0/windextts/frontend/tokenizer.py +272 -0
  20. windextts-0.1.0/windextts/inference.py +748 -0
  21. windextts-0.1.0/windextts/models/__init__.py +1 -0
  22. windextts-0.1.0/windextts/models/bigvgan.py +434 -0
  23. windextts-0.1.0/windextts/models/campplus.py +411 -0
  24. windextts-0.1.0/windextts/models/codec.py +474 -0
  25. windextts-0.1.0/windextts/models/emo_conditioning.py +466 -0
  26. windextts-0.1.0/windextts/models/gpt.py +1255 -0
  27. windextts-0.1.0/windextts/models/length_regulator.py +223 -0
  28. windextts-0.1.0/windextts/models/qwen3.py +451 -0
  29. windextts-0.1.0/windextts/models/qwen_emotion.py +178 -0
  30. windextts-0.1.0/windextts/models/s2mel_cfm.py +498 -0
  31. windextts-0.1.0/windextts/models/s2mel_dit.py +788 -0
  32. windextts-0.1.0/windextts/models/w2v2_bert.py +366 -0
  33. windextts-0.1.0/windextts/profiler.py +540 -0
  34. windextts-0.1.0/windextts/server.py +235 -0
  35. windextts-0.1.0/windextts/webui.py +504 -0
  36. windextts-0.1.0/windextts/weights.py +185 -0
  37. windextts-0.1.0/windextts.egg-info/PKG-INFO +218 -0
  38. windextts-0.1.0/windextts.egg-info/SOURCES.txt +40 -0
  39. windextts-0.1.0/windextts.egg-info/dependency_links.txt +1 -0
  40. windextts-0.1.0/windextts.egg-info/entry_points.txt +5 -0
  41. windextts-0.1.0/windextts.egg-info/requires.txt +26 -0
  42. windextts-0.1.0/windextts.egg-info/top_level.txt +1 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,218 @@
1
+ Metadata-Version: 2.4
2
+ Name: windextts
3
+ Version: 0.1.0
4
+ Summary: Windows-priority, zero-JIT-compile, pure-torch accelerated inference for IndexTTS-2.5
5
+ Author: baicai-1145
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/baicai-1145/WIndexTTS
8
+ Project-URL: Repository, https://github.com/baicai-1145/WIndexTTS
9
+ Project-URL: Issues, https://github.com/baicai-1145/WIndexTTS/issues
10
+ Keywords: tts,text-to-speech,index-tts,voice-cloning,pytorch,cuda-graph
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: torch>=2.4
27
+ Requires-Dist: torchaudio>=2.4
28
+ Requires-Dist: safetensors>=0.4
29
+ Requires-Dist: tiktoken>=0.7
30
+ Requires-Dist: jieba>=0.42
31
+ Requires-Dist: cn2an>=0.5
32
+ Requires-Dist: wetext>=0.1.2
33
+ Requires-Dist: soundfile>=0.12
34
+ Requires-Dist: numpy>=1.24
35
+ Requires-Dist: pyyaml>=6.0
36
+ Requires-Dist: scipy>=1.10
37
+ Provides-Extra: dev
38
+ Requires-Dist: pytest>=8.0; extra == "dev"
39
+ Requires-Dist: pytest-xdist; extra == "dev"
40
+ Provides-Extra: webui
41
+ Requires-Dist: gradio>=4.0; extra == "webui"
42
+ Provides-Extra: quant
43
+ Requires-Dist: torchao>=0.5; extra == "quant"
44
+ Provides-Extra: server
45
+ Requires-Dist: fastapi>=0.110; extra == "server"
46
+ Requires-Dist: uvicorn>=0.29; extra == "server"
47
+ Requires-Dist: pydantic>=2; extra == "server"
48
+ Dynamic: license-file
49
+
50
+ # WIndexTTS
51
+
52
+ Windows-priority, zero-JIT-compile, pure-torch accelerated inference engine for
53
+ **IndexTTS-2.5**.
54
+
55
+ 目标:在 **Windows 上 `pip install` 即用**(无 MSVC / nvcc / triton 编译依赖)的前提下,
56
+ 用纯 PyTorch 重写 IndexTTS-2.5 的神经网络推理,并实现比官方 `use_accel` 更彻底的 CUDA Graph 加速。
57
+
58
+ ## 状态
59
+
60
+ **端到端推理 + 多轮加速优化完成**,纯 torch,比官方 bf16 快 **2.4x**。
61
+
62
+ ### 性能(A10G 24GB,4 段中文,稳态)
63
+
64
+ | 引擎 | 均值 | 最快 | RTF | 说明 |
65
+ |---|---|---|---|---|
66
+ | **WIndexTTS** | **0.67s** | **0.59s** | **5.75x** | fp16 GPT+BigVGAN, 15步CFM+TeaCache, 紧凑KV buffer |
67
+ | 官方 bf16 | 1.81s | 1.75s | — | transformers + HF generate |
68
+ | 官方 fp32 | 2.06s | 1.91s | — | 默认精度 |
69
+
70
+ **WIndexTTS 在零编译依赖下比官方 bf16 快 2.7x、比官方 fp32 快 3.1x。**
71
+
72
+ ### 各阶段拆解(优化后)
73
+
74
+ ```
75
+ GPT-AR(fp16+graph+紧凑buffer) ~150ms ~40% ← 内存带宽受限(纯torch fp16 上限)
76
+ S2Mel-CFM(15步+tc) ~175ms ~37% ← TeaCache 跳过冗余步骤 + 减少欧拉步数
77
+ BigVGAN(fp16) ~58ms ~15% ← cosine 0.9998
78
+ codec+前端+设置 ~50ms ~8%
79
+ ──────────────────────────────────────────
80
+ E2E 稳态 ~0.67s median 0.66s, min 0.59s
81
+ ```
82
+
83
+ ### 加速轮次
84
+
85
+ | 轮次 | 技术 | 效果 | 质量 |
86
+ |---|---|---|---|
87
+ | R1 | TeaCache(S2Mel DiT 步骤跳过) | S2Mel 465→247ms (1.88x) | mel cosine 0.98 |
88
+ | R2 | fp16 GPT-AR(混合精度) | GPT 430→245ms (1.77x) | greedy 78/78 精确 |
89
+ | R3 | fp16 BigVGAN | 89→58ms (1.53x) | cosine 0.9998 |
90
+ | R4 | CFM 欧拉步 25→15 | S2Mel 251→177ms | cosine 0.998 |
91
+ | R5 | 紧凑 KV buffer(max_mel_tokens 1000→300) | GPT 184→124ms (1.48x) | 无截断(实测 68-110 codes) |
92
+
93
+ ### 未采用的方案及原因
94
+
95
+ - **bf16 GPT**:7-bit 尾数不够,greedy 仅 27% 匹配(fp16 的 10-bit 足够,100%)
96
+ - **torch.compile GPT**:与混合精度不兼容(dtype 报错)
97
+ - **GPT INT8 量化**:torchao/bitsandbytes 未安装(零依赖原则)
98
+ - **S2Mel CUDA Graph(全序列)**:T=1045 时 DiT 注意力中间量占用 ~22GB,A10G OOM
99
+ - **S2Mel fp16**:DiT forward 有多处 fp32 内部构造,侵入性大,TeaCache 已减半
100
+ - **Flash attention 解码**:不支持 seqlen_q≠seqlen_k 的 is_causal(解码场景 Q=1,K=90)
101
+ - **流水线 stream overlap**:各阶段串行依赖(每阶段需上阶段输出),单请求无可重叠独立工作
102
+
103
+ ### 可调参数(质量/速度权衡)
104
+
105
+ ```python
106
+ tts.infer(ref, text, 'ZH',
107
+ dtype=torch.float16, # fp16 GPT+BigVGAN(默认 fp32 保对齐)
108
+ cfm_steps=15, # CFM 欧拉步(25=最高质量,10=最快)
109
+ teacache_thresh=0.15, # 0=禁用,0.25=更激进跳步
110
+ cfg_rate=0.7, # CFG 强度(0.3=快10%,0.0=最快无引导)
111
+ )
112
+ ```
113
+
114
+ ### 实现历史(阶段 1-5)
115
+
116
+ - ✅ **阶段1**:全部神经模块纯 torch 重写并数值对齐(diff=0.0~9.5e-7)
117
+ - w2v-bert(580M) / CAMPPlus / EnhancedCodec / GPT-AR / S2Mel-DiT(98M) / CFM / BigVGAN / LengthRegulator
118
+ - ✅ **阶段2**:端到端流水线 `WIndexTTS.infer()` 跑通
119
+ - 前端:tiktoken tokenizer(6/6 精确)/ HiFiGAN mel(9.5e-7)/ SeamlessM4T featurizer
120
+ - ✅ **阶段3**:GPT-AR decode 引擎(KV cache)替代 HF generate,greedy 49/49 精确
121
+ - ✅ **阶段3b**:GPT-AR CUDA Graph,2.28x 加速,logits 逐位一致
122
+ - ✅ **阶段4**:S2Mel CFM CUDA Graph(小序列验证)+ TeaCache 步骤跳过(生产路径)
123
+ - ✅ **阶段5**:参考音频特征缓存 + 加速优化循环(fp16/减步/TeaCache,详见上方加速轮次表)
124
+
125
+ ### 已知限制
126
+
127
+ - **文本归一化**:第一版接受已处理文本;jieba/cn2an 中文归一化待补(非神经,独立任务)
128
+ - **emo audio 项**:用 emovec_mat only(省略 merge_emovec conformer 的 (1-sum)*audio 校正项)
129
+ - **CFM CUDA Graph**:全序列显存不足,默认 eager + TeaCache
130
+
131
+ ## 运行
132
+
133
+ 需要:模型权重(见下)+ 任意参考音频 wav(5-15s 干净人声)。
134
+
135
+ ### 获取模型权重
136
+
137
+ 模型来自 IndexTeam 官方发布,二选一:
138
+
139
+ ```bash
140
+ # HuggingFace(海外)
141
+ pip install -U "huggingface_hub[cli]"
142
+ hf download IndexTeam/IndexTTS-2.5 --local-dir=IndexTTS-2.5
143
+
144
+ # ModelScope(国内)
145
+ pip install modelscope
146
+ modelscope download --model IndexTeam/IndexTTS-2.5 --local_dir IndexTTS-2.5
147
+ ```
148
+
149
+ 下载后把目录路径传给 `--model-dir` / `weights_dir=`,或设环境变量:
150
+
151
+ ```bash
152
+ export WINDEXTTS_WEIGHTS_DIR=/path/to/IndexTTS-2.5
153
+ ```
154
+
155
+ ### 安装
156
+
157
+ ```bash
158
+ pip install windextts # 核心(纯 torch,零 JIT 编译)
159
+ pip install 'windextts[server]' # HTTP API(/v1/audio/speech)
160
+ pip install 'windextts[webui]' # Gradio WebUI
161
+ pip install 'windextts[quant]' # W4A16 INT4 加速(可选)
162
+ ```
163
+
164
+ ### CLI
165
+
166
+ ```bash
167
+ # 基础(fp16)
168
+ windextts --ref voice.wav --text "你好世界" -o out.wav
169
+ # 最快(INT4 量化)
170
+ windextts --ref voice.wav --text "你好世界" -o out.wav --w4a16
171
+ # 3GB 显卡(保持 beam3 质量,稳态 ~2.9GB)
172
+ windextts --ref voice.wav --text "你好" -o out.wav --w4a16 --low-vram
173
+ ```
174
+
175
+ ### HTTP API(OpenAI 兼容)
176
+
177
+ ```bash
178
+ windextts-server --w4a16 --port 8000 --voices default=voice.wav
179
+ ```
180
+
181
+ ```bash
182
+ curl -s http://localhost:8000/v1/audio/speech \
183
+ -H 'Content-Type: application/json' \
184
+ -d '{"model":"windextts","input":"你好世界","voice":"default"}' \
185
+ -o out.wav
186
+ ```
187
+
188
+ ### WebUI(Gradio)
189
+
190
+ ```bash
191
+ # 仓库源码运行(webui.py 不在 pip 包内)
192
+ git clone https://github.com/baicai-1145/WIndexTTS
193
+ cd WIndexTTS && pip install -e ".[webui]"
194
+ python webui.py --model_dir /path/to/IndexTTS-2.5 # 0.0.0.0:7860
195
+ ```
196
+
197
+ 功能:参考音频上传、精度运行时切换(W4A16/fp16/fp32)、低显存模式、多语言、
198
+ 情感控制(向量/文本/参考音频)、采样参数、性能调优、一键基准。
199
+
200
+ ### Python API
201
+
202
+ ```python
203
+ import torch
204
+ from windextts.inference import WIndexTTS
205
+
206
+ tts = WIndexTTS(weights_dir="/path/to/IndexTTS-2.5",
207
+ device="cuda", dtype=torch.float16, enable_w4a16=True)
208
+ tts.warmup()
209
+ sr, wav = tts.infer("voice.wav", "你好世界", "ZH")
210
+ ```
211
+
212
+ ## 设计约束
213
+
214
+ 见 [AGENTS.md](./AGENTS.md)。核心铁律:
215
+
216
+ - **纯 torch,零 JIT 编译**:核心推理路径在无 C/C++/CUDA 编译器的 Windows 上必须能跑。
217
+ - **不依赖 index-tts / transformers / modelscope**:所有 `nn.Module` 自己写,权重只用 `torch.load` + `safetensors`。
218
+ - **接缝魔数不可臆造**:唯一正确性标准是与官方输出 `torch.allclose(atol=1e-4, rtol=1e-3)`。
@@ -0,0 +1,169 @@
1
+ # WIndexTTS
2
+
3
+ Windows-priority, zero-JIT-compile, pure-torch accelerated inference engine for
4
+ **IndexTTS-2.5**.
5
+
6
+ 目标:在 **Windows 上 `pip install` 即用**(无 MSVC / nvcc / triton 编译依赖)的前提下,
7
+ 用纯 PyTorch 重写 IndexTTS-2.5 的神经网络推理,并实现比官方 `use_accel` 更彻底的 CUDA Graph 加速。
8
+
9
+ ## 状态
10
+
11
+ **端到端推理 + 多轮加速优化完成**,纯 torch,比官方 bf16 快 **2.4x**。
12
+
13
+ ### 性能(A10G 24GB,4 段中文,稳态)
14
+
15
+ | 引擎 | 均值 | 最快 | RTF | 说明 |
16
+ |---|---|---|---|---|
17
+ | **WIndexTTS** | **0.67s** | **0.59s** | **5.75x** | fp16 GPT+BigVGAN, 15步CFM+TeaCache, 紧凑KV buffer |
18
+ | 官方 bf16 | 1.81s | 1.75s | — | transformers + HF generate |
19
+ | 官方 fp32 | 2.06s | 1.91s | — | 默认精度 |
20
+
21
+ **WIndexTTS 在零编译依赖下比官方 bf16 快 2.7x、比官方 fp32 快 3.1x。**
22
+
23
+ ### 各阶段拆解(优化后)
24
+
25
+ ```
26
+ GPT-AR(fp16+graph+紧凑buffer) ~150ms ~40% ← 内存带宽受限(纯torch fp16 上限)
27
+ S2Mel-CFM(15步+tc) ~175ms ~37% ← TeaCache 跳过冗余步骤 + 减少欧拉步数
28
+ BigVGAN(fp16) ~58ms ~15% ← cosine 0.9998
29
+ codec+前端+设置 ~50ms ~8%
30
+ ──────────────────────────────────────────
31
+ E2E 稳态 ~0.67s median 0.66s, min 0.59s
32
+ ```
33
+
34
+ ### 加速轮次
35
+
36
+ | 轮次 | 技术 | 效果 | 质量 |
37
+ |---|---|---|---|
38
+ | R1 | TeaCache(S2Mel DiT 步骤跳过) | S2Mel 465→247ms (1.88x) | mel cosine 0.98 |
39
+ | R2 | fp16 GPT-AR(混合精度) | GPT 430→245ms (1.77x) | greedy 78/78 精确 |
40
+ | R3 | fp16 BigVGAN | 89→58ms (1.53x) | cosine 0.9998 |
41
+ | R4 | CFM 欧拉步 25→15 | S2Mel 251→177ms | cosine 0.998 |
42
+ | R5 | 紧凑 KV buffer(max_mel_tokens 1000→300) | GPT 184→124ms (1.48x) | 无截断(实测 68-110 codes) |
43
+
44
+ ### 未采用的方案及原因
45
+
46
+ - **bf16 GPT**:7-bit 尾数不够,greedy 仅 27% 匹配(fp16 的 10-bit 足够,100%)
47
+ - **torch.compile GPT**:与混合精度不兼容(dtype 报错)
48
+ - **GPT INT8 量化**:torchao/bitsandbytes 未安装(零依赖原则)
49
+ - **S2Mel CUDA Graph(全序列)**:T=1045 时 DiT 注意力中间量占用 ~22GB,A10G OOM
50
+ - **S2Mel fp16**:DiT forward 有多处 fp32 内部构造,侵入性大,TeaCache 已减半
51
+ - **Flash attention 解码**:不支持 seqlen_q≠seqlen_k 的 is_causal(解码场景 Q=1,K=90)
52
+ - **流水线 stream overlap**:各阶段串行依赖(每阶段需上阶段输出),单请求无可重叠独立工作
53
+
54
+ ### 可调参数(质量/速度权衡)
55
+
56
+ ```python
57
+ tts.infer(ref, text, 'ZH',
58
+ dtype=torch.float16, # fp16 GPT+BigVGAN(默认 fp32 保对齐)
59
+ cfm_steps=15, # CFM 欧拉步(25=最高质量,10=最快)
60
+ teacache_thresh=0.15, # 0=禁用,0.25=更激进跳步
61
+ cfg_rate=0.7, # CFG 强度(0.3=快10%,0.0=最快无引导)
62
+ )
63
+ ```
64
+
65
+ ### 实现历史(阶段 1-5)
66
+
67
+ - ✅ **阶段1**:全部神经模块纯 torch 重写并数值对齐(diff=0.0~9.5e-7)
68
+ - w2v-bert(580M) / CAMPPlus / EnhancedCodec / GPT-AR / S2Mel-DiT(98M) / CFM / BigVGAN / LengthRegulator
69
+ - ✅ **阶段2**:端到端流水线 `WIndexTTS.infer()` 跑通
70
+ - 前端:tiktoken tokenizer(6/6 精确)/ HiFiGAN mel(9.5e-7)/ SeamlessM4T featurizer
71
+ - ✅ **阶段3**:GPT-AR decode 引擎(KV cache)替代 HF generate,greedy 49/49 精确
72
+ - ✅ **阶段3b**:GPT-AR CUDA Graph,2.28x 加速,logits 逐位一致
73
+ - ✅ **阶段4**:S2Mel CFM CUDA Graph(小序列验证)+ TeaCache 步骤跳过(生产路径)
74
+ - ✅ **阶段5**:参考音频特征缓存 + 加速优化循环(fp16/减步/TeaCache,详见上方加速轮次表)
75
+
76
+ ### 已知限制
77
+
78
+ - **文本归一化**:第一版接受已处理文本;jieba/cn2an 中文归一化待补(非神经,独立任务)
79
+ - **emo audio 项**:用 emovec_mat only(省略 merge_emovec conformer 的 (1-sum)*audio 校正项)
80
+ - **CFM CUDA Graph**:全序列显存不足,默认 eager + TeaCache
81
+
82
+ ## 运行
83
+
84
+ 需要:模型权重(见下)+ 任意参考音频 wav(5-15s 干净人声)。
85
+
86
+ ### 获取模型权重
87
+
88
+ 模型来自 IndexTeam 官方发布,二选一:
89
+
90
+ ```bash
91
+ # HuggingFace(海外)
92
+ pip install -U "huggingface_hub[cli]"
93
+ hf download IndexTeam/IndexTTS-2.5 --local-dir=IndexTTS-2.5
94
+
95
+ # ModelScope(国内)
96
+ pip install modelscope
97
+ modelscope download --model IndexTeam/IndexTTS-2.5 --local_dir IndexTTS-2.5
98
+ ```
99
+
100
+ 下载后把目录路径传给 `--model-dir` / `weights_dir=`,或设环境变量:
101
+
102
+ ```bash
103
+ export WINDEXTTS_WEIGHTS_DIR=/path/to/IndexTTS-2.5
104
+ ```
105
+
106
+ ### 安装
107
+
108
+ ```bash
109
+ pip install windextts # 核心(纯 torch,零 JIT 编译)
110
+ pip install 'windextts[server]' # HTTP API(/v1/audio/speech)
111
+ pip install 'windextts[webui]' # Gradio WebUI
112
+ pip install 'windextts[quant]' # W4A16 INT4 加速(可选)
113
+ ```
114
+
115
+ ### CLI
116
+
117
+ ```bash
118
+ # 基础(fp16)
119
+ windextts --ref voice.wav --text "你好世界" -o out.wav
120
+ # 最快(INT4 量化)
121
+ windextts --ref voice.wav --text "你好世界" -o out.wav --w4a16
122
+ # 3GB 显卡(保持 beam3 质量,稳态 ~2.9GB)
123
+ windextts --ref voice.wav --text "你好" -o out.wav --w4a16 --low-vram
124
+ ```
125
+
126
+ ### HTTP API(OpenAI 兼容)
127
+
128
+ ```bash
129
+ windextts-server --w4a16 --port 8000 --voices default=voice.wav
130
+ ```
131
+
132
+ ```bash
133
+ curl -s http://localhost:8000/v1/audio/speech \
134
+ -H 'Content-Type: application/json' \
135
+ -d '{"model":"windextts","input":"你好世界","voice":"default"}' \
136
+ -o out.wav
137
+ ```
138
+
139
+ ### WebUI(Gradio)
140
+
141
+ ```bash
142
+ # 仓库源码运行(webui.py 不在 pip 包内)
143
+ git clone https://github.com/baicai-1145/WIndexTTS
144
+ cd WIndexTTS && pip install -e ".[webui]"
145
+ python webui.py --model_dir /path/to/IndexTTS-2.5 # 0.0.0.0:7860
146
+ ```
147
+
148
+ 功能:参考音频上传、精度运行时切换(W4A16/fp16/fp32)、低显存模式、多语言、
149
+ 情感控制(向量/文本/参考音频)、采样参数、性能调优、一键基准。
150
+
151
+ ### Python API
152
+
153
+ ```python
154
+ import torch
155
+ from windextts.inference import WIndexTTS
156
+
157
+ tts = WIndexTTS(weights_dir="/path/to/IndexTTS-2.5",
158
+ device="cuda", dtype=torch.float16, enable_w4a16=True)
159
+ tts.warmup()
160
+ sr, wav = tts.infer("voice.wav", "你好世界", "ZH")
161
+ ```
162
+
163
+ ## 设计约束
164
+
165
+ 见 [AGENTS.md](./AGENTS.md)。核心铁律:
166
+
167
+ - **纯 torch,零 JIT 编译**:核心推理路径在无 C/C++/CUDA 编译器的 Windows 上必须能跑。
168
+ - **不依赖 index-tts / transformers / modelscope**:所有 `nn.Module` 自己写,权重只用 `torch.load` + `safetensors`。
169
+ - **接缝魔数不可臆造**:唯一正确性标准是与官方输出 `torch.allclose(atol=1e-4, rtol=1e-3)`。
@@ -0,0 +1,70 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "windextts"
7
+ version = "0.1.0"
8
+ description = "Windows-priority, zero-JIT-compile, pure-torch accelerated inference for IndexTTS-2.5"
9
+ readme = "README.md"
10
+ license = { text = "Apache-2.0" }
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "baicai-1145" }]
13
+ keywords = ["tts", "text-to-speech", "index-tts", "voice-cloning", "pytorch", "cuda-graph"]
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Developers",
17
+ "Intended Audience :: Science/Research",
18
+ "License :: OSI Approved :: Apache Software License",
19
+ "Operating System :: Microsoft :: Windows",
20
+ "Operating System :: POSIX :: Linux",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.10",
23
+ "Programming Language :: Python :: 3.11",
24
+ "Programming Language :: Python :: 3.12",
25
+ "Topic :: Multimedia :: Sound/Audio :: Speech",
26
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
27
+ ]
28
+
29
+ # 极简依赖:核心推理零 JIT 编译依赖。
30
+ # transformers / modelscope / librosa 禁止引入;flash_attn 不进核心推理路径。
31
+ dependencies = [
32
+ "torch>=2.4",
33
+ "torchaudio>=2.4",
34
+ "safetensors>=0.4",
35
+ "tiktoken>=0.7",
36
+ "jieba>=0.42",
37
+ "cn2an>=0.5",
38
+ "wetext>=0.1.2",
39
+ "soundfile>=0.12",
40
+ "numpy>=1.24",
41
+ "pyyaml>=6.0",
42
+ "scipy>=1.10", # BigVGAN 滤波器组可能需要;非神经路径
43
+ ]
44
+
45
+ [project.urls]
46
+ Homepage = "https://github.com/baicai-1145/WIndexTTS"
47
+ Repository = "https://github.com/baicai-1145/WIndexTTS"
48
+ Issues = "https://github.com/baicai-1145/WIndexTTS/issues"
49
+
50
+ [project.optional-dependencies]
51
+ dev = ["pytest>=8.0", "pytest-xdist"]
52
+ webui = ["gradio>=4.0"]
53
+ quant = ["torchao>=0.5"] # W4A16 INT4 GPT quantization (optional accelerator)
54
+ server = ["fastapi>=0.110", "uvicorn>=0.29", "pydantic>=2"] # HTTP API (/v1/audio/speech)
55
+
56
+ [project.scripts]
57
+ windextts = "windextts.cli:main"
58
+ windextts-server = "windextts.server:main"
59
+ windextts-download = "windextts.download:main"
60
+ windextts-webui = "windextts.webui:main"
61
+
62
+ [tool.setuptools.packages.find]
63
+ include = ["windextts*"]
64
+
65
+ [tool.setuptools.package-data]
66
+ windextts = ["data/*.pt", "data/*.npz"]
67
+
68
+ [tool.pytest.ini_options]
69
+ testpaths = ["tests"]
70
+ python_files = ["test_*.py", "*_align.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """WIndexTTS: pure-torch accelerated inference for IndexTTS-2.5."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,5 @@
1
+ """python -m windextts → windextts.cli:main"""
2
+ from windextts.cli import main
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())