Support TOML config, project venv, and public packaging.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
swl
2026-10-10 00:54:07 +08:00
co-authored by Cursor
parent 870dea0825
commit 487aacf864
16 changed files with 323 additions and 172 deletions
-96
View File
@@ -1,96 +0,0 @@
{
"_comment": "songforge 唯一事实来源。改这里,不要改脚本里的硬编码常量。",
"engine": {
"server": "http://127.0.0.1:8188",
"timeout_sec": 3600,
"poll_interval_sec": 10,
"submit_retries": 3
},
"model": {
"checkpoint": "ace_step_1.5_turbo_swl_fused.safetensors",
"lora": "swl_voice_best_ep257.safetensors",
"lora_model_strength": 0.5,
"lora_clip_strength": 0.5,
"denied_checkpoints": [
"yue2_3b_int8_convrot.safetensors",
"ace_step_1.5_turbo_aio.safetensors"
]
},
"sampler": {
"shift": 5.5,
"sampling": "flow",
"steps": 28,
"cfg": 2.0,
"sampler_name": "euler",
"scheduler": "simple",
"denoise": 1.0
},
"encode": {
"cfg_scale": 3.0,
"temperature": 0.68,
"top_p": 0.88,
"top_k": 50,
"min_p": 0.02,
"generate_audio_codes": true,
"timesignature": "4"
},
"paths": {
"_comment": "相对路径均相对 user/default/workflows。本机绝对路径放 local.json(gitignore)。音频在 ComfyUI/output/<output_prefix>/。过程物按日落在 data/runs|tmp/YYYY-MM-DD/。",
"workflow_template": "urbanhiphop-身体先听懂.json",
"runs_dir": "songforge/data/runs",
"tmp_dir": "songforge/data/tmp",
"lyrics_dir": "songforge/input/lyrics",
"qc_cache_dir": "songforge/cache/qc",
"style_cache_dir": "songforge/cache/style",
"index_dir": "songforge/index",
"catalog_file": "songforge/index/catalog.jsonl",
"baseline_dir": "songforge/config/baseline",
"comfy_root": null,
"qc_python": null,
"music_dir": null,
"output_prefix": "MyMusic",
"output_format": "flac"
},
"song": {
"language": "zh",
"time_signature": "4",
"duration_range": [150, 200],
"_duration_extra_comment": "duration_extra_ranges 供短视频/口水歌等场景显式放行短时长,不削弱主区间。主区间是 35 首已验证实歌的经验范围,短时长没有对应实歌背书,所以必须显式列出而不是直接放宽。",
"duration_extra_ranges": [[100, 130]]
},
"lyrics": {
"_comment": "死心塌地时长对应关系。阈值由 8 首已验证可生成的歌实测反推,不是理论值;改前先跑 selftest 实歌回归。",
"_calibrated_on": "remake_v5.py 的 8 首实歌:每可唱小节 4.56~7.64 音节(均值 6.17),每句 5.9~7.4 音节(均值 6.7)",
"sing_bar_ratio": 0.70,
"intro_bars": 8,
"syllable_per_bar_min": 4.40,
"syllable_per_bar_max": 7.80,
"line_syllable_max": 12,
"ideal_line_syllable": [5, 12],
"_profile_comment": "密度档。default = 人声填满整首(中文说唱/流行)。sparse = 音乐主导、人声点缀(英文低声吟唱/纯器乐周边)。",
"_profile_why": "default 档是按 8 首'人声填满全曲'的实歌反推的。直接拿它校验第三张那种'音乐当主角、人声只是点缀'的写法,会把只有几句 ooh ooh 的低音吟唱判成歌词过少,逼着写满 254 音节以上——结果就是'只有人声没有音乐',正好和目标相反。所以稀疏写法必须用另一套阈值,不能共用。",
"profiles": {
"sparse": {
"_comment": "稀疏档:可唱小节只占 25%(其余留给器乐),句子下限放宽到 3 音节,允许 ooh ooh / mmm 这类短语气词。",
"sing_bar_ratio": 0.25,
"syllable_per_bar_min": 4.40,
"syllable_per_bar_max": 7.80,
"line_syllable_max": 12,
"ideal_line_syllable": [3, 12]
}
}
},
"rules": {
"trigger_word": "swlvoice",
"intro_bars": 8
}
}
+80
View File
@@ -0,0 +1,80 @@
# songforge 算法与相对路径的唯一事实来源(可提交)。
# 本机绝对路径请写 local.toml(gitignore),勿写进本文件。
# ComfyUI workflow 图仍是 JSON,只放在 workflows/ 或 Comfy 模板路径下。
[engine]
server = "http://127.0.0.1:8188"
timeout_sec = 3600
poll_interval_sec = 10
submit_retries = 3
[model]
checkpoint = "ace_step_1.5_turbo_swl_fused.safetensors"
lora = "swl_voice_best_ep257.safetensors"
lora_model_strength = 0.5
lora_clip_strength = 0.5
denied_checkpoints = [
"yue2_3b_int8_convrot.safetensors",
"ace_step_1.5_turbo_aio.safetensors",
]
[sampler]
shift = 5.5
sampling = "flow"
steps = 28
cfg = 2.0
sampler_name = "euler"
scheduler = "simple"
denoise = 1.0
[encode]
cfg_scale = 3.0
temperature = 0.68
top_p = 0.88
top_k = 50
min_p = 0.02
generate_audio_codes = true
timesignature = "4"
# 相对路径相对「workflows 父目录」(嵌套在 ComfyUI 时)或克隆仓的父目录。
# 本机 comfy_root / qc_python / music_dir 放 local.toml。
[paths]
workflow_template = "urbanhiphop-身体先听懂.json"
runs_dir = "songforge/data/runs"
tmp_dir = "songforge/data/tmp"
lyrics_dir = "songforge/input/lyrics"
qc_cache_dir = "songforge/cache/qc"
style_cache_dir = "songforge/cache/style"
index_dir = "songforge/index"
catalog_file = "songforge/index/catalog.jsonl"
baseline_dir = "songforge/config/baseline"
output_prefix = "MyMusic"
output_format = "flac"
[song]
language = "zh"
time_signature = "4"
duration_range = [150, 200]
# 短视频等场景显式放行;不削弱主区间
duration_extra_ranges = [[100, 130]]
# 死心塌地时长对应:阈值由 8 首已验证实歌反推,改前先跑 selftest。
[lyrics]
sing_bar_ratio = 0.70
intro_bars = 8
syllable_per_bar_min = 4.40
syllable_per_bar_max = 7.80
line_syllable_max = 12
ideal_line_syllable = [5, 12]
# sparse = 音乐主导、人声点缀(英文低声吟唱等)
[lyrics.profiles.sparse]
sing_bar_ratio = 0.25
syllable_per_bar_min = 4.40
syllable_per_bar_max = 7.80
line_syllable_max = 12
ideal_line_syllable = [3, 12]
[rules]
trigger_word = "swlvoice"
intro_bars = 8
+37 -8
View File
@@ -1,13 +1,21 @@
# -*- coding: utf-8 -*-
"""配置加载与覆盖。
优先级:命令行 > 环境变量 > local.json > default.json > 内置 DEFAULTS。
优先级:命令行 > 环境变量 > local.toml|json > default.toml|json > DEFAULTS。
local.json 放本机绝对路径(gitignore),见 local.json.example。
算法配置用 TOML(与 ComfyUI workflow JSON 分流)。
styles.json / lexicon.json / baseline/*.json 仍是数据文件,保持 JSON。
本机绝对路径只写 local.toml(gitignore)。
"""
import copy
import json
import os
import sys
try:
import tomllib
except ModuleNotFoundError: # Python < 3.11
import tomli as tomllib # type: ignore
ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
CONFIG_DIR = os.path.join(ROOT, "songforge", "config")
@@ -69,19 +77,35 @@ def _deep_merge(base, patch):
return base
def _read(name):
def _read_json(name):
p = os.path.join(CONFIG_DIR, name)
if not os.path.exists(p):
if not os.path.isfile(p):
return {}
with open(p, encoding="utf-8") as f:
return json.load(f)
def _read_toml(name):
p = os.path.join(CONFIG_DIR, name)
if not os.path.isfile(p):
return {}
with open(p, "rb") as f:
return tomllib.load(f)
def _read_layer(basename):
"""同名 .json 与 .toml:先 json 再 toml,toml 覆盖(迁移期兼容)。"""
out = {}
_deep_merge(out, _read_json(basename + ".json"))
_deep_merge(out, _read_toml(basename + ".toml"))
return out
def load(overrides=None):
"""返回最终配置 dict。overrides 是 {'sampler.shift': 5.5} 这种点号路径。"""
cfg = copy.deepcopy(DEFAULTS)
_deep_merge(cfg, _read("default.json"))
_deep_merge(cfg, _read("local.json"))
_deep_merge(cfg, _read_layer("default"))
_deep_merge(cfg, _read_layer("local"))
_deep_merge(cfg, _env_overrides())
if overrides:
for path, val in overrides.items():
@@ -167,13 +191,18 @@ def _env_overrides():
def styles():
return _read("styles.json")
return _read_json("styles.json")
def lexicon():
return _read("lexicon.json")
return _read_json("lexicon.json")
def baseline_path(name):
"""config/baseline/<name> 绝对路径。"""
return os.path.join(CONFIG_DIR, "baseline", name)
def python_hint():
"""当前解释器信息(doctor 用)。"""
return "%s (%s)" % (sys.executable, sys.version.split()[0])
-11
View File
@@ -1,11 +0,0 @@
{
"_comment": "复制为 local.json(已 gitignore)。只放本机绝对路径,勿提交。",
"paths": {
"comfy_root": "D:/CodeFiles/Thinking/ComfyUI-MiniMaxH3",
"qc_python": "C:/comfyui-venv/Scripts/python.exe",
"music_dir": "D:/CodeFiles/Thinking/ComfyUI-MiniMaxH3/output/MyMusic"
},
"engine": {
"server": "http://127.0.0.1:8188"
}
}
+10
View File
@@ -0,0 +1,10 @@
# 复制为 local.toml(已 gitignore)。只放本机绝对路径,勿提交。
# CLI 用项目 .venv;QC 音频栈可继续指向 ComfyUI 专用 venv。
[paths]
comfy_root = "D:/CodeFiles/Thinking/ComfyUI-MiniMaxH3"
qc_python = "C:/comfyui-venv/Scripts/python.exe"
music_dir = "D:/CodeFiles/Thinking/ComfyUI-MiniMaxH3/output/MyMusic"
[engine]
server = "http://127.0.0.1:8188"