@oxiaom/adoremix 1.0.41 → 1.0.42

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.41",
3
+ "version": "1.0.42",
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
@@ -465,6 +465,58 @@ function buildProgram() {
465
465
  try { process.exitCode = mod.status(); } catch (e) { logger.error(e.message); process.exitCode = 1; }
466
466
  });
467
467
 
468
+ const audio8 = program
469
+ .command('audio8')
470
+ .description('Audio8 TTS(本地自部署流式 TTS,自动安装到远程 Linux)');
471
+
472
+ audio8
473
+ .command('install')
474
+ .description('通过 SSH 远程安装 Audio8 TTS 到 Linux 主机(默认 192.168.1.114:8024),自动启动 systemd 服务')
475
+ .option('--host <ip>', '远程主机 IP', '192.168.1.114')
476
+ .option('--user <name>', 'SSH 用户', 'oxiaom')
477
+ .option('--pass <pwd>', 'SSH 密码')
478
+ .option('--workdir <path>', '本地工作目录(写入 config.ini 用)')
479
+ .action(async (opts) => {
480
+ const mod = require('../tts/providers/audio8');
481
+ try {
482
+ process.exitCode = await mod.install(opts);
483
+ } catch (e) {
484
+ logger.error(e.message);
485
+ process.exitCode = 1;
486
+ }
487
+ });
488
+
489
+ audio8
490
+ .command('uninstall')
491
+ .description('卸载远程 Linux 上的 Audio8 TTS 服务')
492
+ .option('--host <ip>', '远程主机 IP', '192.168.1.114')
493
+ .option('--user <name>', 'SSH 用户', 'oxiaom')
494
+ .option('--pass <pwd>', 'SSH 密码')
495
+ .action(async (opts) => {
496
+ const mod = require('../tts/providers/audio8');
497
+ try {
498
+ process.exitCode = await mod.uninstall(opts);
499
+ } catch (e) {
500
+ logger.error(e.message);
501
+ process.exitCode = 1;
502
+ }
503
+ });
504
+
505
+ audio8
506
+ .command('status')
507
+ .description('检查远程 Audio8 TTS 服务健康')
508
+ .option('--host <ip>', '远程主机 IP', '192.168.1.114')
509
+ .option('--url <url>', '自定义 base_url')
510
+ .action(async (opts) => {
511
+ const mod = require('../tts/providers/audio8');
512
+ try {
513
+ process.exitCode = await mod.status(opts);
514
+ } catch (e) {
515
+ logger.error(e.message);
516
+ process.exitCode = 1;
517
+ }
518
+ });
519
+
468
520
  const cfgmgr = program
469
521
  .command('config-manager')
470
522
  .description('设备配置管理 UI(配置 IP / 修改 config.ini / 查看日志),端口 9877,开机自启');
@@ -104,7 +104,7 @@ module.exports = {
104
104
  xf_voice_override: '',
105
105
  minimax_token: '',
106
106
  edge_voice_override: '',
107
- audio8_base_url: 'http://127.0.0.1:7860',
107
+ audio8_base_url: 'http://127.0.0.1:8024',
108
108
  audio8_voice_override: ''
109
109
  }
110
110
  };
@@ -6,8 +6,11 @@
6
6
  * 支持流式 MP3 输出(设备边收边播,匹配现有 quemp3 推送管道)
7
7
  *
8
8
  * 服务部署参考(Audio8-AI/Audio8_TTS):
9
- * pip install audio8-tts(或依官方文档)
10
- * python -m audio8_tts.server # 默认监听 http://0.0.0.0:7860
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)
11
14
  *
12
15
  * 凭证:不需要 API Key(本地服务)
13
16
  * 依赖:lame(mp3 转码),ffmpeg(HTTP 流 → mp3)
@@ -39,7 +42,7 @@ const VOICES = {
39
42
  default: 'zh-CN-XiaoxiaoNeural'
40
43
  };
41
44
 
42
- const DEFAULT_BASE_URL = 'http://127.0.0.1:7860';
45
+ const DEFAULT_BASE_URL = 'http://127.0.0.1:8024';
43
46
  const DEFAULT_TIMEOUT_MS = 30000;
44
47
 
