cortico-world-fish-sing 0.4.22 → 0.4.24
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 +19 -0
- package/package.json +45 -45
- package/src/config.ts +35 -0
- package/src/library.ts +4 -0
- package/src/setup.ts +7 -0
- package/src/sing.ts +11 -0
- package/src/world.ts +10 -2
- package/tests/smoke.mjs +20 -0
- package/tests/test_engine_logic.py +31 -0
- package/worker/dataset.py +83 -6
- package/worker/engine.py +80 -1
- package/worker/server.py +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循语义化。
|
|
4
4
|
|
|
5
|
+
## [0.4.24] - 2026-11-12
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
- **她嘴里那句「还缺 2 个模型权重、现在唱不了」**:环境提示词的装机判断也在数全部权重文件,把可选的出厂模型 dfy2 算成了必需。结果她能唱(用 dfy7)却按提示词说自己唱不了,直接拒绝唱歌。现在只数必需组件(hubert / rmvpe / 两个底模),并且把这段判断抽成 `missingRequiredCount()` 一处实现——面板、环境提示词、自检三处共用,避免再漏。
|
|
9
|
+
|
|
10
|
+
### 新增
|
|
11
|
+
- **和声堆叠(可配置)**:同一音色再唱 1~2 条叠上去,副歌立刻有"后面有人在唱"的厚度——唱片里的主唱都这么干,单轨再干净也薄。
|
|
12
|
+
- 配置「换声」组新增三项:**和声堆叠**(off / 三度 / 三度+五度)、**和声音量**(默认 0.22)、**和声范围**(只叠副歌 / 整首)
|
|
13
|
+
- 实现:和声轨用同一模型按 +3 / +7 半音各转一遍,110Hz 高通、三度偏左五度偏右、按主轨响度做门限(默认只出现在唱得响的段落,避免整段叠显电子味)
|
|
14
|
+
- 代价:每多一条和声,转换时间大约翻倍(默认关闭,不用的人不受影响)
|
|
15
|
+
|
|
16
|
+
## [0.4.23] - 2026-11-12
|
|
17
|
+
|
|
18
|
+
### 修复
|
|
19
|
+
- **混音被当成干声、跳过分离直接进训练集**:`looks_dry()` 原来拿**整个路径**匹配「人声 / vocal」,用户把素材放在「大肥鱼伴奏+人声-某某」这种目录里时,整包都被判成干声。实测案例:`…\带伴奏\whale family|团子大家族.aac` 其实是完整混音(伴奏/人声 = 1.21),却显示「已是干声,跳过分离」。现在只看**文件名**,并且「伴奏 / instrumental / karaoke」这类词优先判为混音。
|
|
20
|
+
|
|
21
|
+
### 新增
|
|
22
|
+
- **干声双重校验**:文件名说是干声时,再取中段 8 秒做一次快分离,算「伴奏 / 人声」能量比——大于 0.5 就纠正为混音并说明原因。宁可多花几秒,也不让混音悄悄污染训练集。嫌慢可设环境变量 `FISHSING_SKIP_DRY_CHECK=1` 关掉。
|
|
23
|
+
|
|
5
24
|
## [0.4.22] - 2026-11-06
|
|
6
25
|
|
|
7
26
|
### 修复
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cortico-world-fish-sing",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./src/index.ts",
|
|
7
|
-
"license": "MIT",
|
|
8
|
-
"author": "FXYXL",
|
|
9
|
-
"keywords": [
|
|
10
|
-
"cortico-world",
|
|
11
|
-
"cortico",
|
|
12
|
-
"coo",
|
|
13
|
-
"sing",
|
|
14
|
-
"rvc",
|
|
15
|
-
"music",
|
|
16
|
-
"qq"
|
|
17
|
-
],
|
|
18
|
-
"engines": {
|
|
19
|
-
"node": ">=22.6"
|
|
20
|
-
},
|
|
21
|
-
"homepage": "https://github.com/FXYXL/cortico-world-fish-sing#readme",
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/FXYXL/cortico-world-fish-sing.git"
|
|
25
|
-
},
|
|
26
|
-
"bugs": {
|
|
27
|
-
"url": "https://github.com/FXYXL/cortico-world-fish-sing/issues"
|
|
28
|
-
},
|
|
29
|
-
"cortico": {
|
|
30
|
-
"kind": "world",
|
|
31
|
-
"api": 6,
|
|
32
|
-
"label": "大肥鱼唱歌",
|
|
33
|
-
"tags": [
|
|
34
|
-
"music",
|
|
35
|
-
"qq",
|
|
36
|
-
"local"
|
|
37
|
-
],
|
|
38
|
-
"describe": "describe.json",
|
|
39
|
-
"webUiClient": "dist/webui-b69dd33a.js"
|
|
40
|
-
},
|
|
41
|
-
"scripts": {
|
|
42
|
-
"doctor": "node tools/doctor.mjs"
|
|
43
|
-
},
|
|
44
|
-
"dependencies": {}
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "cortico-world-fish-sing",
|
|
3
|
+
"version": "0.4.24",
|
|
4
|
+
"description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"author": "FXYXL",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"cortico-world",
|
|
11
|
+
"cortico",
|
|
12
|
+
"coo",
|
|
13
|
+
"sing",
|
|
14
|
+
"rvc",
|
|
15
|
+
"music",
|
|
16
|
+
"qq"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22.6"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/FXYXL/cortico-world-fish-sing#readme",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/FXYXL/cortico-world-fish-sing.git"
|
|
25
|
+
},
|
|
26
|
+
"bugs": {
|
|
27
|
+
"url": "https://github.com/FXYXL/cortico-world-fish-sing/issues"
|
|
28
|
+
},
|
|
29
|
+
"cortico": {
|
|
30
|
+
"kind": "world",
|
|
31
|
+
"api": 6,
|
|
32
|
+
"label": "大肥鱼唱歌",
|
|
33
|
+
"tags": [
|
|
34
|
+
"music",
|
|
35
|
+
"qq",
|
|
36
|
+
"local"
|
|
37
|
+
],
|
|
38
|
+
"describe": "describe.json",
|
|
39
|
+
"webUiClient": "dist/webui-b69dd33a.js"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"doctor": "node tools/doctor.mjs"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {}
|
|
45
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -34,6 +34,12 @@ export interface FishSingConfigSection {
|
|
|
34
34
|
* 0 = 完全跟随原唱(轻唱就是轻唱);1 = 完全用模型自己的音量(轻唱会被唱满)。
|
|
35
35
|
*/
|
|
36
36
|
rmsMixRate: number;
|
|
37
|
+
/** 和声堆叠:同一音色再唱几条叠上去(单轨再干净也薄) */
|
|
38
|
+
harmony: 'off' | 'third' | 'third+fifth';
|
|
39
|
+
/** 和声音量(主轨=1.0 的倍数),0.15~0.30 比较自然 */
|
|
40
|
+
harmonyGain: number;
|
|
41
|
+
/** 和声只叠在唱得响的段落(副歌),免得整段都在叠显得电子味 */
|
|
42
|
+
harmonyScope: 'chorus' | 'all';
|
|
37
43
|
/** full = 带伴奏;vocals = 只要人声 */
|
|
38
44
|
mode: 'full' | 'vocals';
|
|
39
45
|
};
|
|
@@ -109,6 +115,9 @@ export const FISHSING_DEFAULTS: FishSingConfigSection = {
|
|
|
109
115
|
// 0 = 严格跟随原唱的音量起伏。用户实测:温柔的原唱用 0 最好听;
|
|
110
116
|
// 老版本这里是 1.0(等于放弃跟随),轻唱段落会被唱满。
|
|
111
117
|
rmsMixRate: 0,
|
|
118
|
+
harmony: 'off',
|
|
119
|
+
harmonyGain: 0.22,
|
|
120
|
+
harmonyScope: 'chorus',
|
|
112
121
|
mode: 'full',
|
|
113
122
|
},
|
|
114
123
|
play: {
|
|
@@ -208,6 +217,32 @@ export function fishsingConfigGroups(): ConfigGroup[] {
|
|
|
208
217
|
maximum: 1,
|
|
209
218
|
'x-hot': true,
|
|
210
219
|
},
|
|
220
|
+
[at('voice.harmony')]: {
|
|
221
|
+
type: 'string',
|
|
222
|
+
title: '和声堆叠',
|
|
223
|
+
description:
|
|
224
|
+
'同一音色再唱几条叠在一起,副歌立刻有"后面有人在唱"的厚度(唱片里的主唱都这么做)。'
|
|
225
|
+
+ 'off = 关;third = 叠一条三度;third+fifth = 三度 + 五度(更满,也更容易显电子味)。'
|
|
226
|
+
+ '注意:每多一条,转换时间就多一倍左右。',
|
|
227
|
+
enum: ['off', 'third', 'third+fifth'],
|
|
228
|
+
'x-hot': true,
|
|
229
|
+
},
|
|
230
|
+
[at('voice.harmonyGain')]: {
|
|
231
|
+
type: 'number',
|
|
232
|
+
title: '和声音量',
|
|
233
|
+
description: '主轨为 1.0 的相对音量。0.15 很含蓄;0.22 自然(推荐);0.35 以上容易显"合成味"。',
|
|
234
|
+
minimum: 0,
|
|
235
|
+
maximum: 0.6,
|
|
236
|
+
'x-hot': true,
|
|
237
|
+
},
|
|
238
|
+
[at('voice.harmonyScope')]: {
|
|
239
|
+
type: 'string',
|
|
240
|
+
title: '和声范围',
|
|
241
|
+
description:
|
|
242
|
+
'chorus = 只叠在唱得响的段落(按响度自动判断,推荐);all = 整首都在叠(容易电子味重)。',
|
|
243
|
+
enum: ['chorus', 'all'],
|
|
244
|
+
'x-hot': true,
|
|
245
|
+
},
|
|
211
246
|
[at('voice.mode')]: {
|
|
212
247
|
type: 'string',
|
|
213
248
|
title: '默认输出',
|
package/src/library.ts
CHANGED
|
@@ -20,6 +20,10 @@ export interface SingParams {
|
|
|
20
20
|
pitch: number | 'auto';
|
|
21
21
|
/** 音量跟随原唱的程度 0~1(0 = 完全跟随,轻唱不会被唱满) */
|
|
22
22
|
rmsMixRate?: number;
|
|
23
|
+
/** 和声堆叠档位 */
|
|
24
|
+
harmony?: 'off' | 'third' | 'third+fifth';
|
|
25
|
+
harmonyGain?: number;
|
|
26
|
+
harmonyScope?: 'chorus' | 'all';
|
|
23
27
|
mode: string;
|
|
24
28
|
}
|
|
25
29
|
|
package/src/setup.ts
CHANGED
|
@@ -57,6 +57,13 @@ export function loadManifest(): Manifest {
|
|
|
57
57
|
return JSON.parse(readFileSync(MODELS_MANIFEST, 'utf8')) as Manifest;
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/** 还缺几个「必需」组件(hubert / rmvpe / 两个底模)。
|
|
61
|
+
* 出厂默认模型 dfy2 是可选的示例,用户换过模型后删掉很正常——不能算进"缺"里。
|
|
62
|
+
* 面板、环境提示词、自检三处都该用这一个函数,别再各写一遍(之前就漏过两处)。 */
|
|
63
|
+
export function missingRequiredCount(models: ReadonlyArray<{ ready?: boolean; required?: boolean }>): number {
|
|
64
|
+
return models.filter((m) => !m.ready && m.required !== false).length;
|
|
65
|
+
}
|
|
66
|
+
|
|
60
67
|
function dirCount(p: string): number {
|
|
61
68
|
if (!existsSync(p)) return 0;
|
|
62
69
|
try {
|
package/src/sing.ts
CHANGED
|
@@ -64,6 +64,8 @@ export interface SingRequest {
|
|
|
64
64
|
protect?: number;
|
|
65
65
|
/** 音量跟随原唱的程度 0~1(0 = 完全跟随,轻唱不会被唱满) */
|
|
66
66
|
rmsMixRate?: number;
|
|
67
|
+
/** 和声堆叠:off / third / third+fifth */
|
|
68
|
+
harmony?: 'off' | 'third' | 'third+fifth';
|
|
67
69
|
start?: number;
|
|
68
70
|
duration?: number;
|
|
69
71
|
/** 跳过缓存(想重唱一遍时用) */
|
|
@@ -270,6 +272,10 @@ export async function singSong(req: SingRequest, deps: SingDeps): Promise<SingRe
|
|
|
270
272
|
protect: Number(req.protect ?? deps.voice.protect),
|
|
271
273
|
// 0 = 完全跟随原唱音量;1 = 完全用模型自己的(轻唱被唱满)。越界/NaN 一律退回配置值。
|
|
272
274
|
rmsMixRate: clamp01(req.rmsMixRate ?? deps.voice.rmsMixRate),
|
|
275
|
+
harmony: (req.harmony ?? deps.voice.harmony) === 'third+fifth' ? 'third+fifth'
|
|
276
|
+
: (req.harmony ?? deps.voice.harmony) === 'third' ? 'third' : 'off',
|
|
277
|
+
harmonyGain: Math.min(0.6, Math.max(0, Number(deps.voice.harmonyGain ?? 0.22))),
|
|
278
|
+
harmonyScope: deps.voice.harmonyScope === 'all' ? 'all' : 'chorus',
|
|
273
279
|
// 不传 pitch = 按配置默认(配置默认 'auto' = 按音域自动推荐)
|
|
274
280
|
pitch: req.pitch === undefined || req.pitch === 'auto'
|
|
275
281
|
? (deps.voice.pitch ?? 'auto')
|
|
@@ -319,6 +325,11 @@ export async function singSong(req: SingRequest, deps: SingDeps): Promise<SingRe
|
|
|
319
325
|
index_rate: params.indexRate,
|
|
320
326
|
protect: params.protect,
|
|
321
327
|
rms_mix_rate: params.rmsMixRate,
|
|
328
|
+
harmony: params.harmony === 'off' ? null : {
|
|
329
|
+
semis: params.harmony === 'third+fifth' ? [3, 7] : [3],
|
|
330
|
+
gain: params.harmonyGain,
|
|
331
|
+
scope: params.harmonyScope,
|
|
332
|
+
},
|
|
322
333
|
});
|
|
323
334
|
let lastLog = 0;
|
|
324
335
|
const job = await deps.worker.wait(jobId, (p, msg) => {
|
package/src/world.ts
CHANGED
|
@@ -63,6 +63,7 @@ import {
|
|
|
63
63
|
probeRuntime,
|
|
64
64
|
type RuntimeMode,
|
|
65
65
|
type SetupStatus,
|
|
66
|
+
missingRequiredCount,
|
|
66
67
|
} from './setup.ts';
|
|
67
68
|
import { duration, toMp3, type FfmpegDeps } from './audio.ts';
|
|
68
69
|
import { parseTarget, Player, sendRecord } from './deliver.ts';
|
|
@@ -462,6 +463,10 @@ export class FishSingWorld implements World {
|
|
|
462
463
|
protect: Number(cfg.voice?.protect ?? 0.33),
|
|
463
464
|
pitch: (cfg.voice?.pitch as number | 'auto' | undefined) ?? 'auto',
|
|
464
465
|
rmsMixRate: cfg.voice?.rmsMixRate === undefined ? 0 : Number(cfg.voice.rmsMixRate),
|
|
466
|
+
harmony: (cfg.voice?.harmony === 'third' || cfg.voice?.harmony === 'third+fifth'
|
|
467
|
+
? cfg.voice.harmony : 'off') as 'off' | 'third' | 'third+fifth',
|
|
468
|
+
harmonyGain: cfg.voice?.harmonyGain === undefined ? 0.22 : Number(cfg.voice.harmonyGain),
|
|
469
|
+
harmonyScope: cfg.voice?.harmonyScope === 'all' ? 'all' : 'chorus',
|
|
465
470
|
mode: cfg.voice?.mode === 'vocals' ? 'vocals' : 'full',
|
|
466
471
|
},
|
|
467
472
|
};
|
|
@@ -489,7 +494,10 @@ export class FishSingWorld implements World {
|
|
|
489
494
|
: '还没唱过';
|
|
490
495
|
// 装机状态:让她一眼知道现在能不能唱,而不是调了工具才发现缺权重
|
|
491
496
|
const st = inspect(this.routes);
|
|
492
|
-
|
|
497
|
+
// 只算「必需」组件(hubert / rmvpe / 两个底模)。出厂默认模型 dfy2 是可选的示例:
|
|
498
|
+
// 用户换过模型后删掉它很正常。以前这里把所有文件都算上,结果她被告知"还缺 2 个权重、
|
|
499
|
+
// 现在唱不了"——明明能用 dfy7 唱,却按这句话拒绝唱歌。(面板 0.4.22 修过,这里是第三处)
|
|
500
|
+
const missModels = missingRequiredCount(st.models);
|
|
493
501
|
const ready = st.rvc.ready && st.python.ok && missModels === 0;
|
|
494
502
|
// 值写成**人话**而不是枚举:模板只做占位符替换、没有条件语法,
|
|
495
503
|
// 所以这句话本身就是"缺什么 + 去哪补"的行动指引。
|
|
@@ -499,7 +507,7 @@ export class FishSingWorld implements World {
|
|
|
499
507
|
? '还缺插件代码,现在唱不了 —— 让她在控制台「大肥鱼唱歌 → 安装与运行时」页点「刷新」,或重装插件。'
|
|
500
508
|
: !st.python.ok
|
|
501
509
|
? '还缺 Python 运行时,现在唱不了 —— 让她在「安装与运行时」页点「安装 GPU 运行时」。'
|
|
502
|
-
: `还缺 ${missModels}
|
|
510
|
+
: `还缺 ${missModels} 个必需组件,现在唱不了 —— 让她在「安装与运行时」页点「下载必需组件」。`;
|
|
503
511
|
return {
|
|
504
512
|
singModel: model || '未配置',
|
|
505
513
|
singTarget: where,
|
package/tests/smoke.mjs
CHANGED
|
@@ -60,6 +60,26 @@ const key = Object.keys(voiceGroup.schema.properties).find((k) => k.endsWith('vo
|
|
|
60
60
|
check('配置项 voice.rmsMixRate 存在', Boolean(key));
|
|
61
61
|
check('配置项有说明文案', String(voiceGroup.schema.properties[key].description || '').length > 20);
|
|
62
62
|
|
|
63
|
+
// ---- 7. 和声堆叠:默认关,配置项齐全 ----
|
|
64
|
+
check('默认和声 = off', FISHSING_DEFAULTS.voice.harmony === 'off');
|
|
65
|
+
check('默认和声音量 0.22', FISHSING_DEFAULTS.voice.harmonyGain === 0.22);
|
|
66
|
+
const hKeys = ['voice.harmony', 'voice.harmonyGain', 'voice.harmonyScope']
|
|
67
|
+
.map((k) => Object.keys(voiceGroup.schema.properties).find((x) => x.endsWith(k)));
|
|
68
|
+
check('三个和声配置项都在', hKeys.every(Boolean));
|
|
69
|
+
check('和声配置项都有说明', hKeys.every((k) => String(voiceGroup.schema.properties[k].description || '').length > 20));
|
|
70
|
+
|
|
71
|
+
// ---- 8. 「必需组件」计数是唯一来源(面板/环境提示词共用,别再各写一遍) ----
|
|
72
|
+
const { missingRequiredCount } = await import('../src/setup.ts');
|
|
73
|
+
const fake = [
|
|
74
|
+
{ ready: false, required: false }, // 可选(dfy2)
|
|
75
|
+
{ ready: false, required: false }, // 可选(dfy2 索引)
|
|
76
|
+
{ ready: true, required: true },
|
|
77
|
+
{ ready: true, required: true },
|
|
78
|
+
];
|
|
79
|
+
check('可选模型缺失不算缺', missingRequiredCount(fake) === 0);
|
|
80
|
+
check('必需缺失才算缺', missingRequiredCount([...fake, { ready: false, required: true }]) === 1);
|
|
81
|
+
check('没写 required 的按必需算', missingRequiredCount([{ ready: false }]) === 1);
|
|
82
|
+
|
|
63
83
|
if (failed) {
|
|
64
84
|
console.error(`\n${failed} 项失败`);
|
|
65
85
|
process.exit(1);
|
|
@@ -161,5 +161,36 @@ class AugmentWeightExpansion(unittest.TestCase):
|
|
|
161
161
|
self.assertTrue(any('f0D40k' in t for t in req))
|
|
162
162
|
self.assertEqual(len(opt), 2, f'可选应为 dfy2 模型+索引两项,实际 {opt}')
|
|
163
163
|
|
|
164
|
+
def test_looks_dry_ignores_directory_names(self):
|
|
165
|
+
# 用户把素材放在「大肥鱼伴奏+人声-某某」这种目录下时,目录名带「人声」,
|
|
166
|
+
# 老实现用 str(path) 整串匹配,会把整个文件夹都判成干声——实测误判过:
|
|
167
|
+
# …\带伴奏\团子大家族.aac 其实是完整混音(伴奏比人声响 1.2 倍),却跳过分离。
|
|
168
|
+
import sys, pathlib
|
|
169
|
+
sys.path.insert(0, str(pathlib.Path('worker').resolve()))
|
|
170
|
+
from dataset import looks_dry
|
|
171
|
+
self.assertFalse(looks_dry(r'D://AI//大肥鱼伴奏+人声-某某//带伴奏//团子大家族.aac'))
|
|
172
|
+
self.assertTrue(looks_dry(r'D://AI//大肥鱼伴奏+人声-某某//干声//大肥鱼-暖暖-人声.wav'))
|
|
173
|
+
self.assertFalse(looks_dry(r'D://music//song-伴奏.wav'))
|
|
174
|
+
self.assertFalse(looks_dry(r'D://music//普通歌曲.mp3'))
|
|
175
|
+
self.assertTrue(looks_dry(r'D://music//vocal_take.wav'))
|
|
176
|
+
|
|
177
|
+
def test_dry_check_switchable(self):
|
|
178
|
+
# 干声实测校验(切 8 秒做快分离)可以用环境变量关掉,避免慢机器上扫描太慢
|
|
179
|
+
import os, sys, pathlib
|
|
180
|
+
sys.path.insert(0, str(pathlib.Path('worker').resolve()))
|
|
181
|
+
from dataset import _quick_vocal_ratio
|
|
182
|
+
os.environ['FISHSING_SKIP_DRY_CHECK'] = '1'
|
|
183
|
+
try:
|
|
184
|
+
self.assertIsNone(_quick_vocal_ratio('whatever.wav'))
|
|
185
|
+
finally:
|
|
186
|
+
os.environ.pop('FISHSING_SKIP_DRY_CHECK', None)
|
|
187
|
+
|
|
188
|
+
def test_song_accepts_harmony(self):
|
|
189
|
+
# 和声堆叠:默认关(harmony=None),开了才多渲和声轨,别让不用的用户白白多等
|
|
190
|
+
import inspect
|
|
191
|
+
sig = inspect.signature(engine.SingEngine.song)
|
|
192
|
+
self.assertIn('harmony', sig.parameters, 'song() 少了 harmony 参数')
|
|
193
|
+
self.assertIsNone(sig.parameters['harmony'].default, 'harmony 默认应为 None(关闭)')
|
|
194
|
+
|
|
164
195
|
if __name__ == "__main__":
|
|
165
196
|
unittest.main()
|
package/worker/dataset.py
CHANGED
|
@@ -73,10 +73,76 @@ def ffprobe(path) -> dict:
|
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
DRY_HINTS = ("vocal", "干声", "人声", "dry_", "clean_")
|
|
77
|
+
WET_HINTS = ("伴奏", "instrumental", "karaoke", "accompaniment", "off_vocal", "offvocal", "inst_")
|
|
78
|
+
|
|
79
|
+
|
|
76
80
|
def looks_dry(path) -> bool:
|
|
77
|
-
"""
|
|
78
|
-
|
|
79
|
-
|
|
81
|
+
"""文件名像不像已经分离好的人声。
|
|
82
|
+
|
|
83
|
+
只看**文件名**,不看目录:用户把素材放在「大肥鱼伴奏+人声-某某」这种目录里时,
|
|
84
|
+
目录名带「人声」会把整个文件夹都判成干声——实测过:`…\大肥鱼伴奏+人声…\带伴奏\团子大家族.aac`
|
|
85
|
+
其实是完整混音(伴奏比人声还响 1.2 倍),却被跳过分离,等于拿混音去训练。
|
|
86
|
+
|
|
87
|
+
文件名里出现「伴奏 / instrumental / karaoke」等词时一律判为混音,优先级高于干声关键词。
|
|
88
|
+
"""
|
|
89
|
+
stem = Path(str(path)).stem.lower()
|
|
90
|
+
if any(k in stem for k in WET_HINTS):
|
|
91
|
+
return False
|
|
92
|
+
return any(k in stem for k in DRY_HINTS)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _quick_vocal_ratio(path, seconds: float = 8.0):
|
|
96
|
+
r"""切中段几秒做一次快分离,返回 伴奏/人声 的能量比(>0.5 基本就是混音)。
|
|
97
|
+
|
|
98
|
+
只在「文件名说是干声」时才调用,用来兜住文件名骗人的情况——
|
|
99
|
+
比如素材放在 `…\大肥鱼伴奏+人声-某某\` 目录里,文件名却叫 `团子大家族.aac`。
|
|
100
|
+
失败(没装 demucs / 没显卡 / 文件太短)返回 None,调用方按文件名判断走。
|
|
101
|
+
"""
|
|
102
|
+
import os
|
|
103
|
+
import shutil
|
|
104
|
+
import tempfile
|
|
105
|
+
|
|
106
|
+
if os.environ.get("FISHSING_SKIP_DRY_CHECK"): # 想跳过校验就设这个
|
|
107
|
+
return None
|
|
108
|
+
try:
|
|
109
|
+
import numpy as np
|
|
110
|
+
import soundfile as sf
|
|
111
|
+
|
|
112
|
+
# 用 ffprobe 而不是 soundfile:aac/m4a 这类容器 soundfile 读不了(会直接跳过校验)
|
|
113
|
+
dur = float(ffprobe(Path(str(path)))["duration"] or 0)
|
|
114
|
+
if dur < max(6.0, seconds):
|
|
115
|
+
return None
|
|
116
|
+
start = max(0.0, dur / 2 - seconds / 2) # 取中段,避开片头静音
|
|
117
|
+
|
|
118
|
+
tmp = Path(tempfile.mkdtemp(prefix="dryck-"))
|
|
119
|
+
try:
|
|
120
|
+
clip = tmp / "clip.wav"
|
|
121
|
+
ff = os.environ.get("FISHSING_FFMPEG", "ffmpeg")
|
|
122
|
+
subprocess.run(
|
|
123
|
+
[ff, "-y", "-v", "error", "-ss", f"{start:.2f}", "-t", f"{seconds:.2f}",
|
|
124
|
+
"-i", str(path), "-ac", "1", "-ar", "44100", str(clip)],
|
|
125
|
+
capture_output=True, check=True,
|
|
126
|
+
)
|
|
127
|
+
# 懒加载:避免扫描时无谓地拉 torch;兼容"包导入"和"脚本运行"两种方式
|
|
128
|
+
try:
|
|
129
|
+
from .separate import separate_file
|
|
130
|
+
except ImportError:
|
|
131
|
+
from separate import separate_file
|
|
132
|
+
vocals, inst, _sr = separate_file(clip, tmp / "sep", device="auto", quiet=True)
|
|
133
|
+
|
|
134
|
+
def _rms(fp):
|
|
135
|
+
y, _ = sf.read(str(fp), dtype="float32")
|
|
136
|
+
if y.ndim > 1:
|
|
137
|
+
y = y.mean(axis=1)
|
|
138
|
+
return float(np.sqrt(np.mean(y ** 2)))
|
|
139
|
+
|
|
140
|
+
v, i = _rms(vocals), _rms(inst)
|
|
141
|
+
return i / (v + 1e-9)
|
|
142
|
+
finally:
|
|
143
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
144
|
+
except Exception: # noqa: BLE001
|
|
145
|
+
return None
|
|
80
146
|
|
|
81
147
|
|
|
82
148
|
def scan(paths) -> list:
|
|
@@ -101,15 +167,26 @@ def scan(paths) -> list:
|
|
|
101
167
|
except Exception as e: # noqa: BLE001
|
|
102
168
|
out.append({"path": str(f), "name": f.name, "error": str(e)})
|
|
103
169
|
continue
|
|
104
|
-
|
|
170
|
+
dry = looks_dry(f)
|
|
171
|
+
note = ""
|
|
172
|
+
if dry:
|
|
173
|
+
# 文件名说干声,就再实测一次:混音被当干声会直接污染训练集,宁可多花几秒
|
|
174
|
+
ratio = _quick_vocal_ratio(f)
|
|
175
|
+
if ratio is not None and ratio > 0.5:
|
|
176
|
+
dry = False
|
|
177
|
+
note = f"文件名像干声,但实测伴奏/人声={ratio:.2f},按混音处理"
|
|
178
|
+
row = {
|
|
105
179
|
"path": str(f),
|
|
106
180
|
"name": f.name,
|
|
107
181
|
"duration": round(meta["duration"], 2),
|
|
108
182
|
"sr": meta["sr"],
|
|
109
183
|
"channels": meta["channels"],
|
|
110
184
|
"codec": meta["codec"],
|
|
111
|
-
"dry":
|
|
112
|
-
}
|
|
185
|
+
"dry": dry,
|
|
186
|
+
}
|
|
187
|
+
if note:
|
|
188
|
+
row["note"] = note
|
|
189
|
+
out.append(row)
|
|
113
190
|
return out
|
|
114
191
|
|
|
115
192
|
|
package/worker/engine.py
CHANGED
|
@@ -704,10 +704,11 @@ class SingEngine:
|
|
|
704
704
|
def song(self, src: Path, work: Path, *, separate: bool = True, mode: str = "full",
|
|
705
705
|
pitch: "int | str" = 0, index_rate: float = 0.75, protect: float = 0.33,
|
|
706
706
|
rms_mix_rate: float = 0.0,
|
|
707
|
+
harmony: "dict | None" = None,
|
|
707
708
|
progress: Optional[Callable[[float, str], None]] = None,
|
|
708
709
|
cancel: Optional[threading.Event] = None) -> dict:
|
|
709
710
|
"""
|
|
710
|
-
整首歌:分离 →
|
|
711
|
+
整首歌:分离 → 换声(+可选和声) → 混音。
|
|
711
712
|
mode: full=带伴奏 / vocals=只要人声(清唱)/ mixed 同 full 但保留中间文件
|
|
712
713
|
pitch: 半音数;'auto' = 分离后按源曲与模型音域自动推荐。
|
|
713
714
|
"""
|
|
@@ -742,6 +743,21 @@ class SingEngine:
|
|
|
742
743
|
protect=protect, rms_mix_rate=rms_mix_rate,
|
|
743
744
|
progress=lambda p, m: report(0.2 + 0.6 * p, m), cancel=cancel)
|
|
744
745
|
|
|
746
|
+
# 和声堆叠:同一音色再唱几条(三度/五度),按响度门限只叠在"唱得响"的段落。
|
|
747
|
+
# 单轨再干净也薄,叠 1~2 条立刻有"后面有人在唱"的厚度(唱片里的主唱都这么做)。
|
|
748
|
+
harm_semis = [int(x) for x in ((harmony or {}).get("semis") or []) if int(x) != 0]
|
|
749
|
+
if harm_semis:
|
|
750
|
+
report(0.82, f"叠和声({len(harm_semis)} 轨)")
|
|
751
|
+
stacked = self._stack_harmony(
|
|
752
|
+
conv, vocal_src, harm_semis, pitch=pitch, index_rate=index_rate,
|
|
753
|
+
protect=protect, rms_mix_rate=rms_mix_rate,
|
|
754
|
+
gain=float((harmony or {}).get("gain", 0.22)),
|
|
755
|
+
scope=str((harmony or {}).get("scope", "chorus")),
|
|
756
|
+
work=work, report=report, cancel=cancel, base_report=0.82,
|
|
757
|
+
)
|
|
758
|
+
if stacked is not None:
|
|
759
|
+
conv = stacked
|
|
760
|
+
|
|
745
761
|
if mode == "vocals":
|
|
746
762
|
out = work / "result.wav"
|
|
747
763
|
shutil.copyfile(conv, out)
|
|
@@ -778,6 +794,69 @@ class SingEngine:
|
|
|
778
794
|
result["pitchSuggest"] = suggestion
|
|
779
795
|
return result
|
|
780
796
|
|
|
797
|
+
def _stack_harmony(self, main_wav: Path, vocal_src: Path, semis: list,
|
|
798
|
+
*, pitch: int, index_rate: float, protect: float,
|
|
799
|
+
rms_mix_rate: float, gain: float, scope: str,
|
|
800
|
+
work: Path, report, cancel, base_report: float = 0.82) -> "Path | None":
|
|
801
|
+
"""把主轨和若干条同音色和声轨叠成一个立体声人声文件。
|
|
802
|
+
|
|
803
|
+
三条轨的音量比默认是 主:三度:五度 = 1 : gain : gain*0.45;
|
|
804
|
+
和声按响度门限只出现在"唱得响"的段落(scope=chorus),免得整段都在叠显得电子味重。
|
|
805
|
+
和声轨做 110Hz 高通,左右分开(三度偏左、五度偏右)。
|
|
806
|
+
"""
|
|
807
|
+
from scipy.signal import butter, sosfilt # 懒加载,避免无 scipy 时影响其它功能
|
|
808
|
+
|
|
809
|
+
def read(p: Path):
|
|
810
|
+
y, sr = sf.read(str(p), dtype="float32")
|
|
811
|
+
if y.ndim == 1:
|
|
812
|
+
y = np.stack([y, y], axis=1)
|
|
813
|
+
return y, sr
|
|
814
|
+
|
|
815
|
+
base, sr = read(main_wav)
|
|
816
|
+
# 响度门限:以主轨 RMS 的中位数为界,只给响亮段落叠和声
|
|
817
|
+
mono = base.mean(axis=1)
|
|
818
|
+
fl, hl = 2048, 512
|
|
819
|
+
n_fr = max(1, (len(mono) - fl) // hl)
|
|
820
|
+
env = np.array([float(np.sqrt(np.mean(mono[i * hl:i * hl + fl] ** 2) + 1e-12)) for i in range(n_fr)])
|
|
821
|
+
if scope == "all" or len(env) < 4:
|
|
822
|
+
gate = np.ones(len(mono), dtype="float32")
|
|
823
|
+
else:
|
|
824
|
+
thr = float(np.percentile(20 * np.log10(env + 1e-9), 55))
|
|
825
|
+
g = (20 * np.log10(env + 1e-9) > thr).astype("float32")
|
|
826
|
+
k = max(1, int(0.1 * sr / hl)) # 约 100ms 平滑
|
|
827
|
+
g = np.convolve(g, np.ones(k) / k, mode="same")
|
|
828
|
+
gate = np.interp(np.arange(len(mono)), np.arange(len(g)) * hl, g).astype("float32")
|
|
829
|
+
|
|
830
|
+
total = base.copy()
|
|
831
|
+
left = np.zeros(len(mono), dtype="float32")
|
|
832
|
+
right = np.zeros(len(mono), dtype="float32")
|
|
833
|
+
for i, semi in enumerate(semis):
|
|
834
|
+
if cancel.is_set():
|
|
835
|
+
raise RuntimeError("已取消")
|
|
836
|
+
report(base_report + (0.12 * (i + 1) / max(1, len(semis))), f"叠和声 {semi:+d} 半音")
|
|
837
|
+
tmp = work / f"harmony_{semi:+d}.wav"
|
|
838
|
+
self.convert(vocal_src, tmp, pitch=int(pitch) + int(semi), index_rate=index_rate,
|
|
839
|
+
protect=protect, rms_mix_rate=rms_mix_rate,
|
|
840
|
+
progress=lambda p, m: None, cancel=cancel)
|
|
841
|
+
h, _ = read(tmp)
|
|
842
|
+
n = min(len(h), len(mono))
|
|
843
|
+
m = h[:n].mean(axis=1) * gate[:n] * gain * (0.45 if abs(semi) >= 7 else 1.0)
|
|
844
|
+
# 110Hz 高通去浑
|
|
845
|
+
sos = butter(2, 110.0 / (sr / 2), btype="high", output="sos")
|
|
846
|
+
m = sosfilt(sos, m).astype("float32")
|
|
847
|
+
side = -0.3 if i % 2 == 0 else 0.3 # 一左一右
|
|
848
|
+
left[:n] += m * np.sqrt((1 - side) / 2) * 1.41
|
|
849
|
+
right[:n] += m * np.sqrt((1 + side) / 2) * 1.41
|
|
850
|
+
|
|
851
|
+
total[:, 0] += left[:len(total)]
|
|
852
|
+
total[:, 1] += right[:len(total)]
|
|
853
|
+
peak = float(np.abs(total).max())
|
|
854
|
+
if peak > 0.99: # 叠完可能过载,保点余量
|
|
855
|
+
total *= 0.99 / peak
|
|
856
|
+
out = work / "vocals_stacked.wav"
|
|
857
|
+
write_audio(out, total, sr)
|
|
858
|
+
return out
|
|
859
|
+
|
|
781
860
|
@staticmethod
|
|
782
861
|
def pitch_shift_filter(sr: int, semitones: float) -> str:
|
|
783
862
|
"""
|
package/worker/server.py
CHANGED
|
@@ -126,6 +126,7 @@ def run_job(jid: str, kind: str, params: dict, cancel: threading.Event) -> dict:
|
|
|
126
126
|
protect=float(params.get("protect", 0.33)),
|
|
127
127
|
# 0 = 音量完全跟随原唱(轻唱不会被唱满);老版本传 1.0 = 不跟随
|
|
128
128
|
rms_mix_rate=float(params.get("rms_mix_rate", 0.0)),
|
|
129
|
+
harmony=params.get("harmony") or None,
|
|
129
130
|
progress=progress,
|
|
130
131
|
cancel=cancel,
|
|
131
132
|
)
|