Fix opening filler with bare Instrumental and dual-gate QC.
selftest / selftest (push) Canceled after 0s

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>
This commit is contained in:
swl
2026-10-10 14:29:02 +08:00
co-authored by Cursor
parent 6d79ab93a2
commit 8be5782006
6 changed files with 162 additions and 252 deletions
+2 -2
View File
@@ -61,8 +61,8 @@ doctor_all → target → [align] → check → gen [--auto-retry N] → recheck
|----|-----|
| ckpt+LoRA | `ace_step_1.5_turbo_swl_fused` + `swl_voice_best_ep257`(0.5/0.5) |
| 采样 | shift=5.5 / steps=28 / cfg=2.0 / temperature=0.68 |
| 时长 | 150–200s;8 小节器乐前奏(CLI 注入) |
| 衬音 | 禁止开曲衬词;默认 lean tags;禁点名 mm/ooh/嗯 |
| 时长 | 150–200s;8 小节器乐前奏(CLI 注入裸 `[Instrumental]`,勿写冒号散文) |
| 衬音 | 禁止开曲衬词;默认 lean tags;禁点名 mm/ooh/嗯;QC=ASR+人声能量双门 |
| tags | `prefer_lean_tags=true`;勿随意 `--full-tags` |
## 命令速查(Agent 常用)
+1 -1
View File
@@ -117,7 +117,7 @@ def assemble(args, cfg, st, lyrics_raw, title):
st.get("intro_detail") or st.get("instruments"),
bars=ibars)
else:
# 已有 [intro] 头:对齐小节数 + 前奏括号 rhythm 过滤。
# 已有 [intro] 头:收成官方裸 [Instrumental](小节数只在 tags)。
lyrics = ironlaw.force_intro_bars(lyrics, ibars)
lyrics = ironlaw.filter_intro_bracket(lyrics)
lyrics = "\n".join(
+51 -68
View File
@@ -138,7 +138,9 @@ def _t_ironlaw():
lyrics = ironlaw.build_lyrics(
[("[verse]", "第一句歌词\n第二句歌词")], "kick and snare", bars=8)
assert lyrics.lstrip().startswith("[intro]"), "未强制器乐前奏"
assert "[Instrumental: 8 bar" in lyrics, "前奏未写明 8 小节"
assert re.search(r"^\[Instrumental\]\s*$", lyrics, re.M), \
"前奏必须是裸 [Instrumental],不能带冒号散文"
assert "[Instrumental:" not in lyrics, "前奏残留 [Instrumental: ...]"
assert not ironlaw.check_rules(lyrics, tags), ironlaw.check_rules(lyrics, tags)
# 缺前奏必须被拦
no_intro = "[verse]\n没有前奏直接唱"
@@ -191,12 +193,12 @@ def _t_sparse_profile():
"sparse 放行区间 %d~%d 与实测 %d 音节不一致" % (lo, hi, syl)
# 过短仍要拦:sparse 不是"无限制放宽"
thin = ("[intro]\n[Instrumental: 8 bar]\n[verse]\nmmm\nooh\n")
thin = ("[intro]\n[Instrumental]\n[verse]\nmmm\nooh\n")
assert any("过少" in e for e in meter.check(thin, dur, bpm, sparse)[0]), \
"sparse 档放过短歌词"
# 过多仍要拦:写成满首人声时 sparse 也必须报错,否则会退回旧病
fat = ("[intro]\n[Instrumental: 8 bar]\n[verse]\n"
fat = ("[intro]\n[Instrumental]\n[verse]\n"
+ "\n".join(["mmm mmm low and slow"] * 90))
assert any("过多" in e for e in meter.check(fat, dur, bpm, sparse)[0]), \
"sparse 档放过多歌词,音乐主导会被稀释"
@@ -419,22 +421,11 @@ def _t_groove_first_beat():
def _t_intro_instrument_filter():
"""前奏括号必须过滤掉 pad/riser/reverb/lead,只留节奏组。
"""前奏:歌词侧裸 [Instrumental];配器节奏过滤只服务 tags/历史工具。
这是本轮真正起作用的改动。上一轮只在标签里堆禁令,GroovePure 实测
无效(开头 sub 仍 -66.0 dBFS,中段 -55.8 dBFS),因为真正的病灶是
歌词体那一行:
[Instrumental: 8 bar instrumental intro hook, huge supersaw lead,
sidechain compressed pad, punchy electro kick, crisp clap,
trap snare, white noise riser, big reverb, melodic drop, ...]
空场信号(lead/pad/riser/reverb)4 个,节奏组(kick/clap/snare)3 个,
3:4 输了,模型就把前奏铺成 ambient。
所以这里守三件事:
1) 过滤后必须还留着 kick(不能把节奏组也误删成空括号);
2) pad / riser / reverb / lead 一个都不能留在前奏括号里;
3) 标签侧的 instruments 段保持原样——drop 段本来就要 pad 和 lead,
只过滤前奏括号,不能把整首歌的配器改掉。
官方 ACE-Step 无人声条件是精确字符串 [Instrumental]。往括号塞配器
会进歌词通道诱发衬词。intro_rhythm_only 仍保留给 tags / 旧资产,
但 assemble 不再把过滤结果写进歌词。
"""
src = ("huge supersaw lead, sidechain compressed pad, "
"punchy electro kick, crisp clap, trap snare, "
@@ -442,52 +433,43 @@ def _t_intro_instrument_filter():
got = ironlaw.intro_rhythm_only(src)
low = got.lower()
assert "kick" in low, "前奏括号把底鼓也过滤掉了: %r" % got
assert "kick" in low, "节奏过滤把底鼓也删了: %r" % got
for bad in ("pad", "riser", "reverb", "supersaw", "lead", "noise"):
assert bad not in low, "前奏括号残留空场信号 %s: %r" % (bad, got)
assert bad not in low, "节奏过滤残留空场信号 %s: %r" % (bad, got)
assert "bass" in low, "节奏过滤没有 bass:%r" % got
# 加法兜底:kick 和 bass 两条必须显式出现在前奏括号里。
# 上一轮漏了这一条,风格字典里一条贝斯都没写,过滤后只剩三条中高频,
# 结果两版新音频开头 sub 比全曲峰值低 53.5 / 31.2 dB。
assert "bass" in low, "前奏括号没有 bass:%r" % got
# 空 / 中文 / 全被过滤掉 -> 必须回落到默认节奏组,不能留空括号
for probe in ("", None, "ambient pad, huge supersaw lead, big reverb"):
fb = ironlaw.intro_rhythm_only(probe)
assert "kick" in fb.lower(), "前奏括号回落失败 %r -> %r" % (probe, fb)
assert "bass" in fb.lower(), "回落值缺 bass %r -> %r" % (probe, fb)
for bad in ("pad", "riser", "reverb", "supersaw", "lead"):
assert bad not in fb.lower(), "回落值带空场信号 %s: %r" % (bad, fb)
assert "kick" in fb.lower() and "bass" in fb.lower(), \
"节奏过滤回落失败 %r -> %r" % (probe, fb)
# 回落值不能是 DEFAULT_INSTRUMENT:它含 "chord stabs",而 "chord stab"
# 就在 _RHYTHM_DROP 里,回落会把刚剔除掉的空场信号塞回前奏。
assert "stab" not in ironlaw.DEFAULT_INTRO_RHYTHM.lower(), \
"前奏回落值含 chord stab,与过滤规则自相矛盾"
# 标签侧不受影响:instruments 段必须还是原样
tags = ironlaw.build_tags(style="s", instruments=src, mood="m",
instrumental=True)
assert "white noise riser" in tags, \
"过滤逻辑泄漏到了标签侧,drop 段会丢掉 riser"
assert "sidechain compressed pad" in tags, \
"过滤逻辑泄漏到了标签侧,drop 段会丢掉 pad"
assert "white noise riser" in tags, "过滤泄漏到标签侧"
assert "sidechain compressed pad" in tags, "过滤泄漏到标签侧"
# 歌词体里前奏那一行必须既没有 riser/pad,又必须有 bass
lyr = ironlaw.build_inst_lyrics(src, bars=8)
head = lyr.split("\n")[1].lower()
assert "riser" not in head and "pad" not in head, \
"纯器乐歌词体前奏行仍带空场信号: %s" % head
assert "bass" in head, "纯器乐歌词体前奏行缺 bass: %s" % head
lyr2 = ironlaw.build_chill_lyrics([("[verse]", "ooh")], src, bars=8,
total_bars=90)
head2 = lyr2.split("\n")[1].lower()
assert "riser" not in head2 and "pad" not in head2, \
"吟唱歌词体前奏行仍带空场信号: %s" % head2
assert "bass" in head2, "吟唱歌词体前奏行缺 bass: %s" % head2
# 歌词侧:裸标记;旧冒号写法必须被 filter 收成裸
for lyr in (ironlaw.build_inst_lyrics(src, bars=8),
ironlaw.build_chill_lyrics(
[("[verse]", "ooh")], src, bars=8, total_bars=90)):
head = [l.strip() for l in lyr.split("\n") if l.strip()]
assert head[0].lower() == "[intro]"
assert head[1] == "[Instrumental]", \
"歌词前奏不是裸 [Instrumental]: %s" % head[1]
assert ":" not in head[1]
fat = ("[intro]\n[Instrumental: 8 bar hook, pad, riser]\n"
"[instrumental]\n[verse]\nx\n")
fixed = ironlaw.filter_intro_bracket(fat)
assert "[Instrumental: " not in fixed
assert fixed.count("[Instrumental]") == 1
return [("前奏配器过滤",
"前奏括号剔除 pad/riser/reverb/lead,并强制补齐 kick+bass,"
"标签侧配器保持原样")]
"歌词侧裸 [Instrumental];intro_rhythm_only 仍剔 pad/riser;"
"旧冒号写法被 filter 收成裸")]
def _t_chill_no_conflict():
@@ -562,25 +544,26 @@ def _t_chill_integration():
# 再留一遍会让人声提前回来
assert head.count("[inst]") <= n_inst, "chill 结构体器乐占位异常重复"
# 前奏小节数:标签与歌词头必须一致
mh = re.search(r"\[instrumental:[^\]]*?(\d+)\s*bar", lyrics2, re.I)
# 小节数只在 tags;歌词侧必须是裸 [Instrumental]
assert re.search(r"^\[Instrumental\]\s*$", lyrics2, re.M), \
"chill 歌词前奏不是裸 [Instrumental]"
assert "[Instrumental:" not in lyrics2
mt = re.search(r"(\d+)\s*bar instrumental intro", tags2.lower())
assert mh and mt and mh.group(1) == mt.group(1), \
"chill 标签 %s 小节与歌词头 %s 小节不一致" % (
mt.group(1) if mt else "?", mh.group(1) if mh else "?")
# 反向闸门:两者不一致必须被拦下
short_tags = tags2.replace("%s bar instrumental intro" % mt.group(1),
"16 bar instrumental intro", 1)
errs = ironlaw.check_rules(lyrics2, short_tags)
assert any("必须一致" in e for e in errs), \
"tags 与歌词头前奏小节数不一致未被拦截"
assert mt and 4 <= int(mt.group(1)) <= 32, \
"chill tags 缺合法前奏小节数"
# 前奏小节数缺失也必须被拦
errs = ironlaw.check_rules(lyrics2, re.sub(r"\d+\s*bar instrumental",
"instrumental", tags2))
assert any("小节数" in e for e in errs), "tags 未写前奏小节数未被拦截"
# 旧冒号散文必须被拦
bad_head = lyrics2.replace("[Instrumental]",
"[Instrumental: 8 bar pad and riser]", 1)
errs = ironlaw.check_rules(bad_head, tags2)
assert any("裸 [Instrumental]" in e for e in errs), \
"冒号前奏散文未被拦截"
return [("吟唱结构占位",
"人声段之前留了 %d 组纯器乐段(只管密度,不管起点),"
"标签侧完全不讨论人声进场时机" % n_inst)]
@@ -589,7 +572,7 @@ def _t_chill_integration():
def _t_lexicon():
lex = loader.lexicon()
assert "长板" in (lex["banned"].get("longboard") or []), "禁用词表缺 长板"
good = "[intro]\n[Instrumental: 8 bar]\n[verse]\n我在街头双翘上起跳"
good = "[intro]\n[Instrumental]\n[verse]\n我在街头双翘上起跳"
assert not ironlaw.check_lexicon(good, lex), ironlaw.check_lexicon(good, lex)
bad = "[intro]\n[verse]\n我戴着头盔冲下坡"
errs = ironlaw.check_lexicon(bad, lex)
@@ -604,11 +587,11 @@ def _t_density():
assert cap["hi"] > cap["lo"] > 0, "容量区间异常"
# 过短必须被拦
too_thin = "[intro]\n[Instrumental: 8 bar]\n[verse]\n太短了"
too_thin = "[intro]\n[Instrumental]\n[verse]\n太短了"
assert meter.check(too_thin, st["duration"], st["bpm"], cfg)[0], "过短未拦"
# 过多必须被拦
too_fat = "[intro]\n[Instrumental: 8 bar]\n[verse]\n" + \
too_fat = "[intro]\n[Instrumental]\n[verse]\n" + \
"\n".join(["这一句有十二个字刚刚好"] * 300)
assert meter.check(too_fat, st["duration"], st["bpm"], cfg)[0], "过多未拦"
@@ -617,7 +600,7 @@ def _t_density():
line = "这一句刚好十二个字的样子" # 12 音节
nlines = max(1, int(mid / 12))
body = "\n".join([line] * nlines)
ok = "[intro]\n[Instrumental: 8 bar]\n[verse]\n" + body
ok = "[intro]\n[Instrumental]\n[verse]\n" + body
errs, stt = meter.check(ok, st["duration"], st["bpm"], cfg)
assert not errs, "按 target 写的合规歌词被误杀: %s" % errs
return [("时长对应硬校验",
@@ -756,7 +739,7 @@ def _t_window():
line = "这一句刚好十二个字的样子"
def build(n):
return ("[intro]\n[Instrumental: 8 bar]\n[verse]\n"
return ("[intro]\n[Instrumental]\n[verse]\n"
+ "\n".join([line] * n))
n_mid = max(1, int(mid / 12))
+56 -157
View File
@@ -681,17 +681,10 @@ def build_inst_lyrics(intro_detail=None, bars=8):
否则 pad/riser/lead 词会把前奏铺成 ambient 空场(实测 GroovePure
开头 sub 只有 -66 dBFS,中段是 -55.8 dBFS)。
"""
d = intro_rhythm_only(intro_detail)
# 括号里只写配器名词短语。"from the very first beat" 这类介词短语
# 会被 _INTRO_CLAUSE_RE 判为可唱散文——它确实该写进 tags
# (RULE_GROOVE_FIRST_BEAT),不该出现在歌词条件通道里。
head = ("[Instrumental: %d bar instrumental intro hook, %s, "
"four on the floor groove, beat one kick and bass, "
"no vocals, no voice, no singing]" % (bars, d))
# 纯器乐同样用官方裸 [Instrumental];配器细节只在 tags。
body = [
"[intro]",
head,
"[instrumental]",
"[Instrumental]",
"",
"[breakdown]",
"[inst]",
@@ -727,20 +720,20 @@ def build_inst_lyrics(intro_detail=None, bars=8):
def build_intro(detail=None, bars=8):
"""器乐前奏描述。必须纯英文,中文说明词会被模型唱出来。"""
d = detail or DEFAULT_INSTRUMENT
return ("[Instrumental: %d bar instrumental hook, %s, "
"drums enter on the first beat, no vocals, no humming]" % (bars, d))
"""官方 ACE-Step 无人声条件:裸 ``[Instrumental]``(无冒号、无配器散文)。
依据(ACE-Step 1.5 文档 / 社区 prompting guide,2026):
- DiT 用精确字符串 ``[Instrumental]`` 作 no-vocal condition;
- 标记下无正文 = 器乐段;小节数与 groove 写在 caption/tags;
- 有歌词时再在 tags 堆 ``no vocals`` / 往括号塞英文,易诱发无词衬词。
detail/bars 保留入参仅为兼容,不再写入歌词通道。
"""
return "[Instrumental]"
def build_lyrics(sections, intro_detail=None, bars=8, tail=None):
"""sections 为 [(tag, text)],首段强制为器乐前奏。
intro_detail 若是中文会被自动降级为默认英文配器。
"""
if intro_detail and re.search(r"[\u4e00-\u9fff]", intro_detail):
intro_detail = None
out = ["[intro]", build_intro(intro_detail, bars), "[instrumental]", ""]
"""sections 为 [(tag, text)],首段强制为器乐前奏。"""
out = ["[intro]", build_intro(intro_detail, bars), ""]
for tag, text in sections:
out.append(tag)
out.append(text.strip())
@@ -751,13 +744,12 @@ def build_lyrics(sections, intro_detail=None, bars=8, tail=None):
def strip_cn_instrumental(lines):
"""清掉正文里 [Instrumental: ...] 的中文说明,防止被唱出来。"""
"""把任何 [Instrumental: ...] 收成官方裸 [Instrumental]。"""
out = []
for ln in lines:
s = ln.strip()
m = re.match(r"^\[Instrumental:[^\]]*\]$", s, re.I)
if m and re.search(r"[\u4e00-\u9fff]", s):
out.append("[Instrumental: no vocals, drums and bass only]")
if re.match(r"^\[Instrumental:", s, re.I):
out.append("[Instrumental]")
continue
out.append(ln)
return out
@@ -791,12 +783,7 @@ def build_chill_lyrics(sections, intro_detail=None, bars=8, total_bars=90):
total_bars 来自 meter.capacity(),用它算出器乐段要占多少小节,
让"器乐占大部分时长"这个听感成立,而不是随手写三段 [inst]。
"""
d = intro_rhythm_only(intro_detail)
out = ["[intro]",
("[Instrumental: %d bar instrumental intro hook, %s, "
"four on the floor groove, beat one kick and bass, "
"no vocals, no voice, no singing]" % (bars, d)),
"[instrumental]", ""]
out = ["[intro]", "[Instrumental]", ""]
# 先铺满器乐段。留 1/4 给结尾的器乐收尾,其余全放前面。
inst_bars = max(4.0, float(total_bars) - float(bars))
@@ -821,37 +808,19 @@ def build_chill_lyrics(sections, intro_detail=None, bars=8, total_bars=90):
def filter_intro_bracket(lyrics):
"""把已有 [intro] 里的 [Instrumental: ...] 括号过一遍 rhythm 过滤。
"""把 [intro] 段里的 ``[Instrumental: ...]`` / 重复 ``[instrumental]``
收成官方裸 ``[Instrumental]``。
为什么手写歌词也要过滤(2026-10-05):
assemble() 原来分两条路。build_lyrics() / build_chill_lyrics() /
build_inst_lyrics() 这三条自己拼前奏,都调用了 intro_rhythm_only();
但"歌词文件已经自带 [intro] 头"这条分支只调 force_intro_bars()
改了个小节数,括号内容原样透传。
于是作者手写的前奏描述成为唯一一条绕过过滤的路径——而
intro_rhythm_only() 的整段注释(pad/riser 词数 3:4 压过 kick/snare
3 项,模型按多数走)说的正是这条路径会出的问题。实测 ckfunk
批次 12/16 个 seed 前奏 sub 掉到 -80 dB 以下。
只处理 [intro] 段里的第一行括号,段落正文一个字都不动:
正文是要唱的,过滤词表(lead/melody/vocal 等)是为配器串设计的,
拿去过滤歌词会把 "I lead me to the dance floor" 这类正常句子改坏。
括号被过滤到全空时不能空手进模型:空括号等于"这里没内容",模型更容易
直接铺成空场。此时退回 DEFAULT_INTRO_RHYTHM。
作者写的前奏描述优先,不拿风格字典去覆盖它——作者可能刻意写了
"808 sub slide into the hook" 这种会被整项丢掉的词。
依据:ACE-Step DiT 训练的无人声条件是精确字符串 ``[Instrumental]``;
冒号后塞配器/禁令会进歌词条件通道,诱发无词衬词或被原样唱出。
小节数与 groove 只写在 tags(RULE_INTRO / RULE_GROOVE_FIRST_BEAT)。
"""
lines = lyrics.split("\n")
out = []
in_intro = False
saw_inst = False
def _emit(text, src):
"""按原行尾回写,避免 CRLF 文件被改写成混合行尾。
split("\\n") 之后 CRLF 的 "\\r" 仍挂在行尾。直接拼新串会把它丢掉,
而其余行还带着 "\\r",join 之后同一文件里就有两种行尾了。
"""
if src.endswith("\r") and not text.endswith("\r"):
return text + "\r"
return text
@@ -860,81 +829,35 @@ def filter_intro_bracket(lyrics):
s = ln.strip()
if re.match(r"^\[intro\]$", s, re.I):
in_intro = True
saw_inst = False
out.append(ln)
continue
# 顺序要紧:必须先判 [Instrumental: ...],再判"段落结束"。
# 反过来的话它自己就以 "[" 开头,会被当成 intro 收尾,
# 过滤分支永远进不去(2026-10-05 修的就是这个)。
if in_intro and re.match(r"^\[instrumental:", s, re.I):
detail = re.sub(r"^\[Instrumental:\s*", "", s, flags=re.I)
detail = re.sub(r"\s*\]$", "", detail)
# 中文括号整段放行。
#
# intro_rhythm_only() 的分项词表全是英文,中文项匹配不到任何
# KEEP / DROP,只会走兜底把整段替换成 DEFAULT_INTRO_RHYTHM——
# 也就是把作者写的中文前奏描述整句丢掉换成英文。作者写中文说明
# 他清楚自己要什么,改写他反而破坏意图。前奏低频现在主要由标签
# 侧的 RULE_GROOVE_FIRST_BEAT 兜住,不依赖这里过滤中文。
if re.search(r"[\u4e00-\u9fff]", detail):
out.append(ln)
# 先判 Instrumental / inst,再判其它结构标记(否则 [Instrumental: 会收尾)
if in_intro and re.match(
r"^\[instrumental(?::[^\]]*)?\]$", s, re.I):
if not saw_inst:
out.append(_emit("[Instrumental]", ln))
saw_inst = True
in_intro = False
continue
# 保留 "8 bar instrumental intro hook" 这类纯结构性前缀,
# 只对逗号后面的配器串做过滤。
#
# 这里必须先验前缀"干净"再决定保留,不能只看有没有逗号。
# 正则里 (?:,\s*(.*))? 是可选组:写
# [Instrumental: 8 bar intro hook with ambient pad]
# 这种没有逗号的句子时,lazy 的 .*? 会回溯到把整串吃进前缀,
# rest 为空 → 过滤完全不执行,pad 原样留在前奏里。
# 所以前缀只接受不含任何配器词、只由 bar/instrumental/intro/
# hook/groove/break 这类结构词组成的形态,否则整串送过滤。
prefix, rest = "", detail
mpre = re.match(
r"^(\d+\s*bar\b[^,]*?)\s*(?:,\s*(.*))?$", detail, re.I | re.S
)
if mpre and _INTRO_PREFIX_OK.match(mpre.group(1).strip()):
prefix, rest = mpre.group(1).strip(), mpre.group(2) or ""
newd = prefix
if rest.strip():
filtered = intro_rhythm_only(rest)
if filtered:
newd = ("%s, %s" % (prefix, filtered)) if prefix \
else filtered
elif not prefix:
newd = DEFAULT_INTRO_RHYTHM
out.append(_emit("[Instrumental: %s]" % newd, ln))
if in_intro and re.match(r"^\[inst\]$", s, re.I):
if not saw_inst:
out.append(_emit("[Instrumental]", ln))
saw_inst = True
in_intro = False
continue
# intro 段结束:遇到下一个结构标记就收手
if in_intro and s.startswith("["):
if not saw_inst:
out.append("[Instrumental]")
saw_inst = True
in_intro = False
out.append(ln)
return "\n".join(out)
def force_intro_bars(lyrics, bars):
"""把已有 [intro] 头里的前奏小节数改写为 bars。
标签和歌词头必须写同一个数字。之前 chill 标签改成 16 小节、歌词头还是
8 小节,模型同时收到两个互相矛盾的指令,前奏长度完全随机。
这里只改数字,不动描述内容。
"""
def _repl(_m):
return "%d bar" % bars
out = []
for i, ln in enumerate(lyrics.split("\n")):
if i >= 12:
out.append(ln)
continue
s = ln.strip()
if s.lower().startswith("[instrumental:") and \
re.search(r"\d+\s*bar", s, re.I):
out.append(re.sub(r"(\d+)\s*bar", _repl, s, count=1, flags=re.I))
else:
out.append(ln)
return "\n".join(out)
"""历史兼容:小节数只写在 tags。歌词侧统一收成裸 [Instrumental]。"""
return filter_intro_bracket(lyrics)
# 前奏括号里只允许出现"配器名词短语"的机器判据。
@@ -1003,42 +926,27 @@ _INTRO_LEAK_PHRASE_RE = re.compile(
def _check_intro_bracket_speakable(head):
"""前奏括号里不许出现会被唱出来的散文句。
为什么必须机器判(不靠 code review 兜住):括号内容直接进模型的
歌词条件通道,已经两次因为往里塞长句而把生成指令唱进了成品。
第一次靠注释提醒,第二次照样漏——所以把规则写成检查。
两套判据,取并集:
1. _INTRO_CLAUSE_RE —— 结构性信号(系动词 / 代词 / 介词短语…)
2. _INTRO_LEAK_PHRASE_RE —— 实证泄漏过的具体措辞
只用第 1 套会漏掉 "no fading in, no swelling in" 这类纯并列短语,
只用第 2 套则拦不住新写的散文句。两套互补,缺一不可。
白名单前缀 "8 bar instrumental intro hook" 只含 bar / instrumental /
intro / hook,不含任何子句信号,不会被误判。
"""
"""若仍残留 ``[Instrumental: ...]``,禁止散文/泄漏措辞(assemble 应已剥掉)。"""
errs = []
m = re.search(r"\[instrumental:(.*?)\]", head, re.I | re.S)
if not m:
return errs
errs.append(
"前奏请用裸 [Instrumental],不要 [Instrumental: ...]:"
"括号内容进歌词条件通道会诱发衬词或被原样唱出"
)
body = m.group(1)
hits = _INTRO_CLAUSE_RE.findall(body)
if hits:
uniq = sorted(set(h.lower() for h in hits))
errs.append(
"前奏括号含会被唱出的子句成分 [%s]:括号是歌词条件通道,"
"只允许配器名词短语(kick / sub bass / snare / hand claps),"
"要求句与量词句请写进 tags"
% ", ".join(uniq)
"前奏括号含会被唱出的子句成分 [%s]" % ", ".join(uniq)
)
leak = _INTRO_LEAK_PHRASE_RE.findall(body)
if leak:
uniq = sorted(set(l.lower() for l in leak))
errs.append(
"前奏括号含已实证会被唱出的生成指令措辞 [%s]:"
"这几句在 Bounce_s8 的成品里被原样唱了出来,"
"同类要求请写进 tags(RULE_GROOVE_FIRST_BEAT)"
"前奏括号含已实证会被唱出的生成指令措辞 [%s]"
% ", ".join(uniq)
)
return errs
@@ -1058,10 +966,15 @@ def check_rules(lyrics, tags, lean=False):
if not lyrics.lstrip().lower().startswith("[intro]"):
errs.append("歌词首行必须是 [intro]")
head = lyrics[:400]
if "[instrumental:" not in head.lower():
errs.append("歌词开头必须有 [Instrumental: ...] 器乐前奏描述")
elif not re.search(r"\[instrumental:[^\]]*\d+\s*bar", head, re.I):
errs.append("器乐前奏必须写明小节数(如 '8 bar instrumental hook')")
hl = head.lower()
if re.search(r"\[instrumental:", hl):
errs.append(
"前奏请用裸 [Instrumental],不要 [Instrumental: ...] "
"(括号内容进歌词通道会诱发衬词)"
)
elif not re.search(r"\[instrumental\]", hl) and \
not re.search(r"\[inst\]", hl):
errs.append("歌词开头必须有裸 [Instrumental] 或 [inst] 器乐前奏")
for ln in lyrics.split("\n"):
s = ln.strip()
if s.startswith("[") and s.endswith("]") and \
@@ -1087,12 +1000,7 @@ def check_rules(lyrics, tags, lean=False):
if bad in low:
errs.append("tags 点名衬词音节 '%s'(会诱发开曲衬词,请用 "
"no wordless vocals)" % bad)
# 器乐前奏小节数:普通歌曲 8 小节,chill 吟唱 8 小节,纯器乐 8 小节。
# 三种模式现在统一 8 小节(chill 曾试过 16,实测对人声起点毫无作用)。
# 这里仍然只校验"写了且在 4~32 范围内",不写死具体数字:
# 旧校验把整句 "8 bar instrumental intro hook" 写死后,chill 换成 16 小节
# 直接被拦下,而且报错完全指不到真实原因。改成匹配"N bar"后,
# 两种措辞(带 hook / 不带 hook)都接受。
# 小节数只写在 tags(歌词侧是裸 [Instrumental])
m = re.search(r"(\d+)\s*bar instrumental intro(?: hook)?", low)
if not m:
errs.append("tags 必须写明器乐前奏小节数"
@@ -1100,15 +1008,6 @@ def check_rules(lyrics, tags, lean=False):
elif not (4 <= int(m.group(1)) <= 32):
errs.append("器乐前奏小节数 %s 超出合理范围 4~32"
% m.group(1))
else:
# tags 与歌词头必须写同一个小节数。之前 chill 标签改成 16 小节、
# 歌词头还停在 8 小节,模型同时收到两个互相打架的指令,
# 结果是前奏长度完全随机。这里直接把不一致判成错误。
mh = re.search(r"\[instrumental:[^\]]*?(\d+)\s*bar", head, re.I)
if mh and int(mh.group(1)) != int(m.group(1)):
errs.append("tags 写 %s 小节前奏,歌词头写 %s 小节,"
"两处必须一致"
% (m.group(1), mh.group(1)))
return errs
+16 -11
View File
@@ -23,19 +23,23 @@ def main(job):
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)
# 与全量 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 []
# 时间戳相对 clip 起点,整段都在前奏窗内
stats = q.intro_filler_stats(segs, intro_sec + 1.0, lang)
stats = q.intro_filler_stats(
segs, intro_sec, lang, voc=v, vsr=vsr)
hard = q.HARD
fail = (stats["intro_filler_n"] >= hard["intro_filler_min_chars"]
and stats["intro_filler_ratio"] >= hard["intro_filler_ratio"])
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:
@@ -50,6 +54,7 @@ def main(job):
intro_sec=round(intro_sec, 2),
early_content=early,
asr_head=(a.get("text") or "")[:160],
eff_min=eff_min,
**stats,
)
+32 -9
View File
@@ -86,6 +86,9 @@ HARD = dict(
# 阈值刻意偏严:用户要求「不能出开曲衬词」;Whisper 偶发单字可被 min 挡住。
intro_filler_min_chars=6, # 前奏窗内至少累计这么多衬词字/词才判
intro_filler_ratio=0.55, # 衬词占前奏窗 ASR 单元比例
# Whisper 常在纯器乐上幻觉「嗯/啊」;必须再看 demucs vocals 能量。
# 前奏窗 vocals RMS 低于此阈值 → 视为幻觉,不因 ASR 衬词 FAIL。
intro_voc_rms_min=0.008,
# ---- 歌词感知分类阈值(见文件头坑位 6/7)----
# lyric_hit >= 0.34 -> 真唱;instr_hit >= 0.40 -> 生成指令泄漏。
# 这两个数是在 8 首已认可老歌 + 本批 8 首上交叉验证出来的:
@@ -706,11 +709,14 @@ def filler_ratio(asr_text, lang="zh"):
return n / float(len(chars))
def intro_filler_stats(segs, intro_sec, lang="zh"):
def intro_filler_stats(segs, intro_sec, lang="zh", voc=None, vsr=None):
"""前奏时间窗内的衬词统计(硬门用)。
vocal_onset / head_chars 只看「真唱实义词」,会故意丢掉 嗯/呀/ooh,
导致开曲衬词满天飞仍 PASS。这里单独扫前奏窗 ASR。
若传入 demucs vocals(voc/vsr),同时算前奏窗 RMS:Whisper 在纯器乐上
常幻觉衬词,能量门用来区分「真有无词人声」与「ASR 幻觉」。
"""
total = 0
fill = 0
@@ -732,9 +738,15 @@ def intro_filler_stats(segs, intro_sec, lang="zh"):
"".join(f)[:24] if not _is_en(lang)
else " ".join(f)[:24]))
ratio = (fill / float(total)) if total else 0.0
intro_voc_rms = 0.0
if voc is not None and vsr:
n = int(min(float(intro_sec), len(voc) / float(vsr)) * float(vsr))
if n > 0:
intro_voc_rms = _rms(voc[:n])
return dict(intro_filler_n=fill, intro_asr_n=total,
intro_filler_ratio=round(ratio, 4),
intro_filler_samples=samples[:4])
intro_filler_samples=samples[:4],
intro_voc_rms=round(intro_voc_rms, 6))
def coverage(asr_text, lyrics, lang="zh"):
@@ -933,9 +945,10 @@ def measure(path, expect=None, cache_dir=None, with_asr=True):
if expect.get("bpm") and expect.get("intro_bars"):
intro_sec = (float(expect["intro_bars"]) * 60.0
/ float(expect["bpm"]) * 4.0)
ifest = intro_filler_stats(segs, intro_sec, lang) if with_asr else \
ifest = intro_filler_stats(segs, intro_sec, lang, voc=v, vsr=vsr) \
if with_asr else \
dict(intro_filler_n=0, intro_asr_n=0, intro_filler_ratio=0.0,
intro_filler_samples=[])
intro_filler_samples=[], intro_voc_rms=0.0)
# ---- 风格分类:只看混音轨,不掺 demucs(见 qc_style 文件头坑位 4)
svec, sraw = qc_style.features(path, expect_bpm=expect.get("bpm"))
@@ -967,6 +980,7 @@ def measure(path, expect=None, cache_dir=None, with_asr=True):
intro_asr_n=ifest["intro_asr_n"],
intro_filler_ratio=ifest["intro_filler_ratio"],
intro_filler_samples=ifest["intro_filler_samples"],
intro_voc_rms=ifest.get("intro_voc_rms", 0.0),
asr_head=txt[:120],
voice_self=round(float(e_self), 4),
flatness=round(sraw.get("flatness", 0.0), 4),
@@ -1069,17 +1083,26 @@ def judge(rows, baseline):
why.append("前 2s 就已唱出 %d 个%s,疑似纯人声/spoken 开头"
% (r["head_chars_0_2"], unit))
# ---- 铁律一-b:禁止开曲衬词(嗯/呀/ooh…)
# vocal_onset 只看真唱,会漏掉衬词;此处扫前奏窗 ASR。
# ASR 衬词 + demucs vocals 能量双门:纯器乐静音上的幻觉不 FAIL。
# demucs 常有 ~0.09 器乐泄漏,能量门挡的是近零 RMS;有能量时
# 字数门槛降到 2,避免「满屏嗯」却因短窗少计而漏网。
ifn = int(r.get("intro_filler_n") or 0)
ifr = float(r.get("intro_filler_ratio") or 0.0)
if ifn >= HARD["intro_filler_min_chars"] and \
ifr >= HARD["intro_filler_ratio"]:
ivr = float(r.get("intro_voc_rms") or 0.0)
eff_min = HARD["intro_filler_min_chars"]
if ivr >= HARD["intro_voc_rms_min"]:
eff_min = min(eff_min, 2)
if ifn >= eff_min and ifr >= HARD["intro_filler_ratio"] and \
ivr >= HARD["intro_voc_rms_min"]:
samp = r.get("intro_filler_samples") or []
tip = ("; ".join("%ss:%s" % (a, b) for a, b in samp[:2])
if samp else "")
why.append("开曲衬词 %d 单元占比 %.0f%%(≥%d 且 ≥%.0f%%)%s"
% (ifn, ifr * 100, HARD["intro_filler_min_chars"],
why.append(
"开曲衬词 %d 单元占比 %.0f%% 且前奏人声能量 %.4f"
"(≥%d 且 ≥%.0f%% 且 RMS≥%.3f)%s"
% (ifn, ifr * 100, ivr, eff_min,
HARD["intro_filler_ratio"] * 100,
HARD["intro_voc_rms_min"],
(":" + tip) if tip else ""))
# ---- 铁律二:8 小节器乐前奏(完整 8 小节,不是 55%)
# 原来判的是 vocal_onset < want * 0.55,等于"第 4~5 小节进 sang