@oxiaom/adoremix 1.0.57 → 1.0.59

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxiaom/adoremix",
3
- "version": "1.0.57",
3
+ "version": "1.0.59",
4
4
  "description": "AdoreMix broadcast server - cross-platform installer, runner and service manager",
5
5
  "bin": {
6
6
  "adoremix": "./bin/adoremix.js"
package/src/cli.js CHANGED
@@ -512,11 +512,12 @@ function buildProgram() {
512
512
 
513
513
  audio8
514
514
  .command('fetch-model [url]')
515
- .description('单独下载 Audio8 TTS 模型(572MB 0.1B INT8)到 /root/audio8/model/,与 audio8 install 解耦避免 install 卡住')
516
- .action(async (url) => {
515
+ .description('单独下载 Audio8 TTS 模型(核心 ~423MB)到 ~/audio8/onnx_runtime/model/,与 audio8 install 解耦避免 install 卡住')
516
+ .option('--registration', '同时下载声音克隆注册子模型(约 +396MB,基础 TTS 不需要)')
517
+ .action(async (url, opts) => {
517
518
  const mod = require('../tts/providers/audio8');
518
519
  try {
519
- process.exitCode = await mod.fetchModel({ url });
520
+ process.exitCode = await mod.fetchModel({ url, registration: !!opts.registration });
520
521
  } catch (e) {
521
522
  logger.error(e.message);
522
523
  process.exitCode = 1;
@@ -527,10 +528,11 @@ function buildProgram() {
527
528
  program
528
529
  .command('audio8-fetch-model [url]')
529
530
  .description('下载 Audio8 TTS 模型(单独使用,不依赖 audio8 install)')
530
- .action(async (url) => {
531
+ .option('--registration', '同时下载声音克隆注册子模型(约 +396MB,基础 TTS 不需要)')
532
+ .action(async (url, opts) => {
531
533
  const mod = require('../tts/providers/audio8');
532
534
  try {
533
- process.exitCode = await mod.fetchModel({ url });
535
+ process.exitCode = await mod.fetchModel({ url, registration: !!opts.registration });
534
536
  } catch (e) {
535
537
  logger.error(e.message);
536
538
  process.exitCode = 1;
@@ -319,8 +319,21 @@ function install(opts) {
319
319
  if (fs.existsSync(BUNDLED_TARBALL)) {
320
320
  try {
321
321
  logger.log('=== 使用主包内置 Audio8_TTS tarball(离线) ===');
322
- execSync(`rm -rf ~/audio8 && mkdir -p ~/audio8 && tar xzf "${BUNDLED_TARBALL}" --strip-components=1 -C ~/audio8 && ls ~/audio8 | head -3`, { stdio: 'inherit', shell: '/bin/bash' });
323
- cloned = true;
322
+ // tarball 可能带 1~2 层包装目录(如 audio8src/Audio8_TTS-master/)。
323
+ // 不用 --strip-components(层数不定),解压后在 ~/audio8 里循环平仓:
324
+ // 只要目录下只有一个子目录且还看不到 onnx_runtime/,就把子目录内容上提,最多 3 层。
325
+ execSync(`rm -rf ~/audio8 && mkdir -p ~/audio8 && tar xzf "${BUNDLED_TARBALL}" -C ~/audio8 && ` +
326
+ `cd ~/audio8 && for i in 1 2 3; do ` +
327
+ `[ -f onnx_runtime/requirements.txt ] && break; ` +
328
+ `single=$(ls -A | wc -l); [ "$single" = "1" ] || break; ` +
329
+ `d=$(ls -A); [ -d "$d" ] || break; ` +
330
+ `mv "$d"/* . 2>/dev/null; mv "$d"/.[!.]* . 2>/dev/null; rmdir "$d" 2>/dev/null || true; ` +
331
+ `done; ls ~/audio8 | head -5`, { stdio: 'inherit', shell: '/bin/bash' });
332
+ // 平仓后必须能看到 onnx_runtime/requirements.txt,否则视为解压失败
333
+ const flat = execSync('[ -f ~/audio8/onnx_runtime/requirements.txt ] && echo OK || echo MISSING',
334
+ { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
335
+ if (flat === 'OK') cloned = true;
336
+ else logger.warn('内置 tarball 解压后未找到 onnx_runtime/requirements.txt(目录层级异常)');
324
337
  } catch (e) {
325
338
  logger.warn('内置 tarball 解压失败:' + e.message);
326
339
  }
@@ -365,16 +378,38 @@ function install(opts) {
365
378
  logger.warn('解决:手动在 ~/audio8 下放好 Audio8_TTS 源码再重试 install');
366
379
  return 1;
367
380
  }
381
+ // 统一校验目录结构(git clone 路径也可能带包装目录)
382
+ const layoutOk = execSync('[ -f ~/audio8/onnx_runtime/requirements.txt ] && echo OK || echo MISSING',
383
+ { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
384
+ if (layoutOk !== 'OK') {
385
+ logger.error('~/audio8 目录结构异常:未找到 onnx_runtime/requirements.txt(可能多了包装目录)');
386
+ logger.log('当前内容: ' + execSync('ls ~/audio8', { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim().replace(/\n/g, ' '));
387
+ return 1;
388
+ }
368
389
 
369
390
  // venv + pip install(Python 3.11+,numpy 2.4.3 需要)
391
+ // venv 路径必须与 AUDIO8_VENV_DIR/buildSystemdUnit 一致(~/audio8/onnx_runtime/.venv),
392
+ // 否则 systemd ExecStart 指向不存在的解释器,服务起不来
370
393
  const pyBase = (function(){
371
394
  try { execSync('command -v python3.11 2>/dev/null', { shell: '/bin/bash', stdio: 'pipe' }); return 'python3.11'; }
372
395
  catch (e) { return 'python3'; }
373
396
  })();
397
+ const venvDir = AUDIO8_VENV_DIR.replace(/^~/, os.homedir());
374
398
  try {
375
399
  logger.log('=== 创建 venv 并安装 Python 依赖(首次需 5-10 分钟下载 torch 等,Python=' + pyBase + ')===');
376
- execSync(`${pyBase} -m venv ~/.audio8_venv`, { stdio: 'inherit', shell: '/bin/bash' });
377
- execSync(`source ~/.audio8_venv/bin/activate && pip install -U pip --quiet && pip install -r ~/audio8/onnx_runtime/requirements.txt --quiet`, { stdio: 'inherit', shell: '/bin/bash' });
400
+ execSync(`${pyBase} -m venv ${venvDir}`, { stdio: 'inherit', shell: '/bin/bash' });
401
+ // torch 等大包走清华镜像(国内/公司网下官方 PyPI 常超时),失败再回退官方源。
402
+ // requirements.txt 缺 tokenizers(Audio8 运行需要),补装。
403
+ const pipCmd = (idx) =>
404
+ `source ${venvDir}/bin/activate && pip install -U pip --quiet && ` +
405
+ `pip install -r ~/audio8/onnx_runtime/requirements.txt --quiet ${idx} && ` +
406
+ `pip install tokenizers --quiet ${idx}`;
407
+ try {
408
+ execSync(pipCmd('--index-url https://pypi.tuna.tsinghua.edu.cn/simple'), { stdio: 'inherit', shell: '/bin/bash' });
409
+ } catch (e) {
410
+ logger.warn('清华镜像安装失败,回退官方 PyPI 重试: ' + String(e.message).slice(0, 150));
411
+ execSync(pipCmd(''), { stdio: 'inherit', shell: '/bin/bash' });
412
+ }
378
413
  } catch (e) {
379
414
  logger.error('Python 依赖安装失败: ' + e.message.slice(0, 200));
380
415
  return 1;
@@ -391,8 +426,12 @@ function install(opts) {
391
426
  return 1;
392
427
  }
393
428
 
394
- // 等服务健康(含下载 572MB 模型,冷启动最多 60s)
395
- logger.log('=== 等待服务健康(首次启动要下载 ~572MB 模型,最多 60 秒)===');
429
+ // 等服务健康(模型单独用 audio8-fetch-model 下载,未下模型时服务起不来是预期)
430
+ const modelReady = fs.existsSync(path.join(os.homedir(), 'audio8', 'onnx_runtime', 'model', 'runtime_manifest.json'));
431
+ if (!modelReady) {
432
+ logger.warn('模型未下载(' + (cloned ? '正常,模型与 install 解耦' : '') + '): 先执行 adoremix audio8-fetch-model 下载 ~423MB 模型,再 systemctl restart ' + AUDIO8_SYSTEMD_NAME);
433
+ }
434
+ logger.log('=== 等待服务健康(最多 60 秒)===');
396
435
  let ok = false;
397
436
  for (let i = 1; i <= 30; i++) {
398
437
  try {
@@ -404,8 +443,8 @@ function install(opts) {
404
443
  execSync('sleep 2', { stdio: 'pipe', shell: '/bin/bash' });
405
444
  }
406
445
  if (!ok) {
407
- logger.warn('60 秒内未就绪,请手动 systemctl status ' + AUDIO8_SYSTEMD_NAME);
408
- logger.log('也可直接前台启动测试: source ~/.audio8_venv/bin/activate && python -m arktts_runtime.service --model-dir ~/audio8/model --voices-dir ~/audio8/model/voices --port ' + AUDIO8_DEFAULT_PORT);
446
+ logger.warn('60 秒内未就绪: ' + (modelReady ? '请手动 systemctl status ' + AUDIO8_SYSTEMD_NAME : '模型缺失所致,先跑 adoremix audio8-fetch-model'));
447
+ logger.log('前台排查: cd ~/audio8/onnx_runtime && .venv/bin/' + pyBase + ' -m arktts_runtime.service --model-dir ./model --voices-dir ./model/voices --port ' + AUDIO8_DEFAULT_PORT);
409
448
  }
410
449
 
411
450
  // 改本地 config.ini
@@ -432,7 +471,7 @@ function uninstall(opts) {
432
471
  execSync(`systemctl --now disable ${AUDIO8_SYSTEMD_NAME} 2>/dev/null; true`, { stdio: 'pipe', shell: '/bin/bash' });
433
472
  execSync(`systemctl stop ${AUDIO8_SYSTEMD_NAME} 2>/dev/null; true`, { stdio: 'pipe', shell: '/bin/bash' });
434
473
  execSync(`rm -f ${AUDIO8_SYSTEMD_PATH} && systemctl daemon-reload`, { stdio: 'pipe', shell: '/bin/bash' });
435
- execSync(`rm -rf ~/audio8 ~/audio8_venv`, { stdio: 'pipe', shell: '/bin/bash' });
474
+ execSync(`rm -rf ~/audio8 ~/audio8_venv ~/.audio8_venv`, { stdio: 'pipe', shell: '/bin/bash' });
436
475
  execSync(`rm -rf ~/.cache/huggingface/hub/models--Audio8*`, { stdio: 'pipe', shell: '/bin/bash' });
437
476
  } catch (e) {
438
477
  logger.warn('uninstall 清理部分出错: ' + e.message);
@@ -471,66 +510,121 @@ async function status(opts) {
471
510
  }
472
511
  }
473
512
 
474
- module.exports = { synthesize, checkDeps, VOICES, DEFAULT_BASE_URL, install, uninstall, status, fetchModel };
513
+ module.exports = { synthesize, checkDeps, VOICES, DEFAULT_BASE_URL, install, uninstall, status, fetchModel, downloadTo };
475
514
 
476
515
  // === fetchModel: 单独下载 Audio8 TTS 模型 ===
477
- // 默认 URL:HuggingFace 0.1B INT8(~572MB,公司网差可改为自家 OSS 链接)
478
- const MODEL_DEFAULT_URL = process.env.ADOREMIX_AUDIO8_MODEL_URL
479
- || 'https://huggingface.co/Audio8/audio8-TTS-0.1B-ONNX-INT8/resolve/main/';
480
- // 模型要的所有文件(必须下完整,Audio8 启动会校验)
516
+ // 源优先级:环境变量/参数指定 > hf-mirror.com(国内可达) > huggingface.co(官方,国内常被墙)
517
+ // 自托管:把 6 个文件传到自己服务器后 ADOREMIX_AUDIO8_MODEL_URL=https://your-host/xxx/ 或
518
+ // adoremix audio8-fetch-model https://your-host/xxx/
519
+ const MODEL_DEFAULT_URLS = process.env.ADOREMIX_AUDIO8_MODEL_URL
520
+ ? [process.env.ADOREMIX_AUDIO8_MODEL_URL]
521
+ : [
522
+ 'https://hf-mirror.com/Audio8/audio8-TTS-0.1B-ONNX-INT8/resolve/main/',
523
+ 'https://huggingface.co/Audio8/audio8-TTS-0.1B-ONNX-INT8/resolve/main/'
524
+ ];
525
+ // 模型文件清单(以仓库 runtime_manifest.json 为准,2026-10 核对)
526
+ // 核心运行文件 ~423MB;registration/ 子目录是声音克隆注册子模型(+396MB),基础 TTS 不需要
481
527
  const MODEL_FILES = [
482
- 'config.json', 'tokenizer.json', 'tokenizer_config.json', 'special_tokens_map.json',
483
- 'model.onnx', 'model.onnx.data'
528
+ 'runtime_manifest.json',
529
+ 'config.json',
530
+ 'reference_codes.npy',
531
+ 'codec_decoder_fp16.onnx',
532
+ 'codec_decoder_fp16.onnx.data',
533
+ 'slow_ar_int8.onnx',
534
+ 'slow_ar_int8.onnx.data',
535
+ 'fast_ar_int8.onnx',
536
+ 'fast_ar_int8.onnx.data',
537
+ 'tokenizer/tokenizer.json'
538
+ ];
539
+ const MODEL_REGISTRATION_FILES = [
540
+ 'registration/registration_manifest.json',
541
+ 'registration/codec_encoder_fp16.onnx',
542
+ 'registration/codec_encoder_fp16.onnx.data'
484
543
  ];
485
544
 
486
- async function downloadOne(baseUrl, file, targetDir, log) {
487
- const url = baseUrl.replace(/\/$/, '') + '/' + file;
488
- const target = path.join(targetDir, file);
545
+ // 下载单文件到 target。HF 风格 /resolve/ 会 301/302/307/308 跳 CDN,
546
+ // Node 的 http.get 不自动跟随重定向,必须手动跳(最多 5 跳)。
547
+ function downloadTo(url, target, file) {
489
548
  return new Promise((resolve, reject) => {
490
- const lib = url.startsWith('https:') ? require('https') : require('http');
491
- const req = lib.get(url, response => {
492
- if (response.statusCode !== 200) {
493
- response.resume();
494
- return reject(new Error(file + ' HTTP ' + response.statusCode));
495
- }
496
- const ws = require('fs').createWriteStream(target);
497
- response.pipe(ws);
498
- ws.on('finish', () => ws.close(() => resolve(file)));
499
- ws.on('error', reject);
500
- });
501
- req.on('error', reject);
502
- req.setTimeout(600000, () => req.destroy(new Error(file + ' timeout (10min)')));
549
+ const get = (u, hops) => {
550
+ if (hops > 5) return reject(new Error(file + ' 重定向超过 5 跳'));
551
+ const lib = u.startsWith('https:') ? https : http;
552
+ const req = lib.get(u, response => {
553
+ if ([301, 302, 303, 307, 308].indexOf(response.statusCode) >= 0) {
554
+ const loc = response.headers.location;
555
+ response.resume();
556
+ if (!loc) return reject(new Error(file + ' 重定向缺少 Location'));
557
+ return get(new URL(loc, u).href, hops + 1);
558
+ }
559
+ if (response.statusCode !== 200) {
560
+ response.resume();
561
+ return reject(new Error('HTTP ' + response.statusCode));
562
+ }
563
+ const total = parseInt(response.headers['content-length'] || '0', 10);
564
+ const ws = fs.createWriteStream(target);
565
+ let got = 0, lastLog = 0;
566
+ response.on('data', c => {
567
+ got += c.length;
568
+ // 大文件(model.onnx.data ~572MB)每 100MB 报一次进度,避免长时间无输出像卡死
569
+ if (got - lastLog >= 100 * 1024 * 1024) {
570
+ lastLog = got;
571
+ logger.log(` ${file}: ${(got / 1048576).toFixed(0)}MB` + (total ? ` / ${(total / 1048576).toFixed(0)}MB` : ''));
572
+ }
573
+ });
574
+ response.pipe(ws);
575
+ ws.on('finish', () => ws.close(() => resolve({ file, got, total })));
576
+ ws.on('error', reject);
577
+ });
578
+ req.on('error', reject);
579
+ // 10 分钟超时:572MB 在 ≥1MB/s 的链路上够用
580
+ req.setTimeout(600000, () => req.destroy(new Error(file + ' 超时(10min)')));
581
+ };
582
+ get(url, 0);
503
583
  });
504
584
  }
505
585
 
506
586
  async function fetchModel(opts) {
507
587
  opts = opts || {};
508
- const targetDir = process.env.ADOREMIX_AUDIO8_MODEL_DIR || '/root/audio8/model';
509
- const baseUrl = opts.url || MODEL_DEFAULT_URL;
510
- const log = (m) => console.log(m);
511
-
512
- log('Audio8 模型下载 → ' + targetDir);
513
- log('源 URL: ' + baseUrl);
514
- if (!baseUrl.endsWith('/') && !baseUrl.includes('resolve/main')) {
515
- log(' (URL 应以 /resolve/main/ 结尾,自动补)');
516
- }
517
- require('fs').mkdirSync(targetDir, { recursive: true });
588
+ // 目标目录必须与 systemd 单元一致(WorkingDirectory=~/audio8/onnx_runtime + --model-dir ./model)
589
+ const targetDir = process.env.ADOREMIX_AUDIO8_MODEL_DIR
590
+ || path.join(os.homedir(), 'audio8', 'onnx_runtime', 'model');
591
+ const baseUrls = opts.url ? [opts.url] : MODEL_DEFAULT_URLS;
592
+ // --registration / ADOREMIX_AUDIO8_WITH_REGISTRATION=1 时追加声音克隆注册子模型(+396MB)
593
+ const files = (opts.registration || process.env.ADOREMIX_AUDIO8_WITH_REGISTRATION === '1')
594
+ ? MODEL_FILES.concat(MODEL_REGISTRATION_FILES) : MODEL_FILES;
595
+
596
+ logger.log('Audio8 模型下载 → ' + targetDir);
597
+ fs.mkdirSync(targetDir, { recursive: true });
518
598
 
519
599
  let ok = 0, fail = 0;
520
- for (const f of MODEL_FILES) {
521
- try {
522
- log(' → ' + f + ' ...');
523
- await downloadOne(baseUrl, targetDir, f, log);
524
- ok++;
525
- } catch (e) {
526
- log(' ✗ ' + f + ' 失败: ' + e.message);
600
+ for (const f of files) {
601
+ let done = false, lastErr = null;
602
+ // 文件清单含子目录(如 tokenizer/tokenizer.json),先建父目录
603
+ const target = path.join(targetDir, f);
604
+ fs.mkdirSync(path.dirname(target), { recursive: true });
605
+ for (const base of baseUrls) {
606
+ try {
607
+ logger.log(` → ${f}(源 ${new URL(base).host})`);
608
+ const r = await downloadTo(base.replace(/\/+$/, '') + '/' + f, target, f);
609
+ logger.log(` ✓ ${f} 完成 ${(r.got / 1048576).toFixed(1)}MB`);
610
+ done = true;
611
+ break;
612
+ } catch (e) {
613
+ lastErr = e;
614
+ logger.warn(` ✗ 源 ${new URL(base).host} 失败: ${e.message}`);
615
+ }
616
+ }
617
+ if (done) { ok++; }
618
+ else {
527
619
  fail++;
620
+ logger.error(` ✗ ${f} 所有源均失败: ${lastErr ? lastErr.message : '未知错误'}`);
528
621
  }
529
622
  }
530
623
  if (fail > 0) {
531
- log('失败 ' + fail + ' 个,模型可能不完整(重启 Audio8 会报错)');
624
+ logger.error(`失败 ${fail} 个文件,模型不完整。可换源自试: adoremix audio8-fetch-model <url>/`);
532
625
  return 1;
533
626
  }
534
- log('✓ Audio8 模型就绪(' + ok + ' 个文件):' + targetDir);
627
+ logger.ok(`Audio8 模型就绪(${ok} 个文件): ${targetDir}`);
628
+ logger.log('重启服务生效: systemctl restart audio8-tts');
535
629
  return 0;
536
630
  }