45
48
  function checkDeps() {
@@ -105,7 +108,7 @@ function synthesize({ text, voice, volume, speed, outFile }, creds) {
105
108
  // OpenAI 兼容调用:POST /v1/audio/speech,body=json,response=audio/mpeg 流
106
109
  let urlObj;
107
110
  try { urlObj = new URL(baseUrl); } catch (e) {
108
- return reject(new Error(`Audio8 服务地址无效: ${baseUrl}(请在 config.ini [TTS] audio8_base_url 配置,例 http://127.0.0.1:7860)`));
111
+ return reject(new Error(`Audio8 服务地址无效: ${baseUrl}(请在 config.ini [TTS] audio8_base_url 配置,例 http://127.0.0.1:8024)`));
109
112
  }
110
113
  urlObj.pathname = '/v1/audio/speech';
111
114
  const postData = JSON.stringify({
@@ -154,4 +157,145 @@ function synthesize({ text, voice, volume, speed, outFile }, creds) {
154
157
  });
155
158
  }
156
159
 
157
- module.exports = { synthesize, checkDeps, VOICES, DEFAULT_BASE_URL };
160
+ // ===== audio8 install / uninstall / status(类似 nginx install 的可选组件)=====
161
+ // 通过 SSH 远程部署到 Linux 主机,Windows 本机调用只需装 plink。
162
+ // 默认目标:192.168.1.114:22 / 用户 oxiaom。改 SSH_TARGET/SSH_USER 环境变量或 --host/--user 参数即可换机器。
163
+ const AUDIO8_DEFAULT_PORT = 8024;
164
+ const AUDIO8_REPO = 'https://github.com/Audio8-AI/Audio8_TTS.git';
165
+ const AUDIO8_DEPLOY_DIR = '~/audio8';
166
+ const AUDIO8_VENV_DIR = '~/audio8/onnx_runtime/.venv';
167
+ const AUDIO8_REQUIREMENTS = 'onnx_runtime/requirements.txt';
168
+ const AUDIO8_SYSTEMD_NAME = 'audio8-tts';
169
+ const AUDIO8_SYSTEMD_PATH = '/etc/systemd/system/audio8-tts.service';
170
+ const AUDIO8_HEALTH_URL = `http://127.0.0.1:${AUDIO8_DEFAULT_PORT}/v1/models`;
171
+
172
+ function plink() {
173
+ for (const cmd of ['plink', '"C:\\Program Files\\PuTTY\\plink.exe"']) {
174
+ try { return execSync(cmd.replace(/"/g, '').split(' ')[0], { stdio: 'pipe' }); } catch (e) {}
175
+ }
176
+ try { return require('child_process').execSync('where plink', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }).trim().split('\n')[0]; } catch (e) {}
177
+ return null;
178
+ }
179
+
180
+ function sshExec(cmd, opts) {
181
+ opts = opts || {};
182
+ const host = opts.host || process.env.ADOREMIX_AUDIO8_SSH_HOST || '192.168.1.114';
183
+ const user = opts.user || process.env.ADOREMIX_AUDIO8_SSH_USER || 'oxiaom';
184
+ const pass = opts.pass || process.env.ADOREMIX_AUDIO8_SSH_PASS || '123123';
185
+ const pl = plink();
186
+ if (!pl) throw new Error('未找到 plink(PuTTY),请安装 PuTTY 或将其加入 PATH');
187
+ return execSync(`"${pl}" -ssh -batch -pw "${pass}" ${user}@${host} '${cmd.replace(/'/g, "'\\''")}'`, { stdio: 'pipe', encoding: 'utf8' });
188
+ }
189
+
190
+ function buildSystemdUnit(pyCmd) {
191
+ return `[Unit]
192
+ Description=Audio8 TTS (AdoreMix)
193
+ After=network.target
194
+
195
+ [Service]
196
+ Type=simple
197
+ User=root
198
+ WorkingDirectory=${AUDIO8_DEPLOY_DIR}/onnx_runtime
199
+ Environment=PATH=${AUDIO8_VENV_DIR}/bin:/usr/bin:/bin
200
+ ExecStart=${AUDIO8_VENV_DIR}/bin/python -m arktts_runtime.service --model-dir ./model --voices-dir ./model/voices --port ${AUDIO8_DEFAULT_PORT}
201
+ Restart=on-failure
202
+ RestartSec=5
203
+
204
+ [Install]
205
+ WantedBy=multi-user.target
206
+ `;
207
+ }
208
+
209
+ function install(opts) {
210
+ opts = opts || {};
211
+ logger.ok('开始远程安装 Audio8 TTS(目标: ' + (opts.host || '192.168.1.114') + ')');
212
+ const cmds = [
213
+ 'echo "=== 系统检测 ==="',
214
+ 'python3 --version',
215
+ 'pip3 --version',
216
+ 'git --version',
217
+ 'echo "=== 安装系统依赖 ==="',
218
+ 'apt-get update && apt-get install -y git python3-pip python3-venv ffmpeg',
219
+ 'echo "=== clone 仓库(如果不存在)==="',
220
+ `if [ ! -d ${AUDIO8_DEPLOY_DIR} ]; then git clone ${AUDIO8_REPO} ${AUDIO8_DEPLOY_DIR}; else echo "已存在,跳过"; fi`,
221
+ 'echo "=== 创建 venv 并装依赖 ==="',
222
+ `cd ${AUDIO8_DEPLOY_DIR}/onnx_runtime && python3 -m venv .venv`,
223
+ `${AUDIO8_VENV_DIR}/bin/pip install -U pip`,
224
+ `${AUDIO8_VENV_DIR}/bin/pip install -r ${AUDIO8_REQUIREMENTS}`,
225
+ 'echo "=== 写 systemd 单元 ==="',
226
+ // systemd 单元写入使用 heredoc 转义(这里通过 echo + 重定向)
227
+ `bash -c 'cat > ${AUDIO8_SYSTEMD_PATH} <<\"EOF\"\n${buildSystemdUnit()}\nEOF'`,
228
+ 'systemctl daemon-reload',
229
+ `systemctl enable ${AUDIO8_SYSTEMD_NAME}`,
230
+ `systemctl restart ${AUDIO8_SYSTEMD_NAME}`,
231
+ 'echo "=== 等待服务健康(首次启动要下载 ~572MB 模型,最多 60s)==="',
232
+ `for i in $(seq 1 60); do sleep 2; if curl -sf ${AUDIO8_HEALTH_URL} >/dev/null 2>&1; then echo "OK after ${i} attempts"; break; fi; done`,
233
+ `curl -sf ${AUDIO8_HEALTH_URL} >/dev/null && echo "✓ Audio8 服务健康: http://127.0.0.1:${AUDIO8_DEFAULT_PORT}" || echo "⚠ 60s 内未就绪,可手动 systemctl status ${AUDIO8_SYSTEMD_NAME}"`
234
+ ];
235
+ const fullCmd = cmds.join(' && ');
236
+ try {
237
+ const out = sshExec(fullCmd, opts);
238
+ process.stdout.write(out);
239
+ } catch (e) {
240
+ logger.error('SSH 执行失败:' + e.message.slice(0, 200));
241
+ return 1;
242
+ }
243
+ // 修改本地 config.ini 的 [TTS] provider/base_url
244
+ try {
245
+ const cfg = require(path.join(__dirname, '..', 'src', 'config'));
246
+ const localHost = opts.host || '192.168.1.114';
247
+ cfg.setConfigValue(opts.workdir || path.join(os.homedir(), '.local', 'share', 'adoremix'), 'TTS.provider', 'audio8');
248
+ cfg.setConfigValue(opts.workdir || path.join(os.homedir(), '.local', 'share', 'adoremix'), 'TTS.audio8_base_url', `http://${localHost}:${AUDIO8_DEFAULT_PORT}`);
249
+ logger.ok(`本地 config.ini 已更新: provider=audio8, audio8_base_url=http://${localHost}:${AUDIO8_DEFAULT_PORT}`);
250
+ } catch (e) {
251
+ logger.warn('本地 config.ini 更新失败(可手动设置):' + e.message.slice(0, 100));
252
+ }
253
+ logger.ok('Audio8 TTS 远程安装完成');
254
+ logger.log(`访问: http://${opts.host || '192.168.1.114'}:${AUDIO8_DEFAULT_PORT}/docs`);
255
+ return 0;
256
+ }
257
+
258
+ function uninstall(opts) {
259
+ opts = opts || {};
260
+ logger.ok('开始远程卸载 Audio8 TTS');
261
+ const cmds = [
262
+ `systemctl --now disable ${AUDIO8_SYSTEMD_NAME} 2>/dev/null; true`,
263
+ `systemctl stop ${AUDIO8_SYSTEMD_NAME} 2>/dev/null; true`,
264
+ `rm -f ${AUDIO8_SYSTEMD_PATH}`,
265
+ 'systemctl daemon-reload',
266
+ `rm -rf ${AUDIO8_DEPLOY_DIR}`,
267
+ `rm -rf ~/.cache/huggingface/hub/models--Audio8*`
268
+ ];
269
+ try {
270
+ const out = sshExec(cmds.join(' && '), opts);
271
+ process.stdout.write(out);
272
+ } catch (e) {
273
+ logger.error('SSH 执行失败:' + e.message.slice(0, 200));
274
+ return 1;
275
+ }
276
+ logger.ok('Audio8 TTS 远程卸载完成');
277
+ return 0;
278
+ }
279
+
280
+ async function status(opts) {
281
+ opts = opts || {};
282
+ const baseUrl = (opts.url || process.env.ADOREMIX_AUDIO8_BASE_URL || `http://${opts.host || '192.168.1.114'}:${AUDIO8_DEFAULT_PORT}`);
283
+ const urlObj = new URL(`${baseUrl}/v1/models`);
284
+ const lib = urlObj.protocol === 'https:' ? require('https') : http;
285
+ return new Promise(resolve => {
286
+ const req = lib.request({ hostname: urlObj.hostname, port: urlObj.port, path: urlObj.pathname, method: 'GET', timeout: 5000 }, res => {
287
+ if (res.statusCode === 200) {
288
+ logger.ok(`Audio8 服务健康: ${baseUrl}/v1/models 返回 ${res.statusCode}`);
289
+ resolve(0);
290
+ } else {
291
+ logger.warn(`Audio8 服务异常: ${baseUrl} 返回 ${res.statusCode}`);
292
+ resolve(1);
293
+ }
294
+ });
295
+ req.on('error', err => { logger.warn(`Audio8 服务不可达: ${err.message}`); resolve(1); });
296
+ req.on('timeout', () => { req.destroy(); logger.warn(`Audio8 服务超时: ${baseUrl}`); resolve(1); });
297
+ req.end();
298
+ });
299
+ }
300
+
301
+ module.exports = { synthesize, checkDeps, VOICES, DEFAULT_BASE_URL, install, uninstall, status };