Add no-filler tags, media CLI, and ask-before-edit iron law.
selftest / selftest (push) Canceled after 0s
selftest / selftest (push) Canceled after 0s
Default solo-lead tags and report-only filler_ratio; slim Agent docs with media CLI; require consent, git backup or plugin path, and explicit commit/push before code changes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+4
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
命令:
|
||||
doctor / styles / target / check / gen / runs / show / catalog /
|
||||
prune / qc / selftest
|
||||
prune / media / qc / selftest
|
||||
|
||||
设计约束:所有业务参数来自配置/命令行,本文件不写死任何模型或采样常量。
|
||||
实现见 common / assemble / commands / selftest / qc。
|
||||
@@ -146,6 +146,9 @@ def build_parser():
|
||||
help="一并删除 tmp/_migrated 等非日期目录")
|
||||
pr.set_defaults(func=cmds.cmd_prune)
|
||||
|
||||
from .media import add_media
|
||||
add_media(sub)
|
||||
|
||||
from .qc import add_qc
|
||||
add_qc(sub)
|
||||
return p
|
||||
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""songforge media:info / convert / clip(经 qc_python 子进程)。"""
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from ..config import loader
|
||||
from ..core import paths as pmod
|
||||
from .qc import find_qc_python
|
||||
|
||||
ROOT = pmod.PKG_ROOT
|
||||
WORKER = os.path.join(ROOT, "tools", "media_worker.py")
|
||||
|
||||
|
||||
def _run(job, timeout=600):
|
||||
cfg = loader.load({})
|
||||
py = find_qc_python(cfg)
|
||||
if not py:
|
||||
print("[错误] 找不到 qc_python。请在 config/local.toml 配置 paths.qc_python")
|
||||
return 2, None
|
||||
env = dict(os.environ)
|
||||
cro = pmod.comfy_root(cfg=cfg)
|
||||
env["SONGFORGE_COMFY_ROOT"] = cro
|
||||
env["PYTHONIOENCODING"] = "utf-8"
|
||||
cmd = [py, WORKER, json.dumps(job, ensure_ascii=False)]
|
||||
try:
|
||||
r = subprocess.run(cmd, capture_output=True, env=env, timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
print("[错误] media 超时")
|
||||
return 2, None
|
||||
out = r.stdout.decode("utf-8", "replace")
|
||||
if "###JSON###" not in out:
|
||||
print(out[-1500:])
|
||||
print(r.stderr.decode("utf-8", "replace")[-1500:])
|
||||
print("[错误] media_worker 无 JSON 输出")
|
||||
return 2, None
|
||||
blob = json.loads(out.split("###JSON###", 1)[1].strip())
|
||||
if blob.get("error"):
|
||||
print("[错误] %s: %s" % (blob.get("type"), blob["error"]))
|
||||
return 1, blob
|
||||
return 0, blob
|
||||
|
||||
|
||||
def cmd_media_info(args):
|
||||
code, blob = _run(dict(op="info", file=os.path.abspath(args.file)))
|
||||
if blob and not blob.get("error"):
|
||||
print(json.dumps(blob, ensure_ascii=False, indent=1))
|
||||
return code
|
||||
|
||||
|
||||
def cmd_media_convert(args):
|
||||
out = args.out
|
||||
if not out:
|
||||
base, _ = os.path.splitext(args.file)
|
||||
out = base + "." + args.to.lstrip(".")
|
||||
code, blob = _run(dict(
|
||||
op="convert", file=os.path.abspath(args.file),
|
||||
to=args.to, out=os.path.abspath(out)))
|
||||
if blob and not blob.get("error"):
|
||||
print(json.dumps(blob, ensure_ascii=False, indent=1))
|
||||
return code
|
||||
|
||||
|
||||
def cmd_media_clip(args):
|
||||
out = args.out
|
||||
if not out:
|
||||
base, ext = os.path.splitext(args.file)
|
||||
out = "%s_clip%.1f%s" % (base, args.start, ext or ".wav")
|
||||
job = dict(op="clip", file=os.path.abspath(args.file),
|
||||
start=args.start, out=os.path.abspath(out))
|
||||
if args.dur is not None:
|
||||
job["dur"] = args.dur
|
||||
if args.end is not None:
|
||||
job["end"] = args.end
|
||||
code, blob = _run(job)
|
||||
if blob and not blob.get("error"):
|
||||
print(json.dumps(blob, ensure_ascii=False, indent=1))
|
||||
return code
|
||||
|
||||
|
||||
def add_media(sub):
|
||||
m = sub.add_parser("media", help="音频窄接口:info / convert / clip")
|
||||
ms = m.add_subparsers(dest="media_cmd")
|
||||
|
||||
i = ms.add_parser("info", help="时长/采样率/声道/粗 BPM")
|
||||
i.add_argument("--file", required=True)
|
||||
i.set_defaults(func=cmd_media_info)
|
||||
|
||||
c = ms.add_parser("convert", help="转 wav/flac/mp3")
|
||||
c.add_argument("--file", required=True)
|
||||
c.add_argument("--to", required=True, choices=["wav", "flac", "mp3"])
|
||||
c.add_argument("--out")
|
||||
c.set_defaults(func=cmd_media_convert)
|
||||
|
||||
k = ms.add_parser("clip", help="按秒截取")
|
||||
k.add_argument("--file", required=True)
|
||||
k.add_argument("--start", type=float, default=0.0)
|
||||
k.add_argument("--dur", type=float, help="时长(秒)")
|
||||
k.add_argument("--end", type=float, help="结束时刻(秒),与 --dur 二选一")
|
||||
k.add_argument("--out")
|
||||
k.set_defaults(func=cmd_media_clip)
|
||||
|
||||
def _need_sub(args):
|
||||
print("用法: songforge media {info,convert,clip} ...")
|
||||
return 2
|
||||
m.set_defaults(func=_need_sub)
|
||||
return m
|
||||
@@ -333,17 +333,19 @@ def _render(rep, args, rundir=None, cfg=None):
|
||||
% (lk["t0"], hit, lk.get("text", "")))
|
||||
|
||||
print("\n== 声线 / 歌词 ==")
|
||||
print("%-22s %-14s %8s %7s %7s %6s %6s %7s"
|
||||
% ("file", "最近邻老歌", "NN相似", "自相似", "cov", "f0中位",
|
||||
"f0漂移", "t漂移"))
|
||||
print("%-22s %-14s %8s %7s %7s %6s %6s %6s %7s"
|
||||
% ("file", "最近邻老歌", "NN相似", "自相似", "cov", "衬词%",
|
||||
"f0中位", "f0漂移", "t漂移"))
|
||||
for r in rows:
|
||||
if "error" in r:
|
||||
continue
|
||||
print("%-22s %-14s %8.3f %7.3f %6.1f%% %6.1f %5.1fst %6.1f%%"
|
||||
print("%-22s %-14s %8.3f %7.3f %6.1f%% %5.0f%% %6.1f %5.1fst %6.1f%%"
|
||||
% (r["file"][:22], (r.get("voice_nn") or "-")[:14],
|
||||
r.get("voice_nn_sim", 0), r.get("voice_self", 0),
|
||||
r.get("coverage", 0) * 100, r.get("f0_med", 0),
|
||||
r.get("coverage", 0) * 100, r.get("filler_ratio", 0) * 100,
|
||||
r.get("f0_med", 0),
|
||||
r.get("f0_drift_st", 0), r.get("tempo_drift", 0) * 100))
|
||||
print(" (衬词%% = ASR 语气/哼唱占比,弱参考,不单独否决)")
|
||||
|
||||
print("\n== 结论 ==")
|
||||
npass = 0
|
||||
|
||||
+20
-8
@@ -124,8 +124,14 @@ def _t_model_locked():
|
||||
def _t_ironlaw():
|
||||
tags = ironlaw.build_tags("Chinese pop")
|
||||
for kw in ("swlvoice", "8 bar instrumental intro hook", "no opening vocals",
|
||||
"no pure vocal intro", "no humming"):
|
||||
"no pure vocal intro", "no humming",
|
||||
"solo lead vocal only", "no backing vocals",
|
||||
"sing only the exact words"):
|
||||
assert kw in tags, "tags 缺少 %s" % kw
|
||||
assert "call and response" not in tags.lower() or \
|
||||
"no call and response vocals" in tags.lower(), \
|
||||
"MEMO 仍鼓励 call and response 且未禁叠唱"
|
||||
assert "single lead vocal hook" in tags, "缺少单人主唱 hook 描述"
|
||||
lyrics = ironlaw.build_lyrics(
|
||||
[("[verse]", "第一句歌词\n第二句歌词")], "kick and snare", bars=8)
|
||||
assert lyrics.lstrip().startswith("[intro]"), "未强制器乐前奏"
|
||||
@@ -137,7 +143,12 @@ def _t_ironlaw():
|
||||
# 中文结构标记必须被拦
|
||||
marked = lyrics.replace("[verse]", "[主歌]")
|
||||
assert ironlaw.check_rules(marked, tags), "中文结构标记未被拦截"
|
||||
return [("铁律注入", "8 小节器乐前奏 + 反人声条款齐备,缺前奏/中文标记均被拦")]
|
||||
# lean 也必须带衬音硬禁
|
||||
lean = ironlaw.build_tags("Chinese pop", lean=True)
|
||||
for kw in ("solo lead vocal only", "no backing vocals"):
|
||||
assert kw in lean, "lean tags 缺少衬音禁令 %s" % kw
|
||||
return [("铁律注入",
|
||||
"8 小节前奏 + 无衬音/无和声叠唱 + lean 齐备,缺前奏/中文标记均被拦")]
|
||||
|
||||
|
||||
def _t_sparse_profile():
|
||||
@@ -338,15 +349,16 @@ def _t_chill_delay():
|
||||
|
||||
# 但也不能把人声彻底禁掉,否则就是纯器乐、不是吟唱。
|
||||
# 注意只匹配纯器乐专属的反人声条款:
|
||||
# - 不能用裸 "no singing":"no singing in any breakdown" 含这个子串,
|
||||
# 那是吟唱要的人声约束。
|
||||
# - 不能用 "instrumental only":它来自 "intro is instrumental only",
|
||||
# 那是前奏必须保留的约束。
|
||||
for kw in ("no vocals anywhere", "no voice at all", "no lead vocal",
|
||||
"no backing vocal", "this is a backing track",
|
||||
# - 不能用裸 "no singing":"no singing in any breakdown" 含这个子串。
|
||||
# - 不能用 "no backing vocal"(无 s):那是 INST_NEG;默认衬音禁令是
|
||||
# "no backing vocals"(有 s)+ "solo lead vocal only",chill 必须保留。
|
||||
for kw in ("no vocals anywhere", "no voice at all", "no lead vocal,",
|
||||
"no backing vocal,", "this is a backing track",
|
||||
"drums bass synths chords and lead melodies only"):
|
||||
assert kw not in tags.lower(), \
|
||||
"chill tags 含纯器乐条款 %s,吟唱被人声禁令吞掉" % kw
|
||||
assert "no backing vocals" in tags.lower(), \
|
||||
"chill 缺少默认无和声叠唱禁令"
|
||||
|
||||
return [("吟唱标签梯度",
|
||||
"时机类措辞全部禁掉,密度触发词保留,"
|
||||
|
||||
Reference in New Issue
Block a user