cortico-world-fish-sing 0.4.9 → 0.4.11

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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循语义化。
4
4
 
5
+ ## [0.4.11] - 2026-11-03
6
+
7
+ ### 修复
8
+ - **长歌越唱越快、和伴奏越到后面越不合拍**:0.4.0 的接缝处理用的是"重叠交叉淡化",每条缝吃掉 50ms。4 分半的歌 4 条缝 = 人声比伴奏少 200ms,听感就是越唱越快。改成**等长淡出/淡入**(各 8ms),一个样本都不删,既压住接缝爆音又保证时长精确。
9
+ - 验证:115.67 秒真实素材(3 片)转换后输出 115.67 秒、样本数完全相同(差 0.0ms)。
10
+ - 单测改为「接缝处理必须不改时长」,这类事故以后进不了 CI。
11
+
12
+ ## [0.4.10] - 2026-11-02
13
+
14
+ ### 修复
15
+ - **QQ 通知目标只填号码时静默失效**:`qqTarget` 写 `2587509374`(没有 `private:` 前缀)会被 `parseTarget` 判死,然后什么都不发、日志一条没有,看起来像"QQ 渠道坏了"。现在裸数字直接当私聊号处理;格式真的不对时也会 warn 一条「解析不了(要 group:/private:)」。
16
+ - 选模对比没发 QQ 时同样会 warn 说明原因(缺目标 / 缺 OneBot 地址),不再静默。
17
+ - `notify.qqTarget` 改为热更新字段(改完不用重启 Coo)。
18
+
5
19
  ## [0.4.9] - 2026-11-02
6
20
 
7
21
  ### 修复
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-fish-sing",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/config.ts CHANGED
@@ -337,7 +337,8 @@ export function fishsingConfigGroups(): ConfigGroup[] {
337
337
  [at('notify.qqTarget')]: {
338
338
  type: 'string',
339
339
  title: 'QQ 通知目标',
340
- description: 'group:<群号> 或 private:<QQ号>;留空 = 只用桌宠。',
340
+ description: 'group:<群号> 或 private:<QQ号>(只填号码也行);留空 = 只用桌宠。',
341
+ 'x-hot': true,
341
342
  },
342
343
  },
343
344
  },
package/src/deliver.ts CHANGED
@@ -87,9 +87,15 @@ export interface OneBotTarget {
87
87
  label: string;
88
88
  }
89
89
 
