@wocwang/cortico-world-singer-for-coopanion 0.1.21 → 0.1.22

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
@@ -1,5 +1,21 @@
1
1
  # 更新记录
2
2
 
3
+ ## 0.1.22(2026-11-16)模型下载:慢源自动切换、认代理、调整镜像顺序
4
+
5
+ **改动**
6
+
7
+ - 来源速度过低会主动放弃:起步 10 秒后按 6 秒窗口采样,平均低于 100 KB/s 就换下一个来源,
8
+ 已下部分带 `Range` 续传;最后一个来源不按速度放弃(再慢也比装不上强)。此前只有 HTTP 错误、
9
+ 截断或校验失败才切换,卡在慢源上会一直等下去。
10
+ - 认系统代理:设了 `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY`(含小写)时官方源排最前,
11
+ 不再先冲镜像。Node 的 `fetch` 本身不走系统代理,需要以 `--use-env-proxy` 启动 Coopanion
12
+ 才能让请求真正过代理(README 已写明)。
13
+ - 镜像顺序:绮萱包(401 MB)对 ghfast 稳定返回 403,改为 gh-proxy → ghproxy.net → 官方 → ghfast;
14
+ 声码器不受影响,仍是 ghfast → gh-proxy → 官方。设了代理时两者都变成官方最前。
15
+ - 语料不变:旋律与节奏代码没有改动。
16
+
17
+ 新增用例「来源速度长期过低时主动换下一个,并带 Range 续传」,全套 88 个用例通过。
18
+
3
19
  ## 0.1.21(2026-11-16)原版断句 + 新旋律(混合节奏)
4
20
 
5
21
  **改了什么**
package/README.md CHANGED
@@ -47,6 +47,16 @@ Coopanion 的 `kind: world` 插件:**让大肥鱼临场发挥、随意唱歌**
47
47
 
48
48
  装依赖前会先停引擎——worker 在跑时 `pip` 覆盖不了 venv 里的 `.pyd/.dll`。
49
49
 
50
+ 下载来源默认「镜像优先、官方兜底」:绮萱包(401 MB)实测 ghfast 稳定返回 403,顺序是
51
+ gh-proxy → ghproxy.net → 官方 → ghfast;声码器仍是 ghfast → gh-proxy → 官方。
52
+ 设了 `HTTPS_PROXY` / `HTTP_PROXY` / `ALL_PROXY` 时官方一律排最前
53
+ (代理通常已经把 GitHub 打通,不必再多跳一次镜像)。来源在起步 10 秒后按 6 秒窗口采样、
54
+ 平均速度低于 100 KB/s 就会被放弃并换下一个,已下的部分带 `Range` 续传,不会卡在慢源上;
55
+ 最后一个来源不按速度放弃(再慢也比装不上强)。
56
+ 注意 Node 的 `fetch` 不会自动走系统代理:想让请求真正经过代理,需要用 `--use-env-proxy`
57
+ 启动 Coopanion(Node 24 的实验参数);插件本身只按环境变量调整来源顺序。
58
+ 手工下载也可以:按下方文件名与字节数放进数据目录,校验大小一致就当作已下载,跳过网络。
59
+
50
60
  数据目录(`<Coopanion 数据目录>/singer/`):
51
61
 
52
62
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wocwang/cortico-world-singer-for-coopanion",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "description": "Cortico World for Coopanion: let the pet improvise a line and sing it on the spot with DiffSinger (Qixuan voicebank), optionally through RVC",
6
6
  "author": "wocwang",
package/src/catalog.ts CHANGED
@@ -5,7 +5,9 @@
5
5
  * 断点续传、校验通过才落位,然后就地解压(保留完整声库,含使用条款文件),
6
6
  * 解压完把 zip 删掉省下 451 MB。
7
7
  *
8
- * 来源顺序:第三方 GitHub 代理(国内直连 release 只有几十 KB/s)→ 官方 release。
8
+ * 来源顺序:默认镜像优先、官方兜底,个别对某资产不好使的镜像压到官方之后(绮萱包的 ghfast);
9
+ * 设了 HTTPS_PROXY / HTTP_PROXY / ALL_PROXY 时官方源一律排最前——代理通常已经把 GitHub 打通,
10
+ * 不必再多跳一次镜像。任一来源速度过低会被主动放弃并换下一个(见 install.ts)。
9
11
  */
10
12
 
11
13
  /** 绮萱声库(v2.7.0,OpenUTAU 版,ONNX)。 */
@@ -29,20 +31,35 @@ const QIXUAN_URL =
29
31
  const VOCODER_URL =
