Files
songforge/tools/intro_check_worker.py
swlandCursor 8be5782006
selftest / selftest (push) Canceled after 0s
Fix opening filler with bare Instrumental and dual-gate QC.
ACE-Step no-vocal condition is the exact [Instrumental] marker; colon prose in the lyrics channel induced wordless filler. Recheck now ASRs full vocals and pairs filler ratio with demucs energy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 14:29:02 +08:00

71 lines
2.2 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
# 与全量 qc 同口径:对整段 vocals 做 ASR,再按时间窗统计。
# 只切前奏短窗喂 Whisper 会严重少计衬词(实测只吐 1 个「嗯」却 PASS)。
v, vsr = q.vocals_of(path, job.get("cache_dir"))
a = q.asr(v, vsr, lang)
segs = a.get("segments") or []
stats = q.intro_filler_stats(
segs, intro_sec, lang, voc=v, vsr=vsr)
hard = q.HARD
ivr = float(stats.get("intro_voc_rms") or 0)
ifn = int(stats["intro_filler_n"])
ifr = float(stats["intro_filler_ratio"])
# 有人声能量时降低字数门槛:短窗幻觉「单个嗯」也要拦
eff_min = hard["intro_filler_min_chars"]
if ivr >= hard["intro_voc_rms_min"]:
eff_min = min(eff_min, 2)
fail = (ifn >= eff_min and ifr >= hard["intro_filler_ratio"]
and ivr >= hard["intro_voc_rms_min"])
# 前 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],
eff_min=eff_min,
**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))