Skip to content

zenstory-ai/video-recap-skills / skills/video-recap

video-recap

Verified

把一段或多集视频做成带画框字幕的中文解说成片或纯原声高光短片。用户提供 .mp4 / .mov / .mkv / .webm,要求做影视解说、短剧二创、加旁白配音、跨集混剪或导出剪映草稿时使用;串联完成看片识台词、定主线与留原声、按台词停顿切镜头、写词检查、TTS 配音与混音加字幕。触发词:视频解说、影视解说、视频旁白、生成解说、视频 recap、video recap、voiceover、narration、recap。

FileKindSize
SKILL.mdskill md18.4 KB
assets/dashboard/app.jsscript16.2 KB
assets/dashboard/index.htmlother867 B
assets/dashboard/styles.cssother22.6 KB
assets/dashboard/tokens.cssother8.9 KB
assets/dashboard/views.jsscript31.4 KB
references/audio-modes.mdmarkdown3.6 KB
references/config-playbook.mdmarkdown8.1 KB
references/creative-editing-playbook.mdmarkdown12.3 KB
references/data-schema.mdmarkdown34.6 KB
references/index-tts.mdmarkdown2.1 KB
references/jianying/LICENSE.duo-videoother1.0 KB
references/jianying/SOURCE.mdmarkdown703 B
references/jianying/empty_draft_meta_info.jsonconfig1.7 KB
references/jianying/empty_jy_material_video.jsonconfig1.8 KB
references/jianying/empty_jy_meta_material_value.jsonconfig358 B
references/jianying/empty_jy_project_info.jsonconfig3.6 KB
references/jianying/empty_jy_segment.jsonconfig1.3 KB
references/jianying/empty_jy_text_styles.jsonconfig440 B
references/jianying/empty_yj_material_audio.jsonconfig865 B
references/jianying/empty_yj_material_text.jsonconfig2.4 KB
references/packaging.mdmarkdown6.8 KB
references/promotional-copy.mdmarkdown4.1 KB
references/prompt-templates.mdmarkdown2.0 KB
references/research-guide.mdmarkdown2.7 KB
references/resource-library.mdmarkdown12.1 KB
references/shot-review.mdmarkdown4.8 KB
scripts/agent_text.pyscript2.7 KB
scripts/artifacts.pyscript972 B
scripts/asr.pyscript12.5 KB
scripts/asr_timing_evidence.pyscript4.2 KB
scripts/assemble.pyscript31.0 KB
scripts/assemble_constants.pyscript894 B
scripts/assembly_contract.pyscript10.3 KB
scripts/assembly_settings.pyscript3.8 KB
scripts/audio_automation.pyscript6.6 KB
scripts/audio_mix.pyscript18.5 KB
scripts/briefing/__init__.pyscript101 B
scripts/briefing/builder.pyscript31.1 KB
scripts/briefing/context.pyscript6.1 KB
scripts/briefing/timeline.pyscript23.0 KB
scripts/codec_peak.pyscript5.1 KB
scripts/cut.pyscript148 B
scripts/cut_cli.pyscript12.4 KB
scripts/cut_contract.pyscript13.3 KB
scripts/cut_qc.pyscript1.9 KB
scripts/cut_render.pyscript13.2 KB
scripts/dashboard/__init__.pyscript159 B
scripts/dashboard/data.pyscript24.6 KB
scripts/dashboard/io.pyscript7.1 KB
scripts/dashboard/runs.pyscript21.8 KB
scripts/dashboard/templates.pyscript9.6 KB
scripts/dashboard_server.pyscript9.3 KB
scripts/detect.pyscript22.2 KB
scripts/doctor.pyexecutablescript12.9 KB
scripts/entry_suggestion.pyscript4.6 KB
scripts/export_jianying.pyscript5.6 KB
scripts/extract.pyscript2.5 KB
scripts/final_qc.pyscript19.0 KB
scripts/frame_grid.pyscript10.6 KB
scripts/jianying/__init__.pyscript49 B
scripts/jianying/builders.pyscript11.3 KB
scripts/jianying/model.pyscript2.7 KB
scripts/jianying/optional.pyscript1012 B
scripts/jianying/schema.pyscript2.5 KB
scripts/jianying/templates.pyscript1.0 KB
scripts/jianying/timeline_contract.pyscript5.8 KB
scripts/jianying/tracks.pyscript2.0 KB
scripts/jianying/writer.pyscript7.8 KB
scripts/lib.pyscript29.6 KB
scripts/library.pyscript31.1 KB
scripts/lint_summary.pyscript5.0 KB
scripts/loudness.pyscript14.7 KB
scripts/materials.pyscript22.1 KB
scripts/media.pyscript18.8 KB
scripts/narration_audio.pyscript13.5 KB
scripts/narration_lint.pyscript24.1 KB
scripts/narrative_selection.pyscript8.9 KB
scripts/packaging.pyscript6.1 KB
scripts/packaging_fonts.pyscript12.0 KB
scripts/packaging_plates.pyscript31.2 KB
scripts/packaging_studio.pyscript34.1 KB
scripts/providers/__init__.pyscript72 B
scripts/providers/fish_audio.pyscript3.1 KB
scripts/providers/index_tts.pyscript8.8 KB
scripts/recap.pyscript183 B
scripts/recap_cli.pyscript6.9 KB
scripts/recap_inspect.pyscript16.5 KB
scripts/recap_runner.pyscript22.0 KB
scripts/recap_runtime.pyscript11.8 KB
scripts/recap_source.pyscript1.8 KB
scripts/recap_stage_qc.pyscript2.7 KB
scripts/recap_timeline.pyscript7.7 KB
scripts/render_preflight.pyscript1.7 KB
scripts/resources/__init__.pyscript200 B
scripts/resources/lock.pyscript6.8 KB
scripts/resources/project_binding.pyscript16.1 KB
scripts/sentence_boundaries.pyscript28.8 KB
scripts/sentence_gate.pyscript8.6 KB
scripts/sfx_mix.pyscript14.6 KB
scripts/shot_review.pyscript18.9 KB
scripts/source_subtitles.pyscript7.2 KB
scripts/speech_ownership.pyscript9.3 KB
scripts/storyboard.pyscript21.8 KB
scripts/subtitles/__init__.pyscript56 B
scripts/subtitles/core.pyscript19.0 KB
scripts/subtitles/render.pyscript8.0 KB
scripts/timeline.pyscript8.2 KB
scripts/timeline_emit.pyscript5.4 KB
scripts/tts_audio.pyscript9.6 KB
scripts/tts_cache.pyscript4.5 KB
scripts/understand.pyscript171 B
scripts/understanding_brief.pyscript6.3 KB
scripts/understanding_cache.pyscript8.0 KB
scripts/understanding_runner.pyscript9.8 KB
scripts/understanding_storyboard.pyscript11.9 KB
scripts/validate.pyscript5.7 KB
scripts/visual_render.pyscript10.1 KB
scripts/vlm.pyscript16.4 KB
scripts/voiceover.pyscript28.0 KB

