@oxiaom/adoremix 1.0.62 → 1.0.64

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.62",
3
+ "version": "1.0.64",
4
4
  "description": "AdoreMix broadcast server - cross-platform installer, runner and service manager",
5
5
  "bin": {
6
6
  "adoremix": "./bin/adoremix.js"
@@ -0,0 +1,199 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Audio8 本机部署体检(doctor 第 9 节)
5
+ *
6
+ * 检查项(与 v1.0.60+ 部署结构对齐):
7
+ * 1. systemd 单元存在 + enabled + active
8
+ * 2. venv 解释器存在 + 关键 pip 包(onnxruntime <1.24 / tokenizers)
9
+ * 3. 模型目录 + 核心文件(runtime_manifest.json 等)齐全
10
+ * 4. 默认音色(voices/default/{codes.npy,meta.json})
11
+ * 5. /api/health 健康探测
12
+ * 6. 内存余量(模型常驻 ~1.8GB,<2GB 可用会 OOM)
13
+ * 7. 磁盘余量(模型 423MB + 源码 venv ~500MB,<1GB 告警)
14
+ *
15
+ * --fix 行为:服务未 active → restart;模型缺失 → 提示跑 audio8-fetch-model(不自动下 423MB)。
16
+ */
17
+
18
+ const { execSync } = require('child_process');
19
+ const fs = require('fs');
20
+ const os = require('os');
21
+ const path = require('path');
22
+ const logger = require('./logger');
23
+
24
+ const RUNTIME_DIR = 'onnx_runtime_0_1b_int8';
25
+ const UNIT_NAME = 'audio8-tts';
26
+ const UNIT_PATH = `/etc/systemd/system/${UNIT_NAME}.service`;
27
+ const HEALTH_URL = 'http://127.0.0.1:8024/api/health';
28
+
29
+ const MODEL_CORE_FILES = [
30
+ 'runtime_manifest.json',
31
+ 'config.json',
32
+ 'reference_codes.npy',
33
+ 'codec_decoder_fp16.onnx',
34
+ 'codec_decoder_fp16.onnx.data',
35
+ 'slow_ar_int8.onnx',
36
+ 'slow_ar_int8.onnx.data',
37
+ 'fast_ar_int8.onnx',
38
+ 'fast_ar_int8.onnx.data',
39
+ 'tokenizer/tokenizer.json'
40
+ ];
41
+
42
+ function paths() {
43
+ const home = os.homedir();
44
+ const runtime = path.join(home, 'audio8', RUNTIME_DIR);
45
+ return {
46
+ home,
47
+ runtime,
48
+ venvPy: path.join(runtime, '.venv', 'bin', 'python'),
49
+ model: path.join(runtime, 'model'),
50
+ defaultVoiceMeta: path.join(runtime, 'voices', 'default', 'meta.json')
51
+ };
52
+ }
53
+
54
+ function sh(cmd) {
55
+ try {
56
+ return execSync(cmd, { shell: '/bin/bash', encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim();
57
+ } catch (e) { return null; }
58
+ }
59
+
60
+ function isInstalled() {
61
+ return fs.existsSync(UNIT_PATH) || fs.existsSync(paths().runtime);
62
+ }
63
+
64
+ // 内存(MB):/proc/meminfo MemAvailable
65
+ function memAvailableMB() {
66
+ try {
67
+ const m = fs.readFileSync('/proc/meminfo', 'utf8').match(/MemAvailable:\s+(\d+)\s*kB/);
68
+ return m ? Math.round(parseInt(m[1], 10) / 1024) : null;
69
+ } catch (e) { return null; }
70
+ }
71
+
72
+ // 磁盘(MB):runtime 所在挂载点可用空间
73
+ function diskFreeMB(dir) {
74
+ const out = sh(`df -Pm "${dir}" 2>/dev/null | awk 'NR==2 {print $4}'`);
75
+ const n = parseInt(out, 10);
76
+ return isNaN(n) ? null : n;
77
+ }
78
+
79
+ function checkAudio8Deployment(issues, opts) {
80
+ opts = opts || {};
81
+ const p = paths();
82
+ const providerActive = !!opts.providerActive;
83
+
84
+ // ---- 1. systemd 单元 ----
85
+ if (!fs.existsSync(UNIT_PATH)) {
86
+ const msg = `Audio8 systemd 单元不存在(${UNIT_PATH})。本机部署需 adoremix audio8 install;若改用远程 Audio8,请在 config.ini [TTS] audio8_base_url 配远程地址。`;
87
+ issues.push({ type: 'audio8-unit', severity: providerActive ? 'error' : 'warn', msg });
88
+ logger.error(`❌ ${msg}`);
89
+ return; // 单元都没有,后面查了也没意义
90
+ }
91
+ const enabled = sh(`systemctl is-enabled ${UNIT_NAME} 2>/dev/null`) || 'unknown';
92
+ if (enabled === 'enabled') {
93
+ logger.ok(`✓ systemd 单元已注册(开机自启)`);
94
+ } else {
95
+ issues.push({ type: 'audio8-unit', severity: 'warn', msg: `audio8-tts 未 enabled(状态 ${enabled}),重启后不会自动拉起` });
96
+ logger.warn(`⚠ audio8-tts 未开机自启(${enabled}):systemctl enable ${UNIT_NAME}`);
97
+ }
98
+ const active = sh(`systemctl is-active ${UNIT_NAME} 2>/dev/null`) || 'unknown';
99
+ if (active !== 'active') {
100
+ issues.push({ type: 'audio8-active', severity: providerActive ? 'error' : 'warn', msg: `audio8-tts 未运行(${active})。常见原因:模型未下载(adoremix audio8-fetch-model)或端口被占用。排查:journalctl -u ${UNIT_NAME} -n 30` });
101
+ logger.error(`❌ audio8-tts 未运行(${active})`);
102
+ if (opts.fix) {
103
+ logger.info(`==> 自动修复:systemctl restart ${UNIT_NAME}`);
104
+ try {
105
+ execSync(`systemctl restart ${UNIT_NAME}`, { stdio: 'inherit' });
106
+ logger.ok('✓ 已重启(模型冷启动加载约 20-30 秒,稍后再跑 doctor 确认健康)');
107
+ } catch (e) {
108
+ logger.error(`重启失败:${(e.message || '').split('\n')[0]},手动排查 journalctl -u ${UNIT_NAME} -n 30`);
109
+ }
110
+ } else {
111
+ logger.log(` 修复:systemctl restart ${UNIT_NAME}(或 doctor --fix 自动重启)`);
112
+ }
113
+ } else {
114
+ logger.ok(`✓ audio8-tts 运行中`);
115
+ }
116
+
117
+ // ---- 2. venv + 关键 pip 包 ----
118
+ if (!fs.existsSync(p.venvPy)) {
119
+ issues.push({ type: 'audio8-venv', severity: 'error', msg: `venv 解释器缺失:${p.venvPy}(重跑 adoremix audio8 install)` });
120
+ logger.error(`❌ venv 缺失:${p.venvPy}`);
121
+ } else {
122
+ const ortVer = sh(`"${p.venvPy}" -c "import onnxruntime; print(onnxruntime.__version__)" 2>/dev/null`);
123
+ const tokVer = sh(`"${p.venvPy}" -c "import tokenizers; print(tokenizers.__version__)" 2>/dev/null`);
124
+ if (!ortVer) {
125
+ issues.push({ type: 'audio8-venv', severity: 'error', msg: `venv 缺 onnxruntime(重跑 adoremix audio8 install)` });
126
+ logger.error(`❌ venv 缺 onnxruntime`);
127
+ } else if (parseInt(ortVer.split('.')[1] || '0', 10) >= 24) {
128
+ // 0.1B runtime 要求 onnxruntime <1.24
129
+ issues.push({ type: 'audio8-venv', severity: 'error', msg: `onnxruntime ${ortVer} 太新(0.1B runtime 要求 <1.24)。修复:${p.venvPy} -m pip install "onnxruntime>=1.22,<1.24"` });
130
+ logger.error(`❌ onnxruntime ${ortVer}(要求 <1.24)`);
131
+ } else {
132
+ logger.ok(`✓ venv 就绪(onnxruntime ${ortVer}${tokVer ? `, tokenizers ${tokVer}` : ''})`);
133
+ }
134
+ if (ortVer && !tokVer) {
135
+ issues.push({ type: 'audio8-venv', severity: 'error', msg: `venv 缺 tokenizers。修复:${p.venvPy} -m pip install "tokenizers>=0.20,<0.23"` });
136
+ logger.error(`❌ venv 缺 tokenizers`);
137
+ }
138
+ }
139
+
140
+ // ---- 3. 模型核心文件 ----
141
+ const missingFiles = MODEL_CORE_FILES.filter(f => !fs.existsSync(path.join(p.model, f)));
142
+ if (missingFiles.length === MODEL_CORE_FILES.length) {
143
+ issues.push({ type: 'audio8-model', severity: 'error', msg: `模型未下载:${p.model}。执行 adoremix audio8-fetch-model(~423MB),或自托管后 adoremix audio8-fetch-model <url>` });
144
+ logger.error(`❌ 模型未下载:adoremix audio8-fetch-model`);
145
+ } else if (missingFiles.length > 0) {
146
+ issues.push({ type: 'audio8-model', severity: 'error', msg: `模型不完整,缺 ${missingFiles.length} 个文件:${missingFiles.slice(0, 3).join(', ')}${missingFiles.length > 3 ? ' 等' : ''}。重跑 adoremix audio8-fetch-model` });
147
+ logger.error(`❌ 模型不完整(缺 ${missingFiles.length} 个文件),重跑 adoremix audio8-fetch-model`);
148
+ } else {
149
+ let modelMB = null;
150
+ try { modelMB = Math.round(parseInt(sh(`du -sm "${p.model}" | cut -f1`), 10)); } catch (e) {}
151
+ logger.ok(`✓ 模型完整(${p.model}${modelMB ? `, ~${modelMB}MB` : ''})`);
152
+ }
153
+
154
+ // ---- 4. 默认音色 ----
155
+ if (fs.existsSync(p.defaultVoiceMeta)) {
156
+ logger.ok(`✓ 默认音色 default`);
157
+ } else if (missingFiles.length === 0) {
158
+ // 模型在但音色缺(旧版本 fetch-model 不会自动 seed)
159
+ issues.push({ type: 'audio8-voice', severity: 'warn', msg: `默认音色缺失:${p.defaultVoiceMeta}。重跑 adoremix audio8-fetch-model(已有模型文件会秒过,仅补 seed)` });
160
+ logger.warn(`⚠ 默认音色 default 缺失,重跑 adoremix audio8-fetch-model 自动补`);
161
+ }
162
+
163
+ // ---- 5. 健康探测(服务 active 时才查)----
164
+ if (active === 'active') {
165
+ const code = sh(`curl -s -o /dev/null -w "%{http_code}" --max-time 5 "${HEALTH_URL}"`);
166
+ if (code === '200') {
167
+ logger.ok(`✓ /api/health 200`);
168
+ } else if (code === '000') {
169
+ logger.warn(`⚠ /api/health 无响应(模型冷启动中约 20-30 秒属正常,稍后重试)`);
170
+ } else {
171
+ issues.push({ type: 'audio8-health', severity: 'warn', msg: `/api/health 返回 HTTP ${code}` });
172
+ logger.warn(`⚠ /api/health HTTP ${code}`);
173
+ }
174
+ }
175
+
176
+ // ---- 6. 内存余量 ----
177
+ const memMB = memAvailableMB();
178
+ if (memMB !== null) {
179
+ if (memMB < 1000) {
180
+ issues.push({ type: 'audio8-mem', severity: 'error', msg: `可用内存 ${memMB}MB 不足(Audio8 模型常驻 ~1.8GB),加载会 OOM。建议换 ≥3GB 内存机器,或改用云端 TTS(xf/edge)` });
181
+ logger.error(`❌ 可用内存 ${memMB}MB < 1GB(模型加载需 ~1.8GB)`);
182
+ } else if (memMB < 2000) {
183
+ logger.warn(`⚠ 可用内存 ${memMB}MB 偏紧(模型常驻 ~1.8GB,建议 ≥3GB 总内存)`);
184
+ } else {
185
+ logger.ok(`✓ 可用内存 ${memMB}MB`);
186
+ }
187
+ }
188
+
189
+ // ---- 7. 磁盘余量 ----
190
+ const diskMB = fs.existsSync(p.runtime) ? diskFreeMB(p.runtime) : null;
191
+ if (diskMB !== null && diskMB < 1024) {
192
+ issues.push({ type: 'audio8-disk', severity: 'warn', msg: `磁盘可用 ${diskMB}MB 不足 1GB(模型 423MB + venv ~500MB)` });
193
+ logger.warn(`⚠ 磁盘可用 ${diskMB}MB < 1GB`);
194
+ } else if (diskMB !== null) {
195
+ logger.ok(`✓ 磁盘可用 ${diskMB}MB`);
196
+ }
197
+ }
198
+
199
+ module.exports = { checkAudio8Deployment, isInstalled, RUNTIME_DIR };
package/src/doctor.js CHANGED
@@ -439,6 +439,18 @@ function runDoctor(workdir, opts) {
439
439
  }
440
440
  }
441
441
 
442
+ // 9. Audio8 本机部署体检(Linux + 本机装了 audio8 或 provider=audio8 且指向本机时)
443
+ if (process.platform === 'linux') {
444
+ const a8 = require('./doctor-audio8');
445
+ const audio8BaseUrl = (cfgObj.TTS && cfgObj.TTS.audio8_base_url) || 'http://127.0.0.1:8024';
446
+ const isLocalProvider = providerName === 'audio8' && /^https?:\/\/(127\.0\.0\.1|localhost)(:|\/|$)/.test(audio8BaseUrl);
447
+ if (isLocalProvider || a8.isInstalled()) {
448
+ logger.log('');
449
+ logger.log('=== Audio8 本机部署检查 ===');
450
+ a8.checkAudio8Deployment(issues, { fix: !!opts.fix, providerActive: isLocalProvider });
451
+ }
452
+ }
453
+
442
454
  return reportAndExit(issues, opts);
443
455
  }
444
456
 
package/src/tts-deps.js CHANGED
@@ -55,11 +55,11 @@ const PROVIDER_DEPENDENCIES = {
55
55
  nodeModules: [], // 用 Node 内置 http/https
56
56
  creds: [], // 本地服务无 API key
57
57
  systemPkgs: [
58
- { name: 'ffmpeg', cmd: 'ffmpeg' } // 转码用(实际 audio8 直接返回 mp3 不用 ffmpeg,但保留 fallback)
58
+ { name: 'ffmpeg', cmd: 'ffmpeg' } // Audio8 服务端只返回 WAV,provider 层必须 ffmpeg 转 mp3
59
59
  ],
60
60
  pipPkgs: [], // 纯 HTTP 调用,无 Python 依赖
61
61
  executables: [...TRANSCODE_TOOLS],
62
- // 额外:需要本地 Audio8 TTS 服务可达(检查时探测 /v1/models)
62
+ // 额外:需要 Audio8 TTS 服务可达(checkDeps 末尾同步探测 /api/health)
63
63
  extraChecks: ['http_endpoint']
64
64
  }
65
65
  };
