cortico-world-fish-sing 0.4.16 → 0.4.17

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,18 @@
2
2
 
3
3
  格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/);版本号遵循语义化。
4
4
 
5
+ ## [0.4.17] - 2026-11-03
6
+
7
+ ### 修复(来自 issue #1 与市场反馈)
8
+ - **外部 RVC 路径填错会让 Coo 直接启动不了(issue #1)**:把 python 路径填成 `…\rvc\venv`(目录)时,`existsSync` 判定为"存在",于是照样 spawn,Node 抛 `ENOENT` 的**未捕获 'error' 事件**,把 Coo 一起带走。现在:
9
+ - spawn 前校验必须是**文件**(不是目录),错误信息直接给出正确示例 `…\venv\Scripts\python.exe`;
10
+ - 给子进程挂了 `error` 处理,任何 spawn 失败都转成"这次启动失败 + warn 日志",不再崩进程。
11
+ - **人声分离在被墙环境里卡好几分钟(市场反馈:25 秒素材等了 6 分半,`HF_HUB_OFFLINE=1` 后降到 19 秒)**:demucs 的权重下载(`torch.hub`)**没有超时**,缓存一丢(重装运行时、换机器)就会去 `dl.fbaipublicfiles.com` 拉 84 MB,被墙时无限重试。现在分离前做预检:
12
+ - `socket` 默认超时压到 20 秒,联网调用不会无限挂;
13
+ - 本地已有权重 → 设 `HF_HUB_OFFLINE=1` / `TRANSFORMERS_OFFLINE=1`(部分 demucs 版本会走 huggingface_hub);
14
+ - 进度日志里明写"权重已缓存 / 首次需下载 84MB",以后有人报慢能一眼定位;
15
+ - 模型加载耗时也打进日志。
16
+
5
17
  ## [0.4.16] - 2026-11-03
6
18
 
7
19
  ### 修复
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-fish-sing",
3
- "version": "0.4.16",
3
+ "version": "0.4.17",
4
4
  "description": "让她真的开口唱:B 站点歌或本地文件 → 分离 → 换声 → 混音,本机出声或发 QQ 语音条",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/worker.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * · 它崩了不该拖垮 Coo(契约:worker 挂了只影响唱歌,不影响聊天)。
8
8
  */
9
9
  import { spawn, type ChildProcess } from 'node:child_process';
10
- import { existsSync } from 'node:fs';
10
+ import { existsSync, statSync } from 'node:fs';
11
11
  import { fileURLToPath } from 'node:url';
12
12
  import { dirname, join } from 'node:path';
13
13
 
@@ -62,6 +62,8 @@ export class WorkerClient {
62
62
  private opts: WorkerOptions;
63
63
  private readonly log: LoggerLike;
64
64
  private child: ChildProcess | null = null;
65
+ /** spawn 失败的原因(路径是目录、权限不足…),报错时带上它 */
66
+ private spawnError: Error | null = null;
65
67
  private starting: Promise<void> | null = null;
66
68
  /** 上次拉起的时间戳,防止「起不来 → 每次调用都重试 → 疯狂 spawn」。 */
67
69
  private lastSpawnAt = 0;
@@ -135,6 +137,18 @@ export class WorkerClient {
135
137
  if (!existsSync(this.opts.pythonPath)) {
136
138
  return Promise.reject(new Error(`找不到 python:${this.opts.pythonPath}(配置 → 运行时)`));
137
139
  }
140
+ try {
141
+ // 只判断存在不够:填成 venv 目录时 existsSync 也是 true,spawn 才报 ENOENT,
142
+ // 而 ENOENT 是未捕获的 'error' 事件——会把 Coo 一起带走(issue #1)。
143
+ if (!statSync(this.opts.pythonPath).isFile()) {
144
+ return Promise.reject(new Error(
145
+ `python 路径不是一个文件:${this.opts.pythonPath}\n`
146
+ + '应该指向 venv 里的解释器,例如 …\\venv\\Scripts\\python.exe',
147
+ ));
148
+ }
149
+ } catch {
150
+ /* stat 失败就交给 spawn 的 error 处理 */
151
+ }
138
152
  const env: Record<string, string> = {
139
153
  ...(process.env as Record<string, string>),
140
154
  FISHSING_PORT: String(this.opts.port),
@@ -174,12 +188,25 @@ export class WorkerClient {
174
188
  this.maybeRestart();
175
189
  });
176
190
  this.child = child;
191
+ // spawn 的 'error'(二进制损坏、权限不足、路径是目录)不处理就是未捕获事件,
192
+ // Node 会直接抛出去把 Coo 干掉(issue #1)。这里接住,转成一次失败的重试。
193
+ child.on('error', (e: Error) => {
194
+ this.spawnError = e;
195
+ this.log.warn(
196
+ `worker 起不来:${e.message}` + '(配置 → 运行时:python 应指向 …\\venv\\Scripts\\python.exe,不是 venv 目录)',
197
+ );
198
+ if (this.child === child) this.child = null;
199
+ });
177
200
 
178
201
  const deadline = Date.now() + this.opts.startTimeoutMs;
179
202
  return new Promise<void>((resolve, reject) => {
180
203
  const tick = async (): Promise<void> => {
181
204
  if (this.child === null) {
182
- reject(new Error('worker 启动后立刻退出了,看日志里的 [worker:err]'));
205
+ reject(new Error(
206
+ this.spawnError
207
+ ? `worker 起不来:${this.spawnError.message}`
208
+ : 'worker 启动后立刻退出了,看日志里的 [worker:err]',
209
+ ));
183
210
  return;
184
211
  }
185
212
  const h = await this.health(1500);
@@ -23,6 +23,43 @@ import torchaudio
23
23
  from demucs.apply import apply_model
24
24
  from demucs.pretrained import get_model
25
25
 
26
+ # htdemucs 的权重文件名(torch.hub 缓存目录下的名字)
27
+ _DEMUCS_CKPT = "955717e8-8726e21a.th"
28
+
29
+
30
+ def _ckpt_dir():
31
+ base = os.environ.get("TORCH_HOME") or os.path.join(os.path.expanduser("~"), ".cache", "torch")
32
+ return os.path.join(base, "hub", "checkpoints")
33
+
34
+
35
+ def _preflight_weights(model_name, say=None):
36
+ """分离权重预检:本地有就直接用,没有才下载,而且**限时**。
37
+
38
+ 为什么要有这一步:torch.hub 的下载函数没有超时。缓存丢了的机器(重装运行时、
39
+ HOME/用户变了、换机器)会去 dl.fbaipublicfiles.com 拉 84 MB,被墙时一挂就是
40
+ 几分钟——用户实测 25 秒素材等了 6 分半,还以为分离坏了。
41
+
42
+ 这里做三件事:
43
+ 1. socket 默认超时压到 20 秒,任何联网调用不会无限挂;
44
+ 2. 本地有缓存就把 HF 相关联网开关关掉(部分 demucs 版本会走 huggingface_hub);
45
+ 3. 把"权重在不在本地"打进进度日志,下次再有人报慢,一眼能看出是不是没缓存。
46
+ """
47
+ import socket
48
+ socket.setdefaulttimeout(20)
49
+ os.environ.setdefault("HF_HUB_DISABLE_TELEMETRY", "1")
50
+ if model_name != "htdemucs":
51
+ return
52
+ ck = os.path.join(_ckpt_dir(), _DEMUCS_CKPT)
53
+ if os.path.isfile(ck):
54
+ os.environ.setdefault("HF_HUB_OFFLINE", "1")
55
+ os.environ.setdefault("TRANSFORMERS_OFFLINE", "1")
56
+ if say:
57
+ say(f"weights cached {os.path.basename(ck)} {os.path.getsize(ck) // (1 << 20)}MB")
58
+ else:
59
+ # 没有就别设离线,让它去下;但下载有 20 秒超时兜着
60
+ if say:
61
+ say("weights MISSING 首次需下载 84MB(网络差会慢,最多等 20 秒/次)")
62
+
26
63
 
27
64
  def _decode_44100(path):
28
65
  """解码成 (2, n) float32 的 44.1 kHz 立体声。
@@ -61,8 +98,11 @@ def separate_file(src, out_dir, device="auto", model_name="htdemucs", overlap=0.
61
98
  say(f"loaded {data.shape} {sr} dur {data.shape[1] / sr:.1f}s")
62
99
  x = torch.from_numpy(data)
63
100
 
101
+ _preflight_weights(model_name, say)
102
+ t_model = time.time()
64
103
  model = get_model(model_name)
65
104
  model.eval()
105
+ say(f"model loaded {time.time() - t_model:.1f}s")
66
106
  say(f"model {model.sources} sr {model.samplerate}")
67
107
 
68
108
  # 按整段参考信号做均值/方差归一,输出时再还原(demucs 官方做法)