30
32
  'https://github.com/openvpi/vocoders/releases/download/pc-nsf-hifigan-44.1k-hop512-128bin-2025.02/pc_nsf_hifigan_44.1k_hop512_128bin_2025.02.oudep';
31
33
 
32
- /** GitHub 代理:按实测速度排序(ghfast 最快),最后回官方。 */
33
- const PROXIES: ReadonlyArray<(url: string) => string> = [
34
- (url) => `https://ghfast.top/${url}`,
35
- (url) => `https://gh-proxy.com/${url}`,
36
- (url) => url,
37
- ];
34
+ /** GitHub 代理;具体某个文件用哪几个、什么顺序,由 viaProxies 的调用方决定。 */
35
+ const ghfast = (url: string): string => `https://ghfast.top/${url}`;
36
+ const ghProxy = (url: string): string => `https://gh-proxy.com/${url}`;
37
+ const ghproxyNet = (url: string): string => `https://ghproxy.net/${url}`;
38
38
 
39
- const viaProxies = (url: string): string[] => PROXIES.map((wrap) => wrap(url));
39
+ const hasProxyEnv = (): boolean =>
40
+ ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'ALL_PROXY', 'all_proxy']
41
+ .some((name) => Boolean(process.env[name]));
40
42
 
43
+ /**
44
+ * 拼一个文件的来源顺序:设了代理时官方最前(其余顺序不变),否则镜像在前、官方按 `afterOfficial`
45
+ * 决定插在哪。`afterOfficial` 用来把「已知对该资产不好使」的镜像压到官方之后,避免每次白跑一趟。
46
+ */
47
+ const viaProxies = (
48
+ url: string,
49
+ mirrors: ReadonlyArray<(url: string) => string>,
50
+ afterOfficial: ReadonlyArray<(url: string) => string> = [],
51
+ ): string[] => {
52
+ const head = mirrors.map((wrap) => wrap(url));
53
+ const tail = afterOfficial.map((wrap) => wrap(url));
54
+ return hasProxyEnv() ? [url, ...head, ...tail] : [...head, url, ...tail];
55
+ };
56
+
57
+ // 绮萱这个 401 MB 的包对 ghfast 稳定返回 403:官方排在它前面,ghfast 只作最后兜底。
41
58
  export const VOICEBANK_FILE: PinnedFile = {
42
59
  path: `${VOICEBANK_NAME}.zip`,
43
60
  bytes: 420_707_627,
44
61
  sha256: 'fe8ee7c95883d327a2b7facbbe832a7a53e1344918dc791ca83fc23b08034110',
45
- sources: viaProxies(QIXUAN_URL),
62
+ sources: viaProxies(QIXUAN_URL, [ghProxy, ghproxyNet], [ghfast]),
46
63
  };
47
64
 
48
65
  /**
@@ -53,7 +70,7 @@ export const VOCODER_FILE: PinnedFile = {
53
70
  path: `${VOCODER_NAME}.oudep`,
54
71
  bytes: 52_760_610,
55
72
  sha256: 'ba7d43142d41f6900c8264b5662ca7125a50feb8760bb8b9615c61a8f5e6902e',
56
- sources: viaProxies(VOCODER_URL),
73
+ sources: viaProxies(VOCODER_URL, [ghfast, ghProxy]),
57
74
  };
58
75
 
59
76
  export const MODEL_FILES: readonly PinnedFile[] = [VOICEBANK_FILE, VOCODER_FILE];
package/src/install.ts CHANGED
@@ -54,37 +54,78 @@ export function hasFile(dir: string, file: PinnedFile): boolean {
54
54
  /** 校验失败:数据本身不对,`.partial` 必须扔掉,换下一个来源重下。 */
55
55
  class VerifyError extends Error {}
56
56
 
57
+ /** 来源太慢:保留 `.partial`,换下一个来源续传(慢不是错,但不能一直等)。 */
58
+ class SlowSourceError extends Error {}
59
+
60
+ /** 低速判定:先给一段起步时间,之后按窗口平均速度采样,低于阈值就切源。 */
61
+ const envNumber = (name: string, fallback: number): number => {
62
+ const value = Number(process.env[name]);
63
+ return Number.isFinite(value) && value > 0 ? value : fallback;
64
+ };
65
+ const MIN_BPS = (): number => envNumber('SINGER_MIN_BPS', 100 * 1024);
66
+ const GRACE_MS = (): number => envNumber('SINGER_LOW_SPEED_GRACE_MS', 10_000);
67
+ const WINDOW_MS = (): number => envNumber('SINGER_LOW_SPEED_WINDOW_MS', 6_000);
68
+
57
69
  /**
58
70
  * 把一个地址下到 `dest`;`offset > 0` 时带 `Range` 续传。
59
71
  * 服务器忽略 Range(回 200)就截断重下,保证不会把两段数据拼在一起。
72
+ * 起步后按窗口统计速度,低于阈值主动中断并抛 `SlowSourceError`,由调用方换下一个来源续传
73
+ * (最后一个来源传 `enforceSpeed = false`,不因慢而放弃)。
60
74
  */
