Skip to content

A toolbox of film styles made in code for Claude Code: 66 ready to use, and your own. Each style is a style prompt plus a demo film made entirely in code by Claude Opus 5.5, with no video model. By Lemomo. · 一套用代码做片的风格工具箱:66 种现成风格,也能做出你自己的

1.9 KB
Raw Blame
"""Whisper spot check of the final film: slices the mp4 at the narration times and transcribes them (expected text is the asr field of lines.json, or text if there is none), and computes the voice/background SNR in 300–4000 Hz.
Usage (repo root): .venv/bin/python styles/hologram-hud/demo/tools/final_asr.py styles/hologram-hud/hologram-hud.mp4"""
import sys, os, json, re, subprocess, numpy as np, soundfile as sf
from faster_whisper import WhisperModel
from scipy.signal import butter, sosfilt, resample_poly
D = os.environ.get('HH_WORK') or os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
VO = {v['id']: v for v in json.load(open(os.path.join(D, 'timeline.json')))['vo']}
lines = json.load(open(os.path.join(D, 'lines.json')))
tmp = os.path.join(D, 'out', 'final_audio.wav')
subprocess.run(['ffmpeg', '-v', 'error', '-y', '-i', sys.argv[1], '-ac', '1', '-ar', '16000', tmp], check=True)
y, sr = sf.read(tmp); m = WhisperModel('base.en', device='cpu', compute_type='int8')
norm = lambda s: re.sub(r'[^a-z0-9 ]', '', s.lower().replace('-', ' ')).split()
sos = butter(4, [300, 4000], 'band', fs=sr, output='sos'); ok = 0
for L in lines:
    t0 = VO[L['id']]['t']; v, vs = sf.read(os.path.join(D, 'voices', L['id'] + '.wav')); v = resample_poly(v, sr, vs)
    a, b = int((t0 - .3) * sr), int(t0 * sr) + len(v) + int(.3 * sr)
    segs, _ = m.transcribe(y[a:b].astype(np.float32), beam_size=5, language='en')
    got = ' '.join(s.text.strip() for s in segs); exp = L.get('asr', L['text']); good = norm(got) == norm(exp); ok += good
    seg = y[int(t0 * sr):int(t0 * sr) + len(v)]; vb = sosfilt(sos, v[:len(seg)]); sb = sosfilt(sos, seg)
    gain = np.dot(sb, vb) / (np.dot(vb, vb) + 1e-12); rest = sb - gain * vb
    snr = 10 * np.log10(np.sum((gain * vb) ** 2) / (np.sum(rest ** 2) + 1e-12))
    print(('OK  ' if good else 'DIFF'), L['id'], f'SNR {snr:+.1f} dB |', exp, '→', got)
print(f'{ok}/{len(lines)} OK')