Settings file, per-job clip folders, faster polling, voices/ rename
Poll interval wait_for_completion() polled every 3 s, which quantised every clip to a 3 s boundary — across 2075 existing clips, 91% of the gaps landed exactly on a multiple of 3 s. It now starts at 0.25 s and backs off to 2 s after 10 s, so short clips are picked up immediately without hammering the server on long ones. Measured over 34 clips: 4.75 s actual vs 6.35 s under the old poll, a 25% cut in TTS wait (~18 min on a 693-clip episode). Runs now print real generation time, e.g. "done (4.2s)". A WebSocket would remove polling entirely but needs a third-party client, which would cost this script its dependency-free property. settings.ini voice, speed, temperature, max_tokens, strip_leading_ms, trailing_fade_ms, orig_volume, tts_volume, output_dir and comfy_url moved to an INI file next to the script. Precedence is CLI flag > settings.ini > built-in default, wired by feeding loaded values in as argparse defaults. --settings FILE selects an alternative profile. INI rather than TOML (tomllib is 3.11+, this runs on system Python 3.10) or JSON (no comments). A missing, partial, malformed or corrupt file degrades to built-in defaults with a warning instead of killing a long run. Run-specific flags are deliberately excluded: --start, --end, --seed, --regen, --rebuild, --resume-from, --embedded-subs, --skip-tts. Per-job folders All state for one video now lives in <output_dir>/clips/<video name>/ — clips, tts_input.srt, tts_assembled.flac, embedded_sub.srt and video_fragment.mkv. Only <stem>_lektor.mkv stays at the top level. tts_input.srt moved with the clips because they are a matched pair: block N in the SRT is clip_NNNN.flac. Previously both sat at the top level and each new job overwrote the last one's, so rebuilding an older film silently paired its clips with the newest film's text. Any past job can now be rebuilt. A run against the old flat layout gets an explanatory message. gudowski/ -> voices/ VOICE_PROMPTS_DIR is now resolved relative to the script rather than hardcoded, so moving the project no longer breaks it. Voice filenames are unchanged, so --voice gudowski_short still works. Docs updated throughout for the new layout, settings file and poll behaviour. Known issue, not addressed here: with a non-zero --start the voiceover plays early. extract_video_fragment() stream-copies, so it can only cut on a keyframe and seeks backwards to it, while TTS timestamps are relative to the requested start. On S01_E08 at --start 07:40 the nearest earlier keyframe is 458.375 s, putting the voiceover 1.625 s ahead of the picture. Runs with --start 00:00 are unaffected, since 0 is always a keyframe. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+32
-6
@@ -8,13 +8,13 @@ the straightforward version was tried first and broke.
|
|||||||
SRT / embedded track
|
SRT / embedded track
|
||||||
│ parse, clean, split dialogue
|
│ parse, clean, split dialogue
|
||||||
▼
|
▼
|
||||||
subtitle blocks ──────────────► output/tts_input.srt
|
subtitle blocks ──────────────► <job>/tts_input.srt
|
||||||
│ one HTTP job per block
|
│ one HTTP job per block
|
||||||
▼
|
▼
|
||||||
ComfyUI + Higgs Audio V3
|
ComfyUI + Higgs Audio V3
|
||||||
│ per-clip atempo + fade
|
│ per-clip atempo + fade
|
||||||
▼
|
▼
|
||||||
clips/clip_NNNN.flac
|
<job>/clip_NNNN.flac
|
||||||
│ adelay + amix, batched
|
│ adelay + amix, batched
|
||||||
▼
|
▼
|
||||||
tts_assembled.flac
|
tts_assembled.flac
|
||||||
@@ -49,15 +49,41 @@ in step 3 would silently miss it.
|
|||||||
`split_dialogue_blocks()` then divides a two-speaker block into one clip per
|
`split_dialogue_blocks()` then divides a two-speaker block into one clip per
|
||||||
line, apportioning the block's duration by character count.
|
line, apportioning the block's duration by character count.
|
||||||
|
|
||||||
The result is written to `output/tts_input.srt`. That file is the source of
|
The result is written to `tts_input.srt` in that video's job folder
|
||||||
truth for block numbering: block *N* there is `clips/clip_NNNN.flac` and the
|
(`output/clips/<video name>/`). It is the source of truth for block
|
||||||
|
numbering: block *N* there is `clip_NNNN.flac` beside it and the
|
||||||
argument to `--regen N`.
|
argument to `--regen N`.
|
||||||
|
|
||||||
## 2. Speech generation
|
## 2. Speech generation
|
||||||
|
|
||||||
For each block the script POSTs a workflow graph to `/prompt`, polls
|
For each block the script POSTs a workflow graph to `/prompt`, polls
|
||||||
`/history/{id}` every 3 s, and reads the resulting file directly from ComfyUI's
|
`/history/{id}` until it completes, and reads the resulting file directly from
|
||||||
output directory.
|
ComfyUI's output directory.
|
||||||
|
|
||||||
|
**Polling cadence is a performance decision, not a detail.** A clip that
|
||||||
|
finishes just after a poll waits for the next one, so the interval — not the
|
||||||
|
GPU — sets the floor on throughput. It was originally a flat 3 s, which
|
||||||
|
quantised every clip to a 3 s boundary: measured across 2075 real clips, 91% of
|
||||||
|
the gaps landed exactly on a multiple of 3 s.
|
||||||
|
|
||||||
|
`wait_for_completion()` now starts at 0.25 s and backs off to 2 s once a job
|
||||||
|
passes 10 s, so the common case is picked up almost immediately while a stuck
|
||||||
|
generation does not sit at 4 requests/second indefinitely. Measured over 34
|
||||||
|
clips:
|
||||||
|
|
||||||
|
| | mean | median | 34 clips |
|
||||||
|
|---|---|---|---|
|
||||||
|
| Actual generation | 4.75 s | 4.60 s | 162 s |
|
||||||
|
| Old flat 3 s poll | 6.35 s | 6.00 s | 216 s |
|
||||||
|
|
||||||
|
That is 1.60 s wasted per clip, a **25% reduction in TTS wait** — about 18
|
||||||
|
minutes on a 693-clip episode. The run also now prints real generation time
|
||||||
|
(`done (4.2s)`), which is what makes this measurable at all.
|
||||||
|
|
||||||
|
ComfyUI also pushes completion events over a WebSocket, which would remove
|
||||||
|
polling entirely. It is not used because Python has no standard-library
|
||||||
|
WebSocket client, and that would cost this script its only real virtue as a
|
||||||
|
dependency-free file. Polling at 0.25 s recovers most of the benefit.
|
||||||
|
|
||||||
The graph has five nodes:
|
The graph has five nodes:
|
||||||
|
|
||||||
|
|||||||
+21
-11
@@ -144,20 +144,30 @@ is not needed; the script drives everything over HTTP.
|
|||||||
|
|
||||||
## Configuring the script
|
## Configuring the script
|
||||||
|
|
||||||
`lektor_ai_comfy.py` has four constants at the top. If you installed anywhere
|
Most settings live in **`settings.ini`** next to the script — see
|
||||||
other than the defaults, edit them:
|
[usage.md](usage.md#settings-file). The backend address in particular:
|
||||||
|
|
||||||
```python
|
```ini
|
||||||
COMFY_URL = "http://127.0.0.1:8189"
|
[comfy]
|
||||||
COMFY_OUTPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/output")
|
comfy_url = http://127.0.0.1:8189
|
||||||
COMFY_INPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/input")
|
|
||||||
VOICE_PROMPTS_DIR = Path("/home/lukas/Programy/lektor_ai/gudowski")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
`COMFY_URL` can also be overridden per-run with `--comfy-url`. The two directory
|
Two paths remain constants in `lektor_ai_comfy.py`, because the script touches
|
||||||
constants cannot — the script reads generated audio directly from ComfyUI's
|
ComfyUI's own directories directly rather than over HTTP:
|
||||||
output directory and copies voice references into its input directory, so both
|
|
||||||
must be real paths on the same filesystem.
|
```python
|
||||||
|
COMFY_OUTPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/output")
|
||||||
|
COMFY_INPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/input")
|
||||||
|
```
|
||||||
|
|
||||||
|
Generated audio is read straight out of the output directory and voice
|
||||||
|
references are copied into the input directory, so both must be real paths
|
||||||
|
reachable from wherever the script runs. **If you installed ComfyUI anywhere
|
||||||
|
other than `~/comfy-tts-app`, edit these two lines.** They are also what would
|
||||||
|
have to change first to drive a ComfyUI instance on another machine.
|
||||||
|
|
||||||
|
A third path, `VOICE_PROMPTS_DIR`, resolves to `voices/` beside the script and
|
||||||
|
needs no editing as long as the project stays intact.
|
||||||
|
|
||||||
The script itself needs no installation. Ensure ffmpeg is present:
|
The script itself needs no installation. Ensure ffmpeg is present:
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ text and cannot drive TTS without OCR; the `--embedded-subs` picker marks them
|
|||||||
as unusable. They are still copied to the output untouched.
|
as unusable. They are still copied to the output untouched.
|
||||||
|
|
||||||
**Voice reference** — a `.wav` plus a `.txt` holding its exact transcript, both
|
**Voice reference** — a `.wav` plus a `.txt` holding its exact transcript, both
|
||||||
in `gudowski/`. Three are bundled:
|
in `voices/`. Three are bundled:
|
||||||
|
|
||||||
| Voice | Length | Format |
|
| Voice | Length | Format |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ instead — the image tracks are still copied to the output.
|
|||||||
### Wrong language selected
|
### Wrong language selected
|
||||||
|
|
||||||
The picker lists language tags but they are only as good as the source's
|
The picker lists language tags but they are only as good as the source's
|
||||||
metadata. `output/embedded_sub.srt` holds exactly what was extracted; check it
|
metadata. `embedded_sub.srt` in the job folder holds exactly what was extracted; check it
|
||||||
before committing to a full run.
|
before committing to a full run.
|
||||||
|
|
||||||
## Backend problems
|
## Backend problems
|
||||||
|
|||||||
+105
-13
@@ -60,7 +60,7 @@ Lists the video's subtitle tracks and prompts for one:
|
|||||||
Select track number: 30
|
Select track number: 30
|
||||||
```
|
```
|
||||||
|
|
||||||
The chosen track is extracted to `output/embedded_sub.srt` and then processed
|
The chosen track is extracted to `embedded_sub.srt` in the job folder and processed
|
||||||
exactly like an external file. Image-based tracks are listed but marked
|
exactly like an external file. Image-based tracks are listed but marked
|
||||||
unusable — they hold bitmaps, not text.
|
unusable — they hold bitmaps, not text.
|
||||||
|
|
||||||
@@ -74,9 +74,9 @@ python3 lektor_ai_comfy.py input/film.mkv --rebuild
|
|||||||
python3 lektor_ai_comfy.py input/film.mkv --rebuild --orig-volume 0.5 --tts-volume 2.0
|
python3 lektor_ai_comfy.py input/film.mkv --rebuild --orig-volume 0.5 --tts-volume 2.0
|
||||||
```
|
```
|
||||||
|
|
||||||
Use it after `--regen`, or to adjust the mix. It requires `output/tts_input.srt`
|
Use it after `--regen`, or to adjust the mix. It reads that video's job folder
|
||||||
and a complete set of `output/clips/clip_NNNN.flac`, and reports which are
|
(`output/clips/<video name>/`) and needs its `tts_input.srt` plus a complete set
|
||||||
missing if any are.
|
of `clip_NNNN.flac`, reporting which are missing if any are.
|
||||||
|
|
||||||
If the original run used `--end`, pass it again so the same video fragment is
|
If the original run used `--end`, pass it again so the same video fragment is
|
||||||
used.
|
used.
|
||||||
@@ -90,7 +90,7 @@ python3 lektor_ai_comfy.py input/film.mkv --regen 12 22 41
|
|||||||
python3 lektor_ai_comfy.py input/film.mkv --rebuild # then apply
|
python3 lektor_ai_comfy.py input/film.mkv --rebuild # then apply
|
||||||
```
|
```
|
||||||
|
|
||||||
Block numbers match `output/tts_input.srt` and the `clip_NNNN.flac` filenames.
|
Block numbers match that job's `tts_input.srt` and its `clip_NNNN.flac` files.
|
||||||
Only the selected FLAC files are replaced — `--rebuild` afterwards is what
|
Only the selected FLAC files are replaced — `--rebuild` afterwards is what
|
||||||
actually updates the video.
|
actually updates the video.
|
||||||
|
|
||||||
@@ -116,11 +116,79 @@ the last one that completed.
|
|||||||
Uses a pre-assembled audio file and goes straight to the mux.
|
Uses a pre-assembled audio file and goes straight to the mux.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python3 lektor_ai_comfy.py input/film.mkv --skip-tts output/tts_assembled.flac
|
python3 lektor_ai_comfy.py input/film.mkv --skip-tts "output/clips/film/tts_assembled.flac"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Settings file
|
||||||
|
|
||||||
|
Defaults live in **`settings.ini`** next to the script, so the values you always
|
||||||
|
want no longer need to be typed on every run. Precedence:
|
||||||
|
|
||||||
|
```
|
||||||
|
command-line flag > settings.ini > built-in default
|
||||||
|
```
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[tts]
|
||||||
|
voice = gudowski_short
|
||||||
|
speed = 1.2
|
||||||
|
temperature = 0.9
|
||||||
|
max_tokens = 4096
|
||||||
|
strip_leading_ms = 0
|
||||||
|
trailing_fade_ms = 80
|
||||||
|
|
||||||
|
[mix]
|
||||||
|
orig_volume = 0.60
|
||||||
|
tts_volume = 1.8
|
||||||
|
|
||||||
|
[paths]
|
||||||
|
output_dir = output
|
||||||
|
|
||||||
|
[comfy]
|
||||||
|
comfy_url = http://127.0.0.1:8189
|
||||||
|
```
|
||||||
|
|
||||||
|
Every one of these has a matching flag that overrides it for a single run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# settings.ini says tts_volume = 1.8; this run uses 2.5
|
||||||
|
python3 lektor_ai_comfy.py film.mkv --embedded-subs --tts-volume 2.5
|
||||||
|
```
|
||||||
|
|
||||||
|
Each run prints which file it used, so there is never any doubt:
|
||||||
|
|
||||||
|
```
|
||||||
|
Settings: /home/lukas/Programy/lektor_ai/settings.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
**Alternative profiles** — keep per-show settings side by side and select one:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 lektor_ai_comfy.py film.mkv --embedded-subs --settings profiles/docu.ini
|
||||||
|
```
|
||||||
|
|
||||||
|
**Behaviour when things are missing or wrong**, none of which is fatal:
|
||||||
|
|
||||||
|
| Situation | Result |
|
||||||
|
|---|---|
|
||||||
|
| No `settings.ini` | Built-in defaults; the run says so |
|
||||||
|
| Key absent from the file | That key falls back to its built-in default |
|
||||||
|
| Value unparseable (`speed = fast`) | Warning, that key falls back, run continues |
|
||||||
|
| File is not valid INI | Warning, all built-in defaults, run continues |
|
||||||
|
|
||||||
|
Comments use `#` or `;`, inline comments included. Deleting a line is a valid
|
||||||
|
way to return it to its built-in default.
|
||||||
|
|
||||||
|
**Not in the file, by design**: `--start`, `--end`, `--seed`, `--regen`,
|
||||||
|
`--rebuild`, `--resume-from`, `--embedded-subs`, `--skip-tts`. These describe a
|
||||||
|
particular run rather than your setup, so pinning them in config would be a
|
||||||
|
trap.
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
|
Every option below can also be set in `settings.ini`, except those noted as
|
||||||
|
run-specific.
|
||||||
|
|
||||||
### Range
|
### Range
|
||||||
|
|
||||||
| Flag | Default | Meaning |
|
| Flag | Default | Meaning |
|
||||||
@@ -128,7 +196,7 @@ python3 lektor_ai_comfy.py input/film.mkv --skip-tts output/tts_assembled.flac
|
|||||||
| `--start MM:SS` | `00:00` | Start of the range to process |
|
| `--start MM:SS` | `00:00` | Start of the range to process |
|
||||||
| `--end MM:SS` | *(end)* | End of the range |
|
| `--end MM:SS` | *(end)* | End of the range |
|
||||||
|
|
||||||
With `--end`, a matching fragment is extracted to `output/video_fragment.mkv`
|
With `--end`, a matching fragment is extracted to `video_fragment.mkv` in the job folder
|
||||||
and all TTS timestamps become relative to `--start`. Pass the same values to any
|
and all TTS timestamps become relative to `--start`. Pass the same values to any
|
||||||
later `--rebuild`, or the audio will not line up.
|
later `--rebuild`, or the audio will not line up.
|
||||||
|
|
||||||
@@ -138,7 +206,7 @@ later `--rebuild`, or the audio will not line up.
|
|||||||
|
|
||||||
| Flag | Default | Meaning |
|
| Flag | Default | Meaning |
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| `--voice NAME\|PATH` | `gudowski_short` | Name in `gudowski/`, or a path to a WAV |
|
| `--voice NAME\|PATH` | `gudowski_short` | Name in `voices/`, or a path to a WAV |
|
||||||
| `--seed N` | `0` | Base seed; `0` randomises each run |
|
| `--seed N` | `0` | Base seed; `0` randomises each run |
|
||||||
| `--temperature T` | `0.9` | Sampling temperature |
|
| `--temperature T` | `0.9` | Sampling temperature |
|
||||||
| `--max-tokens N` | `4096` | Token ceiling per clip |
|
| `--max-tokens N` | `4096` | Token ceiling per clip |
|
||||||
@@ -187,16 +255,40 @@ Typical starting point for dialogue-heavy material: `--orig-volume 0.5
|
|||||||
|
|
||||||
## Output
|
## Output
|
||||||
|
|
||||||
|
Everything belonging to one video is kept together in a **job folder** named
|
||||||
|
after the video file. Only the finished video is written to the top level.
|
||||||
|
|
||||||
```
|
```
|
||||||
output/
|
output/
|
||||||
tts_input.srt processed text actually sent to TTS — inspect this
|
clips/
|
||||||
embedded_sub.srt extracted embedded subtitle (--embedded-subs only)
|
S01_E01 The Eyes/ job folder, named after the video file
|
||||||
clips/clip_NNNN.flac one lossless clip per block, kept for --regen
|
clip_NNNN.flac one lossless clip per block, kept for --regen
|
||||||
|
tts_input.srt processed text actually sent to TTS
|
||||||
tts_assembled.flac all clips at their final positions, lossless
|
tts_assembled.flac all clips at their final positions, lossless
|
||||||
|
embedded_sub.srt extracted subtitle (--embedded-subs only)
|
||||||
video_fragment.mkv extracted segment (--end only)
|
video_fragment.mkv extracted segment (--end only)
|
||||||
{stem}_lektor.mkv the finished video
|
F1 The Movie 2025/
|
||||||
|
...
|
||||||
|
S01_E01 The Eyes_lektor.mkv the finished video
|
||||||
|
F1 The Movie 2025_lektor.mkv
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Each run prints the folder it is using:
|
||||||
|
|
||||||
|
```
|
||||||
|
Job folder: output/clips/S01_E01 The Eyes
|
||||||
|
```
|
||||||
|
|
||||||
|
This is what makes `--rebuild` and `--regen` safe across films. `tts_input.srt`
|
||||||
|
and the clips are a matched pair — block *N* in the SRT is `clip_NNNN.flac` —
|
||||||
|
so both live in the job folder. They previously sat at the top level and every
|
||||||
|
new job overwrote the last one's, which meant rebuilding an older film paired
|
||||||
|
its clips with the newest film's text. Any past job can now be rebuilt at any
|
||||||
|
time.
|
||||||
|
|
||||||
|
The folder is derived from the video filename, so `--rebuild` and `--regen`
|
||||||
|
locate it automatically; just pass the same video path.
|
||||||
|
|
||||||
The finished file contains:
|
The finished file contains:
|
||||||
|
|
||||||
| Track | Content |
|
| Track | Content |
|
||||||
@@ -229,7 +321,7 @@ python3 lektor_ai_comfy.py input/film.mkv --rebuild --orig-volume 0.45 --tts-vol
|
|||||||
**Fix a handful of bad clips**
|
**Fix a handful of bad clips**
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# read output/tts_input.srt, note the offending block numbers
|
# read output/clips/<video name>/tts_input.srt, note the offending block numbers
|
||||||
python3 lektor_ai_comfy.py input/film.mkv --regen 88 91 104
|
python3 lektor_ai_comfy.py input/film.mkv --regen 88 91 104
|
||||||
python3 lektor_ai_comfy.py input/film.mkv --rebuild
|
python3 lektor_ai_comfy.py input/film.mkv --rebuild
|
||||||
```
|
```
|
||||||
|
|||||||
+180
-45
@@ -9,6 +9,7 @@ Requires ComfyUI with TTS-Audio-Suite running at http://127.0.0.1:8189
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import configparser
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
@@ -25,10 +26,63 @@ from urllib.request import urlopen, Request
|
|||||||
# Config
|
# Config
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
COMFY_URL = "http://127.0.0.1:8189"
|
|
||||||
COMFY_OUTPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/output")
|
COMFY_OUTPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/output")
|
||||||
COMFY_INPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/input")
|
COMFY_INPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/input")
|
||||||
VOICE_PROMPTS_DIR = Path("/home/lukas/Programy/lektor_ai/gudowski")
|
VOICE_PROMPTS_DIR = Path(__file__).resolve().parent / "voices"
|
||||||
|
|
||||||
|
SETTINGS_FILE = Path(__file__).resolve().parent / "settings.ini"
|
||||||
|
|
||||||
|
# Fallback values, used when settings.ini is absent or omits a key. Keeping them
|
||||||
|
# here means the script still runs correctly with no settings file at all.
|
||||||
|
# Each entry is (ini_section, ini_key, type, value).
|
||||||
|
_DEFAULTS = {
|
||||||
|
"voice": ("tts", "voice", str, "gudowski_short"),
|
||||||
|
"speed": ("tts", "speed", float, 1.2),
|
||||||
|
"temperature": ("tts", "temperature", float, 0.9),
|
||||||
|
"max_tokens": ("tts", "max_tokens", int, 4096),
|
||||||
|
"strip_leading_ms": ("tts", "strip_leading_ms", float, 0.0),
|
||||||
|
"trailing_fade_ms": ("tts", "trailing_fade_ms", float, 80.0),
|
||||||
|
"orig_volume": ("mix", "orig_volume", float, 0.60),
|
||||||
|
"tts_volume": ("mix", "tts_volume", float, 1.8),
|
||||||
|
"output_dir": ("paths", "output_dir", str, "output"),
|
||||||
|
"comfy_url": ("comfy", "comfy_url", str, "http://127.0.0.1:8189"),
|
||||||
|
}
|
||||||
|
|
||||||
|
COMFY_URL = _DEFAULTS["comfy_url"][3] # rebound from settings/CLI in main()
|
||||||
|
|
||||||
|
|
||||||
|
def load_settings(path: Path) -> dict:
|
||||||
|
"""Read settings.ini, falling back to _DEFAULTS for anything missing.
|
||||||
|
|
||||||
|
Values here become argparse's defaults, so precedence ends up as
|
||||||
|
CLI flag > settings.ini > _DEFAULTS without any extra bookkeeping.
|
||||||
|
A malformed or unreadable file is reported and then ignored rather than
|
||||||
|
being fatal — a typo in a config file should not cost you a long run.
|
||||||
|
"""
|
||||||
|
values = {key: spec[3] for key, spec in _DEFAULTS.items()}
|
||||||
|
if not path.is_file():
|
||||||
|
return values
|
||||||
|
|
||||||
|
parser = configparser.ConfigParser(inline_comment_prefixes=("#", ";"))
|
||||||
|
try:
|
||||||
|
parser.read(path, encoding="utf-8")
|
||||||
|
except (configparser.Error, OSError) as exc:
|
||||||
|
print(f" WARNING: could not read {path.name} ({exc}) — using built-in defaults",
|
||||||
|
file=sys.stderr)
|
||||||
|
return values
|
||||||
|
|
||||||
|
for key, (section, option, cast, fallback) in _DEFAULTS.items():
|
||||||
|
if not parser.has_option(section, option):
|
||||||
|
continue
|
||||||
|
raw = parser.get(section, option).strip()
|
||||||
|
if not raw:
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
values[key] = cast(raw)
|
||||||
|
except ValueError:
|
||||||
|
print(f" WARNING: {path.name} [{section}] {option}={raw!r} is not a valid "
|
||||||
|
f"{cast.__name__} — using {fallback!r}", file=sys.stderr)
|
||||||
|
return values
|
||||||
|
|
||||||
# Subtitle codecs that carry real text and can therefore be extracted and fed
|
# Subtitle codecs that carry real text and can therefore be extracted and fed
|
||||||
# to the TTS engine. Used only by the --embedded-subs picker; image-based
|
# to the TTS engine. Used only by the --embedded-subs picker; image-based
|
||||||
@@ -642,14 +696,31 @@ def submit_workflow(workflow: dict) -> str:
|
|||||||
return resp["prompt_id"]
|
return resp["prompt_id"]
|
||||||
|
|
||||||
|
|
||||||
def wait_for_completion(prompt_id: str, poll_interval: int = 3) -> dict:
|
def wait_for_completion(prompt_id: str, poll_interval: float = 0.25,
|
||||||
|
max_interval: float = 2.0, backoff_after: float = 10.0) -> dict:
|
||||||
|
"""Block until ComfyUI reports the job finished, then return its history entry.
|
||||||
|
|
||||||
|
The poll interval, not the GPU, governs perceived generation speed: a clip
|
||||||
|
that finishes 100 ms after a poll still waits for the next one. This used to
|
||||||
|
be a flat 3 s, which quantised every clip to a 3 s boundary — measured across
|
||||||
|
2075 real clips, 91% of the gaps landed exactly on a multiple of 3 s, and
|
||||||
|
roughly a third of each run was spent sleeping on already-completed work.
|
||||||
|
|
||||||
|
Polling starts tight so the common case (most clips finish in 3-6 s) is
|
||||||
|
picked up almost immediately, then backs off once a job looks slow so a
|
||||||
|
stuck or very long generation does not sit at 4 requests/second forever.
|
||||||
|
"""
|
||||||
print(f" Waiting for {prompt_id[:8]}…", end="", flush=True)
|
print(f" Waiting for {prompt_id[:8]}…", end="", flush=True)
|
||||||
|
start = time.monotonic()
|
||||||
|
interval = poll_interval
|
||||||
|
next_dot = 1.0
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
history = _comfy_get(f"/history/{prompt_id}")
|
history = _comfy_get(f"/history/{prompt_id}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"\n Poll error: {e}", file=sys.stderr)
|
print(f"\n Poll error: {e}", file=sys.stderr)
|
||||||
time.sleep(poll_interval)
|
time.sleep(min(interval, 1.0))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if prompt_id in history:
|
if prompt_id in history:
|
||||||
@@ -660,11 +731,17 @@ def wait_for_completion(prompt_id: str, poll_interval: int = 3) -> dict:
|
|||||||
print(f"\nComfyUI error: {msg_data}", file=sys.stderr)
|
print(f"\nComfyUI error: {msg_data}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if status.get("completed"):
|
if status.get("completed"):
|
||||||
print(" done.")
|
print(f" done ({time.monotonic() - start:.1f}s).")
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
|
elapsed = time.monotonic() - start
|
||||||
|
# One dot per second regardless of poll rate, or the line fills with dots.
|
||||||
|
if elapsed >= next_dot:
|
||||||
print(".", end="", flush=True)
|
print(".", end="", flush=True)
|
||||||
time.sleep(poll_interval)
|
next_dot += 1.0
|
||||||
|
time.sleep(interval)
|
||||||
|
if elapsed > backoff_after:
|
||||||
|
interval = min(interval * 1.5, max_interval)
|
||||||
|
|
||||||
|
|
||||||
def extract_output_audio(history_entry: dict) -> Path:
|
def extract_output_audio(history_entry: dict) -> Path:
|
||||||
@@ -762,18 +839,45 @@ def generate_clips(blocks: list, voice_filename: str, voice_ref_text: str,
|
|||||||
# Rebuild / Regen helpers
|
# Rebuild / Regen helpers
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def job_dir(out_dir: Path, video_path: str) -> Path:
|
||||||
|
"""Per-job working directory: <output_dir>/clips/<video filename without extension>/
|
||||||
|
|
||||||
|
Everything that belongs to one video lives here — the clips, the processed
|
||||||
|
tts_input.srt, the assembled audio, any extracted subtitle or video
|
||||||
|
fragment. Only the finished <stem>_lektor.mkv is written to <output_dir>.
|
||||||
|
|
||||||
|
Without this separation every job overwrote the previous one's clip_NNNN.flac
|
||||||
|
and tts_input.srt, so --rebuild and --regen were only ever safe on the most
|
||||||
|
recent run. The clips and tts_input.srt are a matched pair — block N in the
|
||||||
|
SRT is clip_NNNN.flac — which is why the SRT lives here too rather than at
|
||||||
|
the top level.
|
||||||
|
"""
|
||||||
|
return out_dir / "clips" / Path(video_path).stem
|
||||||
|
|
||||||
|
|
||||||
|
def _legacy_hint(out_dir: Path, job: Path) -> str:
|
||||||
|
"""Point at the pre-per-job layout if that is what the user actually has."""
|
||||||
|
if (out_dir / "tts_input.srt").is_file():
|
||||||
|
return (f"\n\nA tts_input.srt exists at {out_dir} in the old shared layout. "
|
||||||
|
f"Clips are now kept per job in {job}. Move that run's files there, "
|
||||||
|
f"or regenerate it.")
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def _rebuild_video(args, out_dir: Path):
|
def _rebuild_video(args, out_dir: Path):
|
||||||
"""Re-assemble audio from existing clips and rebuild the final video.
|
"""Re-assemble audio from existing clips and rebuild the final video.
|
||||||
No TTS generation — use this to change volumes or fix assembly without
|
No TTS generation — use this to change volumes or fix assembly without
|
||||||
waiting for the model to run again.
|
waiting for the model to run again.
|
||||||
"""
|
"""
|
||||||
tts_srt = out_dir / "tts_input.srt"
|
job = job_dir(out_dir, args.video)
|
||||||
|
tts_srt = job / "tts_input.srt"
|
||||||
if not tts_srt.exists():
|
if not tts_srt.exists():
|
||||||
sys.exit(f"No tts_input.srt found in {out_dir} — run a full generation first.")
|
sys.exit(f"No tts_input.srt found in {job} — run a full generation first."
|
||||||
|
+ _legacy_hint(out_dir, job))
|
||||||
|
|
||||||
blocks = load_tts_input_srt(tts_srt)
|
blocks = load_tts_input_srt(tts_srt)
|
||||||
total = len(blocks)
|
total = len(blocks)
|
||||||
clips_dir = out_dir / "clips"
|
clips_dir = job
|
||||||
|
|
||||||
missing = [
|
missing = [
|
||||||
clips_dir / f"clip_{i+1:04d}.flac"
|
clips_dir / f"clip_{i+1:04d}.flac"
|
||||||
@@ -793,7 +897,7 @@ def _rebuild_video(args, out_dir: Path):
|
|||||||
clips.append((actual_start, clip_path))
|
clips.append((actual_start, clip_path))
|
||||||
cursor = actual_start + duration
|
cursor = actual_start + duration
|
||||||
|
|
||||||
assembled_tts = out_dir / "tts_assembled.flac"
|
assembled_tts = job / "tts_assembled.flac"
|
||||||
print(f"\n Assembling {total} clips…")
|
print(f"\n Assembling {total} clips…")
|
||||||
assemble_timed_audio(clips, str(assembled_tts))
|
assemble_timed_audio(clips, str(assembled_tts))
|
||||||
print(f" Assembled: {assembled_tts} ({assembled_tts.stat().st_size // 1024} KB)")
|
print(f" Assembled: {assembled_tts} ({assembled_tts.stat().st_size // 1024} KB)")
|
||||||
@@ -803,7 +907,7 @@ def _rebuild_video(args, out_dir: Path):
|
|||||||
if args.end:
|
if args.end:
|
||||||
start_sec = _parse_mmss(args.start)
|
start_sec = _parse_mmss(args.start)
|
||||||
end_sec = _parse_mmss(args.end)
|
end_sec = _parse_mmss(args.end)
|
||||||
video_fragment = out_dir / "video_fragment.mkv"
|
video_fragment = job / "video_fragment.mkv"
|
||||||
if not video_fragment.exists():
|
if not video_fragment.exists():
|
||||||
extract_video_fragment(args.video, start_sec, end_sec, str(video_fragment))
|
extract_video_fragment(args.video, start_sec, end_sec, str(video_fragment))
|
||||||
video_src = str(video_fragment)
|
video_src = str(video_fragment)
|
||||||
@@ -824,15 +928,17 @@ def _regen_clips(args, out_dir: Path):
|
|||||||
"""Regenerate specific clips by tts_input block number.
|
"""Regenerate specific clips by tts_input block number.
|
||||||
Only replaces FLAC files — run --rebuild afterwards to reassemble audio and video.
|
Only replaces FLAC files — run --rebuild afterwards to reassemble audio and video.
|
||||||
"""
|
"""
|
||||||
tts_srt = out_dir / "tts_input.srt"
|
job = job_dir(out_dir, args.video)
|
||||||
|
tts_srt = job / "tts_input.srt"
|
||||||
if not tts_srt.exists():
|
if not tts_srt.exists():
|
||||||
sys.exit(f"No tts_input.srt found in {out_dir} — run a full generation first.")
|
sys.exit(f"No tts_input.srt found in {job} — run a full generation first."
|
||||||
|
+ _legacy_hint(out_dir, job))
|
||||||
|
|
||||||
blocks = load_tts_input_srt(tts_srt)
|
blocks = load_tts_input_srt(tts_srt)
|
||||||
total = len(blocks)
|
total = len(blocks)
|
||||||
regen_set = set(args.regen)
|
regen_set = set(args.regen)
|
||||||
clips_dir = out_dir / "clips"
|
clips_dir = job
|
||||||
clips_dir.mkdir(exist_ok=True)
|
clips_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
bad = [n for n in regen_set if n < 1 or n > total]
|
bad = [n for n in regen_set if n < 1 or n > total]
|
||||||
if bad:
|
if bad:
|
||||||
@@ -874,9 +980,23 @@ def _regen_clips(args, out_dir: Path):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
global COMFY_URL
|
global COMFY_URL
|
||||||
|
|
||||||
|
# --settings is resolved before the main parser is built, because the file's
|
||||||
|
# contents become that parser's defaults.
|
||||||
|
pre = argparse.ArgumentParser(add_help=False)
|
||||||
|
pre.add_argument("--settings", default=str(SETTINGS_FILE), metavar="FILE")
|
||||||
|
pre_args, _ = pre.parse_known_args()
|
||||||
|
settings_path = Path(pre_args.settings)
|
||||||
|
cfg = load_settings(settings_path)
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="Generate AI voiceover via ComfyUI + Higgs Audio V3, per-subtitle."
|
description="Generate AI voiceover via ComfyUI + Higgs Audio V3, per-subtitle.",
|
||||||
|
epilog=f"Defaults are read from {SETTINGS_FILE.name} next to this script; "
|
||||||
|
f"any flag given on the command line overrides it.",
|
||||||
)
|
)
|
||||||
|
parser.add_argument("--settings", default=str(SETTINGS_FILE), metavar="FILE",
|
||||||
|
help=f"Settings file to read defaults from "
|
||||||
|
f"(default: {SETTINGS_FILE.name})")
|
||||||
parser.add_argument("srt", nargs="?", default=None,
|
parser.add_argument("srt", nargs="?", default=None,
|
||||||
help="Input SRT subtitle file (omit with --embedded-subs)")
|
help="Input SRT subtitle file (omit with --embedded-subs)")
|
||||||
parser.add_argument("video", nargs="?", default=None,
|
parser.add_argument("video", nargs="?", default=None,
|
||||||
@@ -885,33 +1005,39 @@ def main():
|
|||||||
help="Fragment start time (default: 00:00)")
|
help="Fragment start time (default: 00:00)")
|
||||||
parser.add_argument("--end", default=None, metavar="MM:SS",
|
parser.add_argument("--end", default=None, metavar="MM:SS",
|
||||||
help="Fragment end time")
|
help="Fragment end time")
|
||||||
parser.add_argument("--voice", default="gudowski_short",
|
parser.add_argument("--voice", default=cfg["voice"],
|
||||||
help="Voice prompt name or WAV path (default: gudowski_short)")
|
help=f"Voice prompt name or WAV path (default: {cfg['voice']})")
|
||||||
parser.add_argument("--speed", type=float, default=1.2, metavar="FACTOR",
|
parser.add_argument("--speed", type=float, default=cfg["speed"], metavar="FACTOR",
|
||||||
help="Per-clip playback speed via atempo (default: 1.2)")
|
help=f"Per-clip playback speed via atempo (default: {cfg['speed']})")
|
||||||
parser.add_argument("--seed", type=int, default=0,
|
parser.add_argument("--seed", type=int, default=0,
|
||||||
help="Base generation seed (default: 0 = random each run)")
|
help="Base generation seed (default: 0 = random each run)")
|
||||||
parser.add_argument("--orig-volume", type=float, default=0.60, metavar="0-1",
|
parser.add_argument("--orig-volume", type=float, default=cfg["orig_volume"], metavar="0-1",
|
||||||
help="Original audio volume in mix (default: 0.60)")
|
help=f"Original audio volume in mix (default: {cfg['orig_volume']})")
|
||||||
parser.add_argument("--tts-volume", type=float, default=1.8, metavar="0-2",
|
parser.add_argument("--tts-volume", type=float, default=cfg["tts_volume"], metavar="0-2",
|
||||||
help="Voiceover volume in mix (default: 1.8)")
|
help=f"Voiceover volume in mix (default: {cfg['tts_volume']})")
|
||||||
parser.add_argument("--output-dir", default="output",
|
parser.add_argument("--output-dir", default=cfg["output_dir"],
|
||||||
help="Output directory (default: output/)")
|
help=f"Output directory (default: {cfg['output_dir']}/)")
|
||||||
parser.add_argument("--comfy-url", default=COMFY_URL,
|
parser.add_argument("--comfy-url", default=cfg["comfy_url"],
|
||||||
help=f"ComfyUI URL (default: {COMFY_URL})")
|
help=f"ComfyUI URL (default: {cfg['comfy_url']})")
|
||||||
parser.add_argument("--skip-tts", metavar="AUDIO_FILE",
|
parser.add_argument("--skip-tts", metavar="AUDIO_FILE",
|
||||||
help="Skip TTS and use this pre-assembled audio file")
|
help="Skip TTS and use this pre-assembled audio file")
|
||||||
parser.add_argument("--temperature", type=float, default=0.9, metavar="T",
|
parser.add_argument("--temperature", type=float, default=cfg["temperature"], metavar="T",
|
||||||
help="Sampling temperature (default: 0.9; lower = more deterministic)")
|
help=f"Sampling temperature (default: {cfg['temperature']}; "
|
||||||
parser.add_argument("--strip-leading-ms", type=float, default=0.0, metavar="MS",
|
f"lower = more deterministic)")
|
||||||
help="Strip N ms from the start of each TTS clip to remove "
|
parser.add_argument("--strip-leading-ms", type=float, default=cfg["strip_leading_ms"],
|
||||||
"leading breath/noise artifact (default: 0, try 80–150)")
|
metavar="MS",
|
||||||
parser.add_argument("--trailing-fade-ms", type=float, default=80.0, metavar="MS",
|
help=f"Strip N ms from the start of each TTS clip to remove "
|
||||||
help="Fade out the last N ms of each TTS clip to suppress "
|
f"leading breath/noise artifact "
|
||||||
"tail pops/noise (default: 80, set 0 to disable)")
|
f"(default: {cfg['strip_leading_ms']}, try 80–150)")
|
||||||
parser.add_argument("--max-tokens", type=int, default=4096, metavar="N",
|
parser.add_argument("--trailing-fade-ms", type=float, default=cfg["trailing_fade_ms"],
|
||||||
help="Max audio tokens the TTS model may generate per clip "
|
metavar="MS",
|
||||||
"(default: 4096; raise if long clips are cut off mid-word)")
|
help=f"Fade out the last N ms of each TTS clip to suppress "
|
||||||
|
f"tail pops/noise (default: {cfg['trailing_fade_ms']}, "
|
||||||
|
f"set 0 to disable)")
|
||||||
|
parser.add_argument("--max-tokens", type=int, default=cfg["max_tokens"], metavar="N",
|
||||||
|
help=f"Max audio tokens the TTS model may generate per clip "
|
||||||
|
f"(default: {cfg['max_tokens']}; raise if long clips are "
|
||||||
|
f"cut off mid-word)")
|
||||||
parser.add_argument("--resume-from", type=int, default=0, metavar="N",
|
parser.add_argument("--resume-from", type=int, default=0, metavar="N",
|
||||||
help="Resume a crashed run: skip blocks 1..(N-1) by loading "
|
help="Resume a crashed run: skip blocks 1..(N-1) by loading "
|
||||||
"their existing clip files, generate from block N onwards.")
|
"their existing clip files, generate from block N onwards.")
|
||||||
@@ -933,6 +1059,11 @@ def main():
|
|||||||
|
|
||||||
COMFY_URL = args.comfy_url
|
COMFY_URL = args.comfy_url
|
||||||
|
|
||||||
|
if settings_path.is_file():
|
||||||
|
print(f" Settings: {settings_path}")
|
||||||
|
else:
|
||||||
|
print(f" Settings: {settings_path.name} not found — using built-in defaults")
|
||||||
|
|
||||||
# ── Resolve positional ambiguity for modes that don't need an SRT file ────
|
# ── Resolve positional ambiguity for modes that don't need an SRT file ────
|
||||||
# When the user writes `script.py video.mkv --embedded-subs` (or --rebuild /
|
# When the user writes `script.py video.mkv --embedded-subs` (or --rebuild /
|
||||||
# --regen without an SRT), argparse puts the lone positional into args.srt.
|
# --regen without an SRT), argparse puts the lone positional into args.srt.
|
||||||
@@ -949,8 +1080,6 @@ def main():
|
|||||||
|
|
||||||
out_dir = Path(args.output_dir)
|
out_dir = Path(args.output_dir)
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
clips_dir = out_dir / "clips"
|
|
||||||
clips_dir.mkdir(exist_ok=True)
|
|
||||||
|
|
||||||
# ── Rebuild mode: reassemble + remux from existing clips, no TTS ─────────
|
# ── Rebuild mode: reassemble + remux from existing clips, no TTS ─────────
|
||||||
if args.rebuild:
|
if args.rebuild:
|
||||||
@@ -962,6 +1091,12 @@ def main():
|
|||||||
_regen_clips(args, out_dir)
|
_regen_clips(args, out_dir)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Everything belonging to this video lives together, so successive jobs
|
||||||
|
# cannot overwrite each other's clips or tts_input.srt.
|
||||||
|
clips_dir = job_dir(out_dir, args.video)
|
||||||
|
clips_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
print(f" Job folder: {clips_dir}")
|
||||||
|
|
||||||
start_sec = _parse_mmss(args.start)
|
start_sec = _parse_mmss(args.start)
|
||||||
end_sec = _parse_mmss(args.end) if args.end else None
|
end_sec = _parse_mmss(args.end) if args.end else None
|
||||||
|
|
||||||
@@ -991,7 +1126,7 @@ def main():
|
|||||||
if chosen['codec_name'].lower() not in _TEXT_SUB_CODECS:
|
if chosen['codec_name'].lower() not in _TEXT_SUB_CODECS:
|
||||||
sys.exit(f"Stream #{chosen['index']} ({chosen['codec_name']}) is image-based "
|
sys.exit(f"Stream #{chosen['index']} ({chosen['codec_name']}) is image-based "
|
||||||
"and cannot be converted to text for TTS.")
|
"and cannot be converted to text for TTS.")
|
||||||
embedded_srt = out_dir / "embedded_sub.srt"
|
embedded_srt = clips_dir / "embedded_sub.srt"
|
||||||
extract_subtitle_track(args.video, chosen['index'], str(embedded_srt))
|
extract_subtitle_track(args.video, chosen['index'], str(embedded_srt))
|
||||||
srt_path = str(embedded_srt)
|
srt_path = str(embedded_srt)
|
||||||
else:
|
else:
|
||||||
@@ -1005,7 +1140,7 @@ def main():
|
|||||||
blocks = split_dialogue_blocks(blocks)
|
blocks = split_dialogue_blocks(blocks)
|
||||||
print(f" {len(blocks)} entries after dialogue splitting.")
|
print(f" {len(blocks)} entries after dialogue splitting.")
|
||||||
|
|
||||||
srt_preview = out_dir / "tts_input.srt"
|
srt_preview = clips_dir / "tts_input.srt"
|
||||||
srt_preview.write_text(blocks_to_srt(blocks), encoding="utf-8")
|
srt_preview.write_text(blocks_to_srt(blocks), encoding="utf-8")
|
||||||
print(f" Saved to {srt_preview} for inspection.")
|
print(f" Saved to {srt_preview} for inspection.")
|
||||||
|
|
||||||
@@ -1035,7 +1170,7 @@ def main():
|
|||||||
trailing_fade_ms=args.trailing_fade_ms,
|
trailing_fade_ms=args.trailing_fade_ms,
|
||||||
max_new_tokens=args.max_tokens)
|
max_new_tokens=args.max_tokens)
|
||||||
|
|
||||||
assembled_tts = out_dir / "tts_assembled.flac"
|
assembled_tts = clips_dir / "tts_assembled.flac"
|
||||||
assemble_timed_audio(clips, str(assembled_tts))
|
assemble_timed_audio(clips, str(assembled_tts))
|
||||||
print(f" Assembled: {assembled_tts} ({assembled_tts.stat().st_size // 1024} KB)")
|
print(f" Assembled: {assembled_tts} ({assembled_tts.stat().st_size // 1024} KB)")
|
||||||
print(f" Clips saved to {clips_dir}")
|
print(f" Clips saved to {clips_dir}")
|
||||||
@@ -1044,7 +1179,7 @@ def main():
|
|||||||
print(f"\n[3/4] Extracting video fragment…")
|
print(f"\n[3/4] Extracting video fragment…")
|
||||||
real_end = _parse_mmss(args.end) if args.end else None
|
real_end = _parse_mmss(args.end) if args.end else None
|
||||||
if real_end is not None:
|
if real_end is not None:
|
||||||
video_fragment = out_dir / "video_fragment.mkv"
|
video_fragment = clips_dir / "video_fragment.mkv"
|
||||||
extract_video_fragment(args.video, start_sec, real_end, str(video_fragment))
|
extract_video_fragment(args.video, start_sec, real_end, str(video_fragment))
|
||||||
else:
|
else:
|
||||||
video_fragment = Path(args.video)
|
video_fragment = Path(args.video)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ from urllib.request import urlopen, Request
|
|||||||
COMFY_URL = "http://127.0.0.1:8189"
|
COMFY_URL = "http://127.0.0.1:8189"
|
||||||
COMFY_OUTPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/output")
|
COMFY_OUTPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/output")
|
||||||
COMFY_INPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/input")
|
COMFY_INPUT_DIR = Path("/home/lukas/comfy-tts-app/ComfyUI/input")
|
||||||
VOICE_PROMPTS_DIR = Path("/home/lukas/Programy/lektor_ai/gudowski")
|
VOICE_PROMPTS_DIR = Path("/home/lukas/Programy/lektor_ai/voices")
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# SRT helpers
|
# SRT helpers
|
||||||
+26
-6
@@ -24,7 +24,17 @@ Requirements
|
|||||||
- Model: higgs-audio-v3-tts-4b (bosonai/higgs-audio-v3)
|
- Model: higgs-audio-v3-tts-4b (bosonai/higgs-audio-v3)
|
||||||
- ffmpeg and ffprobe available on PATH
|
- ffmpeg and ffprobe available on PATH
|
||||||
- Voice reference: a WAV file + matching .txt transcript in the voice directory
|
- Voice reference: a WAV file + matching .txt transcript in the voice directory
|
||||||
(default: gudowski/gudowski.wav + gudowski/gudowski.txt)
|
(default: voices/gudowski_short.wav + voices/gudowski_short.txt)
|
||||||
|
|
||||||
|
Settings
|
||||||
|
--------
|
||||||
|
Defaults live in settings.ini next to the script:
|
||||||
|
voice, speed, temperature, max_tokens, strip_leading_ms, trailing_fade_ms,
|
||||||
|
orig_volume, tts_volume, output_dir, comfy_url
|
||||||
|
|
||||||
|
Precedence: command-line flag > settings.ini > built-in default.
|
||||||
|
Use --settings FILE to select a different profile.
|
||||||
|
See docs/usage.md for the full description.
|
||||||
|
|
||||||
|
|
||||||
Basic Usage
|
Basic Usage
|
||||||
@@ -54,7 +64,7 @@ Both external SRT files and embedded subtitle tracks go through the same cleanin
|
|||||||
- Missing terminal punctuation added (… or . depending on context)
|
- Missing terminal punctuation added (… or . depending on context)
|
||||||
- Dialogue lines (prefixed with -) are split into separate clips with proportional timing
|
- Dialogue lines (prefixed with -) are split into separate clips with proportional timing
|
||||||
|
|
||||||
With --embedded-subs the extracted subtitles are saved to output/embedded_sub.srt
|
With --embedded-subs the extracted subtitles are saved to the job folder as embedded_sub.srt
|
||||||
so you can inspect them before or after the run.
|
so you can inspect them before or after the run.
|
||||||
|
|
||||||
The final MKV preserves all subtitle tracks from the source video — text-based
|
The final MKV preserves all subtitle tracks from the source video — text-based
|
||||||
@@ -64,17 +74,27 @@ stream copy with no conversion.
|
|||||||
|
|
||||||
Output Files
|
Output Files
|
||||||
------------
|
------------
|
||||||
|
Everything belonging to one video is kept together in a job folder named after
|
||||||
|
the video file. Only the finished video is written to the top level.
|
||||||
|
|
||||||
output/
|
output/
|
||||||
|
clips/
|
||||||
|
<video name>/ — job folder for one video:
|
||||||
|
clip_NNNN.flac — individual TTS clips, one per block (lossless)
|
||||||
tts_input.srt — processed subtitle text sent to TTS (inspect to verify)
|
tts_input.srt — processed subtitle text sent to TTS (inspect to verify)
|
||||||
embedded_sub.srt — extracted embedded subtitle (only when --embedded-subs)
|
|
||||||
clips/clip_NNNN.flac — individual TTS clips, one per subtitle block (lossless)
|
|
||||||
tts_assembled.flac — all clips assembled with correct timing (lossless)
|
tts_assembled.flac — all clips assembled with correct timing (lossless)
|
||||||
|
embedded_sub.srt — extracted embedded subtitle (only with --embedded-subs)
|
||||||
video_fragment.mkv — extracted video segment (only when --end is used)
|
video_fragment.mkv — extracted video segment (only when --end is used)
|
||||||
{stem}_lektor.mkv — final video with two audio tracks + all original subtitles:
|
{stem}_lektor.mkv — final video with two audio tracks + all original subtitles:
|
||||||
Track 0 — Original (source audio, stream-copied as-is)
|
Track 0 — Original (source audio, stream-copied as-is)
|
||||||
Track 1 — Polish lektor (TTS + original mixed,
|
Track 1 — Polish lektor (TTS + original mixed,
|
||||||
AAC 192k stereo)
|
AAC 192k stereo)
|
||||||
|
|
||||||
|
Each run prints the job folder it uses. tts_input.srt and the clips are a
|
||||||
|
matched pair (block N is clip_NNNN.flac), which is why they live together —
|
||||||
|
previously each new job overwrote the last one's, so --rebuild on an older
|
||||||
|
film silently paired its clips with the newest film's text.
|
||||||
|
|
||||||
|
|
||||||
All Options
|
All Options
|
||||||
-----------
|
-----------
|
||||||
@@ -139,7 +159,7 @@ Regenerate specific clips by block number (same numbering as tts_input.srt):
|
|||||||
|
|
||||||
python3 lektor_ai_comfy.py input/film.mkv --regen 12 22 41
|
python3 lektor_ai_comfy.py input/film.mkv --regen 12 22 41
|
||||||
|
|
||||||
Only replaces the selected clips/clip_NNNN.flac files — does not reassemble
|
Only replaces the selected clip_NNNN.flac files in the job folder — does not reassemble
|
||||||
or rebuild the video. Run --rebuild afterwards to apply the changes.
|
or rebuild the video. Run --rebuild afterwards to apply the changes.
|
||||||
Useful for fixing hallucinations, mumbling, or cut-off clips.
|
Useful for fixing hallucinations, mumbling, or cut-off clips.
|
||||||
|
|
||||||
@@ -158,7 +178,7 @@ Reassemble audio from all existing clips and rebuild the final video
|
|||||||
Tips
|
Tips
|
||||||
----
|
----
|
||||||
|
|
||||||
- Check output/tts_input.srt before or after a run to see the exact text sent to TTS.
|
- Check output/clips/<video name>/tts_input.srt to see the exact text sent to TTS.
|
||||||
Block numbers in that file match the clip_NNNN.flac filenames.
|
Block numbers in that file match the clip_NNNN.flac filenames.
|
||||||
|
|
||||||
- If a clip sounds wrong (hallucination, wrong language, cut off), note its block
|
- If a clip sounds wrong (hallucination, wrong language, cut off), note its block
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# lektor_ai_comfy — default settings
|
||||||
|
#
|
||||||
|
# These are the values used when a flag is not given on the command line.
|
||||||
|
# Precedence: command-line flag > this file > built-in defaults
|
||||||
|
#
|
||||||
|
# Delete a line (or the whole file) to fall back to the built-in default.
|
||||||
|
# A malformed value is reported and ignored, never fatal.
|
||||||
|
#
|
||||||
|
# Not configurable here, because they belong to a single run rather than to
|
||||||
|
# your setup: --start --end --seed --regen --rebuild --resume-from
|
||||||
|
# --embedded-subs --skip-tts
|
||||||
|
|
||||||
|
|
||||||
|
[tts]
|
||||||
|
# Voice reference. Either a name in voices/ (expects NAME.wav + NAME.txt),
|
||||||
|
# or a full path to a .wav file.
|
||||||
|
voice = gudowski_short
|
||||||
|
|
||||||
|
# Per-clip speed-up applied with atempo, before assembly.
|
||||||
|
# Raise it if speech regularly overruns its subtitle window; 1.0 = no change.
|
||||||
|
speed = 1.2
|
||||||
|
|
||||||
|
# Sampling temperature. 1.0 makes the model occasionally recite the reference
|
||||||
|
# transcript instead of the subtitle; 0.9 largely prevents that. Lower is more
|
||||||
|
# deterministic but flatter.
|
||||||
|
temperature = 0.7
|
||||||
|
|
||||||
|
# Ceiling on audio tokens per clip. Raise only if long clips are cut off
|
||||||
|
# mid-word.
|
||||||
|
max_tokens = 4096
|
||||||
|
|
||||||
|
# Trim this many ms from the start of every clip, to remove an inhale artifact.
|
||||||
|
# Try 80-150 if you hear one. Too high clips the first consonant.
|
||||||
|
strip_leading_ms = 0
|
||||||
|
|
||||||
|
# Fade out the last N ms of every clip to suppress tail pops. 0 disables.
|
||||||
|
trailing_fade_ms = 80
|
||||||
|
|
||||||
|
|
||||||
|
[mix]
|
||||||
|
# Levels inside the Polish lektor track only. Track 0 is always the untouched
|
||||||
|
# original, so mixing aggressively here costs you nothing.
|
||||||
|
# Dialogue-heavy sources: orig 0.5 / tts 2.0. Quiet sources: orig 1.0 / tts 1.4.
|
||||||
|
orig_volume = 0.70
|
||||||
|
tts_volume = 1.4
|
||||||
|
|
||||||
|
|
||||||
|
[paths]
|
||||||
|
# Where clips, assembled audio and the finished video are written.
|
||||||
|
# Relative paths are resolved from wherever you run the script.
|
||||||
|
output_dir = output
|
||||||
|
|
||||||
|
|
||||||
|
[comfy]
|
||||||
|
# Address of the ComfyUI backend running Higgs Audio V3.
|
||||||
|
comfy_url = http://127.0.0.1:8189
|
||||||
Reference in New Issue
Block a user