Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI Builder Club Skills gen ass

From Leeroopedia
Knowledge Sources
Domains Video_Processing, Subtitling
Last Updated 2026-10-24 00:00 GMT

Overview

Concrete tool for generating karaoke-style ASS subtitle files with word-by-word sweeping highlights from word-level timestamps, provided by the karaoke-captions skill.

Description

The gen_ass.py script transforms word-level timestamp JSON into a karaoke ASS subtitle file. It groups words into short phrases (one screen each), generates ASS Dialogue events with inline \1c color overrides that sweep a highlight color word-by-word, and optionally renders two-layer soft drop shadows for a high-end TikTok/Shorts aesthetic. Supports CJK text detection (no spaces between words), auto-resolution detection via ffprobe, and configurable phrase grouping (max words per line, max silence gap, punctuation breaks).

Usage

Run this script after extracting word timestamps with extract_words and selecting a style with match_style_from_image (or a preset). The output ASS file is burned into video by render.sh.

Code Reference

Source Location

Signature

def group_words(words: list, cfg: dict) -> list:
    """Split the word stream into short phrases (one screen each).

    Splits when: max_words_per_line reached, punctuation detected, or
    silence gap > max_gap seconds.

    Returns: list of phrases, each a list of word dicts.
    """

def build_events(phrases: list, cfg: dict) -> list:
    """Build ASS Dialogue events with word-by-word highlight sweeping.

    For each word in each phrase, creates a (start, end, plain_text, hi_text)
    tuple where hi_text uses inline \\1c overrides to highlight one word at a time.
    Highlight holds until the next word starts (prevents flicker).

    Returns: list of (start, end, plain_text, highlighted_text) tuples.
    """

def probe_video_res(video_path: str) -> tuple:
    """Probe video dimensions via ffprobe. Returns (width, height) or (None, None)."""

def is_cjk(text: str) -> bool:
    """Check if text contains Chinese/Japanese/Korean characters."""

def main():
    """CLI entry point.

    Args (via argparse):
        words: str   - Path to words.json
        style: str   - Path to style.json
        ass: str     - Path to output captions.ass
        --video: str - Optional video for auto-detect PlayResX/PlayResY
    """

Import

# Run as CLI script:
# gen_ass.py words.json style.json captions.ass [--video input.mp4]

# Or import the core functions:
from gen_ass import group_words, build_events, probe_video_res

I/O Contract

Inputs

Name Type Required Description
words str (file path) Yes Path to words.json from extract_words
style str (file path) Yes Path to style.json from match_style_from_image or a preset
ass str (file path) Yes Output ASS subtitle path
--video str (file path) No Video file for auto-detect PlayResX/PlayResY (auto-scales font for 720p)

Outputs

Name Type Description
captions.ass ASS subtitle file ASS script with [Script Info], [V4+ Styles] (KaraokeShadow + Karaoke styles), [Events] — word-by-word sweeping highlight with inline color overrides; optional two-layer soft shadow

Key Configuration (DEFAULTS dict, overridable by style.json)

Parameter Default Description
max_words_per_line 4 Max words per phrase/screen
max_gap 0.8s Split phrase on silence longer than this
break_on_punctuation True Split on sentence-ending punctuation
soft_shadow True Two-layer blurred drop shadow rendering
blur 7 Gaussian blur amount for shadow layer
alignment 2 Bottom-center alignment
uppercase True Convert all text to uppercase

Usage Examples

Basic ASS Generation

# Generate ASS captions from word timestamps and style
python gen_ass.py words.json style.json captions.ass

# Output:
# Generated 42 phrases, 168 events -> captions.ass

With Video Auto-Resolution

# Auto-detect PlayResX/PlayResY from the source video
python gen_ass.py words.json style.json captions.ass --video input.mp4

# If 720p detected and not explicitly set in style.json:
#   font_size=64, outline=4, shadow=5, margin_v=60

Using a Preset Style

# Use the neon-green 720p preset directly
python gen_ass.py words.json \
  skills/karaoke-captions/presets/style.json \
  captions.ass --video input.mp4

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment