srtspeak 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 (55) hide show
  1. srtspeak-0.1.0/LICENSE +201 -0
  2. srtspeak-0.1.0/PKG-INFO +434 -0
  3. srtspeak-0.1.0/README.md +399 -0
  4. srtspeak-0.1.0/pyproject.toml +69 -0
  5. srtspeak-0.1.0/setup.cfg +4 -0
  6. srtspeak-0.1.0/src/srtspeak/__init__.py +3 -0
  7. srtspeak-0.1.0/src/srtspeak/__main__.py +8 -0
  8. srtspeak-0.1.0/src/srtspeak/cli.py +610 -0
  9. srtspeak-0.1.0/src/srtspeak/core/__init__.py +1 -0
  10. srtspeak-0.1.0/src/srtspeak/core/cache.py +59 -0
  11. srtspeak-0.1.0/src/srtspeak/core/cancel.py +23 -0
  12. srtspeak-0.1.0/src/srtspeak/core/ffmpeg_resolve.py +51 -0
  13. srtspeak-0.1.0/src/srtspeak/core/fit.py +279 -0
  14. srtspeak-0.1.0/src/srtspeak/core/ja_yomi.py +81 -0
  15. srtspeak-0.1.0/src/srtspeak/core/languages.py +123 -0
  16. srtspeak-0.1.0/src/srtspeak/core/models.py +47 -0
  17. srtspeak-0.1.0/src/srtspeak/core/pipeline.py +513 -0
  18. srtspeak-0.1.0/src/srtspeak/core/progress.py +77 -0
  19. srtspeak-0.1.0/src/srtspeak/core/report.py +27 -0
  20. srtspeak-0.1.0/src/srtspeak/core/secrets.py +39 -0
  21. srtspeak-0.1.0/src/srtspeak/core/srt_parser.py +241 -0
  22. srtspeak-0.1.0/src/srtspeak/core/timeline.py +75 -0
  23. srtspeak-0.1.0/src/srtspeak/core/tts_xai.py +259 -0
  24. srtspeak-0.1.0/src/srtspeak/core/util.py +70 -0
  25. srtspeak-0.1.0/src/srtspeak/core/voices.py +93 -0
  26. srtspeak-0.1.0/src/srtspeak/gui/__init__.py +1 -0
  27. srtspeak-0.1.0/src/srtspeak/gui/app.py +493 -0
  28. srtspeak-0.1.0/src/srtspeak/i18n.py +155 -0
  29. srtspeak-0.1.0/src/srtspeak/locales/en/LC_MESSAGES/srtspeak.mo +0 -0
  30. srtspeak-0.1.0/src/srtspeak/locales/en/LC_MESSAGES/srtspeak.po +711 -0
  31. srtspeak-0.1.0/src/srtspeak/locales/ja/LC_MESSAGES/srtspeak.mo +0 -0
  32. srtspeak-0.1.0/src/srtspeak/locales/ja/LC_MESSAGES/srtspeak.po +676 -0
  33. srtspeak-0.1.0/src/srtspeak/locales/srtspeak.pot +646 -0
  34. srtspeak-0.1.0/src/srtspeak.egg-info/PKG-INFO +434 -0
  35. srtspeak-0.1.0/src/srtspeak.egg-info/SOURCES.txt +53 -0
  36. srtspeak-0.1.0/src/srtspeak.egg-info/dependency_links.txt +1 -0
  37. srtspeak-0.1.0/src/srtspeak.egg-info/entry_points.txt +2 -0
  38. srtspeak-0.1.0/src/srtspeak.egg-info/requires.txt +14 -0
  39. srtspeak-0.1.0/src/srtspeak.egg-info/top_level.txt +1 -0
  40. srtspeak-0.1.0/tests/test_cache.py +54 -0
  41. srtspeak-0.1.0/tests/test_cli_i18n.py +73 -0
  42. srtspeak-0.1.0/tests/test_dry_run.py +46 -0
  43. srtspeak-0.1.0/tests/test_fit.py +88 -0
  44. srtspeak-0.1.0/tests/test_i18n.py +205 -0
  45. srtspeak-0.1.0/tests/test_ja_yomi.py +94 -0
  46. srtspeak-0.1.0/tests/test_languages.py +61 -0
  47. srtspeak-0.1.0/tests/test_models.py +58 -0
  48. srtspeak-0.1.0/tests/test_out_dir.py +37 -0
  49. srtspeak-0.1.0/tests/test_pipeline_e2e.py +212 -0
  50. srtspeak-0.1.0/tests/test_progress.py +40 -0
  51. srtspeak-0.1.0/tests/test_secrets.py +40 -0
  52. srtspeak-0.1.0/tests/test_srt_parser.py +178 -0
  53. srtspeak-0.1.0/tests/test_timeline.py +72 -0
  54. srtspeak-0.1.0/tests/test_tts_xai.py +157 -0
  55. srtspeak-0.1.0/tests/test_voices.py +56 -0
