@oxiaom/adoremix 1.0.59 → 1.0.60

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.59",
3
+ "version": "1.0.60",
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,7 +512,7 @@ function buildProgram() {
512
512
 
513
513
  audio8
514
514
  .command('fetch-model [url]')
515
- .description('单独下载 Audio8 TTS 模型(核心 ~423MB)到 ~/audio8/onnx_runtime/model/,与 audio8 install 解耦避免 install 卡住')
515
+ .description('单独下载 Audio8 TTS 模型(核心 ~423MB)到 ~/audio8/onnx_runtime_0_1b_int8/model/,与 audio8 install 解耦避免 install 卡住')
516
516
  .option('--registration', '同时下载声音克隆注册子模型(约 +396MB,基础 TTS 不需要)')
517
517
  .action(async (url, opts) => {
518
518
  const mod = require('../tts/providers/audio8');
@@ -2,24 +2,24 @@
2
2
 
3
3
  /**
4
4
  * Audio8 TTS provider
5
- * 调用方式:HTTP 调用本地 Audio8 TTS 服务(OpenAI 兼容 /v1/audio/speech)
6
- * 支持流式 MP3 输出(设备边收边播,匹配现有 quemp3 推送管道)
5
+ * 调用方式:HTTP 调用本地 Audio8 TTS 服务(OpenAI 兼容路径 POST /v1/audio/speech)
6
+ * 服务只返回 WAV(response_format 仅支持 wav|pcm)→ 本地 ffmpeg 转 MP3 给设备管道
7
7
  *
8
- * 服务部署参考(Audio8-AI/Audio8_TTS):
9
- * git clone https://github.com/Audio8-AI/Audio8_TTS.git ~/audio8
10
- * cd ~/audio8/onnx_runtime && python3 -m venv .venv && . .venv/bin/activate
11
- * pip install -r requirements.txt # torch/transformers/onnxruntime 等
12
- * bash start_server.sh # 默认监听 http://0.0.0.0:8024
13
- * 首次启动自动从 HuggingFace 下载 ~572MB 模型(0.1B-INT8)
8
+ * 部署:adoremix audio8 install(装 onnx_runtime_0_1b_int8 + venv + systemd)
9
+ * adoremix audio8-fetch-model(下 ~423MB 0.1B INT8 模型 + 生成默认音色)
10
+ * systemctl restart audio8-tts
11
+ * 端点:GET /api/health 健康检查;voice 必填(default=模型内置参考音)
14
12
  *
15
13
  * 凭证:不需要 API Key(本地服务)
16
- * 依赖:lame(mp3 转码),ffmpeg(HTTP 流 → mp3)
14
+ * 依赖:ffmpeg(WAV → MP3 转码,必需)
17
15
  *
18
- * 速度支持:x-speed 头(0.5~2.0,1.0=正常;2.0=2x 加速)
19
- * 声音克隆:3~10 秒参考音频,但需在 Audio8 服务端预设(请求时用 voice 参数指定)
16
+ * 性能提示:CPU int8 推理慢(2 核 Celeron 实测 ~15s 生成 1s 音频,线程数已按核数自适应),
17
+ * 适合定时广播预生成,弱 CPU 不建议实时喊话。
18
+ * 声音克隆:0.5-30s 参考音频 + 转写文本,POST /api/voices/register(需额外下 registration 模型,
19
+ * adoremix audio8-fetch-model --registration)
20
20
  */
21
21
 
22
- const { execFileSync, execSync } = require('child_process');
22
+ const { execFileSync, execSync, execFile } = require('child_process');
23
23
  const fs = require('fs');
24
24
  const path = require('path');
25
25
  const os = require('os');
@@ -28,23 +28,18 @@ const http = require('http');
28
28
  const { URL } = require('url');
29
29
  const logger = require('../../src/logger');
30
30
 
31
- // 中文常用 voice(Audio8 的 zh-CN voices,按性别分组)
31
+ // Audio8 没有预置音色库(每个音色需注册克隆)。install/fetch-model 会自动把模型内置
32
+ // 参考音物化为 default 音色——所有短名先都映射到 default,注册克隆音色后再扩展。
32
33
  const VOICES = {
33
- // 女声
34
- xiaoxiao: 'zh-CN-XiaoxiaoNeural', // 晓晓(温柔女声)
35
- xiaoyi: 'zh-CN-XiaoyiNeural', // 晓伊(活力女声)
36
- xiaomo: 'zh-CN-XiaomoNeural', // 晓墨(文艺女声)
37
- xiaoxuan: 'zh-CN-XiaoxuanNeural', // 晓萱(新闻女声)
38
- // 男声
39
- yunxi: 'zh-CN-YunxiNeural', // 云希(青年男声)
40
- yunjian: 'zh-CN-YunjianNeural', // 云健(浑厚男声)
41
- yunyang: 'zh-CN-YunyangNeural', // 云扬(播音男声)
42
- // 默认
43
- default: 'zh-CN-XiaoxiaoNeural'
34
+ xiaoxiao: 'default', xiaoyi: 'default', xiaomo: 'default', xiaoxuan: 'default',
35
+ yunxi: 'default', yunjian: 'default', yunyang: 'default',
36
+ default: 'default'
44
37
  };
45
38
 
46
39
  const DEFAULT_BASE_URL = 'http://127.0.0.1:8024';
47
- const DEFAULT_TIMEOUT_MS = 30000;
40
+ // 弱 CPU 上 0.1B int8 合成很慢(实测 2 核 Celeron 约 15s/1s 音频),
41
+ // 服务端算完才回包,socket 空闲时间长,超时必须放宽到 10 分钟
42
+ const DEFAULT_TIMEOUT_MS = 600000;
48
43
 
49
44
  function checkDeps() {
50
45
  const issues = [];
@@ -90,6 +85,18 @@ function streamToFile(audioStream, outFile) {
90
85
  });
91
86
  }
92
87
 
88
+ // ffmpeg WAV → MP3(Audio8 的 /v1/audio/speech 只支持 wav|pcm,设备端要 mp3,本地转码)
89
+ function transcodeToMp3(wavFile, mp3File) {
90
+ return new Promise((resolve, reject) => {
91
+ execFile('ffmpeg',
92
+ ['-y', '-loglevel', 'error', '-i', wavFile, '-codec:a', 'libmp3lame', '-qscale:a', '4', mp3File],
93
+ (err, stdout, stderr) => {
94
+ if (err) return reject(new Error('ffmpeg WAV→MP3 转码失败: ' + String(stderr || err.message).split('\n')[0]));
95
+ resolve();
96
+ });
97
+ });
98
+ }
99
+
93
100
  function synthesize({ text, voice, volume, speed, outFile }, creds) {
94
101
  return new Promise((resolve, reject) => {
95
102
  const issues = checkDeps();
@@ -99,14 +106,9 @@ function synthesize({ text, voice, volume, speed, outFile }, creds) {
99
106
 
100
107
  const baseUrl = (creds && creds.audio8_base_url) || DEFAULT_BASE_URL;
101
108
  const wantedVoice = VOICES[voice] || VOICES.default;
102
- // 音量:Audio8 用 dB 偏移(-6~6 dB),UI 传的是 0~100 百分比,转 dB
103
- const vo = parseInt(volume) || 50;
104
- const volumeDb = Math.round((vo - 50) * 0.12);
105
- // 速度:Audio8 用 0.5~2.0 倍速,UI 传 0~100 转 0.5~2.0
106
- const sp = parseInt(speed) || 50;
107
- const speedMul = 0.5 + (sp / 100) * 1.5;
108
-
109
- // OpenAI 兼容调用:POST /v1/audio/speech,body=json,response=audio/mpeg 流
109
+
110
+ // OpenAI 兼容路径:POST /v1/audio/speech。仅支持 response_format=wav|pcm,
111
+ // 音量/语速服务端不支持(静默忽略),mp3 由本地 ffmpeg 转码。
110
112
  let urlObj;
111
113
  try { urlObj = new URL(baseUrl); } catch (e) {
112
114
  return reject(new Error(`Audio8 服务地址无效: ${baseUrl}(请在 config.ini [TTS] audio8_base_url 配置,例 http://127.0.0.1:8024)`));
@@ -115,10 +117,7 @@ function synthesize({ text, voice, volume, speed, outFile }, creds) {
115
117
  const postData = JSON.stringify({
116
118
  input: text,
117
119
  voice: wantedVoice,
118
- model: 'audio8-tts',
119
- response_format: 'mp3',
120
- speed: speedMul,
121
- volume: volumeDb
120
+ response_format: 'wav'
122
121
  });
123
122
  const opts = {
124
123
  hostname: urlObj.hostname,
@@ -141,17 +140,24 @@ function synthesize({ text, voice, volume, speed, outFile }, creds) {
141
140
  });
142
141
  return;
143
142
  }
144
- // 流式保存
145
- streamToFile(res, outFile)
146
- .then(bytes => resolve({ bytes }))
143
+ // 服务端算完才回 WAV(弱 CPU 上要几十秒到几分钟) → 落临时 wav → ffmpeg 转 mp3
144
+ const wavTmp = outFile + '.a8wav';
145
+ streamToFile(res, wavTmp)
146
+ .then(() => transcodeToMp3(wavTmp, outFile))
147
+ .then(() => {
148
+ try { fs.unlinkSync(wavTmp); } catch (e) {}
149
+ let bytes = 0;
150
+ try { bytes = fs.statSync(outFile).size; } catch (e) {}
151
+ resolve({ bytes });
152
+ })
147
153
  .catch(reject);
148
154
  });
149
155
  req.on('error', err => {
150
- reject(new Error(`Audio8 连接失败(${baseUrl}): ${err.message}。请确认 Audio8 TTS 服务已启动,且 config.ini [TTS] audio8_base_url 配置正确。`));
156
+ reject(new Error(`Audio8 连接失败(${baseUrl}): ${err.message}。请确认 Audio8 TTS 服务已启动(adoremix audio8 status),且 config.ini [TTS] audio8_base_url 配置正确。`));
151
157
  });
152
158
  req.on('timeout', () => {
153
159
  req.destroy();
154
- reject(new Error(`Audio8 请求超时(${DEFAULT_TIMEOUT_MS / 1000}s)。服务可能在转码长文本。`));
160
+ reject(new Error(`Audio8 请求超时(${DEFAULT_TIMEOUT_MS / 1000}s)。弱 CPU 上合成慢属正常(约 15s/1s 音频),可稍后重试或换短文本。`));
155
161
  });
156
162
  req.write(postData);
157
163
  req.end();
@@ -165,13 +171,14 @@ function synthesize({ text, voice, volume, speed, outFile }, creds) {
165
171
  const AUDIO8_DEFAULT_PORT = 8024;
166
172
  const AUDIO8_REPO = 'https://github.com/Audio8-AI/Audio8_TTS.git';
167
173
  const AUDIO8_DEPLOY_DIR = '~/audio8';
168
- const AUDIO8_VENV_DIR = '~/audio8/onnx_runtime/.venv';
169
- const AUDIO8_REQUIREMENTS = 'onnx_runtime/requirements.txt';
174
+ // 0.1B INT8 模型必须配套 onnx_runtime_0_1b_int8/ 运行时(官方模型卡明示:
175
+ // onnx_runtime/ 目录是 0.6B INT4 专用,与 0.1B INT8 图不兼容——实测 cache 输入名对不上必报 KeyError)
176
+ const AUDIO8_RUNTIME_DIR = 'onnx_runtime_0_1b_int8';
177
+ const AUDIO8_VENV_DIR = `~/audio8/${AUDIO8_RUNTIME_DIR}/.venv`;
178
+ const AUDIO8_REQUIREMENTS = `${AUDIO8_RUNTIME_DIR}/requirements.txt`;
170
179
  const AUDIO8_SYSTEMD_NAME = 'audio8-tts';
171
180
  const AUDIO8_SYSTEMD_PATH = '/etc/systemd/system/audio8-tts.service';
172
- const AUDIO8_HEALTH_URL = `http://127.0.0.1:${AUDIO8_DEFAULT_PORT}/v1/models`;
173
- // 自托管的预下载模型(可选,存到 ~/audio8_models/0.1B/ 下,避免每次 git clone 后再下 572MB)
174
- const AUDIO8_MODEL_DIR = '~/audio8_models/audio8-TTS-0.1B-ONNX-INT8';
181
+ const AUDIO8_HEALTH_URL = `http://127.0.0.1:${AUDIO8_DEFAULT_PORT}/api/health`;
175
182
 
176
183
  // 包管理器嗅探(apt/dnf/yum/apk/pacman)
177
184
  // 用 which 而非 command -v(Debian/Ubuntu 12+ 的 /bin/sh 没有 command 内建,且 PATH 不一定对)
@@ -205,19 +212,16 @@ function systemInstallCmd(pkgMgr, pkgs) {
205
212
  }
206
213
 
207
214
  function buildSystemdUnit() {
208
- // Audio8 onnx_runtime 需要 numpy 2.4.3(需 Python ≥ 3.11),Ubuntu 22.04 默认 3.10
209
- // 自动探测 python3.11(PPA/官方包),fallback 到 python3
210
- const pyBin = (function(){
211
- try { execSync('command -v python3.11 2>/dev/null', { shell: '/bin/bash', stdio: 'pipe' }); return 'python3.11'; }
212
- catch (e) { return 'python3'; }
213
- })();
214
215
  // systemd 不展开 ~,必须用绝对路径(root 下 $HOME=/root)
215
216
  const home = (function(){
216
217
  try { return execSync('/bin/bash -c "echo $HOME"', { shell: '/bin/bash', stdio: 'pipe', encoding: 'utf8' }).trim() || '/root'; }
217
218
  catch (e) { return '/root'; }
218
219
  })();
219
- const deployDir = AUDIO8_DEPLOY_DIR.replace(/^~/, home);
220
+ const runtimeDir = path.join(home, 'audio8', AUDIO8_RUNTIME_DIR);
220
221
  const venvDir = AUDIO8_VENV_DIR.replace(/^~/, home);
222
+ // 推理线程数 = CPU 核数(默认 5 在少核机器上严重超订阅,实测 2 核 Celeron:
223
+ // THREADS=5 要 93s,THREADS=2 只要 37s,2.5 倍差距)
224
+ const threads = os.cpus().length || 2;
221
225
  return `[Unit]
222
226
  Description=Audio8 TTS (AdoreMix)
223
227
  After=network.target
@@ -225,9 +229,15 @@ After=network.target
225
229
  [Service]
226
230
  Type=simple
227
231
  User=root
228
- WorkingDirectory=${deployDir}/onnx_runtime
232
+ WorkingDirectory=${runtimeDir}
229
233
  Environment=PATH=${venvDir}/bin:/usr/bin:/bin
230
- ExecStart=${venvDir}/bin/${pyBin} -m arktts_runtime.service --model-dir ./model --voices-dir ./model/voices --port ${AUDIO8_DEFAULT_PORT}
234
+ Environment=ARKTTS_MODEL_DIR=${runtimeDir}/model
235
+ Environment=ARKTTS_VOICES_DIR=${runtimeDir}/voices
236
+ Environment=ARKTTS_PRECISION=int8
237
+ Environment=ARKTTS_CODEC_PRECISION=fp16
238
+ Environment=ARKTTS_THREADS=${threads}
239
+ # service.py 只定义 FastAPI app,无启动入口,必须用 uvicorn 拉起(python -m arktts_runtime.service 会静默退出)
240
+ ExecStart=${venvDir}/bin/python -m uvicorn arktts_runtime.service:app --host 0.0.0.0 --port ${AUDIO8_DEFAULT_PORT}
231
241
  Restart=on-failure
232
242
  RestartSec=5
233
243
 
@@ -301,7 +311,7 @@ function install(opts) {
301
311
  const wd = opts.workdir || process.env.ADOREMIX_WORKDIR || path.join(os.homedir(), '.local', 'share', 'adoremix');
302
312
  modelDir = cfg.getConfigValue(wd, 'TTS.audio8_model_dir') || '';
303
313
  } catch (e) {}
304
- const modelLink = `~/audio8/onnx_runtime/model`; // Audio8 期望的相对路径
314
+ const modelLink = `~/audio8/${AUDIO8_RUNTIME_DIR}/model`; // Audio8 期望的模型目录
305
315
  // 如果有预托管模型目录,建软链指向
306
316
  if (modelDir) {
307
317
  try {
@@ -324,16 +334,16 @@ function install(opts) {
324
334
  // 只要目录下只有一个子目录且还看不到 onnx_runtime/,就把子目录内容上提,最多 3 层。
325
335
  execSync(`rm -rf ~/audio8 && mkdir -p ~/audio8 && tar xzf "${BUNDLED_TARBALL}" -C ~/audio8 && ` +
326
336
  `cd ~/audio8 && for i in 1 2 3; do ` +
327
- `[ -f onnx_runtime/requirements.txt ] && break; ` +
337
+ `[ -f ${AUDIO8_RUNTIME_DIR}/requirements.txt ] && break; ` +
328
338
  `single=$(ls -A | wc -l); [ "$single" = "1" ] || break; ` +
329
339
  `d=$(ls -A); [ -d "$d" ] || break; ` +
330
340
  `mv "$d"/* . 2>/dev/null; mv "$d"/.[!.]* . 2>/dev/null; rmdir "$d" 2>/dev/null || true; ` +
331
341
  `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',
342
+ // 平仓后必须能看到 runtime 的 requirements.txt,否则视为解压失败
343
+ const flat = execSync(`[ -f ~/audio8/${AUDIO8_RUNTIME_DIR}/requirements.txt ] && echo OK || echo MISSING`,
334
344
  { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
335
345
  if (flat === 'OK') cloned = true;
336
- else logger.warn('内置 tarball 解压后未找到 onnx_runtime/requirements.txt(目录层级异常)');
346
+ else logger.warn(`内置 tarball 解压后未找到 ${AUDIO8_RUNTIME_DIR}/requirements.txt(目录层级异常)`);
337
347
  } catch (e) {
338
348
  logger.warn('内置 tarball 解压失败:' + e.message);
339
349
  }
@@ -379,16 +389,16 @@ function install(opts) {
379
389
  return 1;
380
390
  }
381
391
  // 统一校验目录结构(git clone 路径也可能带包装目录)
382
- const layoutOk = execSync('[ -f ~/audio8/onnx_runtime/requirements.txt ] && echo OK || echo MISSING',
392
+ const layoutOk = execSync(`[ -f ~/audio8/${AUDIO8_RUNTIME_DIR}/requirements.txt ] && echo OK || echo MISSING`,
383
393
  { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
384
394
  if (layoutOk !== 'OK') {
385
- logger.error('~/audio8 目录结构异常:未找到 onnx_runtime/requirements.txt(可能多了包装目录)');
395
+ logger.error(`~/audio8 目录结构异常:未找到 ${AUDIO8_RUNTIME_DIR}/requirements.txt(可能多了包装目录)`);
386
396
  logger.log('当前内容: ' + execSync('ls ~/audio8', { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim().replace(/\n/g, ' '));
387
397
  return 1;
388
398
  }
389
399
 
390
400
  // venv + pip install(Python 3.11+,numpy 2.4.3 需要)
391
- // venv 路径必须与 AUDIO8_VENV_DIR/buildSystemdUnit 一致(~/audio8/onnx_runtime/.venv),
401
+ // venv 路径必须与 AUDIO8_VENV_DIR/buildSystemdUnit 一致(~/audio8/onnx_runtime_0_1b_int8/.venv),
392
402
  // 否则 systemd ExecStart 指向不存在的解释器,服务起不来
393
403
  const pyBase = (function(){
394
404
  try { execSync('command -v python3.11 2>/dev/null', { shell: '/bin/bash', stdio: 'pipe' }); return 'python3.11'; }
@@ -396,14 +406,13 @@ function install(opts) {
396
406
  })();
397
407
  const venvDir = AUDIO8_VENV_DIR.replace(/^~/, os.homedir());
398
408
  try {
399
- logger.log('=== 创建 venv 并安装 Python 依赖(首次需 5-10 分钟下载 torch 等,Python=' + pyBase + ')===');
409
+ logger.log('=== 创建 venv 并安装 Python 依赖(onnxruntime 等约 100MB,Python=' + pyBase + ')===');
400
410
  execSync(`${pyBase} -m venv ${venvDir}`, { stdio: 'inherit', shell: '/bin/bash' });
401
- // torch 等大包走清华镜像(国内/公司网下官方 PyPI 常超时),失败再回退官方源。
402
- // requirements.txt 缺 tokenizers(Audio8 运行需要),补装。
411
+ // 大包走清华镜像(国内/公司网下官方 PyPI 常超时),失败再回退官方源。
412
+ // 0.1B runtime 的 requirements 已含 tokenizers(>=0.20,<0.23) 与 onnxruntime(>=1.22,<1.24) 约束。
403
413
  const pipCmd = (idx) =>
404
414
  `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}`;
415
+ `pip install -r ~/audio8/${AUDIO8_RUNTIME_DIR}/requirements.txt --quiet ${idx}`;
407
416
  try {
408
417
  execSync(pipCmd('--index-url https://pypi.tuna.tsinghua.edu.cn/simple'), { stdio: 'inherit', shell: '/bin/bash' });
409
418
  } catch (e) {
@@ -427,11 +436,14 @@ function install(opts) {
427
436
  }
428
437
 
429
438
  // 等服务健康(模型单独用 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);
439
+ const modelDirFull = path.join(os.homedir(), 'audio8', AUDIO8_RUNTIME_DIR, 'model');
440
+ const modelReady = fs.existsSync(path.join(modelDirFull, 'runtime_manifest.json'));
441
+ if (modelReady) {
442
+ seedDefaultVoice(modelDirFull);
443
+ } else {
444
+ logger.warn('模型未下载(正常,模型与 install 解耦): 先执行 adoremix audio8-fetch-model 下载 ~423MB 模型,再 systemctl restart ' + AUDIO8_SYSTEMD_NAME);
433
445
  }
434
- logger.log('=== 等待服务健康(最多 60 秒)===');
446
+ logger.log('=== 等待服务健康(最多 60 秒,模型冷启动加载约 20-30 秒)===');
435
447
  let ok = false;
436
448
  for (let i = 1; i <= 30; i++) {
437
449
  try {
@@ -444,7 +456,7 @@ function install(opts) {
444
456
  }
445
457
  if (!ok) {
446
458
  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);
459
+ logger.log('前台排查: journalctl -u ' + AUDIO8_SYSTEMD_NAME + ' -n 30');
448
460
  }
449
461
 
450
462
  // 改本地 config.ini
@@ -485,7 +497,7 @@ async function status(opts) {
485
497
  opts = opts || {};
486
498
  const baseUrl = opts.url || process.env.ADOREMIX_AUDIO8_BASE_URL || `http://127.0.0.1:${AUDIO8_DEFAULT_PORT}`;
487
499
  try {
488
- const urlObj = new URL(`${baseUrl}/v1/models`);
500
+ const urlObj = new URL(`${baseUrl}/api/health`);
489
501
  const lib = urlObj.protocol === 'https:' ? require('https') : require('http');
490
502
  await new Promise(resolve => {
491
503
  const req = lib.request({ hostname: urlObj.hostname, port: urlObj.port, path: urlObj.pathname, method: 'GET', timeout: 5000 }, res => {
@@ -583,11 +595,41 @@ function downloadTo(url, target, file) {
583
595
  });
584
596
  }
585
597
 
598
+ // Audio8 没有预置音色库——每个音色都要注册(克隆)。但模型自带 reference_codes.npy +
599
+ // manifest.reference_text 就是官方默认参考音的原料,物化成 voices/default/ 即可直接合成。
600
+ // (VoiceStore.load 只认 voices/<name>/{codes.npy,meta.json},meta 只强依赖 reference_text)
601
+ function seedDefaultVoice(modelDir) {
602
+ try {
603
+ const voicesDefault = path.join(path.dirname(modelDir), 'voices', 'default');
604
+ const metaPath = path.join(voicesDefault, 'meta.json');
605
+ if (fs.existsSync(metaPath)) return true; // 已有默认音色
606
+ const codesSrc = path.join(modelDir, 'reference_codes.npy');
607
+ const manifestPath = path.join(modelDir, 'runtime_manifest.json');
608
+ if (!fs.existsSync(codesSrc) || !fs.existsSync(manifestPath)) return false;
609
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
610
+ if (!manifest.reference_text) return false;
611
+ fs.mkdirSync(voicesDefault, { recursive: true });
612
+ fs.copyFileSync(codesSrc, path.join(voicesDefault, 'codes.npy'));
613
+ fs.writeFileSync(metaPath, JSON.stringify({
614
+ name: 'default',
615
+ reference_text: manifest.reference_text,
616
+ dtype: 'int64',
617
+ sample_rate: manifest.sample_rate || 44100,
618
+ source: 'builtin'
619
+ }), 'utf8');
620
+ logger.ok('已生成默认音色 default(模型内置参考音)→ ' + voicesDefault);
621
+ return true;
622
+ } catch (e) {
623
+ logger.warn('默认音色生成失败: ' + e.message);
624
+ return false;
625
+ }
626
+ }
627
+
586
628
  async function fetchModel(opts) {
587
629
  opts = opts || {};
588
- // 目标目录必须与 systemd 单元一致(WorkingDirectory=~/audio8/onnx_runtime + --model-dir ./model)
630
+ // 目标目录必须与 systemd 单元一致(ARKTTS_MODEL_DIR=~/audio8/<runtime>/model)
589
631
  const targetDir = process.env.ADOREMIX_AUDIO8_MODEL_DIR
590
- || path.join(os.homedir(), 'audio8', 'onnx_runtime', 'model');
632
+ || path.join(os.homedir(), 'audio8', AUDIO8_RUNTIME_DIR, 'model');
591
633
  const baseUrls = opts.url ? [opts.url] : MODEL_DEFAULT_URLS;
592
634
  // --registration / ADOREMIX_AUDIO8_WITH_REGISTRATION=1 时追加声音克隆注册子模型(+396MB)
593
635
  const files = (opts.registration || process.env.ADOREMIX_AUDIO8_WITH_REGISTRATION === '1')
@@ -625,6 +667,7 @@ async function fetchModel(opts) {
625
667
  return 1;
626
668
  }
627
669
  logger.ok(`Audio8 模型就绪(${ok} 个文件): ${targetDir}`);
670
+ seedDefaultVoice(targetDir);
628
671
  logger.log('重启服务生效: systemctl restart audio8-tts');
629
672
  return 0;
630
673
  }