90
- /** `group:123` / `private:456`;也接受 `群:123` / `私聊:456`(她有时候会这么写)。 */
90
+ /** `group:123` / `private:456`;也接受 `群:123` / `私聊:456`(她有时候会这么写)。
91
+ * 裸数字当成私聊 QQ 号——用户第一反应就是直接填号码,不能因为少个前缀就静默不发。 */
91
92
  export function parseTarget(to: string): OneBotTarget | null {
92
93
  const text = String(to || '').trim();
94
+ const bare = /^(\d{5,12})$/.exec(text);
95
+ if (bare) {
96
+ const id = Number(bare[1]);
97
+ return { action: 'send_private_msg', params: { user_id: id }, label: `私聊 ${id}` };
98
+ }
93
99
  const m = /^(group|群|private|私聊)\s*[::]\s*(\d+)$/.exec(text);
94
100
  if (!m) return null;
95
101
  const isGroup = m[1] === 'group' || m[1] === '群';
package/src/notify.ts CHANGED
@@ -36,7 +36,13 @@ export async function notify(deps: NotifyDeps, title: string, body = ''): Promis
36
36
  const text = body ? `${title}\n${body}` : title;
37
37
 
38
38
  const channel = deps.cfg.channel ?? 'auto';
39
- const target = parseTarget(String(deps.cfg.qqTarget ?? ''));
39
+ const rawTarget = String(deps.cfg.qqTarget ?? '').trim();
40
+ const target = parseTarget(rawTarget);
41
+ if (channel === 'auto' && rawTarget && !target) {
42
+ // 这里以前是完全静默的:qqTarget 写了但格式不对 → 直接走桌宠,日志一条没有,
43
+ // 用户以为"QQ 渠道坏了"(0.4.9 的真实事故:填了裸号码没写 private:)。
44
+ deps.log.warn(`QQ 通知目标「${rawTarget}」解析不了(要 group:<群号> 或 private:<QQ号>),走桌宠`);
45
+ }
40
46
  const wantQQ = channel === 'qq' || (channel === 'auto' && Boolean(target) && Boolean(deps.onebot.httpUrl));
41
47
  if (wantQQ) {
42
48
  if (target && deps.onebot.httpUrl) {
package/src/world.ts CHANGED
@@ -417,6 +417,11 @@ export class FishSingWorld implements World {
417
417
  } catch (e) {
418
418
  this.host?.log.warn(`[fish-sing] 选模片段发 QQ 失败:${e instanceof Error ? e.message : String(e)}`);
419
419
  }
420
+ } else {
421
+ // 别静默:用户会以为"QQ 渠道坏了",实际是配置缺一半
422
+ this.host?.log.warn(
423
+ `[fish-sing] 选模片段没发 QQ:${!obTarget ? 'qqTarget 没配或格式不对(要 group:/private: 前缀)' : 'OneBot HTTP 地址没配'}`,
424
+ );
420
425
  }
421
426
  }
422
427
  this.host?.log.info(`[fish-sing] 选模对比已生成:${labels.join(' / ')}(${outDir})`);
package/tests/smoke.mjs CHANGED
@@ -1,52 +1,59 @@
1
- /**
2
- * Node 侧冒烟测试:入口能加载、通知渠道兜底逻辑正确。
3
- * 跑法:node --experimental-strip-types tests/smoke.mjs
4
- */
5
- import { notify } from '../src/notify.ts';
6
-
7
- let failed = 0;
8
- function check(name, ok, detail = '') {
9
- console.log(`${ok ? '✓' : '✗'} ${name}${detail ? `(${detail})` : ''}`);
10
- if (!ok) failed += 1;
11
- }
12
-
13
- const log = { info: () => {}, warn: () => {}, error: () => {} };
14
-
15
- // ---- 1. 桌宠渠道:pushEvent 被调用 ----
16
- let pushed = [];
17
- const r1 = await notify(
18
- { cfg: { enabled: true, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
19
- '训练完成:dfy3', '200 轮全部完成。',
20
- );
21
- check('桌宠渠道走 pushEvent', r1.via === 'pet' && pushed.length === 1 && pushed[0].type === 'fishsing.notify');
22
- check('事件带正文', typeof pushed[0]?.text === 'string' && pushed[0].text.includes('dfy3'));
23
-
24
- // ---- 2. auto + 没配 QQ 目标 → 退桌宠 ----
25
- pushed = [];
26
- const r2 = await notify(
27
- { cfg: { enabled: true, channel: 'auto' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
28
- '测试2',
29
- );
30
- check('auto 无 QQ 目标 → 桌宠', r2.via === 'pet' && pushed.length === 1);
31
-
32
- // ---- 3. QQ 不通 → 退桌宠(用户定的兜底规则) ----
33
- pushed = [];
34
- const r3 = await notify(
35
- { cfg: { enabled: true, channel: 'auto', qqTarget: 'group:123' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: 'http://127.0.0.1:59999' }, log },
36
- '测试3',
37
- );
38
- check('QQ 不通退桌宠', r3.via === 'pet' && pushed.length === 1);
39
-
40
- // ---- 4. 关闭 → 不发 ----
41
- pushed = [];
42
- const r4 = await notify(
43
- { cfg: { enabled: false, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
44
- '测试4',
45
- );
46
- check('enabled=false 不发', r4.via === 'off' && pushed.length === 0);
47
-
48
- if (failed) {
49
- console.error(`\n${failed} 项失败`);
50
- process.exit(1);
51
- }
52
- console.log('\n冒烟测试全部通过');
1
+ /**
2
+ * Node 侧冒烟测试:入口能加载、通知渠道兜底逻辑正确。
3
+ * 跑法:node --experimental-strip-types tests/smoke.mjs
4
+ */
5
+ import { notify } from '../src/notify.ts';
6
+
7
+ let failed = 0;
8
+ function check(name, ok, detail = '') {
9
+ console.log(`${ok ? '✓' : '✗'} ${name}${detail ? `(${detail})` : ''}`);
10
+ if (!ok) failed += 1;
11
+ }
12
+
13
+ const log = { info: () => {}, warn: () => {}, error: () => {} };
14
+
15
+ // ---- 1. 桌宠渠道:pushEvent 被调用 ----
16
+ let pushed = [];
17
+ const r1 = await notify(
18
+ { cfg: { enabled: true, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
19
+ '训练完成:dfy3', '200 轮全部完成。',
20
+ );
21
+ check('桌宠渠道走 pushEvent', r1.via === 'pet' && pushed.length === 1 && pushed[0].type === 'fishsing.notify');
22
+ check('事件带正文', typeof pushed[0]?.text === 'string' && pushed[0].text.includes('dfy3'));
23
+
24
+ // ---- 2. auto + 没配 QQ 目标 → 退桌宠 ----
25
+ pushed = [];
26
+ const r2 = await notify(
27
+ { cfg: { enabled: true, channel: 'auto' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
28
+ '测试2',
29
+ );
30
+ check('auto 无 QQ 目标 → 桌宠', r2.via === 'pet' && pushed.length === 1);
31
+
32
+ // ---- 3. QQ 不通 → 退桌宠(用户定的兜底规则) ----
33
+ pushed = [];
34
+ const r3 = await notify(
35
+ { cfg: { enabled: true, channel: 'auto', qqTarget: 'group:123' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: 'http://127.0.0.1:59999' }, log },
36
+ '测试3',
37
+ );
38
+ check('QQ 不通退桌宠', r3.via === 'pet' && pushed.length === 1);
39
+
40
+ // ---- 4. 关闭 → 不发 ----
41
+ pushed = [];
42
+ const r4 = await notify(
43
+ { cfg: { enabled: false, channel: 'pet' }, pushEvent: (e) => pushed.push(e), onebot: { httpUrl: '' }, log },
44
+ '测试4',
45
+ );
46
+ check('enabled=false 不发', r4.via === 'off' && pushed.length === 0);
47
+
48
+
49
+ // ---- 5. 裸号码当私聊(0.4.10 的坑:填了号码没前缀就静默不发) ----
50
+ const { parseTarget } = await import('../src/deliver.ts');
51
+ const t1 = parseTarget('2587509374');
52
+ check('裸号码 → 私聊', Boolean(t1) && t1.action === 'send_private_msg' && t1.params.user_id === 2587509374);
53
+ check('乱码 → null', parseTarget('2587509374abc') === null);
54
+
55
+ if (failed) {
56
+ console.error(`\n${failed} 项失败`);
57
+ process.exit(1);
58
+ }
59
+ console.log('\n冒烟测试全部通过');
@@ -1,130 +1,130 @@
1
- """引擎侧纯逻辑测试(需要 numpy + soundfile;torch/librosa 不需要)。
2
-
3
- 跑法:python -m unittest discover -s tests -v
4
- """
5
- import os
6
- import sys
7
- import tempfile
8
- import unittest
9
- from pathlib import Path
10
-
11
- ROOT = Path(__file__).resolve().parent.parent
12
- sys.path.insert(0, str(ROOT / "worker"))
13
-
14
- # RVC_ROOT 探测链在 import 时求值:指向一个确定的空目录,别让测试落到开发机的旧路径
15
- _TMP = tempfile.mkdtemp(prefix="fishsing-test-")
16
- os.environ["FISHSING_RVC_ROOT"] = _TMP
17
-
18
- import numpy as np # noqa: E402
19
- import engine # noqa: E402
20
-
21
- SR = 40000
22
-
23
-
24
- class SuggestPitch(unittest.TestCase):
25
- def setUp(self):
26
- self.model = {"p5": 313.0, "median": 356.0, "p95": 477.0}
27
-
28
- def test_female_source_stays_zero(self):
29
- # 源曲低音比模型数据下限低 7.9 半音——在 8 半音容忍范围内,不移调
30
- s = engine.SingEngine.suggest_pitch({"p5": 198.0}, self.model)
31
- self.assertEqual(s["pitch"], 0)
32
-
33
- def test_male_source_capped_plus6(self):
34
- s = engine.SingEngine.suggest_pitch({"p5": 120.0}, self.model)
35
- self.assertEqual(s["pitch"], 6)
36
- self.assertIn("男声", s["reason"])
37
-
38
- def test_moderate_male(self):
39
- # 差 12.75 半音 → ceil(12.75-8)=5
40
- s = engine.SingEngine.suggest_pitch({"p5": 150.0}, self.model)
41
- self.assertEqual(s["pitch"], 5)
42
-
43
- def test_way_higher_capped_minus3(self):
44
- s = engine.SingEngine.suggest_pitch({"p5": 700.0}, self.model)
45
- self.assertEqual(s["pitch"], -3)
46
-
47
- def test_missing_data_zero(self):
48
- self.assertEqual(engine.SingEngine.suggest_pitch(None, self.model)["pitch"], 0)
49
- self.assertEqual(engine.SingEngine.suggest_pitch({"p5": 200}, None)["pitch"], 0)
50
-
51
-
52
- class ResolveRvcRoot(unittest.TestCase):
53
- def test_env_wins(self):
54
- os.environ["FISHSING_RVC_ROOT"] = str(Path(_TMP) / "custom")
55
- try:
56
- self.assertEqual(str(engine._resolve_rvc_root()), str(Path(_TMP) / "custom"))
57
- finally:
58
- os.environ["FISHSING_RVC_ROOT"] = _TMP
59
-
60
- def test_fallback_workdir_sibling(self):
61
- os.environ.pop("FISHSING_RVC_ROOT", None)
62
- work = Path(_TMP) / "data" / "fish-sing" / "work"
63
- rvc = Path(_TMP) / "data" / "fish-sing" / "runtime" / "rvc"
64
- (rvc / "assets" / "weights").mkdir(parents=True, exist_ok=True)
65
- os.environ["FISHSING_WORK"] = str(work)
66
- try:
67
- self.assertEqual(engine._resolve_rvc_root(), rvc)
68
- finally:
69
- os.environ.pop("FISHSING_WORK", None)
70
-
71
-
72
- class SmoothSeams(unittest.TestCase):
73
- @staticmethod
74
- def sine(freq, sec, amp=0.3, phase=0.0):
75
- t = np.arange(int(SR * sec)) / SR
76
- return (amp * np.sin(2 * np.pi * freq * t + phase)).reshape(-1, 1).astype(np.float32)
77
-
78
- def test_click_removed(self):
79
- # 两段同频正弦,第二段开头有 0.5 的台阶——硬拼会咔哒一声
80
- a = self.sine(440, 1.0)
81
- b = self.sine(440, 1.0) + np.float32(0.5)
82
- raw_jump = abs(float(a[-1, 0]) - float(b[0, 0]))
83
- self.assertGreater(raw_jump, 0.1) # 确实有跳变
84
- out = engine.SingEngine._smooth_seams([a.copy(), b.copy()], SR)
85
- n = int(SR * 0.05)
86
- seam = out[0][-n:] # 交叉淡化区
87
- d = np.abs(np.diff(seam[:, 0]))
88
- # 0.5 的台阶被摊到 2000 个样本上,逐样本差应只剩正弦斜率量级
89
- self.assertLess(float(np.max(d)), 0.05)
90
-
91
- def test_dynamics_preserved(self):
92
- # 安静主歌 vs 炸副歌的响度差是音乐动态,不许被拉平
93
- # (接缝淡化会把少量响侧能量混进静侧尾部,比值略降是正常物理,不许趋近 1)
94
- quiet = self.sine(440, 1.0, amp=0.02)
95
- loud = self.sine(220, 1.0, amp=0.30)
96
- out = engine.SingEngine._smooth_seams([quiet.copy(), loud.copy()], SR)
97
- r = [float(np.sqrt(np.mean(p.astype(np.float64) ** 2))) for p in out]
98
- self.assertGreater(r[1] / max(r[0], 1e-9), 5.0) # 响度差还在(完全拉平会是 ~1)
99
-
100
- def test_lengths(self):
101
- a = self.sine(440, 2.0)
102
- b = self.sine(440, 2.0)
103
- c = self.sine(440, 2.0)
104
- out = engine.SingEngine._smooth_seams([a, b, c], SR)
105
- n = int(SR * 0.05)
106
- # 每条缝损失 50ms:首片丢右侧,中片左右各丢一次,尾片丢左侧
107
- self.assertEqual(out[0].shape[0], 2 * SR)
108
- self.assertEqual(out[1].shape[0], 2 * SR - n)
109
- self.assertEqual(out[2].shape[0], 2 * SR - n)
110
-
111
- def test_single_piece_untouched(self):
112
- a = self.sine(440, 1.0)
113
- out = engine.SingEngine._smooth_seams([a.copy()], SR)
114
- self.assertTrue(np.array_equal(out[0], a))
115
-
116
-
117
- class AugmentWeightExpansion(unittest.TestCase):
118
- """trainer 的同名逻辑在这里再验一遍口径(两处共用命名约定)。"""
119
-
120
- def test_naming_matches_trainer(self):
121
- import trainer
122
- w = {"slice001.wav": 3.0}
123
- e = trainer.expand_aug_weights(w, [-2, -4])
124
- # 增强副本文件名(prepare 生成)必须能被权重表覆盖
125
- for shift in (-2, -4):
126
- self.assertIn(f"aug{shift}_slice001.wav", e)
127
-
128
-
129
- if __name__ == "__main__":
130
- unittest.main()
1
+ """引擎侧纯逻辑测试(需要 numpy + soundfile;torch/librosa 不需要)。
2
+
3
+ 跑法:python -m unittest discover -s tests -v
4
+ """
5
+ import os
6
+ import sys
7
+ import tempfile
8
+ import unittest
9
+ from pathlib import Path
10
+
11
+ ROOT = Path(__file__).resolve().parent.parent
12
+ sys.path.insert(0, str(ROOT / "worker"))
13
+
14
+ # RVC_ROOT 探测链在 import 时求值:指向一个确定的空目录,别让测试落到开发机的旧路径
15
+ _TMP = tempfile.mkdtemp(prefix="fishsing-test-")
16
+ os.environ["FISHSING_RVC_ROOT"] = _TMP
17
+
18
+ import numpy as np # noqa: E402
19
+ import engine # noqa: E402
20
+
21
+ SR = 40000
22
+
23
+
24
+ class SuggestPitch(unittest.TestCase):
25
+ def setUp(self):
26
+ self.model = {"p5": 313.0, "median": 356.0, "p95": 477.0}
27
+
28
+ def test_female_source_stays_zero(self):
29
+ # 源曲低音比模型数据下限低 7.9 半音——在 8 半音容忍范围内,不移调
30
+ s = engine.SingEngine.suggest_pitch({"p5": 198.0}, self.model)
31
+ self.assertEqual(s["pitch"], 0)
32
+
33
+ def test_male_source_capped_plus6(self):
34
+ s = engine.SingEngine.suggest_pitch({"p5": 120.0}, self.model)
35
+ self.assertEqual(s["pitch"], 6)
36
+ self.assertIn("男声", s["reason"])
37
+
38
+ def test_moderate_male(self):
39
+ # 差 12.75 半音 → ceil(12.75-8)=5
40
+ s = engine.SingEngine.suggest_pitch({"p5": 150.0}, self.model)
41
+ self.assertEqual(s["pitch"], 5)
42
+
43
+ def test_way_higher_capped_minus3(self):
44
+ s = engine.SingEngine.suggest_pitch({"p5": 700.0}, self.model)
45
+ self.assertEqual(s["pitch"], -3)
46
+
47
+ def test_missing_data_zero(self):
48
+ self.assertEqual(engine.SingEngine.suggest_pitch(None, self.model)["pitch"], 0)
49
+ self.assertEqual(engine.SingEngine.suggest_pitch({"p5": 200}, None)["pitch"], 0)
50
+
51
+
52
+ class ResolveRvcRoot(unittest.TestCase):
53
+ def test_env_wins(self):
54
+ os.environ["FISHSING_RVC_ROOT"] = str(Path(_TMP) / "custom")
55
+ try:
56
+ self.assertEqual(str(engine._resolve_rvc_root()), str(Path(_TMP) / "custom"))
57
+ finally:
58
+ os.environ["FISHSING_RVC_ROOT"] = _TMP
59
+
60
+ def test_fallback_workdir_sibling(self):
61
+ os.environ.pop("FISHSING_RVC_ROOT", None)
62
+ work = Path(_TMP) / "data" / "fish-sing" / "work"
63
+ rvc = Path(_TMP) / "data" / "fish-sing" / "runtime" / "rvc"
64
+ (rvc / "assets" / "weights").mkdir(parents=True, exist_ok=True)
65
+ os.environ["FISHSING_WORK"] = str(work)
66
+ try:
67
+ self.assertEqual(engine._resolve_rvc_root(), rvc)
68
+ finally:
69
+ os.environ.pop("FISHSING_WORK", None)
70
+
71
+
72
+ class SmoothSeams(unittest.TestCase):
73
+ @staticmethod
74
+ def sine(freq, sec, amp=0.3, phase=0.0):
75
+ t = np.arange(int(SR * sec)) / SR
76
+ return (amp * np.sin(2 * np.pi * freq * t + phase)).reshape(-1, 1).astype(np.float32)
77
+
78
+ def test_click_removed(self):
79
+ # 两段同频正弦,第二段开头有 0.5 的台阶——硬拼会咔哒一声
80
+ a = self.sine(440, 1.0)
81
+ b = self.sine(440, 1.0) + np.float32(0.5)
82
+ raw_jump = abs(float(a[-1, 0]) - float(b[0, 0]))
83
+ self.assertGreater(raw_jump, 0.1) # 确实有跳变
84
+ out = engine.SingEngine._smooth_seams([a.copy(), b.copy()], SR)
85
+ n = int(SR * 0.05)
86
+ seam = out[0][-n:] # 交叉淡化区
87
+ d = np.abs(np.diff(seam[:, 0]))
88
+ # 0.5 的台阶被摊到 2000 个样本上,逐样本差应只剩正弦斜率量级
89
+ self.assertLess(float(np.max(d)), 0.05)
90
+
91
+ def test_dynamics_preserved(self):
92
+ # 安静主歌 vs 炸副歌的响度差是音乐动态,不许被拉平
93
+ # (接缝淡化会把少量响侧能量混进静侧尾部,比值略降是正常物理,不许趋近 1)
94
+ quiet = self.sine(440, 1.0, amp=0.02)
95
+ loud = self.sine(220, 1.0, amp=0.30)
96
+ out = engine.SingEngine._smooth_seams([quiet.copy(), loud.copy()], SR)
97
+ r = [float(np.sqrt(np.mean(p.astype(np.float64) ** 2))) for p in out]
98
+ self.assertGreater(r[1] / max(r[0], 1e-9), 5.0) # 响度差还在(完全拉平会是 ~1)
99
+
100
+ def test_lengths_preserved(self):
101
+ # 接缝处理**必须不改时长**:0.4.0 的重叠交叉淡化每条缝吃掉 50ms,
102
+ # 4 分半的歌人声就比伴奏快 200ms(用户实测越唱越不合拍)。
103
+ a = self.sine(440, 2.0)
104
+ b = self.sine(440, 2.0)
105
+ c = self.sine(440, 2.0)
106
+ out = engine.SingEngine._smooth_seams([a, b, c], SR)
107
+ for i in range(3):
108
+ self.assertEqual(out[i].shape[0], 2 * SR, f'第 {i} 片长度被改了')
109
+ self.assertEqual(sum(p.shape[0] for p in out), 6 * SR)
110
+
111
+ def test_single_piece_untouched(self):
112
+ a = self.sine(440, 1.0)
113
+ out = engine.SingEngine._smooth_seams([a.copy()], SR)
114
+ self.assertTrue(np.array_equal(out[0], a))
115
+
116
+
117
+ class AugmentWeightExpansion(unittest.TestCase):
118
+ """trainer 的同名逻辑在这里再验一遍口径(两处共用命名约定)。"""
119
+
120
+ def test_naming_matches_trainer(self):
121
+ import trainer
122
+ w = {"slice001.wav": 3.0}
123
+ e = trainer.expand_aug_weights(w, [-2, -4])
124
+ # 增强副本文件名(prepare 生成)必须能被权重表覆盖
125
+ for shift in (-2, -4):
126
+ self.assertIn(f"aug{shift}_slice001.wav", e)
127
+
128
+
129
+ if __name__ == "__main__":
130
+ unittest.main()
package/worker/engine.py CHANGED
@@ -557,26 +557,28 @@ class SingEngine:
557
557
  shutil.rmtree(tmp, ignore_errors=True)
558
558
 
559
559
  @staticmethod
560
- def _smooth_seams(pieces: list, out_sr: int, *, fade_ms: int = 50) -> list:
560
+ def _smooth_seams(pieces: list, out_sr: int, *, fade_ms: int = 8) -> list:
561
561
  """
562
562
  分片接缝处理:各片独立推理,片边容易有响度跳变和相位不连续(听感是
563
563
  "接缝处咯噔一下")。
564
564
 
565
- 只做边界 50ms 线性交叉淡化——相邻片是连续时间轴上切开的,把跳变摊到
566
- 50ms 里就听不出来了。**不做**片间响度归一:55 秒一片的歌,安静主歌和
567
- 炸副歌的响度差是音乐本身的动态,拉平会毁掉听感(本地实测教训)。
565
+ **绝不改时长**:只做边界等长的淡出/淡入(各 fade_ms),一个样本都不删。
566
+ 0.4.0 第一版用的是"重叠交叉淡化",每条缝吃掉 50ms——4 分半的歌 4 条缝
567
+ 就少 200ms,人声比伴奏越唱越快(用户实测"越到后面越不合拍")。改成等长
568
+ 淡化后,既压住爆音,时长又精确对齐伴奏。
569
+ **也不做**片间响度归一:主歌/副歌的响度差是音乐动态,拉平会毁听感。
568
570
  """
569
571
  if len(pieces) < 2:
570
572
  return pieces
571
573
  n = int(out_sr * fade_ms / 1000)
572
- if n > 0:
573
- w = np.linspace(0.0, 1.0, n).reshape(-1, 1)
574
- for i in range(1, len(pieces)):
575
- a, b = pieces[i - 1], pieces[i]
576
- if a.shape[0] > n and b.shape[0] > n:
577
- seam = a[-n:] * (1 - w) + b[:n] * w
578
- pieces[i - 1] = np.concatenate([a[:-n], seam], axis=0)
579
- pieces[i] = b[n:]
574
+ if n <= 0:
575
+ return pieces
576
+ ramp = np.linspace(0.0, 1.0, n).reshape(-1, 1)
577
+ for i in range(1, len(pieces)):
578
+ a, b = pieces[i - 1], pieces[i]
579
+ if a.shape[0] > n and b.shape[0] > n:
580
+ pieces[i - 1] = np.concatenate([a[:-n], a[-n:] * (1.0 - ramp)], axis=0) # 尾巴淡出
581
+ pieces[i] = np.concatenate([b[:n] * ramp, b[n:]], axis=0) # 开头淡入
580
582
  return pieces
581
583
 
582
584
  # -- 混音 ------------------------------------------------------