srtspeak-0.1.0/LICENSE ADDED
@@ -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 2026 Hirofumi Ukawa
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,434 @@
1
+ Metadata-Version: 2.4
2
+ Name: srtspeak
3
+ Version: 0.1.0
4
+ Summary: SRT multilingual TTS with forced cue-window timing (xAI Grok)
5
+ Author-email: Hirofumi Ukawa <hirofumi@ukawa.biz>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/awaku7/srtspeak
8
+ Project-URL: Repository, https://github.com/awaku7/srtspeak
9
+ Project-URL: Issues, https://github.com/awaku7/srtspeak/issues
10
+ Keywords: srt,tts,xai,grok,ffmpeg,subtitle
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: End Users/Desktop
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
20
+ Classifier: Topic :: Multimedia :: Video
21
+ Requires-Python: >=3.11
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Provides-Extra: ja
25
+ Requires-Dist: kanjiconv; extra == "ja"
26
+ Provides-Extra: gui
27
+ Requires-Dist: PySide6>=6.6; extra == "gui"
28
+ Provides-Extra: ffmpeg
29
+ Requires-Dist: imageio-ffmpeg>=0.5; extra == "ffmpeg"
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=8.0; extra == "dev"
32
+ Requires-Dist: ruff>=0.6; extra == "dev"
33
+ Requires-Dist: Babel>=2.14; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # srtspeak
37
+
38
+ Multilingual SRT TTS. Forces each cue into its exact start/end window (xAI Grok TTS + ffmpeg).
39
+
40
+ Authoritative design: `DESIGN.md`.
41
+
42
+ **Languages:** [English](README.md) | [日本語](README.ja.md)
43
+
44
+ ## Requirements
45
+
46
+ | Item | Detail |
47
+ |------|--------|
48
+ | OS | Windows / macOS / Linux (developed and verified on Windows) |
49
+ | Python | 3.11+ |
50
+ | ffmpeg / ffprobe | Prefer on `PATH`; optional fallback via `imageio-ffmpeg` |
51
+ | API key | `XAI_API_KEY` only for real TTS (not needed for dry-run) |
52
+
53
+ ## Install
54
+
55
+ From the repository root:
56
+
57
+ ```bat
58
+ python -m pip install -e .
59
+ ```
60
+
61
+ With GUI:
62
+
63
+ ```bat
64
+ python -m pip install -e ".[gui]"
65
+ ```
66
+
67
+ Dev extras (pytest / ruff / Babel):
68
+
69
+ ```bat
70
+ python -m pip install -e ".[dev]"
71
+ ```
72
+
73
+ Optional ffmpeg fallback via pip:
74
+
75
+ ```bat
76
+ python -m pip install -e ".[ffmpeg]"
77
+ ```
78
+
79
+ After editable install, the `srtspeak` command is available. Without install:
80
+
81
+ ```bat
82
+ set PYTHONPATH=src
83
+ python -m srtspeak --help
84
+ ```
85
+
86
+ Japanese yomi preprocess (kanji→hiragana via kanjiconv):
87
+
88
+ ```bat
89
+ python -m pip install -e ".[ja]"
90
+ ```
91
+
92
+ Combined extras example:
93
+
94
+ ```bat
95
+ python -m pip install -e ".[gui,ja]"
96
+ ```
97
+
98
+ ## Launch (Windows)
99
+
100
+ Double-click or run from the repo root:
101
+
102
+ | Script | Action |
103
+ |--------|--------|
104
+ | `run_gui.bat` | Start GUI |
105
+ | `run_doctor.bat` | Environment check |
106
+ | `run_srtspeak.bat …` | CLI passthrough (same args as `srtspeak`) |
107
+
108
+ Examples:
109
+
110
+ ```bat
111
+ run_gui.bat
112
+ run_doctor.bat
113
+ run_srtspeak.bat --help
114
+ run_srtspeak.bat dry-run --srt GRAN_TENKU_japan.srt --lang ja
115
+ ```
116
+
117
+ Equivalent without bat:
118
+
119
+ ```bat
120
+ srtspeak gui
121
+ python -m srtspeak gui
122
+ ```
123
+
124
+ Notes:
125
+
126
+ - Scripts `cd` to the repo root automatically.
127
+ - If `srtspeak` is not on `PATH`, they set `PYTHONPATH=src` and use `python -m srtspeak`.
128
+ - If `XAI_API_KEY` is unset and `UAGENT_GROK_API_KEY` is set, it is copied for the session only (not persisted).
129
+
130
+ ## When ffmpeg is missing
131
+
132
+ Resolution order (`core/ffmpeg_resolve.py`):
133
+
134
+ 1. `ffmpeg` / `ffprobe` on `PATH` (`shutil.which`)
135
+ 2. Optional dependency `imageio-ffmpeg` bundled binary (`get_ffmpeg_exe()`)
136
+ 3. Otherwise `FFmpegNotFoundError`
137
+
138
+ | Situation | Behavior |
139
+ |-----------|----------|
140
+ | `srtspeak doctor` | Prints `ffmpeg: MISSING (...)`. Exit code **0** (diagnostics only) |
141
+ | `dry-run` | ffmpeg **not required** (parse + char count + cost estimate only) |
142
+ | Real `build` / `build-all` | Fails at fit stage. CLI: `error: ffmpeg not found on PATH and imageio-ffmpeg is unavailable`, exit code **2** |
143
+ | `imageio-ffmpeg` only | Works, but `ffprobe` may be `(none)`. Full PATH ffmpeg build is **recommended** |
144
+
145
+ ### Install examples (Windows)
146
+
147
+ WinGet (recommended):
148
+
149
+ ```bat
150
+ winget install Gyan.FFmpeg
151
+ ```
152
+
153
+ Then in a **new** terminal:
154
+
155
+ ```bat
156
+ ffmpeg -version
157
+ ffprobe -version
158
+ srtspeak doctor
159
+ ```
160
+
161
+ If you prefer not to change PATH:
162
+
163
+ ```bat
164
+ python -m pip install -e ".[ffmpeg]"
165
+ srtspeak doctor
166
+ ```
167
+
168
+ `doctor` shows `source: path` for system ffmpeg, or `source: imageio_ffmpeg` for the pip bundle.
169
+
170
+ ## xAI (Grok TTS) signup and API key
171
+
172
+ TTS is **xAI Grok only** (`POST https://api.x.ai/v1/tts`). Create the key in the console.
173
+
174
+ ### 1. Account
175
+
176
+ 1. Open [https://console.x.ai/](https://console.x.ai/)
177
+ 2. Sign up / log in (xAI account)
178
+ 3. Accept terms and set up billing / credits as guided
179
+ - TTS is usage-based. dry-run estimate uses **$15 / 1M characters** (implementation unit price)
180
+
181
+ ### 2. Create an API key
182
+
183
+ 1. Open **API Keys** (or equivalent) in the console
184
+ 2. Create a new key
185
+ 3. Copy the value (often starts with `xai-`)
186
+ - It may **not be shown again** — put it in an env var immediately
187
+ 4. Do not put the key in chat, Git, `report.json`, or screenshots
188
+
189
+ Official docs:
190
+
191
+ - [Text to Speech](https://docs.x.ai/developers/model-capabilities/audio/text-to-speech)
192
+ - [Voice](https://docs.x.ai/developers/model-capabilities/audio/voice)
193
+ - API: `https://api.x.ai/v1/tts` / voices: `https://api.x.ai/v1/tts/voices`
194
+
195
+ ### 3. How this tool reads the key
196
+
197
+ | Rule | Detail |
198
+ |------|--------|
199
+ | Variable | **`XAI_API_KEY` only** |
200
+ | CLI flag | No `--api-key` (avoids shell history) |
201
+ | Persistence | No `.env` read/write; never written to report/logs |
202
+ | dry-run | Key optional |
203
+ | Real TTS | env → (CLI) `getpass` prompt → else exit code 2 |
204
+ | GUI | env first; masked session input if missing |
205
+
206
+ Windows cmd (current window only):
207
+
208
+ ```bat
209
+ set "XAI_API_KEY=xai-..."
210
+ srtspeak doctor
211
+ ```
212
+
213
+ PowerShell:
214
+
215
+ ```powershell
216
+ $env:XAI_API_KEY = "xai-..."
217
+ srtspeak doctor
218
+ ```
219
+
220
+ Persist for new terminals (cmd):
221
+
222
+ ```bat
223
+ setx XAI_API_KEY "xai-..."
224
+ ```
225
+
226
+ `doctor` shows presence only:
227
+
228
+ ```text
229
+ XAI_API_KEY: set (env)
230
+ ```
231
+
232
+ or:
233
+
234
+ ```text
235
+ XAI_API_KEY: missing
236
+ ```
237
+
238
+ Invalid key / insufficient balance surfaces as `TTS error: ...` during build (exit code 1).
239
+
240
+ ## Commands
241
+
242
+ ```bat
243
+ srtspeak --help
244
+ srtspeak doctor
245
+ srtspeak languages
246
+ srtspeak voices
247
+ srtspeak gui
248
+ srtspeak build --help
249
+ srtspeak build-all --help
250
+ srtspeak dry-run --help
251
+ ```
252
+
253
+ | Command | Purpose |
254
+ |---------|---------|
255
+ | `doctor` | Check `XAI_API_KEY`, ffmpeg/ffprobe, PySide6 |
256
+ | `languages` | Language codes sendable to the API |
257
+ | `voices` | Grok voices (API if key present, else builtin) |
258
+ | `dry-run` | Parse + char count + cost estimate (no key, no ffmpeg) |
259
+ | `build` | Generate one language |
260
+ | `build-all` | Generate multiple languages in sequence |
261
+ | `gui` | PySide6 GUI |
262
+
263
+ Global options:
264
+
265
+ ```text
266
+ --locale en|ja UI locale (default: SRTSPEAK_LOCALE → LC_ALL/LANG → system → en)
267
+ --verbose / --quiet
268
+ ```
269
+
270
+ Place `--quiet` / `--verbose` **before** the subcommand:
271
+
272
+ ```bat
273
+ srtspeak --locale ja doctor
274
+ srtspeak --verbose build --srt sample.srt --lang ja --dry-run
275
+ ```
276
+
277
+ ## Input / output layout
278
+
279
+ `--out` is the **output root**. Artifacts always go under `{out}/{lang}/`.
280
+
281
+ ```text
282
+ out/{lang}/
283
+ cues/ per-cue audio
284
+ fitted/ duration-fitted audio
285
+ GRAN_TENKU_{lang}.wav final track (fixed name)
286
+ report.json
287
+ work/{lang}/
288
+ raw/
289
+ cache/
290
+ ```
291
+
292
+ - Default root: `out` → e.g. `out/ja/`
293
+ - `--out out/en` with `--lang en` → `out/en/` (no double nesting)
294
+ - `--out artifacts` with `--lang pt` → `artifacts/pt/`
295
+ - `build-all` writes `summary.json` at the out root
296
+
297
+ ## Usage
298
+
299
+ ### Environment check
300
+
301
+ ```bat
302
+ srtspeak doctor
303
+ ```
304
+
305
+ Before a real build you typically want:
306
+
307
+ - `XAI_API_KEY: set (env)`
308
+ - `ffmpeg:` path with `source: path` (or `imageio_ffmpeg`)
309
+
310
+ ### Cost estimate (no key, no ffmpeg)
311
+
312
+ ```bat
313
+ srtspeak dry-run --srt GRAN_TENKU_japan.srt --lang ja
314
+ ```
315
+
316
+ ### Single-language build
317
+
318
+ ```bat
319
+ set "XAI_API_KEY=xai-..."
320
+
321
+ srtspeak build --srt GRAN_TENKU_japan.srt --lang ja --voice-id leo
322
+ srtspeak build --srt GRAN_TENKU_English.srt --lang en --voice-id leo --out out
323
+ srtspeak build --srt GRAN_TENKU_Portugus.srt --lang pt --voice-id leo
324
+ ```
325
+
326
+ Main options:
327
+
328
+ | Option | Meaning | Default |
329
+ |--------|---------|---------|
330
+ | `--srt` | Input SRT | required |
331
+ | `--lang` | Internal key `ja` / `en` / `pt` … | may be guessed from filename |
332
+ | `--language-code` | BCP-47 sent to API | lang default (`pt`→`pt-BR`) |
333
+ | `--out` | Output root (lang appended) | `out` |
334
+ | `--work-dir` | Work root | `work` |
335
+ | `--voice-id` | Voice ID | `leo` |
336
+ | `--short-mode` | `pad` / `stretch` | `pad` |
337
+ | `--limit N` | First N cues only | all |
338
+ | `--dry-run` | Estimate only | off |
339
+ | `--also-mp3` | Also write mp3 | off |
340
+ | `--jobs` | Parallelism (MVP: 1 only) | `1` |
341
+
342
+ Smoke a few cues:
343
+
344
+ ```bat
345
+ srtspeak build --srt GRAN_TENKU_japan.srt --lang ja --limit 3 --voice-id leo
346
+ ```
347
+
348
+ Portuguese as pt-PT:
349
+
350
+ ```bat
351
+ srtspeak build --srt GRAN_TENKU_Portugus.srt --lang pt --language-code pt-PT --voice-id leo
352
+ ```
353
+
354
+ ### Multi-language batch
355
+
356
+ ```bat
357
+ srtspeak build-all ^
358
+ --map ja=GRAN_TENKU_japan.srt ^
359
+ --map en=GRAN_TENKU_English.srt ^
360
+ --map pt=GRAN_TENKU_Portugus.srt ^
361
+ --voice-id leo ^
362
+ --out out
363
+ ```
364
+
365
+ Per-language voices:
366
+
367
+ ```bat
368
+ srtspeak build-all ^
369
+ --map ja=GRAN_TENKU_japan.srt ^
370
+ --map en=GRAN_TENKU_English.srt ^
371
+ --voice-id ja=leo --voice-id en=orion
372
+ ```
373
+
374
+ ### GUI
375
+
376
+ ```bat
377
+ python -m pip install -e ".[gui]"
378
+ srtspeak gui
379
+ ```
380
+
381
+ - Out field is the **root** (default `out`); lang is appended at run time
382
+ - API key: env preferred; masked session input if unset
383
+
384
+ ## Processing notes
385
+
386
+ - TTS: xAI Grok unary REST only (`speed` always 1.0)
387
+ - Fit: ffmpeg CLI only (`atempo` 0.5–2.0 multi-stage; short cues default to pad)
388
+ - Timeline: silence canvas + PCM placement; half-open window `[start, end)`
389
+ - Track length: aligned to last cue end (±50 ms)
390
+ - Audio: mono s16le 24 kHz WAV
391
+ - Cost estimate (dry-run): $15 / 1M chars
392
+
393
+ ## Exit codes
394
+
395
+ | Code | Meaning |
396
+ |------|---------|
397
+ | 0 | Success (`doctor` is 0 even if ffmpeg is missing) |
398
+ | 1 | Runtime errors (e.g. TTS) |
399
+ | 2 | Config/args/invalid SRT/**ffmpeg missing**/key missing |
400
+ | 130 | Cancelled (Ctrl+C) |
401
+
402
+ ## Development
403
+
404
+ ```bat
405
+ python -m pip install -e ".[dev]"
406
+ set PYTHONPATH=src
407
+ python -m pytest -q
408
+ python -m ruff check src tests
409
+ python -m ruff format src tests
410
+ ```
411
+
412
+ i18n (when messages change):
413
+
414
+ ```bat
415
+ python scripts/update_i18n.py
416
+ ```
417
+
418
+ ## Sample inputs (expected alongside the repo)
419
+
420
+ | File | lang | Notes |
421
+ |------|------|-------|
422
+ | `GRAN_TENKU_japan.srt` | `ja` | |
423
+ | `GRAN_TENKU_English.srt` | `en` | |
424
+ | `GRAN_TENKU_Portugus.srt` | `pt` | API default `pt-BR` if unspecified |
425
+
426
+ Timecodes are assumed aligned across the three files (design-time: 293 cues, `00:00:07,600`–`00:12:44,000`).
427
+
428
+ ## License
429
+
430
+ Apache License 2.0 (see `LICENSE`)
431
+
432
+ ## Author
433
+
434
+ Hirofumi Ukawa <hirofumi@ukawa.biz>