Files
songforge/tools/intro_check_worker.py
T
swlandCursor 6d79ab93a2
selftest / selftest (push) Canceled after 0s
Add align/recheck/compare, plugins, and refresh Agent docs.
Wire deliver_report/listen_pack/retry hooks; gen --auto-retry and intro light check; make AGENTS_MIN the up-to-date agent entry with full command map.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 13:03:44 +08:00

66 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
"""开曲轻检:只切前奏窗做 ASR 衬词统计(比全曲 QC 快)。
用法(qc_python):
python intro_check_worker.py '{"file":"...","bpm":104,"intro_bars":8,"lang":"zh"}'
"""
import json
import os
import sys
import traceback
HERE = os.path.dirname(os.path.abspath(__file__))
if HERE not in sys.path:
sys.path.insert(0, HERE)
def main(job):
import numpy as np
import qc_worker as q
path = job["file"]
bpm = float(job.get("bpm") or 104)
bars = int(job.get("intro_bars") or 8)
lang = job.get("lang") or "zh"
intro_sec = bars * 60.0 / bpm * 4.0
# 多取 0.5s 余量
take = min(intro_sec + 0.5, 60.0)
y, sr, ch = q._load_audio(path)
n = int(take * sr)
head = y[:max(1, n)]
a = q.asr(head, sr, lang)
segs = a.get("segments") or []
# 时间戳相对 clip 起点,整段都在前奏窗内
stats = q.intro_filler_stats(segs, intro_sec + 1.0, lang)
hard = q.HARD
fail = (stats["intro_filler_n"] >= hard["intro_filler_min_chars"]
and stats["intro_filler_ratio"] >= hard["intro_filler_ratio"])
# 前 2s 真唱字(content words)也算开曲违规
early = 0
for s in segs:
if float(s.get("t0", 0)) >= 2.0:
continue
early += len(q.content_words(s.get("text") or "", lang))
if early > 0:
fail = True
return dict(
ok=not fail,
fail=fail,
intro_sec=round(intro_sec, 2),
early_content=early,
asr_head=(a.get("text") or "")[:160],
**stats,
)
if __name__ == "__main__":
try:
job = json.loads(sys.argv[1])
out = main(job)
except Exception as e:
out = dict(error=str(e), type=type(e).__name__,
trace=traceback.format_exc()[-800:])
print("###JSON###")
print(json.dumps(out, ensure_ascii=False))