61
- async function fetchTo(url: string, dest: string, offset: number, signal: AbortSignal): Promise<void> {
75
+ async function fetchTo(url: string, dest: string, offset: number, signal: AbortSignal, enforceSpeed: boolean): Promise<void> {
62
76
  const headers = offset > 0 ? { Range: `bytes=${offset}-` } : undefined;
63
- const res = await fetch(url, { signal, redirect: 'follow', headers });
77
+ const local = new AbortController();
78
+ const combined = AbortSignal.any([signal, local.signal]);
79
+ const res = await fetch(url, { signal: combined, redirect: 'follow', headers });
64
80
  if (res.status === 416 && offset > 0) return; // 已经下到头,交给调用方校验
65
81
  if (!res.ok || !res.body) throw new Error(`HTTP ${res.status}`);
66
82
  const append = offset > 0 && res.status === 206;
67
83
  if (!append && offset > 0) rmSync(dest, { force: true });
84
+ let received = offset;
68
85
  const counter = new Transform({
69
- transform(chunk: Buffer, _enc, done) { done(null, chunk); },
86
+ transform(chunk: Buffer, _enc, done) { received += chunk.length; done(null, chunk); },
70
87
  });
88
+ const startedAt = Date.now();
89
+ let lastAt = startedAt;
90
+ let lastBytes = received;
91
+ const monitor = setInterval(() => {
92
+ const now = Date.now();
93
+ const elapsed = (now - lastAt) / 1000;
94
+ if (enforceSpeed && now - startedAt >= GRACE_MS()) {
95
+ const bps = (received - lastBytes) / Math.max(elapsed, 0.001);
96
+ if (bps < MIN_BPS()) {
97
+ local.abort(new SlowSourceError(`速度 ${(bps / 1024).toFixed(0)} KB/s,低于 ${(MIN_BPS() / 1024).toFixed(0)} KB/s`));
98
+ return;
99
+ }
100
+ }
101
+ lastAt = now;
102
+ lastBytes = received;
103
+ }, WINDOW_MS());
71
104
  mkdirSync(dirname(dest), { recursive: true });
72
- await pipeline(Readable.fromWeb(res.body as import('node:stream/web').ReadableStream), counter, createWriteStream(dest, { flags: append ? 'a' : 'w' }), { signal });
105
+ try {
106
+ await pipeline(Readable.fromWeb(res.body as import('node:stream/web').ReadableStream), counter, createWriteStream(dest, { flags: append ? 'a' : 'w' }), { signal: combined });
107
+ } catch (err) {
108
+ if (local.signal.aborted) throw local.signal.reason ?? err;
109
+ throw err;
110
+ } finally {
111
+ clearInterval(monitor);
112
+ }
73
113
  }
74
114
 
75
- /** 按来源顺序下完一个文件;网络中断保留 `.partial` 供下次续传,校验失败则丢弃重来。 */
115
+ /** 按来源顺序下完一个文件;网络中断/速度过慢保留 `.partial` 供下一个来源续传,校验失败则丢弃重来。 */
76
116
  async function downloadFile(dir: string, file: PinnedFile, signal: AbortSignal): Promise<void> {
77
117
  const dest = join(dir, file.path);
78
118
  const partial = `${dest}.partial`;
79
119
  if (hasFile(dir, file)) return;
80
120
  mkdirSync(dirname(dest), { recursive: true });
81
121
  const errors: string[] = [];
82
- for (const url of file.sources) {
122
+ for (const [index, url] of file.sources.entries()) {
83
123
  if (signal.aborted) throw new Error('已取消');
84
124
  let offset = sizeOf(partial);
85
125
  if (offset > file.bytes) { rmSync(partial, { force: true }); offset = 0; }
86
126
  try {
87
- await fetchTo(url, partial, offset, signal);
127
+ // 最后一个来源不按速度放弃:再慢也比彻底装不上强。
128
+ await fetchTo(url, partial, offset, signal, index < file.sources.length - 1);
88
129
  const size = sizeOf(partial);
89
130
  if (size !== file.bytes) throw new VerifyError(`大小 ${size},应为 ${file.bytes}`);
90
131
  if (await sha256File(partial) !== file.sha256) throw new VerifyError('SHA-256 不符');