@oxiaom/adoremix 1.0.57 → 1.0.58

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.58",
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;
@@ -471,66 +471,121 @@ async function status(opts) {
471
471
  }
472
472
  }
473
473
 
474
- module.exports = { synthesize, checkDeps, VOICES, DEFAULT_BASE_URL, install, uninstall, status, fetchModel };
474
+ module.exports = { synthesize, checkDeps, VOICES, DEFAULT_BASE_URL, install, uninstall, status, fetchModel, downloadTo };
475
475
 
476
476
  // === 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 启动会校验)
477
+ // 源优先级:环境变量/参数指定 > hf-mirror.com(国内可达) > huggingface.co(官方,国内常被墙)
478
+ // 自托管:把 6 个文件传到自己服务器后 ADOREMIX_AUDIO8_MODEL_URL=https://your-host/xxx/ 或
479
+ // adoremix audio8-fetch-model https://your-host/xxx/
480
+ const MODEL_DEFAULT_URLS = process.env.ADOREMIX_AUDIO8_MODEL_URL
481
+ ? [process.env.ADOREMIX_AUDIO8_MODEL_URL]
482
+ : [
483
+ 'https://hf-mirror.com/Audio8/audio8-TTS-0.1B-ONNX-INT8/resolve/main/',
484
+ 'https://huggingface.co/Audio8/audio8-TTS-0.1B-ONNX-INT8/resolve/main/'
485
+ ];
486
+ // 模型文件清单(以仓库 runtime_manifest.json 为准,2026-10 核对)
487
+ // 核心运行文件 ~423MB;registration/ 子目录是声音克隆注册子模型(+396MB),基础 TTS 不需要
481
488
  const MODEL_FILES = [
482
- 'config.json', 'tokenizer.json', 'tokenizer_config.json', 'special_tokens_map.json',
483
- 'model.onnx', 'model.onnx.data'
489
+ 'runtime_manifest.json',
490
+ 'config.json',
491
+ 'reference_codes.npy',
492
+ 'codec_decoder_fp16.onnx',
493
+ 'codec_decoder_fp16.onnx.data',
494
+ 'slow_ar_int8.onnx',
495
+ 'slow_ar_int8.onnx.data',
496
+ 'fast_ar_int8.onnx',
497
+ 'fast_ar_int8.onnx.data',
498
+ 'tokenizer/tokenizer.json'
499
+ ];
500
+ const MODEL_REGISTRATION_FILES = [
501
+ 'registration/registration_manifest.json',
502
+ 'registration/codec_encoder_fp16.onnx',
503
+ 'registration/codec_encoder_fp16.onnx.data'
484
504
  ];
485
505
 
486
- async function downloadOne(baseUrl, file, targetDir, log) {
487
- const url = baseUrl.replace(/\/$/, '') + '/' + file;
488
- const target = path.join(targetDir, file);
506
+ // 下载单文件到 target。HF 风格 /resolve/ 会 301/302/307/308 跳 CDN,
507
+ // Node 的 http.get 不自动跟随重定向,必须手动跳(最多 5 跳)。
508
+ function downloadTo(url, target, file) {
489
509
  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)')));
510
+ const get = (u, hops) => {
511
+ if (hops > 5) return reject(new Error(file + ' 重定向超过 5 跳'));
512
+ const lib = u.startsWith('https:') ? https : http;
513
+ const req = lib.get(u, response => {
514
+ if ([301, 302, 303, 307, 308].indexOf(response.statusCode) >= 0) {
515
+ const loc = response.headers.location;
516
+ response.resume();
517
+ if (!loc) return reject(new Error(file + ' 重定向缺少 Location'));
518
+ return get(new URL(loc, u).href, hops + 1);
519
+ }
520
+ if (response.statusCode !== 200) {
521
+ response.resume();
522
+ return reject(new Error('HTTP ' + response.statusCode));
523
+ }
524
+ const total = parseInt(response.headers['content-length'] || '0', 10);
525
+ const ws = fs.createWriteStream(target);
526
+ let got = 0, lastLog = 0;
527
+ response.on('data', c => {
528
+ got += c.length;
529
+ // 大文件(model.onnx.data ~572MB)每 100MB 报一次进度,避免长时间无输出像卡死
530
+ if (got - lastLog >= 100 * 1024 * 1024) {
531
+ lastLog = got;
532
+ logger.log(` ${file}: ${(got / 1048576).toFixed(0)}MB` + (total ? ` / ${(total / 1048576).toFixed(0)}MB` : ''));
533
+ }
534
+ });
535
+ response.pipe(ws);
536
+ ws.on('finish', () => ws.close(() => resolve({ file, got, total })));
537
+ ws.on('error', reject);
538
+ });
539
+ req.on('error', reject);
540
+ // 10 分钟超时:572MB 在 ≥1MB/s 的链路上够用
541
+ req.setTimeout(600000, () => req.destroy(new Error(file + ' 超时(10min)')));
542
+ };
543
+ get(url, 0);
503
544
  });
