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:
2026-08-09 21:56:42 +02:00
co-authored by Claude Opus 5
parent fc4b761f52
commit 3dde6e58e4
15 changed files with 430 additions and 91 deletions
+29 -9
View File
@@ -24,7 +24,17 @@ Requirements
- Model: higgs-audio-v3-tts-4b (bosonai/higgs-audio-v3)
- ffmpeg and ffprobe available on PATH
- 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
@@ -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)
- 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.
The final MKV preserves all subtitle tracks from the source video — text-based
@@ -64,17 +74,27 @@ stream copy with no conversion.
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/
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)
video_fragment.mkv — extracted video segment (only when --end is used)
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_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)
{stem}_lektor.mkv — final video with two audio tracks + all original subtitles:
Track 0 — Original (source audio, stream-copied as-is)
Track 1 — Polish lektor (TTS + original mixed,
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
-----------
@@ -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
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.
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
----
- 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.
- If a clip sounds wrong (hallucination, wrong language, cut off), note its block