cortico-world-fish-sing 0.1.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/{webui-39b0a58f.js → webui-47b496dd.js} +30 -2
- package/dist/webui.js +37 -2
- package/package.json +2 -2
- package/src/config.ts +7 -0
- package/src/world.ts +115 -4
- package/tools/publish.mjs +99 -0
- package/worker/engine.py +82 -0
- package/worker/server.py +13 -2
- package/worker/trainer.py +59 -5
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循语义化。
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2026-11-01
|
|
6
|
+
|
|
7
|
+
### 新增
|
|
8
|
+
- **低音增强(治"低音不像"的根本手段)**:训练时把每个切片用 ffmpeg 合成 -2/-4 半音的低音数据一起训练,模型由此学到低音区的音色映射,不再只靠采样加权硬顶。训练页勾选框「低音增强」(默认开)。
|
|
9
|
+
- 副本命名 `aug<shift>_<原名>`,与原切片一起铺进 F0/特征两层;
|
|
10
|
+
- 采样权重按「源 + 副本」总份数摊薄(3x 低音源 + 2 副本 → 各 1x),避免与加权叠加成 9x 过采样;
|
|
11
|
+
- 实测:415Hz 切片的 -2/-4 副本基频 370/329Hz,精确命中理论值。
|
|
12
|
+
- 代价:F0/特征提取时间约 ×3(数据量 ×3)。
|
|
13
|
+
- **发版脚本 `tools/publish.mjs`**:CHANGELOG 缺条目硬性拦截 → npm publish → 轮询 tarball 可用(覆盖 2~6 分钟 CDN 延迟)→ 收尾提醒。`--check` 只查不发。
|
|
14
|
+
|
|
15
|
+
## [0.2.1] - 2026-11-01
|
|
16
|
+
|
|
17
|
+
### 新增
|
|
18
|
+
- **选模对比进面板 + 手动入口**:训练页新增勾选框「训练完生成选模对比」(默认勾)与「生成选模对比」按钮(对实验名里的实验手动跑一次,前提是还有中间档)。此前该功能只有 config.json 字段且纯自动触发,界面上完全不可见。
|
|
19
|
+
|
|
20
|
+
## [0.2.0] - 2026-11-01
|
|
21
|
+
|
|
22
|
+
### 新增
|
|
23
|
+
- **选模对比试听(自动化)**:训练完成后自动用一句训练切片(目标音色清唱),对 final + 最后两个中间档各换声一遍——输入完全一致,听出来的差异全是存档本身的差别。片段进作品库;配了 `notify.qqTarget` 的话同时逐条发 QQ,桌宠也会说一声。
|
|
24
|
+
- 模型热切换:worker 不重启,临时把 `weight_root` 指到存档所在目录后 `get_vc`,对比完恢复原模型。
|
|
25
|
+
- 配置 `train.abTest`(默认开)可关。
|
|
26
|
+
|
|
27
|
+
### 修复
|
|
28
|
+
- 引擎初始状态的 `model_path` 补上绝对路径——之前选模对比结束后的「恢复原模型」会按相对路径找不到文件。
|
|
29
|
+
|
|
5
30
|
## [0.1.9] - 2026-11-01
|
|
6
31
|
|
|
7
32
|
### 新增
|
|
@@ -1199,7 +1199,13 @@ function mountTrain(ctx) {
|
|
|
1199
1199
|
const pruneAfterLbl = el('label', 'fs-meta', '训练完自动清理中间档');
|
|
1200
1200
|
pruneAfterLbl.prepend(pruneAfterChk);
|
|
1201
1201
|
pruneAfterLbl.title = '按下面「每 N 轮留一个」保留,其余删掉。不勾就只是提醒你手动清。';
|
|
1202
|
-
|
|
1202
|
+
const abChk = el('input', 'fs-ck');
|
|
1203
|
+
abChk.type = 'checkbox';
|
|
1204
|
+
abChk.checked = true;
|
|
1205
|
+
const abLbl = el('label', 'fs-meta', '训练完生成选模对比');
|
|
1206
|
+
abLbl.prepend(abChk);
|
|
1207
|
+
abLbl.title = '用同一句训练切片,final 和最后两个中间档各唱一遍,进作品库对比听';
|
|
1208
|
+
chkRow.append(resumeLbl, rebuildLbl, pruneAfterLbl, abLbl, el('span', 'fs-grow'), startT, stopT);
|
|
1203
1209
|
|
|
1204
1210
|
const tProg = el('div', 'fs-prog');
|
|
1205
1211
|
const tFill = el('i');
|
|
@@ -1219,8 +1225,10 @@ function mountTrain(ctx) {
|
|
|
1219
1225
|
keepIn.style.width = '64px';
|
|
1220
1226
|
const pruneBtn = el('button', 'fs-btn', '清理中间档');
|
|
1221
1227
|
pruneBtn.title = '只删 assets/weights/<exp>_eN_sX.pth 这种导出的小模型;完整存档、索引、最终模型都不动';
|
|
1228
|
+
const abBtn = el('button', 'fs-btn', '生成选模对比');
|
|
1229
|
+
abBtn.title = '用当前实验的存档(final + 最后两个中间档)各唱同一句训练切片,生成对比试听进作品库';
|
|
1222
1230
|
ckptBar.append(el('span', 'fs-meta', '中间档:'), ckptMeta, el('span', 'fs-meta', '每'),
|
|
1223
|
-
keepIn, el('span', 'fs-meta', '轮留一个'), el('span', 'fs-grow'), pruneBtn);
|
|
1231
|
+
keepIn, el('span', 'fs-meta', '轮留一个'), el('span', 'fs-grow'), abBtn, pruneBtn);
|
|
1224
1232
|
trainBox.append(tTitle, tForm, chkRow, tProg, tMsg, losses, lossAxis, tModels, ckptBar);
|
|
1225
1233
|
|
|
1226
1234
|
let trainExp = '';
|
|
@@ -1236,6 +1244,25 @@ function mountTrain(ctx) {
|
|
|
1236
1244
|
} catch { /* 忽略 */ }
|
|
1237
1245
|
};
|
|
1238
1246
|
|
|
1247
|
+
abBtn.addEventListener('click', async () => {
|
|
1248
|
+
const exp = String(expIn.value || '').trim() || trainExp;
|
|
1249
|
+
if (!exp) {
|
|
1250
|
+
tMsg.textContent = '先填实验名(或跑一次训练)再生成选模对比';
|
|
1251
|
+
return;
|
|
1252
|
+
}
|
|
1253
|
+
abBtn.disabled = true;
|
|
1254
|
+
abBtn.textContent = '生成中…';
|
|
1255
|
+
try {
|
|
1256
|
+
const r = await ctx.invoke('trainAbTest', [{ exp }]);
|
|
1257
|
+
tMsg.textContent = (r && r.text) || `选模对比已生成(${exp})`;
|
|
1258
|
+
} catch (e) {
|
|
1259
|
+
tMsg.textContent = `选模对比失败:${(e && e.message) || e}`;
|
|
1260
|
+
} finally {
|
|
1261
|
+
abBtn.disabled = false;
|
|
1262
|
+
abBtn.textContent = '生成选模对比';
|
|
1263
|
+
}
|
|
1264
|
+
});
|
|
1265
|
+
|
|
1239
1266
|
pruneBtn.addEventListener('click', async () => {
|
|
1240
1267
|
if (!trainExp) return;
|
|
1241
1268
|
const step = Math.max(1, Number(keepIn.value) || 50);
|
|
@@ -1408,6 +1435,7 @@ function mountTrain(ctx) {
|
|
|
1408
1435
|
resume: resumeChk.checked,
|
|
1409
1436
|
rebuild: rebuildChk.checked,
|
|
1410
1437
|
pruneAfter: pruneAfterChk.checked,
|
|
1438
|
+
abTest: abChk.checked,
|
|
1411
1439
|
keepEvery: Math.max(1, Number(keepIn.value) || 50),
|
|
1412
1440
|
}]);
|
|
1413
1441
|
if (r && r.exp) {
|
package/dist/webui.js
CHANGED
|
@@ -1199,7 +1199,19 @@ function mountTrain(ctx) {
|
|
|
1199
1199
|
const pruneAfterLbl = el('label', 'fs-meta', '训练完自动清理中间档');
|
|
1200
1200
|
pruneAfterLbl.prepend(pruneAfterChk);
|
|
1201
1201
|
pruneAfterLbl.title = '按下面「每 N 轮留一个」保留,其余删掉。不勾就只是提醒你手动清。';
|
|
1202
|
-
|
|
1202
|
+
const abChk = el('input', 'fs-ck');
|
|
1203
|
+
abChk.type = 'checkbox';
|
|
1204
|
+
abChk.checked = true;
|
|
1205
|
+
const abLbl = el('label', 'fs-meta', '训练完生成选模对比');
|
|
1206
|
+
abLbl.prepend(abChk);
|
|
1207
|
+
abLbl.title = '用同一句训练切片,final 和最后两个中间档各唱一遍,进作品库对比听';
|
|
1208
|
+
const lowChk = el('input', 'fs-ck');
|
|
1209
|
+
lowChk.type = 'checkbox';
|
|
1210
|
+
lowChk.checked = true;
|
|
1211
|
+
const lowLbl = el('label', 'fs-meta', '低音增强');
|
|
1212
|
+
lowLbl.prepend(lowChk);
|
|
1213
|
+
lowLbl.title = '把每个切片合成 -2/-4 半音的低音数据一起训练,治"低音不像"。F0/特征提取时间约 ×3';
|
|
1214
|
+
chkRow.append(resumeLbl, rebuildLbl, pruneAfterLbl, abLbl, lowLbl, el('span', 'fs-grow'), startT, stopT);
|
|
1203
1215
|
|
|
1204
1216
|
const tProg = el('div', 'fs-prog');
|
|
1205
1217
|
const tFill = el('i');
|
|
@@ -1219,8 +1231,10 @@ function mountTrain(ctx) {
|
|
|
1219
1231
|
keepIn.style.width = '64px';
|
|
1220
1232
|
const pruneBtn = el('button', 'fs-btn', '清理中间档');
|
|
1221
1233
|
pruneBtn.title = '只删 assets/weights/<exp>_eN_sX.pth 这种导出的小模型;完整存档、索引、最终模型都不动';
|
|
1234
|
+
const abBtn = el('button', 'fs-btn', '生成选模对比');
|
|
1235
|
+
abBtn.title = '用当前实验的存档(final + 最后两个中间档)各唱同一句训练切片,生成对比试听进作品库';
|
|
1222
1236
|
ckptBar.append(el('span', 'fs-meta', '中间档:'), ckptMeta, el('span', 'fs-meta', '每'),
|
|
1223
|
-
keepIn, el('span', 'fs-meta', '轮留一个'), el('span', 'fs-grow'), pruneBtn);
|
|
1237
|
+
keepIn, el('span', 'fs-meta', '轮留一个'), el('span', 'fs-grow'), abBtn, pruneBtn);
|
|
1224
1238
|
trainBox.append(tTitle, tForm, chkRow, tProg, tMsg, losses, lossAxis, tModels, ckptBar);
|
|
1225
1239
|
|
|
1226
1240
|
let trainExp = '';
|
|
@@ -1236,6 +1250,25 @@ function mountTrain(ctx) {
|
|
|
1236
1250
|
} catch { /* 忽略 */ }
|
|
1237
1251
|
};
|
|
1238
1252
|
|
|
1253
|
+
abBtn.addEventListener('click', async () => {
|
|
1254
|
+
const exp = String(expIn.value || '').trim() || trainExp;
|
|
1255
|
+
if (!exp) {
|
|
1256
|
+
tMsg.textContent = '先填实验名(或跑一次训练)再生成选模对比';
|
|
1257
|
+
return;
|
|
1258
|
+
}
|
|
1259
|
+
abBtn.disabled = true;
|
|
1260
|
+
abBtn.textContent = '生成中…';
|
|
1261
|
+
try {
|
|
1262
|
+
const r = await ctx.invoke('trainAbTest', [{ exp }]);
|
|
1263
|
+
tMsg.textContent = (r && r.text) || `选模对比已生成(${exp})`;
|
|
1264
|
+
} catch (e) {
|
|
1265
|
+
tMsg.textContent = `选模对比失败:${(e && e.message) || e}`;
|
|
1266
|
+
} finally {
|
|
1267
|
+
abBtn.disabled = false;
|
|
1268
|
+
abBtn.textContent = '生成选模对比';
|
|
1269
|
+
}
|
|
1270
|
+
});
|
|
1271
|
+
|
|
1239
1272
|
pruneBtn.addEventListener('click', async () => {
|
|
1240
1273
|
if (!trainExp) return;
|
|
1241
1274
|
const step = Math.max(1, Number(keepIn.value) || 50);
|
|
@@ -1408,6 +1441,8 @@ function mountTrain(ctx) {
|
|
|
1408
1441
|
resume: resumeChk.checked,
|
|
1409
1442
|
rebuild: rebuildChk.checked,
|
|
1410
1443
|
pruneAfter: pruneAfterChk.checked,
|
|
1444
|
+
abTest: abChk.checked,
|
|
1445
|
+
augment: lowChk.checked,
|
|
1411
1446
|
keepEvery: Math.max(1, Number(keepIn.value) || 50),
|
|
1412
1447
|
}]);
|
|
1413
1448
|
if (r && r.exp) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-fish-sing",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"local"
|
|
37
37
|
],
|
|
38
38
|
"describe": "describe.json",
|
|
39
|
-
"webUiClient": "dist/webui-
|
|
39
|
+
"webUiClient": "dist/webui-47b496dd.js"
|
|
40
40
|
},
|
|
41
41
|
"scripts": {
|
|
42
42
|
"doctor": "node tools/doctor.mjs"
|
package/src/config.ts
CHANGED
|
@@ -59,6 +59,10 @@ export interface FishSingConfigSection {
|
|
|
59
59
|
/** QQ 通知发到哪:group:<群号> 或 private:<QQ号>;空 = 只用桌宠 */
|
|
60
60
|
qqTarget?: string;
|
|
61
61
|
};
|
|
62
|
+
train?: {
|
|
63
|
+
/** 训练完成后自动生成选模对比试听(同一句训练切片,最后几个存档各唱一遍);默认开 */
|
|
64
|
+
abTest?: boolean;
|
|
65
|
+
};
|
|
62
66
|
worker: {
|
|
63
67
|
/** 自托管根目录;留空 = <数据目录>/runtime(推荐) */
|
|
64
68
|
runtimeRoot: string;
|
|
@@ -129,6 +133,9 @@ export const FISHSING_DEFAULTS: FishSingConfigSection = {
|
|
|
129
133
|
channel: 'auto',
|
|
130
134
|
qqTarget: '',
|
|
131
135
|
},
|
|
136
|
+
train: {
|
|
137
|
+
abTest: true,
|
|
138
|
+
},
|
|
132
139
|
};
|
|
133
140
|
|
|
134
141
|
const at = (path: string): string => `worlds.${FISHSING_ID}.${path}`;
|
package/src/world.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* · 重活全在 Python worker 里(模型常驻、55 秒切片),TS 侧只做编排和投递。
|
|
9
9
|
*/
|
|
10
10
|
import { spawn } from 'node:child_process';
|
|
11
|
-
import { existsSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
11
|
+
import { existsSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
12
12
|
import { basename, dirname, join } from 'node:path';
|
|
13
13
|
import { fileURLToPath } from 'node:url';
|
|
14
14
|
|
|
@@ -64,9 +64,9 @@ import {
|
|
|
64
64
|
type RuntimeMode,
|
|
65
65
|
type SetupStatus,
|
|
66
66
|
} from './setup.ts';
|
|
67
|
-
import { duration, type FfmpegDeps } from './audio.ts';
|
|
68
|
-
import { Player } from './deliver.ts';
|
|
69
|
-
import { dropFromLibrary, listLibrary, loadLibrary, pruneCache, renameInLibrary, type LibraryOptions } from './library.ts';
|
|
67
|
+
import { duration, toMp3, type FfmpegDeps } from './audio.ts';
|
|
68
|
+
import { parseTarget, Player, sendRecord } from './deliver.ts';
|
|
69
|
+
import { addToLibrary, dropFromLibrary, listLibrary, loadLibrary, pruneCache, renameInLibrary, type LibraryOptions } from './library.ts';
|
|
70
70
|
import { singSong, type SingDeps } from './sing.ts';
|
|
71
71
|
import { notify } from './notify.ts';
|
|
72
72
|
import { WorkerClient } from './worker.ts';
|
|
@@ -309,6 +309,101 @@ export class FishSingWorld implements World {
|
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
311
|
|
|
312
|
+
/**
|
|
313
|
+
* 训练完成后自动生成选模对比试听:同一句训练切片(目标音色清唱),用
|
|
314
|
+
* final + 最后两个中间档各换声一遍。输入完全一致,听出来的差异全是存档本身
|
|
315
|
+
* 的差别——比拿着不同版本整首唱一遍再凭记忆比要靠谱。
|
|
316
|
+
* 片段进作品库;配了 notify.qqTarget 就同时发 QQ。
|
|
317
|
+
*/
|
|
318
|
+
private async runAbTest(exp: string, enabled?: boolean): Promise<string> {
|
|
319
|
+
if (enabled === false || this.opts.cfg.train?.abTest === false) return '';
|
|
320
|
+
const weights = join(this.routes.rvcRoot, 'assets', 'weights');
|
|
321
|
+
const logDir = join(this.routes.rvcRoot, 'logs', exp);
|
|
322
|
+
const indexOf = (dir: string): string => {
|
|
323
|
+
try {
|
|
324
|
+
const idx = readdirSync(dir).find((f) => f.endsWith('.index'));
|
|
325
|
+
return idx ? join(dir, idx) : '';
|
|
326
|
+
} catch {
|
|
327
|
+
return '';
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
const variants: { ckpt: string; label: string; index: string }[] = [];
|
|
331
|
+
const finalPth = join(weights, `${exp}.pth`);
|
|
332
|
+
if (existsSync(finalPth)) variants.push({ ckpt: finalPth, label: 'final', index: indexOf(logDir) });
|
|
333
|
+
try {
|
|
334
|
+
// 中间档从新到旧取 2 个(G_2333333 是完整存档,跟 final 重复,不算)
|
|
335
|
+
const gs = readdirSync(logDir)
|
|
336
|
+
.map((f) => /^G_(\d+)\.pth$/.exec(f))
|
|
337
|
+
.filter((m): m is RegExpExecArray => Boolean(m) && m[1] !== '2333333')
|
|
338
|
+
.sort((a, b) => Number(b[1]) - Number(a[1]))
|
|
339
|
+
.slice(0, 2);
|
|
340
|
+
for (const m of gs) variants.push({ ckpt: join(logDir, m[0]), label: `e${m[1]}`, index: indexOf(logDir) });
|
|
341
|
+
} catch {
|
|
342
|
+
/* 没有中间档就只用 final */
|
|
343
|
+
}
|
|
344
|
+
if (variants.length < 2) {
|
|
345
|
+
this.host?.log.info(`[fish-sing] ${exp} 只有一个可用存档(中间档可能被清理了),跳过选模对比`);
|
|
346
|
+
return '';
|
|
347
|
+
}
|
|
348
|
+
const gtDir = join(logDir, '0_gt_wavs');
|
|
349
|
+
let test = '';
|
|
350
|
+
try {
|
|
351
|
+
const wavs = readdirSync(gtDir).filter((f) => f.endsWith('.wav')).sort();
|
|
352
|
+
const mid = wavs[Math.floor(wavs.length / 2)];
|
|
353
|
+
test = mid ? join(gtDir, mid) : '';
|
|
354
|
+
} catch {
|
|
355
|
+
test = '';
|
|
356
|
+
}
|
|
357
|
+
if (!test || !existsSync(test)) {
|
|
358
|
+
this.host?.log.warn('[fish-sing] 没找到可用的训练切片当测试句,跳过选模对比');
|
|
359
|
+
return '';
|
|
360
|
+
}
|
|
361
|
+
const ts = new Date().toISOString().slice(0, 16).replace(/[-:T]/g, '');
|
|
362
|
+
const outDir = join(this.data().dataDir, 'ab', `${exp}-${ts}`);
|
|
363
|
+
const jobId = await this.worker.submit('ab', {
|
|
364
|
+
test, out: outDir, variants, pitch: 0, index_rate: 0.75, protect: 0.33,
|
|
365
|
+
});
|
|
366
|
+
const job = await this.worker.wait(
|
|
367
|
+
jobId,
|
|
368
|
+
(p, msg) => this.host?.log.info(`[fish-sing] 选模对比 ${Math.round(p * 100)}%:${msg}`),
|
|
369
|
+
{ stallMs: 10 * 60_000 },
|
|
370
|
+
);
|
|
371
|
+
const outputs = ((job.result?.outputs ?? []) as { label: string; file: string }[])
|
|
372
|
+
.filter((o) => existsSync(o.file));
|
|
373
|
+
if (!outputs.length) return;
|
|
374
|
+
const labels: string[] = [];
|
|
375
|
+
const obTarget = parseTarget(String(this.opts.cfg.notify?.qqTarget ?? ''));
|
|
376
|
+
const onebot = { httpUrl: String(this.opts.cfg.send?.httpUrl ?? ''), token: this.onebotToken() };
|
|
377
|
+
for (const o of outputs) {
|
|
378
|
+
const mp3 = join(outDir, `${o.label}.mp3`);
|
|
379
|
+
await toMp3(o.file, mp3, this.ffmpeg(), '192k');
|
|
380
|
+
labels.push(o.label);
|
|
381
|
+
addToLibrary(this.data(), {
|
|
382
|
+
id: `ab-${exp}-${o.label}`,
|
|
383
|
+
title: `${exp} 选模对比 · ${o.label}`,
|
|
384
|
+
source: 'ab-test', bvid: '',
|
|
385
|
+
file: mp3,
|
|
386
|
+
durationSec: await duration(mp3, this.ffmpeg()).catch(() => 0),
|
|
387
|
+
at: Date.now(),
|
|
388
|
+
params: { model: o.label, index: '', indexRate: 0.75, protect: 0.33, pitch: 0, mode: 'vocals' },
|
|
389
|
+
target: '',
|
|
390
|
+
}, mp3);
|
|
391
|
+
if (obTarget && onebot.httpUrl) {
|
|
392
|
+
try {
|
|
393
|
+
await sendRecord(onebot, obTarget, mp3);
|
|
394
|
+
} catch (e) {
|
|
395
|
+
this.host?.log.warn(`[fish-sing] 选模片段发 QQ 失败:${e instanceof Error ? e.message : String(e)}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
this.host?.log.info(`[fish-sing] 选模对比已生成:${labels.join(' / ')}(${outDir})`);
|
|
400
|
+
void this.notifyEvent(
|
|
401
|
+
`选模试听已生成:${exp}`,
|
|
402
|
+
`同一句训练切片,用 ${labels.join('、')} 各唱了一遍。在作品库里对比听(fish_sing_library)${obTarget ? ',QQ 那边也各发了一条' : ''}。`,
|
|
403
|
+
);
|
|
404
|
+
return labels.join(' / ');
|
|
405
|
+
}
|
|
406
|
+
|
|
312
407
|
private deps(): SingDeps {
|
|
313
408
|
const cfg = this.opts.cfg;
|
|
314
409
|
return {
|
|
@@ -893,6 +988,10 @@ export class FishSingWorld implements World {
|
|
|
893
988
|
rebuild?: boolean;
|
|
894
989
|
/** 训练完自动清理中间档(默认不勾:删了只能重训才拿得回来) */
|
|
895
990
|
pruneAfter?: boolean;
|
|
991
|
+
/** 训练完生成选模对比试听(默认开) */
|
|
992
|
+
abTest?: boolean;
|
|
993
|
+
/** 低音增强:合成 -2/-4 半音低音数据(默认开) */
|
|
994
|
+
augment?: boolean;
|
|
896
995
|
keepEvery?: number;
|
|
897
996
|
};
|
|
898
997
|
const dir = this.datasetJob?.dir;
|
|
@@ -943,6 +1042,8 @@ export class FishSingWorld implements World {
|
|
|
943
1042
|
saveEvery,
|
|
944
1043
|
resume: cfg.resume === true,
|
|
945
1044
|
rebuild: cfg.rebuild === true,
|
|
1045
|
+
// 低音增强:-2/-4 半音各合成一份低音数据,副本权重按份数摊薄(见 trainer.prepare)
|
|
1046
|
+
augmentShifts: cfg.augment === false ? [] : [-2, -4],
|
|
946
1047
|
weightMap,
|
|
947
1048
|
});
|
|
948
1049
|
job.id = id;
|
|
@@ -983,6 +1084,9 @@ export class FishSingWorld implements World {
|
|
|
983
1084
|
}
|
|
984
1085
|
}
|
|
985
1086
|
void this.notifyEvent(`训练完成:${exp}`, `${epochs} 轮全部完成。${job.msg}`);
|
|
1087
|
+
void this.runAbTest(exp, cfg.abTest !== false).catch((e: unknown) => {
|
|
1088
|
+
this.host?.log.warn(`[fish-sing] 选模对比失败:${e instanceof Error ? e.message : String(e)}`);
|
|
1089
|
+
});
|
|
986
1090
|
})
|
|
987
1091
|
.catch((e: unknown) => {
|
|
988
1092
|
job.state = 'error';
|
|
@@ -1060,6 +1164,13 @@ export class FishSingWorld implements World {
|
|
|
1060
1164
|
};
|
|
1061
1165
|
}
|
|
1062
1166
|
|
|
1167
|
+
if (method === 'trainAbTest') {
|
|
1168
|
+
const exp = String(args[0]?.exp ?? '').trim() || this.trainJob?.exp || '';
|
|
1169
|
+
if (!exp) throw new Error('没有实验名:先在「训练」页填实验名,或跑一次训练');
|
|
1170
|
+
const text = await this.runAbTest(exp, true);
|
|
1171
|
+
return { text: text || `没生成:${exp} 只找到一个可用存档(中间档可能已被清理)` };
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1063
1174
|
if (method === 'trainStop') {
|
|
1064
1175
|
await this.worker.cancel();
|
|
1065
1176
|
if (this.trainJob?.state === 'running') {
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 发版一条龙:CHANGELOG 检查 → npm publish → 轮询 tarball 可用。
|
|
4
|
+
*
|
|
5
|
+
* 为什么不用裸 npm publish:
|
|
6
|
+
* · CHANGELOG 忘了写,用户不知道更新了啥(0.2.x 之前的教训,现在硬性拦截);
|
|
7
|
+
* · publish 显示成功 ≠ 注册表可下载——tarball CDN 有 404 窗口期,实测 2~6 分钟,
|
|
8
|
+
* 紧接着跑 pnpm add 会报 404(0.1.4~0.1.9 每个版本都踩了一遍);
|
|
9
|
+
* · E409(版本被 npm 暂存)时给出明确指引,而不是让人对着报错猜。
|
|
10
|
+
*
|
|
11
|
+
* 用法(在仓库根目录):
|
|
12
|
+
* node tools/publish.mjs # 发布 package.json 里的当前版本
|
|
13
|
+
* node tools/publish.mjs --check # 只检查 CHANGELOG,不发布
|
|
14
|
+
*
|
|
15
|
+
* 前置:npm 已登录(npx npm whoami 验证);CHANGELOG.md 里有 `## [当前版本]` 条目。
|
|
16
|
+
*/
|
|
17
|
+
import { readFileSync } from 'node:fs';
|
|
18
|
+
import { join, dirname } from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import { execSync } from 'node:child_process';
|
|
21
|
+
|
|
22
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
23
|
+
const PKG = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
24
|
+
const VERSION = PKG.version;
|
|
25
|
+
const NAME = PKG.name;
|
|
26
|
+
const CHANGELOG = join(ROOT, 'CHANGELOG.md');
|
|
27
|
+
|
|
28
|
+
const step = (m) => console.log(`\n==> ${m}`);
|
|
29
|
+
|
|
30
|
+
// ---- 1. CHANGELOG 检查 ------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
step(`检查 CHANGELOG(${NAME}@${VERSION})`);
|
|
33
|
+
const changelog = readFileSync(CHANGELOG, 'utf8');
|
|
34
|
+
if (!changelog.includes(`## [${VERSION}]`)) {
|
|
35
|
+
console.error(`✗ CHANGELOG.md 里没有 "## [${VERSION}]" 条目。`);
|
|
36
|
+
console.error(' 先把这一版改了什么写进去,再发版——别人要知道更新了啥。');
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
console.log('✓ CHANGELOG 条目在');
|
|
40
|
+
|
|
41
|
+
// --check 模式到此为止
|
|
42
|
+
if (process.argv.includes('--check')) {
|
|
43
|
+
console.log('\n--check 通过,未发布。');
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---- 2. npm publish --------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
step('npm publish');
|
|
50
|
+
try {
|
|
51
|
+
execSync('npm publish --access public', { cwd: ROOT, stdio: 'inherit' });
|
|
52
|
+
} catch (e) {
|
|
53
|
+
const out = String(e.stdout || '') + String(e.stderr || '');
|
|
54
|
+
if (out.includes('E409') || out.includes('cannot be published') || out.includes(' 版本已被') || out.includes('staged')) {
|
|
55
|
+
console.error('✗ npm 拒绝了这个版本(可能被暂存,如 0.1.1 那次)。');
|
|
56
|
+
console.error(' 处理:升一个版本号(package.json + CHANGELOG)后重试本脚本。');
|
|
57
|
+
}
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
console.log(`✓ ${NAME}@${VERSION} 已提交到注册表`);
|
|
61
|
+
|
|
62
|
+
// ---- 3. 轮询 tarball 可用 --------------------------------------------------
|
|
63
|
+
|
|
64
|
+
const tarball = `https://registry.npmjs.org/${NAME}/-/${NAME}-${VERSION}.tgz`;
|
|
65
|
+
const POLL_MAX = 12; // 12 次 × 40 秒 ≈ 8 分钟,覆盖实测的 CDN 延迟
|
|
66
|
+
const POLL_EVERY = 40_000;
|
|
67
|
+
|
|
68
|
+
step(`轮询 tarball(${tarball})`);
|
|
69
|
+
let ok = false;
|
|
70
|
+
for (let i = 1; i <= POLL_MAX; i += 1) {
|
|
71
|
+
try {
|
|
72
|
+
const res = await fetch(tarball, { method: 'HEAD', signal: AbortSignal.timeout(30_000) });
|
|
73
|
+
console.log(` 第 ${i} 次:HTTP ${res.status}`);
|
|
74
|
+
if (res.status === 200) {
|
|
75
|
+
ok = true;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
} catch (e) {
|
|
79
|
+
console.log(` 第 ${i} 次:网络错误 ${e.message}`);
|
|
80
|
+
}
|
|
81
|
+
await new Promise((r) => setTimeout(r, POLL_EVERY));
|
|
82
|
+
}
|
|
83
|
+
if (!ok) {
|
|
84
|
+
console.error(`✗ ${POLL_MAX * (POLL_EVERY / 1000)} 秒后 tarball 仍 404。可能被暂存或 CDN 异常,稍后手动查:`);
|
|
85
|
+
console.error(` ${tarball}`);
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ---- 4. 收尾提醒 -----------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
console.log(`
|
|
92
|
+
✓ ${NAME}@${VERSION} 发布完成,tarball 已可下载。
|
|
93
|
+
|
|
94
|
+
别忘了两件事:
|
|
95
|
+
1. 本机/反馈者升级:pnpm add ${NAME}@${VERSION}(受 minimumReleaseAge 限制的话,
|
|
96
|
+
把版本加进 pnpm-workspace.yaml 的 minimumReleaseAgeExclude);
|
|
97
|
+
2. 市场更新日志:索引仓的同步 Action 靠 [sync] issue 触发。市场里没显示的话,
|
|
98
|
+
去 Pal-AI-Lab/cortico-extensions 开一个标题为 "[sync] ${NAME}" 的空 issue。
|
|
99
|
+
`);
|
package/worker/engine.py
CHANGED
|
@@ -204,6 +204,7 @@ class SingEngine:
|
|
|
204
204
|
|
|
205
205
|
def __init__(self, model: str = DEFAULT_MODEL, index: str = DEFAULT_INDEX):
|
|
206
206
|
self.model = model
|
|
207
|
+
self.model_path = str(RVC_ROOT / "assets" / "weights" / model) # 绝对路径,恢复原模型时要用
|
|
207
208
|
self.index = index if index and Path(index).is_file() else ""
|
|
208
209
|
self.ready = False
|
|
209
210
|
self.load_ms = 0
|
|
@@ -211,6 +212,44 @@ class SingEngine:
|
|
|
211
212
|
self._lock = threading.Lock()
|
|
212
213
|
self._vc = None
|
|
213
214
|
|
|
215
|
+
# -- 模型热切换(选模对比试听用) --------------------------------
|
|
216
|
+
|
|
217
|
+
def set_model(self, ckpt: "Path | str", index: str = "") -> None:
|
|
218
|
+
"""热切换加载的模型/索引,不用重启进程。
|
|
219
|
+
|
|
220
|
+
ckpt 可以是任意位置的 .pth:RVC 的 get_vc 用 f'{weight_root}/{sid}' 拼路径,
|
|
221
|
+
所以这里临时把 weight_root 指到 ckpt 所在目录。线程安全由任务串行保证。
|
|
222
|
+
"""
|
|
223
|
+
ckpt = Path(ckpt)
|
|
224
|
+
index = index if index and Path(index).is_file() else ""
|
|
225
|
+
if self.ready and str(ckpt) == self.model_path and index == self.index:
|
|
226
|
+
return
|
|
227
|
+
if not self.ready:
|
|
228
|
+
self.model = ckpt.name
|
|
229
|
+
self.index = index
|
|
230
|
+
self.load()
|
|
231
|
+
self.model_path = str(ckpt)
|
|
232
|
+
return
|
|
233
|
+
cwd_bak = os.getcwd()
|
|
234
|
+
os.chdir(RVC_ROOT)
|
|
235
|
+
old_root = os.environ.get("weight_root")
|
|
236
|
+
try:
|
|
237
|
+
os.environ["weight_root"] = str(ckpt.parent)
|
|
238
|
+
with self._lock:
|
|
239
|
+
self._vc.get_vc(ckpt.name)
|
|
240
|
+
self.model = ckpt.name
|
|
241
|
+
self.model_path = str(ckpt)
|
|
242
|
+
self.index = index
|
|
243
|
+
try:
|
|
244
|
+
self.sr = int(self._vc.cpt["config"][-1])
|
|
245
|
+
except Exception: # noqa: BLE001
|
|
246
|
+
pass
|
|
247
|
+
log(f"已切换模型:{self.model}(索引={'有' if self.index else '无'})")
|
|
248
|
+
finally:
|
|
249
|
+
if old_root is not None:
|
|
250
|
+
os.environ["weight_root"] = old_root
|
|
251
|
+
os.chdir(cwd_bak)
|
|
252
|
+
|
|
214
253
|
# -- 加载 ------------------------------------------------------
|
|
215
254
|
|
|
216
255
|
def load(self) -> None:
|
|
@@ -248,6 +287,7 @@ class SingEngine:
|
|
|
248
287
|
self.sr = 40000
|
|
249
288
|
os.chdir(cwd_bak)
|
|
250
289
|
self.ready = True
|
|
290
|
+
self.model_path = str(RVC_ROOT / "assets" / "weights" / self.model)
|
|
251
291
|
self.load_ms = int((time.time() - t0) * 1000)
|
|
252
292
|
log(f"模型就绪:{self.model}({self.load_ms} ms)索引={'有' if self.index else '无'}")
|
|
253
293
|
|
|
@@ -698,6 +738,48 @@ class SingEngine:
|
|
|
698
738
|
result["pitchSuggest"] = suggestion
|
|
699
739
|
return result
|
|
700
740
|
|
|
741
|
+
# -- 选模对比试听 -----------------------------------------------
|
|
742
|
+
|
|
743
|
+
def ab_test(self, test: Path, out_dir: Path, variants: list, *, pitch: int = 0,
|
|
744
|
+
index_rate: float = 0.75, protect: float = 0.33,
|
|
745
|
+
progress: Optional[Callable[[float, str], None]] = None,
|
|
746
|
+
cancel: Optional[threading.Event] = None) -> dict:
|
|
747
|
+
"""
|
|
748
|
+
选模对比:同一测试句,每个变体(.pth)各换声一遍,结束后恢复原模型。
|
|
749
|
+
|
|
750
|
+
variants: [{"ckpt": <pth 路径>, "label": "e100", "index": <index 路径或 "">}, ...]
|
|
751
|
+
测试句用训练切片(0_gt_wavs,目标音色清唱)——换回模型本身就是最干净的
|
|
752
|
+
存档对比:输入完全一致,听出来的差异全是模型/存档本身的差别。
|
|
753
|
+
"""
|
|
754
|
+
cancel = cancel or threading.Event()
|
|
755
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
756
|
+
report = progress or (lambda p, m: None)
|
|
757
|
+
original = (self.model_path or str(RVC_ROOT / "assets" / "weights" / self.model), self.index)
|
|
758
|
+
outputs: list = []
|
|
759
|
+
n = max(1, len(variants))
|
|
760
|
+
try:
|
|
761
|
+
for i, v in enumerate(variants):
|
|
762
|
+
if cancel.is_set():
|
|
763
|
+
raise RuntimeError("已取消")
|
|
764
|
+
label = str(v.get("label") or Path(str(v["ckpt"])).stem)
|
|
765
|
+
report(i / n, f"切换到 {label}")
|
|
766
|
+
self.set_model(Path(str(v["ckpt"])), str(v.get("index") or ""))
|
|
767
|
+
dst = out_dir / f"{label}.wav"
|
|
768
|
+
report((i + 0.25) / n, f"换声:{label}")
|
|
769
|
+
self.convert(
|
|
770
|
+
test, dst, pitch=pitch, index_rate=index_rate, protect=protect,
|
|
771
|
+
progress=lambda p, m, _i=i, _n=n: report((_i + 0.25 + 0.7 * p) / _n, m),
|
|
772
|
+
cancel=cancel,
|
|
773
|
+
)
|
|
774
|
+
outputs.append({"label": label, "ckpt": str(v["ckpt"]), "file": str(dst)})
|
|
775
|
+
finally:
|
|
776
|
+
try:
|
|
777
|
+
self.set_model(Path(original[0]), original[1]) # 恢复原模型,别让唱歌用错档
|
|
778
|
+
except Exception as e: # noqa: BLE001
|
|
779
|
+
log(f"恢复原模型失败:{e}")
|
|
780
|
+
report(1.0, "完成")
|
|
781
|
+
return {"outputs": outputs}
|
|
782
|
+
|
|
701
783
|
|
|
702
784
|
# ---------------------------------------------------------------- 自检
|
|
703
785
|
|
package/worker/server.py
CHANGED
|
@@ -105,7 +105,7 @@ def worker_loop() -> None:
|
|
|
105
105
|
|
|
106
106
|
def run_job(jid: str, kind: str, params: dict, cancel: threading.Event) -> dict:
|
|
107
107
|
# 做数据集不需要唱歌模型:白加载会占用 1.5 GB 显存,还会让 demucs 更容易 OOM
|
|
108
|
-
if kind in ("song", "convert") and not ENGINE.ready:
|
|
108
|
+
if kind in ("song", "convert", "ab") and not ENGINE.ready:
|
|
109
109
|
update(jid, message="加载模型")
|
|
110
110
|
ENGINE.load()
|
|
111
111
|
|
|
@@ -141,6 +141,17 @@ def run_job(jid: str, kind: str, params: dict, cancel: threading.Event) -> dict:
|
|
|
141
141
|
progress=progress, cancel=cancel,
|
|
142
142
|
)
|
|
143
143
|
|
|
144
|
+
if kind == "ab":
|
|
145
|
+
out_dir = Path(params.get("out") or (WORK_ROOT / jid))
|
|
146
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
147
|
+
return ENGINE.ab_test(
|
|
148
|
+
Path(params["test"]), out_dir, list(params.get("variants") or []),
|
|
149
|
+
pitch=int(params.get("pitch", 0)),
|
|
150
|
+
index_rate=float(params.get("index_rate", 0.75)),
|
|
151
|
+
protect=float(params.get("protect", 0.33)),
|
|
152
|
+
progress=progress, cancel=cancel,
|
|
153
|
+
)
|
|
154
|
+
|
|
144
155
|
if kind == "train":
|
|
145
156
|
import trainer
|
|
146
157
|
return trainer.train_run(
|
|
@@ -289,7 +300,7 @@ class Handler(BaseHTTPRequestHandler):
|
|
|
289
300
|
if self.path.startswith("/job"):
|
|
290
301
|
body = self._body()
|
|
291
302
|
kind = str(body.pop("kind", "song"))
|
|
292
|
-
if kind not in ("song", "convert", "dataset", "train"):
|
|
303
|
+
if kind not in ("song", "convert", "dataset", "train", "ab"):
|
|
293
304
|
self._json(400, {"ok": False, "message": f"未知任务类型:{kind}"})
|
|
294
305
|
return
|
|
295
306
|
job = new_job(kind, body)
|
package/worker/trainer.py
CHANGED
|
@@ -119,12 +119,16 @@ def find_checkpoint(exp: str):
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
def prepare(exp, dataset_dir: Path, progress, cancel, keep_existing=True):
|
|
122
|
+
def prepare(exp, dataset_dir: Path, progress, cancel, keep_existing=True, augment_shifts=None, weights=None):
|
|
123
123
|
"""
|
|
124
124
|
建实验目录并把切片铺成 RVC 需要的三层结构。
|
|
125
125
|
|
|
126
126
|
- 0_gt_wavs:40k 原样(训练时读它算 mel)
|
|
127
127
|
- 1_16k_wavs:16k 单声道(F0 和 ContentVec 都只认这个)
|
|
128
|
+
|
|
129
|
+
augment_shifts:低音增强。给每个切片用 ffmpeg asetrate+atempo 合成降调副本
|
|
130
|
+
(如 [-2, -4] = 各降 2/4 个半音),一起铺进两层——模型由此学到低音区的音色映射。
|
|
131
|
+
副本命名 aug<shift>_<原名>.wav;weights 里的同名权重会按副本数摊薄(见 train_run)。
|
|
128
132
|
"""
|
|
129
133
|
exp_dir = exp_dir_of(exp)
|
|
130
134
|
exp_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -139,11 +143,39 @@ def prepare(exp, dataset_dir: Path, progress, cancel, keep_existing=True):
|
|
|
139
143
|
gt.mkdir(exist_ok=True)
|
|
140
144
|
hi.mkdir(exist_ok=True)
|
|
141
145
|
|
|
146
|
+
shifts = [int(s) for s in (augment_shifts or []) if int(s) != 0]
|
|
142
147
|
slices = sorted((dataset_dir / "slices").glob("*.wav"))
|
|
143
148
|
if not slices:
|
|
144
149
|
raise RuntimeError(f"{dataset_dir / 'slices'} 里没有切片,先跑数据准备")
|
|
145
150
|
total = len(slices)
|
|
146
|
-
log(f"切片 {total} 个 → {exp_dir}")
|
|
151
|
+
log(f"切片 {total} 个 → {exp_dir}" + (f",低音增强 {shifts}" if shifts else ""))
|
|
152
|
+
|
|
153
|
+
aug_made = 0
|
|
154
|
+
|
|
155
|
+
def lay_augmented(src: Path) -> None:
|
|
156
|
+
"""合成 src 的降调副本,铺进 0_gt/1_16k 两层。ffmpeg 子进程,不占 GIL。"""
|
|
157
|
+
nonlocal aug_made
|
|
158
|
+
try:
|
|
159
|
+
import soundfile as sf
|
|
160
|
+
sr_in = sf.info(str(src)).samplerate
|
|
161
|
+
except Exception: # noqa: BLE001
|
|
162
|
+
sr_in = 40000
|
|
163
|
+
for s in shifts:
|
|
164
|
+
name = f"aug{s}_{src.name}"
|
|
165
|
+
dst0 = gt / name
|
|
166
|
+
dst1 = hi / name
|
|
167
|
+
if dst0.exists() and dst1.exists():
|
|
168
|
+
continue
|
|
169
|
+
factor = 2 ** (s / 12)
|
|
170
|
+
tempo = 2 ** (-s / 12)
|
|
171
|
+
# 40k 副本:降调 + 补速度(asetrate 降调会拖长,atempo 拉回来)
|
|
172
|
+
run([FFMPEG, "-y", "-v", "error", "-i", str(src),
|
|
173
|
+
"-af", f"asetrate={sr_in}*{factor:.8f},aresample={sr_in},atempo={tempo:.8f}",
|
|
174
|
+
"-c:a", "pcm_s16le", str(dst0)], f"低音增强 {s} 半音")
|
|
175
|
+
# 16k 单声道副本:从 40k 副本重采样(跟原切片同一套流程)
|
|
176
|
+
run([FFMPEG, "-y", "-v", "error", "-i", str(dst0),
|
|
177
|
+
"-ac", "1", "-ar", "16000", "-c:a", "pcm_s16le", str(dst1)], "重采样 16k")
|
|
178
|
+
aug_made += 1
|
|
147
179
|
|
|
148
180
|
added = 0
|
|
149
181
|
for i, src in enumerate(slices):
|
|
@@ -160,9 +192,17 @@ def prepare(exp, dataset_dir: Path, progress, cancel, keep_existing=True):
|
|
|
160
192
|
if not dst1.exists():
|
|
161
193
|
run([FFMPEG, "-y", "-v", "error", "-i", str(src), "-ac", "1", "-ar", "16000",
|
|
162
194
|
"-c:a", "pcm_s16le", str(dst1)], "重采样 16k")
|
|
195
|
+
if shifts:
|
|
196
|
+
lay_augmented(src)
|
|
163
197
|
if i % 50 == 0 or i == total - 1:
|
|
164
|
-
progress(0.02 + 0.06 * ((i + 1) / total), f"铺切片 {i + 1}/{total}")
|
|
165
|
-
log(f"新增 {added} 个(已存在的跳过)")
|
|
198
|
+
progress(0.02 + 0.06 * ((i + 1) / total), f"铺切片 {i + 1}/{total}" + (f"(增强 {aug_made})" if shifts else ""))
|
|
199
|
+
log(f"新增 {added} 个(已存在的跳过)" + (f",低音增强副本 {aug_made} 个" if shifts else ""))
|
|
200
|
+
|
|
201
|
+
if shifts:
|
|
202
|
+
(exp_dir / "aug_manifest.json").write_text(
|
|
203
|
+
json.dumps({"shifts": shifts, "created": aug_made, "slices": total}, ensure_ascii=False),
|
|
204
|
+
encoding="utf8",
|
|
205
|
+
)
|
|
166
206
|
return exp_dir
|
|
167
207
|
|
|
168
208
|
|
|
@@ -234,11 +274,25 @@ def train_run(exp, dataset_dir, params, progress, cancel, weights=None):
|
|
|
234
274
|
"""
|
|
235
275
|
完整流水线。params:
|
|
236
276
|
epochs / batch / saveEvery / resume(bool) / fromG / fromD / rebuild(bool)
|
|
277
|
+
augmentShifts([int]):低音增强,如 [-2, -4](合成降调副本,见 prepare)
|
|
237
278
|
"""
|
|
238
279
|
t0 = time.time()
|
|
239
|
-
|
|
280
|
+
augment_shifts = [int(s) for s in (params.get("augmentShifts") or [])]
|
|
281
|
+
exp_dir = prepare(exp, Path(dataset_dir), progress, cancel,
|
|
282
|
+
augment_shifts=augment_shifts, weights=weights)
|
|
240
283
|
total = count_files(exp_dir / "0_gt_wavs", ".wav")
|
|
241
284
|
|
|
285
|
+
# 增强副本继承源切片权重,但按「源 + 副本」的总份数摊薄:
|
|
286
|
+
# 低音 3x 的源片 + 2 个副本 → 各 1x,总重要度还是 3x,材料时长翻了 3 倍。
|
|
287
|
+
if augment_shifts and weights:
|
|
288
|
+
div = len(augment_shifts) + 1
|
|
289
|
+
expanded = dict(weights)
|
|
290
|
+
for s in augment_shifts:
|
|
291
|
+
for k, v in weights.items():
|
|
292
|
+
expanded[f"aug{s}_{k}"] = float(v) / div
|
|
293
|
+
weights = expanded
|
|
294
|
+
log(f"权重已扩展到增强副本(÷{div})")
|
|
295
|
+
|
|
242
296
|
rebuild = bool(params.get("rebuild", False))
|
|
243
297
|
|
|
244
298
|
# ---- F0
|