cortico-world-fish-sing 0.4.11 → 0.4.12

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,13 @@
2
2
 
3
3
  格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循语义化。
4
4
 
5
+ ## [0.4.12] - 2026-11-03
6
+
7
+ ### 修复
8
+ - **变调只改人声、伴奏留在原调**:pitch≠0 时人声被移调、伴奏却不动,两者相差 N 个半音(三全音是最刺耳的那档)。听感是「这版听着怪、说不上哪儿不对」,唱男声歌几乎必中(自动变调会给 +6)。现在**伴奏同步变调**(`asetrate` + `aresample` + `atempo`,保持时长),整首歌一起移调,等于正常的升调/降调翻唱。
9
+ - 用户实测确认:同一段《山丘》+6,B 版(伴奏一起移)明显更好听。
10
+ - 新增单测:变调滤镜的倍率必须等于 2^(n/12)、atempo 必须是其倒数。
11
+
5
12
  ## [0.4.11] - 2026-11-03
6
13
 
7
14
  ### 修复
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-fish-sing",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -126,5 +126,17 @@ class AugmentWeightExpansion(unittest.TestCase):
126
126
  self.assertIn(f"aug{shift}_slice001.wav", e)
127
127
 
128
128
 
129
+ def test_pitch_shift_filter_keeps_ratio(self):
130
+ # 变调滤镜:asetrate 的倍率必须等于 2^(n/12),atempo 必须是它的倒数(保时长)
131
+ import re as _re
132
+ for semi in (6, -5, 3):
133
+ flt = engine.SingEngine.pitch_shift_filter(44100, semi)
134
+ m = _re.search(r'asetrate=(\d+)', flt)
135
+ t = _re.search(r'atempo=([\d.]+)', flt)
136
+ self.assertIsNotNone(m, flt)
137
+ ratio = int(m.group(1)) / 44100
138
+ self.assertAlmostEqual(ratio, 2 ** (semi / 12), places=3)
139
+ self.assertAlmostEqual(float(t.group(1)), 1 / ratio, places=3)
140
+
129
141
  if __name__ == "__main__":
130
142
  unittest.main()
package/worker/engine.py CHANGED
@@ -746,9 +746,22 @@ class SingEngine:
746
746
  shutil.copyfile(conv, out)
747
747
  mix_info = {"sr": info["sr"], "seconds": info["seconds"]}
748
748
  else:
749
+ inst_for_mix = inst
750
+ if pitch and inst is not None:
751
+ # 整体变调:伴奏必须跟着一起移,否则人声和伴奏差 N 个半音。
752
+ # (0.4.12 之前的真实问题:pitch≠0 时"听着怪但说不出哪不对",
753
+ # 唱男声歌几乎必中——自动变调会给 +6,伴奏却一直在原调。)
754
+ report(0.82, f"伴奏同步变调 {pitch:+d} 半音")
755
+ inst_for_mix = work / "inst_shifted.wav"
756
+ try:
757
+ sr_i = int(sf.info(str(inst)).samplerate)
758
+ except Exception: # noqa: BLE001
759
+ sr_i = 44100
760
+ run_ff([FFMPEG, "-y", "-hide_banner", "-loglevel", "error", "-i", str(inst),
761
+ "-af", self.pitch_shift_filter(sr_i, pitch), str(inst_for_mix)])
749
762
  report(0.85, "混音")
750
763
  out = work / "result.wav"
751
- mix_info = self.mix(conv, inst, out)
764
+ mix_info = self.mix(conv, inst_for_mix, out)
752
765
 
753
766
  report(1.0, "完成")
754
767
  result = {
@@ -764,6 +777,17 @@ class SingEngine:
764
777
  result["pitchSuggest"] = suggestion
765
778
  return result
766
779
 
780
+ @staticmethod
781
+ def pitch_shift_filter(sr: int, semitones: float) -> str:
782
+ """
783
+ 变调但**保持时长**的 ffmpeg 滤镜串。
784
+
785
+ asetrate 改采样率等价于"升调+加速",所以后面必须用 atempo 把时长拉回来
786
+ (atempo=1/factor)。这样人声/伴奏都能整段移调而不改变节奏。
787
+ """
788
+ f = 2.0 ** (float(semitones) / 12.0)
789
+ return f"asetrate={int(round(sr * f))},aresample={sr},atempo={1.0 / f:.6f}"
790
+
767
791
  # -- 选模对比试听 -----------------------------------------------
768
792
 
769
793
  def ab_test(self, test: Path, out_dir: Path, variants: list, *, pitch: int = 0,