@@ -241,37 +241,24 @@ function checkDeps(workdir, providerName, cfg) {
241
241
  });
242
242
  }
243
243
 
244
- // audio8:探测本地服务可达性(GET /v1/models,超时 3 秒)
244
+ // audio8:探测本地服务可达性(GET /api/health,超时 3 秒,同步等待结果)
245
245
  if (providerName === 'audio8') {
246
- const http = require('http');
247
- const https = require('https');
248
- const url = require('url');
249
- const audio8BaseUrl = (cfg && cfg.TTS && cfg.TTS.audio8_base_url) || 'http://127.0.0.1:7860';
246
+ const audio8BaseUrl = (cfg && cfg.TTS && cfg.TTS.audio8_base_url) || 'http://127.0.0.1:8024';
250
247
  let u;
251
248
  try { u = new URL(audio8BaseUrl); } catch (e) {
252
- issues.push({ severity: 'error', category: 'service', msg: `audio8_base_url 无效: ${audio8BaseUrl}(需 config.ini [TTS] audio8_base_url 配置,如 http://127.0.0.1:7860)`, autoFixable: false });
249
+ issues.push({ severity: 'error', category: 'service', msg: `audio8_base_url 无效: ${audio8BaseUrl}(需 config.ini [TTS] audio8_base_url 配置,如 http://127.0.0.1:8024)`, autoFixable: false });
253
250
  }
254
251
  if (u) {
255
- try {
256
- const lib = u.protocol === 'https:' ? https : http;
257
- const req = lib.request({
258
- hostname: u.hostname,
259
- port: u.port || (u.protocol === 'https:' ? 443 : 80),
260
- path: '/v1/models',
261
- method: 'GET',
262
- timeout: 3000
263
- }, res => {
264
- if (res.statusCode !== 200) {
265
- issues.push({ severity: 'error', category: 'service', msg: `Audio8 服务不可达:${audio8BaseUrl} 返回 HTTP ${res.statusCode}`, autoFixable: false });
266
- }
267
- });
268
- req.on('error', err => {
269
- issues.push({ severity: 'error', category: 'service', msg: `Audio8 服务不可达(${audio8BaseUrl}):${err.message}。请确认 Audio8 TTS 服务已启动(参考 Audio8-AI/Audio8_TTS),并在 config.ini [TTS] audio8_base_url 配置正确地址。`, autoFixable: false });
270
- });
271
- req.on('timeout', () => { req.destroy(); issues.push({ severity: 'error', category: 'service', msg: `Audio8 服务超时(${audio8BaseUrl}/v1/models 3s 无响应)`, autoFixable: false }); });
272
- req.end();
273
- } catch (e) {
274
- issues.push({ severity: 'error', category: 'service', msg: `audio8 服务探测失败:${e.message}`, autoFixable: false });
252
+ // 同步 HTTP 探测(不能 execSync curl: Windows 无 curl/bash;也不能 async 回调:
253
+ // checkDeps 是同步函数,回调里的 push 会丢)。spawn curl 带平台回退。
254
+ const statusCode = httpStatusSync(u, '/api/health', 3000);
255
+ if (statusCode === -1) {
256
+ // 平台无任何 HTTP 探测工具,跳过(不阻断安装)
257
+ } else if (statusCode !== 200) {
258
+ const detail = statusCode === null
259
+ ? '无响应/连接失败'
260
+ : `HTTP ${statusCode}`;
261
+ issues.push({ severity: 'error', category: 'service', msg: `Audio8 服务不可达(${audio8BaseUrl}):${detail}。本机部署用 systemctl restart audio8-tts 拉起;远程部署确认网络可达。`, autoFixable: false });
275
262
  }
276
263
  }
277
264
  }
@@ -279,6 +266,29 @@ function checkDeps(workdir, providerName, cfg) {
279
266
  return { issues, provider: providerName };
280
267
  }
281
268
 
269
+ // 同步获取 HTTP 状态码:优先 curl(Linux/macOS),Windows 用 powershell,都没有回退 node 子进程。
270
+ function httpStatusSync(u, healthPath, timeoutMs) {
271
+ const url = u.href.replace(/\/+$/, '') + healthPath;
272
+ // 1) curl
273
+ try {
274
+ const out = execSync(`curl -s -o /dev/null -w "%{http_code}" --max-time ${Math.ceil(timeoutMs / 1000)} "${url}"`,
275
+ { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true }).trim();
276
+ if (/^\d+$/.test(out)) return parseInt(out, 10);
277
+ } catch (e) { /* 无 curl 或请求失败,继续 */ }
278
+ // 2) Windows powershell
279
+ if (process.platform === 'win32') {
280
+ try {
281
+ const ps = `$r=try{(Invoke-WebRequest -Uri '${url}' -TimeoutSec ${Math.ceil(timeoutMs / 1000)} -UseBasicParsing).StatusCode}catch{if($_.Exception.Response){[int]$_.Exception.Response.StatusCode}else{0}}; $r`;
282
+ const out = execSync(`powershell -NoProfile -Command "${ps}"`,
283
+ { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true }).trim();
284
+ const n = parseInt(out, 10);
285
+ return isNaN(n) || n === 0 ? null : n;
286
+ } catch (e) { return null; }
287
+ }
288
+ // 3) 无工具可用(Linux 无 curl 极少见): 返回 null 视为未知,不误报也不放行真故障
289
+ return -1;
290
+ }
291
+
282
292
  /**
283
293
  * 自动修复(仅 autoFixable=true 的)
284
294
  */