cortico-world-fish-sing 0.4.23 → 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 CHANGED
@@ -2,6 +2,17 @@
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
+
5
16
  ## [0.4.23] - 2026-11-12
6
17
 
7
18
  ### 修复
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-fish-sing",
3
- "version": "0.4.23",
3
+ "version": "0.4.24",
4
4
  "description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
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
- const missModels = st.models.filter((m) => !m.ready).length;
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);
@@ -185,5 +185,12 @@ class AugmentWeightExpansion(unittest.TestCase):
185
185
  finally:
186
186
  os.environ.pop('FISHSING_SKIP_DRY_CHECK', None)
187
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
+
188
195
  if __name__ == "__main__":
189
196
  unittest.main()
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
  )