scripts/tts_audio.py

View on GitHub
"""Loudness normalization and a duration sanity bound for synthesized TTS blocks.

Split out of voiceover.py to keep that module within the bundle's per-module line
budget. Dependency-free on purpose (stdlib `wave` + `array` only) so QC and assembly
can reuse the returned metadata without pulling in the synthesis path.
"""
import array
import math
import os
import re
import struct
import sys
import wave
from pathlib import Path

from lib import CONFIG


def _parse_riff_wav_chunks(raw_bytes, input_wav):
    """Parse RIFF/WAVE fmt + data chunks for PCM (tag 1) or IEEE float (tag 3)."""
    if len(raw_bytes) < 44 or raw_bytes[:4] != b"RIFF" or raw_bytes[8:12] != b"WAVE":
        raise ValueError(f"无效 WAV 文件: {input_wav}")
    offset = 12
    fmt = None
    data = None
    while offset + 8 <= len(raw_bytes):
        chunk_id = raw_bytes[offset:offset + 4]
        chunk_size = struct.unpack_from("<I", raw_bytes, offset + 4)[0]
        body_start = offset + 8
        body_end = min(len(raw_bytes), body_start + chunk_size)
        if chunk_id == b"fmt " and body_end - body_start >= 16:
            fmt_tag, channels, framerate, _, block_align, bits = struct.unpack_from(
                "<HHIIHH", raw_bytes, body_start
            )
            if fmt_tag == 0xFFFE and body_end - body_start >= 26:
                fmt_tag = struct.unpack_from("<H", raw_bytes, body_start + 24)[0]
            fmt = (fmt_tag, channels, framerate, block_align, bits)
        elif chunk_id == b"data":
            data = raw_bytes[body_start:body_end]
            break
        offset = body_start + chunk_size + (chunk_size & 1)
    if fmt is None or data is None:
        raise ValueError(f"WAV 缺少 fmt 或 data 块: {input_wav}")
    if fmt[1] < 1 or fmt[2] < 1:
        raise ValueError(f"无效 WAV 声道数或采样率 (channels={fmt[1]}, rate={fmt[2]}): {input_wav}")
    return fmt, data


