toolnet-capcut-tts 1.0.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 (49) hide show
  1. toolnet_capcut_tts-1.0.0/CHANGELOG.md +31 -0
  2. toolnet_capcut_tts-1.0.0/LICENSE +22 -0
  3. toolnet_capcut_tts-1.0.0/MANIFEST.in +8 -0
  4. toolnet_capcut_tts-1.0.0/NOTICE +26 -0
  5. toolnet_capcut_tts-1.0.0/PKG-INFO +588 -0
  6. toolnet_capcut_tts-1.0.0/PUBLISHING.md +80 -0
  7. toolnet_capcut_tts-1.0.0/README.en.md +413 -0
  8. toolnet_capcut_tts-1.0.0/README.md +555 -0
  9. toolnet_capcut_tts-1.0.0/README.zh-CN.md +380 -0
  10. toolnet_capcut_tts-1.0.0/capcut_tts_api/Voice.json +1837 -0
  11. toolnet_capcut_tts-1.0.0/capcut_tts_api/__init__.py +46 -0
  12. toolnet_capcut_tts-1.0.0/capcut_tts_api/__main__.py +6 -0
  13. toolnet_capcut_tts-1.0.0/capcut_tts_api/action.py +3 -0
  14. toolnet_capcut_tts-1.0.0/capcut_tts_api/cli.py +3 -0
  15. toolnet_capcut_tts-1.0.0/capcut_tts_api/client.py +9 -0
  16. toolnet_capcut_tts-1.0.0/capcut_tts_api/config.py +3 -0
  17. toolnet_capcut_tts-1.0.0/capcut_tts_api/exceptions.py +3 -0
  18. toolnet_capcut_tts-1.0.0/capcut_tts_api/language.json +145 -0
  19. toolnet_capcut_tts-1.0.0/capcut_tts_api/models.py +3 -0
  20. toolnet_capcut_tts-1.0.0/capcut_tts_api/signer.py +8 -0
  21. toolnet_capcut_tts-1.0.0/capcut_tts_api/uploader.py +4 -0
  22. toolnet_capcut_tts-1.0.0/pyproject.toml +77 -0
  23. toolnet_capcut_tts-1.0.0/setup.cfg +4 -0
  24. toolnet_capcut_tts-1.0.0/tests/conftest.py +151 -0
  25. toolnet_capcut_tts-1.0.0/tests/test_action.py +69 -0
  26. toolnet_capcut_tts-1.0.0/tests/test_cli.py +101 -0
  27. toolnet_capcut_tts-1.0.0/tests/test_client.py +281 -0
  28. toolnet_capcut_tts-1.0.0/tests/test_models.py +161 -0
  29. toolnet_capcut_tts-1.0.0/tests/test_package.py +95 -0
  30. toolnet_capcut_tts-1.0.0/tests/test_signer_uploader.py +114 -0
  31. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/Voice.json +1837 -0
  32. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/__init__.py +50 -0
  33. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/__main__.py +6 -0
  34. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/action.py +69 -0
  35. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/cli.py +325 -0
  36. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/client.py +801 -0
  37. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/config.py +38 -0
  38. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/exceptions.py +36 -0
  39. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/language.json +145 -0
  40. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/models.py +241 -0
  41. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/py.typed +0 -0
  42. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/signer.py +280 -0
  43. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts/uploader.py +217 -0
  44. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts.egg-info/PKG-INFO +588 -0
  45. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts.egg-info/SOURCES.txt +47 -0
  46. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts.egg-info/dependency_links.txt +1 -0
  47. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts.egg-info/entry_points.txt +3 -0
  48. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts.egg-info/requires.txt +4 -0
  49. toolnet_capcut_tts-1.0.0/toolnet_capcut_tts.egg-info/top_level.txt +2 -0
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 - 2026-11-10
4
+
5
+ Bản phát hành độc lập đầu tiên của ToolNet CapCut TTS.
6
+
7
+ ### Thương hiệu và đóng gói
8
+
9
+ - Đổi tên distribution thành `toolnet-capcut-tts`.
10
+ - Package chính mới: `toolnet_capcut_tts`.
11
+ - Giữ package tương thích `capcut_tts_api` cho mã nguồn hiện có.
12
+ - CLI mới: `toolnet-capcut-tts`; giữ alias `capcut-tts-api`.
13
+ - Viết lại README tiếng Việt, bổ sung README tiếng Anh và tiếng Trung.
14
+ - Bổ sung LICENSE, NOTICE và metadata giấy phép MIT.
15
+
16
+ ### Chức năng
17
+
18
+ - Giữ nguyên TTS, STT, dịch, SRT, catalog giọng đọc và upload VOD.
19
+ - Bổ sung `CapCutClient.list_languages()` và `list_language_categories()`.
20
+ - Bổ sung CLI `list-languages`.
21
+ - Bổ sung kiểm thử tự động cho model, client, CLI, uploader và package.
22
+
23
+ ### Sửa lỗi
24
+
25
+ - Nhận diện trạng thái task lỗi không phân biệt hoa/thường.
26
+ - Báo lỗi rõ ràng khi response tạo task thiếu `id`/`token`.
27
+ - Truyền `base_url` tùy chỉnh vào luồng upload VOD.
28
+ - Resolve voice khi người dùng truyền trực tiếp `resource_id`.
29
+ - Đồng bộ docstring của helper ký payload với hành vi thực tế.
30
+ - Sửa `write_srt()` để tương thích Python 3.9 (không dùng tham số
31
+ `newline` chỉ có từ Python 3.10 của `Path.write_text`).
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 CapCut API Contributors
4
+ Copyright (c) 2026 ToolNetWorks
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include README.en.md
3
+ include README.zh-CN.md
4
+ include CHANGELOG.md
5
+ include PUBLISHING.md
6
+ include LICENSE
7
+ include NOTICE
8
+ recursive-include tests *.py
@@ -0,0 +1,26 @@
1
+ ToolNet CapCut TTS
2
+ ==================
3
+
4
+ This software is an independent, rebranded distribution derived from the
5
+ "capcut-tts-api" Python package.
6
+
7
+ Original work
8
+ -------------
9
+ Project: capcut-tts-api
10
+ Copyright (c) 2026 CapCut API Contributors
11
+ License declared by the original project: MIT
12
+ The original repository did not include a standalone LICENSE file. The MIT
13
+ terms declared in its package metadata are reproduced in LICENSE together
14
+ with the original copyright notice.
15
+
16
+ Modifications
17
+ -------------
18
+ - Repackaged and rebranded as ToolNet CapCut TTS.
19
+ - Canonical import package: toolnet_capcut_tts.
20
+ - capcut_tts_api is retained as a compatibility facade for existing imports.
21
+ - Documentation, CLI entry points, tests and package metadata were updated.
22
+ - Bug fixes are limited to task-status handling, base URL propagation, voice
23
+ resolution and language-catalog helpers. The core TTS/STT algorithms are
24
+ unchanged.
25
+
26
+ The MIT license and the original copyright notice are preserved in LICENSE.
@@ -0,0 +1,588 @@
1
+ Metadata-Version: 2.4
2
+ Name: toolnet-capcut-tts
3
+ Version: 1.0.0
4
+ Summary: ToolNet CapCut TTS - Python SDK and CLI for CapCut text-to-speech, speech-to-text, translation and SRT workflows
5
+ Author: ToolNetWorks
6
+ Maintainer: ToolNetWorks
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/ToolNetWorks/toolnet-capcut-tts
9
+ Project-URL: Repository, https://github.com/ToolNetWorks/toolnet-capcut-tts
10
+ Project-URL: Issues, https://github.com/ToolNetWorks/toolnet-capcut-tts/issues
11
+ Project-URL: Changelog, https://github.com/ToolNetWorks/toolnet-capcut-tts/blob/main/CHANGELOG.md
12
+ Project-URL: PyPI, https://pypi.org/project/toolnet-capcut-tts/
13
+ Keywords: toolnet,capcut,tts,stt,text-to-speech,speech-to-text,translation,srt,vod,api
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ License-File: NOTICE
29
+ Requires-Dist: requests>=2.25.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # ToolNet CapCut TTS
35
+
36
+ **SDK Python và CLI độc lập cho các quy trình Text-to-Speech (TTS), Speech-to-Text (STT), dịch phụ đề và SRT trên CapCut Common Task API.**
37
+
38
+ [English](README.en.md) · [简体中文](README.zh-CN.md)
39
+
40
+ ---
41
+
42
+ ## Giới thiệu
43
+
44
+ ToolNet CapCut TTS là một dự án Python độc lập, phát hành theo giấy phép MIT.
45
+ Dự án cung cấp:
46
+
47
+ - thư viện Python để tạo và theo dõi task TTS, tải audio trả về;
48
+ - upload media lên VOD, gửi task STT, nhận dạng lời nói;
49
+ - dịch phụ đề trong cùng luồng STT nếu dịch vụ hỗ trợ;
50
+ - đọc/ghi SRT, tạo audio theo từng cue hoặc một audio gộp;
51
+ - catalog giọng đọc và mã ngôn ngữ đi kèm package;
52
+ - CLI đầy đủ cho các thao tác thường dùng.
53
+
54
+ > **Lưu ý:** Đây là dự án độc lập, không phải sản phẩm chính thức của CapCut,
55
+ > ByteDance hay bất kỳ bên thứ ba nào. API được sử dụng là endpoint quan sát
56
+ > được từ ứng dụng CapCut; dịch vụ có thể thay đổi, giới hạn khu vực hoặc yêu
57
+ > cầu thông tin xác thực mà không báo trước. Hãy kiểm tra quyền sử dụng dịch vụ
58
+ > và nội dung trước khi triển khai thực tế.
59
+
60
+ ## Tính năng
61
+
62
+ | Nhóm | Chức năng |
63
+ | --- | --- |
64
+ | TTS | Tạo task, poll trạng thái, tải artifact MP3 |
65
+ | STT | Upload media, nhận dạng, lấy timing câu và từ |
66
+ | Dịch | Bật `use_translation`, ghi SRT đã dịch |
67
+ | SRT | Đọc SRT, tạo audio từng cue, tạo audio gộp |
68
+ | Catalog | Danh sách giọng đọc, resolve voice, danh sách ngôn ngữ |
69
+ | SDK | `CapCutClient`, dataclass, exception công khai |
70
+ | CLI | 11 chế độ, hỗ trợ `--dry-run`, xuất JSON |
71
+ | Tương thích | Giữ import cũ `capcut_tts_api` bên cạnh package mới |
72
+
73
+ ## Yêu cầu
74
+
75
+ - Python **3.9+**
76
+ - `requests>=2.25.0`
77
+ - Kết nối mạng tới endpoint CapCut nếu muốn gọi dịch vụ thật
78
+ - Không bắt buộc ffmpeg: việc tạo audio gộp do dịch vụ thực hiện
79
+
80
+ ## Cài đặt
81
+
82
+ ### Từ PyPI (khuyến nghị)
83
+
84
+ ```bash
85
+ python -m pip install --upgrade pip
86
+ python -m pip install toolnet-capcut-tts
87
+ ```
88
+
89
+ Bản phát hành chính thức: <https://pypi.org/project/toolnet-capcut-tts/>.
90
+
91
+ ### Từ source
92
+
93
+ ```bash
94
+ git clone https://github.com/ToolNetWorks/toolnet-capcut-tts.git
95
+ cd toolnet-capcut-tts
96
+
97
+ python -m venv .venv
98
+ source .venv/bin/activate # Linux/macOS
99
+ # .\.venv\Scripts\Activate.ps1 # Windows PowerShell
100
+
101
+ python -m pip install --upgrade pip
102
+ python -m pip install -e .
103
+ ```
104
+
105
+ ### Cài kèm công cụ phát triển
106
+
107
+ ```bash
108
+ python -m pip install -e ".[dev]"
109
+ ```
110
+
111
+ ### Kiểm tra cài đặt
112
+
113
+ ```bash
114
+ toolnet-capcut-tts --version
115
+ toolnet-capcut-tts --help
116
+ python -c "import toolnet_capcut_tts; print(toolnet_capcut_tts.__version__)"
117
+ ```
118
+
119
+ ## Bắt đầu nhanh
120
+
121
+ ### 1. Tạo client và xem giọng đọc
122
+
123
+ ```python
124
+ from toolnet_capcut_tts import CapCutClient
125
+
126
+ client = CapCutClient(timeout=60)
127
+
128
+ # Catalog cục bộ, không gọi mạng.
129
+ for voice in client.list_voices(lang="vi-VN")[:5]:
130
+ print(voice.voice_type, voice.display_name, voice.resource_id)
131
+
132
+ voice_type, resource_id = client.resolve_voice("BV421_vivn_streaming")
133
+ print(voice_type, resource_id)
134
+ ```
135
+
136
+ `list_voices()` đọc `Voice.json` đi kèm package. Catalog có thể cũ; quyền dùng
137
+ voice thực tế vẫn do dịch vụ và tài khoản quyết định.
138
+
139
+ ### 2. Xem danh sách ngôn ngữ
140
+
141
+ ```python
142
+ from toolnet_capcut_tts import CapCutClient
143
+
144
+ client = CapCutClient()
145
+ print(client.list_language_categories())
146
+ print(client.list_languages(category="tts_catalog_languages"))
147
+ print(client.list_languages(category="media_asr_exact_observed"))
148
+ ```
149
+
150
+ Các nhóm ngôn ngữ phản ánh phạm vi bằng chứng khác nhau:
151
+
152
+ - `tts_catalog_languages`: ngôn ngữ có trong catalog TTS;
153
+ - `media_asr_exact_observed`: mã ASR quan sát được;
154
+ - `media_asr_lowercase_aliases_observed`: alias chữ thường;
155
+ - `draft_subtitle_language_examples`: ví dụ ngôn ngữ phụ đề;
156
+ - `draft_translate_target_examples`: ví dụ ngôn ngữ đích;
157
+ - `ui_locales_observed`: locale giao diện.
158
+
159
+ Đây không phải danh sách đầy đủ mọi ngôn ngữ mà dịch vụ hỗ trợ.
160
+
161
+ ### 3. Tạo giọng nói và lưu file
162
+
163
+ ```python
164
+ from toolnet_capcut_tts import CapCutClient
165
+
166
+ client = CapCutClient(timeout=60)
167
+ result = client.generate_speech(
168
+ "Xin chào từ ToolNet CapCut TTS.",
169
+ voice="BV421_vivn_streaming",
170
+ timeout=180,
171
+ )
172
+ audio_path = client.download_tts_audio(result, "hello.mp3")
173
+ print(f"Đã lưu: {audio_path}")
174
+ ```
175
+
176
+ Mặc định `generate_speech()` chờ task hoàn tất. Dùng `wait=False` nếu muốn tự
177
+ quản lý polling:
178
+
179
+ ```python
180
+ created = client.generate_speech(
181
+ "Task đang chờ",
182
+ voice="BV421_vivn_streaming",
183
+ wait=False,
184
+ )
185
+ task = created["data"]["tasks"][0]
186
+
187
+ import time
188
+
189
+ deadline = time.monotonic() + 180
190
+ while time.monotonic() < deadline:
191
+ completed = client.query_tts_task(
192
+ task["id"], task["token"], task.get("bind_id", "")
193
+ )
194
+ status = (completed.get("data", {}).get("tasks") or [{}])[0].get("status", "")
195
+ if status.lower() in {"success", "succeed", "succeeded", "completed", "done"}:
196
+ break
197
+ if status.lower() in {"failed", "failure", "error", "cancelled", "canceled"}:
198
+ raise RuntimeError(f"TTS task lỗi: {completed}")
199
+ time.sleep(1)
200
+ else:
201
+ raise TimeoutError("TTS task chưa hoàn thành trong thời hạn")
202
+
203
+ audio_path = client.download_tts_audio(completed, "queued-task.mp3")
204
+ print(status, audio_path)
205
+ ```
206
+
207
+ ### 4. Nhận dạng file và ghi SRT
208
+
209
+ ```python
210
+ from toolnet_capcut_tts import CapCutClient
211
+
212
+ client = CapCutClient(timeout=60)
213
+ stt = client.transcribe_file(
214
+ "recording.mp3",
215
+ language="vi-VN",
216
+ timeout=180,
217
+ )
218
+ subtitles = client.extract_subtitles(stt)
219
+ subtitles.write_srt("recording.vi.srt")
220
+ print(subtitles.full_text)
221
+ ```
222
+
223
+ `transcribe_file()` upload media, tạo task STT, poll và trả response hoàn tất.
224
+ Dùng `wait=False` để nhận response tạo task.
225
+
226
+ ### 5. Dịch và ghi SRT đã dịch
227
+
228
+ ```python
229
+ translated = client.transcribe_file(
230
+ "recording.mp3",
231
+ language="vi-VN",
232
+ translation_language="en-US",
233
+ use_translation=True,
234
+ timeout=180,
235
+ )
236
+ client.write_srt(translated, "recording.en.srt", use_translation=True)
237
+ ```
238
+
239
+ Bản dịch lấy từ trường `translation_text` do dịch vụ trả về. Nếu dịch vụ không
240
+ trả trường này, SDK không tự tạo bản dịch.
241
+
242
+ ### 6. Tạo audio từ SRT
243
+
244
+ ```python
245
+ # Một artifact cho mỗi cue không rỗng.
246
+ parts = client.generate_speech_from_srt(
247
+ "captions.srt",
248
+ voice="BV421_vivn_streaming",
249
+ output_dir="voice-parts",
250
+ part=True,
251
+ )
252
+ print(parts["cues"])
253
+
254
+ # Một request với toàn bộ text, một artifact audio gộp.
255
+ combined = client.generate_speech_from_srt(
256
+ "captions.srt",
257
+ voice="BV421_vivn_streaming",
258
+ audio_path="captions.mp3",
259
+ part=False,
260
+ )
261
+ print(combined["audio_path"])
262
+ ```
263
+
264
+ Thời gian bắt đầu/kết thúc của cue được giữ trong metadata trả về. Chế độ
265
+ `part=False` gửi text đã gộp cho dịch vụ và không tự ghép từng file MP3 cục bộ;
266
+ do đó audio gộp không đảm bảo khớp chính xác timing từng cue. Nếu cần đồng bộ
267
+ theo cue, dùng `part=True`.
268
+
269
+ ### 7. TTS rồi STT trên cùng một file
270
+
271
+ ```python
272
+ result = client.generate_speech_and_transcribe(
273
+ "Xin chào từ ToolNet CapCut TTS.",
274
+ voice="BV421_vivn_streaming",
275
+ audio_path="roundtrip.mp3",
276
+ srt_path="roundtrip.srt",
277
+ language="vi-VN",
278
+ )
279
+ print(result["audio_path"], result["srt_path"])
280
+ ```
281
+
282
+ ## Python API
283
+
284
+ ### `CapCutClient`
285
+
286
+ ```python
287
+ from toolnet_capcut_tts import CapCutClient
288
+
289
+ client = CapCutClient(
290
+ device=None, # DeviceConfig, dict, hoặc đường dẫn JSON
291
+ session=None, # requests.Session tùy chọn
292
+ base_url=None, # mặc định CAPCUT_BASE_URL hoặc endpoint quan sát được
293
+ headers=None, # header bổ sung
294
+ timeout=60.0, # timeout HTTP mặc định (giây)
295
+ )
296
+ ```
297
+
298
+ Các phương thức chính:
299
+
300
+ | Phương thức | Mô tả |
301
+ | --- | --- |
302
+ | `list_voices(lang=None, catalog_path=None)` | Liệt kê voice từ catalog |
303
+ | `resolve_voice(voice=None, resource_id=None)` | Resolve voice type và resource ID |
304
+ | `load_language_catalog()` | Đọc toàn bộ catalog ngôn ngữ |
305
+ | `list_language_categories()` | Liệt kê nhóm ngôn ngữ |
306
+ | `list_languages(category=...)` | Liệt kê mã ngôn ngữ theo nhóm |
307
+ | `build_tts_new_request(...)` | Tạo request TTS, không gửi |
308
+ | `create_tts_task(...)` | Gửi request tạo task TTS |
309
+ | `generate_speech(...)` | Tạo task và poll tới khi xong |
310
+ | `query_tts_task(...)` | Truy vấn task TTS |
311
+ | `extract_tts_artifacts(response)` | Lấy metadata artifact |
312
+ | `download_tts_audio(response, path)` | Tải artifact audio |
313
+ | `upload_audio(path)` | Upload media lên VOD |
314
+ | `build_stt_new_request(...)` | Tạo request STT, không gửi |
315
+ | `create_stt_task(...)` | Gửi request tạo task STT |
316
+ | `transcribe_file(...)` | Upload + tạo task + poll STT |
317
+ | `query_stt_task(...)` | Truy vấn task STT |
318
+ | `extract_subtitles(response)` | Parse utterance/word |
319
+ | `write_srt(response, path, ...)` | Ghi SRT nguồn hoặc bản dịch |
320
+ | `generate_speech_from_srt(...)` | TTS theo cue hoặc audio gộp |
321
+ | `generate_speech_and_transcribe(...)` | TTS rồi STT trên cùng file |
322
+
323
+ ### Request builder và worker
324
+
325
+ ```python
326
+ created = client.create_tts_task(
327
+ ["Câu thứ nhất", "Câu thứ hai"],
328
+ voice="BV421_vivn_streaming",
329
+ )
330
+ task = created["data"]["tasks"][0]
331
+
332
+ tts_result = client.query_tts_task(
333
+ task_id=task["id"],
334
+ token=task["token"],
335
+ bind_id=task.get("bind_id", ""),
336
+ )
337
+
338
+ for artifact in client.extract_tts_artifacts(tts_result):
339
+ print(artifact)
340
+ ```
341
+
342
+ ```python
343
+ upload = client.upload_audio("recording.mp3")
344
+ created = client.create_stt_task(
345
+ audio_vid=upload.vid,
346
+ audio_md5=upload.md5,
347
+ duration_ms=upload.duration_ms,
348
+ language="vi-VN",
349
+ translation_language="en-US",
350
+ use_translation=True,
351
+ )
352
+ task = created["data"]["tasks"][0]
353
+ stt_result = client.query_stt_task(task["id"], task["token"], task.get("bind_id", ""))
354
+ subtitles = client.extract_subtitles(stt_result)
355
+ subtitles.write_srt("recording.en.srt", use_translation=True)
356
+ ```
357
+
358
+ ### Tương thích import cũ
359
+
360
+ Package `capcut_tts_api` được giữ làm facade:
361
+
362
+ ```python
363
+ from capcut_tts_api import CapCutClient # vẫn hoạt động
364
+ from capcut_tts_api.models import SubtitleResult
365
+ ```
366
+
367
+ API công khai và class name không thay đổi. Đường dẫn CLI cũ
368
+ `capcut-tts-api` cũng được giữ làm alias.
369
+
370
+ ## CLI
371
+
372
+ CLI chính:
373
+
374
+ ```bash
375
+ toolnet-capcut-tts --help
376
+ toolnet-capcut-tts --version
377
+ ```
378
+
379
+ Alias tương thích:
380
+
381
+ ```bash
382
+ capcut-tts-api --help
383
+ ```
384
+
385
+ Chạy không cần cài console script:
386
+
387
+ ```bash
388
+ python -m toolnet_capcut_tts --help
389
+ python -m capcut_tts_api --help
390
+ ```
391
+
392
+ ### Các chế độ
393
+
394
+ | Chế độ | Mục đích |
395
+ | --- | --- |
396
+ | `list-voices` | Liệt kê giọng đọc; bỏ `--language` để xem tất cả |
397
+ | `list-languages` | Liệt kê mã ngôn ngữ theo nhóm |
398
+ | `tts-new` | Tạo request/task TTS từ text |
399
+ | `tts-action` | Tạo envelope TTS action cục bộ |
400
+ | `tts-srt` | Tạo audio từ file SRT |
401
+ | `tts-query` | Truy vấn task TTS |
402
+ | `upload-audio` | Upload media lên VOD |
403
+ | `stt-new` | Tạo task STT từ vid/md5 đã có |
404
+ | `stt-query` | Truy vấn task STT |
405
+ | `stt-file` | Upload + tạo + poll STT từ file |
406
+ | `translate` | Upload + STT + dịch + ghi SRT |
407
+
408
+ ### Ví dụ
409
+
410
+ ```bash
411
+ # Giọng đọc
412
+ toolnet-capcut-tts list-voices --language vi-VN
413
+ toolnet-capcut-tts list-voices --out voices.json
414
+
415
+ # Ngôn ngữ
416
+ toolnet-capcut-tts list-languages
417
+ toolnet-capcut-tts list-languages --language-category media_asr_exact_observed
418
+
419
+ # TTS: chỉ xem request
420
+ toolnet-capcut-tts tts-new \
421
+ --text "Xin chào" \
422
+ --voice BV421_vivn_streaming \
423
+ --dry-run
424
+
425
+ # TTS: gửi request
426
+ toolnet-capcut-tts tts-new \
427
+ --text "Xin chào" \
428
+ --voice BV421_vivn_streaming \
429
+ --out tts-task.json
430
+
431
+ # TTS từ SRT: mỗi cue một MP3
432
+ toolnet-capcut-tts tts-srt \
433
+ --srt-file captions.srt \
434
+ --voice BV421_vivn_streaming \
435
+ --part \
436
+ --output-dir voice-parts
437
+
438
+ # TTS từ SRT: một audio gộp
439
+ toolnet-capcut-tts tts-srt \
440
+ --srt-file captions.srt \
441
+ --voice BV421_vivn_streaming \
442
+ --no-part \
443
+ --audio-out captions.mp3
444
+
445
+ # STT từ file
446
+ toolnet-capcut-tts stt-file \
447
+ --audio-file recording.mp3 \
448
+ --language vi-VN \
449
+ --srt-out recording.srt
450
+
451
+ # Dịch
452
+ toolnet-capcut-tts translate \
453
+ --audio-file recording.mp3 \
454
+ --language vi-VN \
455
+ --translation-language en-US \
456
+ --srt-out recording.en.srt
457
+
458
+ # Upload và tạo STT riêng
459
+ toolnet-capcut-tts upload-audio --audio-file recording.mp3 --out upload.json
460
+ toolnet-capcut-tts stt-new \
461
+ --audio-vid VOD_ID \
462
+ --audio-md5 MD5 \
463
+ --duration-ms 10000 \
464
+ --language vi-VN
465
+
466
+ # Truy vấn task
467
+ toolnet-capcut-tts tts-query --task-id TASK_ID --token TASK_TOKEN
468
+ toolnet-capcut-tts stt-query --task-id TASK_ID --token TASK_TOKEN
469
+ ```
470
+
471
+ Mọi chế độ gửi request đều hỗ trợ `--dry-run` khi có thể dựng request, và
472
+ `--out` để ghi JSON kết quả.
473
+
474
+ ## Xác thực và cấu hình
475
+
476
+ SDK chỉ đọc thông tin xác thực do người dùng cung cấp qua biến môi trường hoặc
477
+ header. Package **không** đọc cookie browser hay cơ sở dữ liệu cookie.
478
+
479
+ | Biến môi trường | Ý nghĩa |
480
+ | --- | --- |
481
+ | `CAPCUT_BASE_URL` | Ghi đè API origin |
482
+ | `CAPCUT_COOKIE` | Cookie header tùy chọn |
483
+ | `CAPCUT_BEARER` | Bearer token tùy chọn |
484
+ | `CAPCUT_HEADERS_JSON` | JSON object chứa header bổ sung |
485
+
486
+ Alias cũ `LYRA_TTS_COOKIE`, `LYRA_TTS_BEARER`, `LYRA_TTS_HEADERS_JSON` vẫn được
487
+ hỗ trợ.
488
+
489
+ Ví dụ:
490
+
491
+ ```bash
492
+ export CAPCUT_BASE_URL="https://editor-api-sg.capcutapi.com"
493
+ export CAPCUT_BEARER="..."
494
+ toolnet-capcut-tts list-voices --language vi-VN
495
+ ```
496
+
497
+ Không commit token, cookie, API key hoặc file cấu hình chứa bí mật vào Git.
498
+
499
+ ## Lỗi, timeout và retry
500
+
501
+ - Lỗi HTTP hoặc `ret != 0` được raise thành `CapCutAPIError` kèm
502
+ `status_code` và `response_data`.
503
+ - Task thất bại hoặc quá hạn được raise thành `CapCutTaskError`.
504
+ - `CapCutClient(timeout=...)` áp dụng cho từng request HTTP.
505
+ - `generate_speech(timeout=...)`, `transcribe_file(timeout=...)` và
506
+ `generate_speech_from_srt(timeout=...)` giới hạn tổng thời gian polling.
507
+ - SDK hiện không tự retry request. Nếu cần, bọc lời gọi trong vòng lặp của ứng
508
+ dụng và chỉ retry các lỗi mạng/timeout có thể thử lại an toàn.
509
+ - `--no-wait` cho phép nhận task ID ngay và tự quản lý polling sau đó.
510
+
511
+ ```python
512
+ from toolnet_capcut_tts import CapCutAPIError, CapCutError, CapCutTaskError
513
+
514
+ try:
515
+ client.generate_speech("test", voice="BV421_vivn_streaming", timeout=180)
516
+ except CapCutTaskError as exc:
517
+ print(f"Task lỗi hoặc quá hạn: {exc}")
518
+ except CapCutAPIError as exc:
519
+ print(f"Dịch vụ trả lỗi: {exc}")
520
+ except CapCutError as exc:
521
+ print(f"Lỗi client: {exc}")
522
+ ```
523
+
524
+ ## Cấu trúc dự án
525
+
526
+ ```text
527
+ toolnet-capcut-tts/
528
+ ├── toolnet_capcut_tts/ # Package chính
529
+ │ ├── action.py # Envelope TTS action cục bộ
530
+ │ ├── cli.py # CLI
531
+ │ ├── client.py # CapCutClient
532
+ │ ├── config.py # Endpoint và device profile
533
+ │ ├── exceptions.py # Exception công khai
534
+ │ ├── models.py # Dataclass, SRT, catalog voice
535
+ │ ├── signer.py # Header và helper ký request
536
+ │ ├── uploader.py # Upload VOD
537
+ │ ├── Voice.json # Catalog giọng đọc
538
+ │ └── language.json # Catalog ngôn ngữ
539
+ ├── capcut_tts_api/ # Facade tương thích import cũ
540
+ ├── tests/ # Unit test
541
+ ├── pyproject.toml
542
+ ├── LICENSE
543
+ ├── NOTICE
544
+ └── README.md
545
+ ```
546
+
547
+ ## Kiểm thử
548
+
549
+ ```bash
550
+ python -m pip install -e ".[dev]"
551
+ python -m pytest
552
+ ```
553
+
554
+ Kiểm tra nhanh không cần dịch vụ:
555
+
556
+ ```bash
557
+ python -m compileall -q toolnet_capcut_tts capcut_tts_api
558
+ toolnet-capcut-tts --help
559
+ toolnet-capcut-tts list-voices --language vi-VN
560
+ toolnet-capcut-tts list-languages
561
+ toolnet-capcut-tts tts-new --text "Xin chào" --dry-run
562
+ ```
563
+
564
+ Các kiểm thử TTS/STT thật cần quyền truy cập dịch vụ và vùng mạng phù hợp.
565
+ Kết quả có thể khác nhau theo tài khoản, voice và thời điểm.
566
+
567
+ ## Giới hạn và lưu ý
568
+
569
+ - Đây là API không chính thức, được quan sát từ ứng dụng; có thể thay đổi.
570
+ - Catalog voice/ngôn ngữ chỉ là dữ liệu tham khảo, không đảm bảo quyền truy cập.
571
+ - Không phải mọi tài khoản/khu vực đều dùng được mọi voice.
572
+ - Audio gộp từ SRT không tự đồng bộ timing từng cue; dùng `part=True` nếu cần.
573
+ - Chất lượng dịch phụ thuộc dịch vụ; SDK không tự dịch khi thiếu dữ liệu.
574
+ - Không upload nội dung riêng tư hoặc media không có quyền lên dịch vụ bên thứ ba.
575
+ - Luôn tuân thủ điều khoản dịch vụ và pháp luật về nội dung, bản quyền, dữ liệu
576
+ cá nhân tại khu vực sử dụng.
577
+
578
+ ## Giấy phép và ghi công
579
+
580
+ Dự án phát hành theo giấy phép **MIT**. Xem [LICENSE](LICENSE) để biết toàn văn
581
+ điều kiện cấp phép và thông báo bản quyền.
582
+
583
+ Thông tin về tác phẩm gốc, các thay đổi khi tái cấu trúc thương hiệu và việc bảo
584
+ toàn thông báo bản quyền được ghi trong [NOTICE](NOTICE).
585
+
586
+ MIT cho phép sử dụng, sao chép, sửa đổi và phân phối, với điều kiện giữ lại
587
+ thông báo bản quyền và điều kiện giấy phép trong bản sao hoặc phần quan trọng
588
+ của phần mềm.