504
545
  }
505
546
 
506
547
  async function fetchModel(opts) {
507
548
  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 });
549
+ // 目标目录必须与 systemd 单元一致(WorkingDirectory=~/audio8/onnx_runtime + --model-dir ./model)
550
+ const targetDir = process.env.ADOREMIX_AUDIO8_MODEL_DIR
551
+ || path.join(os.homedir(), 'audio8', 'onnx_runtime', 'model');
552
+ const baseUrls = opts.url ? [opts.url] : MODEL_DEFAULT_URLS;
553
+ // --registration / ADOREMIX_AUDIO8_WITH_REGISTRATION=1 时追加声音克隆注册子模型(+396MB)
554
+ const files = (opts.registration || process.env.ADOREMIX_AUDIO8_WITH_REGISTRATION === '1')
555
+ ? MODEL_FILES.concat(MODEL_REGISTRATION_FILES) : MODEL_FILES;
556
+
557
+ logger.log('Audio8 模型下载 → ' + targetDir);
558
+ fs.mkdirSync(targetDir, { recursive: true });
518
559
 
519
560
  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);
561
+ for (const f of files) {
562
+ let done = false, lastErr = null;
563
+ // 文件清单含子目录(如 tokenizer/tokenizer.json),先建父目录
564
+ const target = path.join(targetDir, f);
565
+ fs.mkdirSync(path.dirname(target), { recursive: true });
566
+ for (const base of baseUrls) {
567
+ try {
568
+ logger.log(` → ${f}(源 ${new URL(base).host})`);
569
+ const r = await downloadTo(base.replace(/\/+$/, '') + '/' + f, target, f);
570
+ logger.log(` ✓ ${f} 完成 ${(r.got / 1048576).toFixed(1)}MB`);
571
+ done = true;
572
+ break;
573
+ } catch (e) {
574
+ lastErr = e;
575
+ logger.warn(` ✗ 源 ${new URL(base).host} 失败: ${e.message}`);
576
+ }
577
+ }
578
+ if (done) { ok++; }
579
+ else {
527
580
  fail++;
581
+ logger.error(` ✗ ${f} 所有源均失败: ${lastErr ? lastErr.message : '未知错误'}`);
528
582
  }
529
583
  }
530
584
  if (fail > 0) {
531
- log('失败 ' + fail + ' 个,模型可能不完整(重启 Audio8 会报错)');
585
+ logger.error(`失败 ${fail} 个文件,模型不完整。可换源自试: adoremix audio8-fetch-model <url>/`);
532
586
  return 1;
533
587
  }
534
- log('✓ Audio8 模型就绪(' + ok + ' 个文件):' + targetDir);
588
+ logger.ok(`Audio8 模型就绪(${ok} 个文件): ${targetDir}`);
589
+ logger.log('重启服务生效: systemctl restart audio8-tts');
535
590
  return 0;
536
591
  }