def _decode_wav_samples_16bit_scale(input_wav):
    """Return (channels, framerate, is_pcm16, samples_in_int16_scale)."""
    raw_bytes = input_wav.read_bytes()
    (fmt_tag, channels, framerate, _block_align, bits), data = _parse_riff_wav_chunks(
        raw_bytes, input_wav
    )
    is_pcm16 = False
    if fmt_tag == 1 and bits == 16:
        samples = array.array("h")
        usable = len(data) - (len(data) % 2)
        samples.frombytes(data[:usable])
        if sys.byteorder != "little":
            samples.byteswap()
        is_pcm16 = True
    elif fmt_tag == 1 and bits == 8:
        samples = [(b - 128) * 256.0 for b in data]
    elif fmt_tag == 1 and bits == 24:
        usable = len(data) - (len(data) % 3)
        samples = [
            int.from_bytes(data[i:i + 3], "little", signed=True) / 256.0
            for i in range(0, usable, 3)
        ]
    elif fmt_tag == 1 and bits == 32:
        usable = len(data) - (len(data) % 4)
        ints = array.array("i")
        ints.frombytes(data[:usable])
        if sys.byteorder != "little":
            ints.byteswap()
        samples = [v / 65536.0 for v in ints]
    elif fmt_tag == 3 and bits in (32, 64):
        step = bits // 8
        fmt_code = "<f" if bits == 32 else "<d"
        usable = len(data) - (len(data) % step)
        samples = []
        for (s,) in struct.iter_unpack(fmt_code, data[:usable]):
            if not math.isfinite(s):
                s = 0.0
            samples.append(int(round(max(-1.0, min(1.0, s)) * 32767.0)))
    else:
        raise ValueError(f"不支持的 WAV 编码 (format={fmt_tag}, bits={bits}): {input_wav}")

    aligned = (len(samples) // channels) * channels
    if aligned < len(samples):
        samples = samples[:aligned]
        is_pcm16 = False
    return channels, framerate, is_pcm16, samples


_decode_wav_samples_to_i16 = _decode_wav_samples_16bit_scale


def _normalize_tts_wav_rms(input_wav, output_wav, *, target_rms_dbfs=-20.0, peak_limit=0.98):
    """Normalize a PCM (8/16/24/32-bit) or IEEE-float WAV to 16-bit PCM at target RMS.

    This helper is intentionally dependency-free so QC/assembly can reuse the
    returned metadata even when normalization is applied in a later lane.
    """
    input_wav = Path(input_wav)
    output_wav = Path(output_wav)
    channels, framerate, is_pcm16, samples = _decode_wav_samples_16bit_scale(input_wav)
    if not samples:
        # A silent block has no RMS to normalize toward; copy 16-bit WAV through verbatim
        # (or write an empty 16-bit PCM WAV) rather than dividing by a zero sample count.
        if is_pcm16:
            output_wav.write_bytes(input_wav.read_bytes())
        else:
            with wave.open(str(output_wav), "wb") as wf:
                wf.setnchannels(channels)
                wf.setsampwidth(2)
                wf.setframerate(framerate)
                wf.writeframes(b"")
        return {
            "rms_dbfs_before": None,
            "rms_dbfs_after": None,
            "peak_after": 0.0,
            "gain_db": 0.0,
        }
    count = len(samples)
    rms = math.sqrt(sum(s * s for s in samples) / count)
    peak = max(max(samples), -min(samples)) / 32768.0
    rms_dbfs_before = 20 * math.log10(max(rms, 1e-9) / 32768.0)
    target_linear = 10 ** (target_rms_dbfs / 20.0) * 32768.0
    gain = target_linear / max(rms, 1e-9)
    if peak > 0:
        gain = min(gain, peak_limit / peak)

    # Accumulate the output statistics while normalizing instead of decoding the result back.
    normalized = array.array("h", bytes(2 * count))
    out_square_sum = 0
    out_peak_raw = 0
    for i in range(count):
        value = max(-32768, min(32767, int(round(samples[i] * gain))))
        normalized[i] = value
        out_square_sum += value * value
        out_peak_raw = max(out_peak_raw, abs(value))
    out_bytes = normalized
    if sys.byteorder != "little":
        out_bytes = array.array("h", normalized)
        out_bytes.byteswap()
    with wave.open(str(output_wav), "wb") as wf:
        wf.setnchannels(channels)
        wf.setsampwidth(2)
        wf.setframerate(framerate)
        wf.writeframes(out_bytes.tobytes())

    out_rms = math.sqrt(out_square_sum / count)
    return {
        "rms_dbfs_before": rms_dbfs_before,
        "rms_dbfs_after": 20 * math.log10(max(out_rms, 1e-9) / 32768.0),
        "peak_after": out_peak_raw / 32768.0,
        "gain_db": 20 * math.log10(max(gain, 1e-9)),
    }


def _maybe_normalize_tts_wav(output_wav):
    """Normalize a synthesized TTS block in-place; None when normalization is disabled."""
    if not CONFIG["tts_segment_normalize"]:
        return None
    output_wav = Path(output_wav)
    tmp = output_wav.with_name(f"{output_wav.stem}_norm{output_wav.suffix}")
    meta = _normalize_tts_wav_rms(
        output_wav,
        tmp,
        target_rms_dbfs=CONFIG["tts_segment_target_rms_dbfs"],
        peak_limit=CONFIG["tts_segment_peak_limit"],
    )
    os.replace(tmp, output_wav)
    return meta


# Speech units for the duration bound: a CJK character or a digit (half or full width, read
# one by one as in 二〇二六) is one syllable, "%" is three (百分之), a Latin word about one and
# a half. Pause marks get a fixed allowance each; "……" is a long pause.
_CJK_OR_DIGIT = re.compile(r"[\u3007\u3400-\u4dbf\u4e00-\u9fff\uf900-\ufaff0-9\uff10-\uff19]")
_PERCENT = re.compile(r"[%\uff05]")
_PERCENT_UNITS = 3
_LATIN_WORD = re.compile(r"[A-Za-z]+(?:'[A-Za-z]+)?")
_LONG_PAUSE = re.compile(r"……|\.\.\.|——")
_PAUSE_MARK = re.compile(r"[,。!?;:、,.!?;:]")
TTS_EDGE_SILENCE_SECONDS = 1.5
TTS_PAUSE_SECONDS = 0.4
TTS_LONG_PAUSE_SECONDS = 0.8


def speech_units(text):
    """Syllable-like units a faithful reading of `text` speaks (pauses not included)."""
    rest = _LONG_PAUSE.sub("", text)
    return (len(_CJK_OR_DIGIT.findall(rest)) + _PERCENT_UNITS * len(_PERCENT.findall(rest))
            + 1.5 * len(_LATIN_WORD.findall(rest)))


def max_plausible_tts_seconds(text):
    """Longest a faithful reading of `text` can last, or None when the bound is disabled.

    Reading every unit at TTS_MIN_SPEECH_RATE (default 2.5 units/s; MiMo's median is ~3.5
    CJK chars/s) plus generous pause and edge-silence allowances. Audio past this is the
    provider reading more than the text: MiMo TTS has returned a sentence followed by
    invented speech at 1.17x this bound, while the slowest of ~100 faithful MiMo segments
    from real runs reached 0.86x."""
    min_rate = CONFIG["tts_min_speech_rate"]
    if min_rate <= 0:
        return None
    long_pauses = len(_LONG_PAUSE.findall(text))
    rest = _LONG_PAUSE.sub("", text)
    return (TTS_EDGE_SILENCE_SECONDS + speech_units(text) / min_rate
            + TTS_PAUSE_SECONDS * len(_PAUSE_MARK.findall(rest))
            + TTS_LONG_PAUSE_SECONDS * long_pauses)


def implausible_tts_duration(text, duration):
    """A user-facing reason when `duration` is too long to be a reading of `text`, else None."""
    limit = max_plausible_tts_seconds(text)
    if limit is None or duration <= limit:
        return None
    return (f"音频 {duration:.1f}s 超过这段文字({len(text)} 字)的合理上限 {limit:.1f}s,"
            "疑似 TTS 多读了原稿以外的内容(幻读),这段音频不会被缓存或交付")


def rejected_take_path(output_wav):
    """Where the latest take rejected by the bound is kept for listening."""
    output_wav = Path(output_wav)
    return output_wav.with_name(f"{output_wav.stem}.rejected{output_wav.suffix}")


def rejected_take_hint(rejected):
    """Where the last rejected take is, and how to accept such takes; empty when none was kept."""
    if not Path(rejected).is_file():
        return ""
    return (f";最后一次被拒的音频保留在 {rejected},试听确认确实只读了原稿时,"
            "可调低 TTS_MIN_SPEECH_RATE(0 关闭检查)后重跑")
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall