jbc-dssi 1.1.154 → 1.1.156

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/index.js CHANGED
@@ -26,6 +26,7 @@ import { createGroupsEventBuffer, shouldBufferGroupEvent } from './lib/groups-ev
26
26
  import { createScheduleEngine } from './lib/schedules.js';
27
27
  import { createProcEngine } from './lib/proc-commands.js';
28
28
  import { createTtsEngine } from './lib/tts.js';
29
+ import { createEdgeTts, EDGE_VOICES } from './lib/edge-tts.js';
29
30
  import { createAppReleaseWatch } from './lib/app-release-watch.js';
30
31
  import { PLUGIN_FEATURES } from './lib/plugin-features.js';
31
32
  import { MAX_FILE_BYTES, mimeOfFile, resolveWorkspaceFilePath } from './lib/workspace-bytes.js';
@@ -2178,6 +2179,23 @@ class BridgeConnection {
2178
2179
  });
2179
2180
  if (op === 'stop') {
2180
2181
  this.tts.stop(id);
2182
+ this.edge?.stop(id);
2183
+ return;
2184
+ }
2185
+ if (op === 'voices') {
2186
+ this.send(FRAME.VOICE_LIST, { voices: EDGE_VOICES });
2187
+ return;
2188
+ }
2189
+ if (op === 'player') {
2190
+ this.edge ??= createEdgeTts({ log: (message) => this.opts.log(message) });
2191
+ const result = await this.edge.synthesize({
2192
+ id,
2193
+ text: payload?.text,
2194
+ voice: payload?.voice,
2195
+ onChunk: (frame) => this.send(FRAME.TTS_AUDIO, frame),
2196
+ });
2197
+ if (result?.ok) this.send(FRAME.TTS_AUDIO, { id, done: true, codec: 'mp3', bytes: result.bytes ?? 0 });
2198
+ else this.send(FRAME.TTS_AUDIO, { id, error: { code: 'player', message: result?.message ?? '语音合成失败' } });
2181
2199
  return;
2182
2200
  }
2183
2201
  if (op === 'open') {
@@ -2233,6 +2251,7 @@ class BridgeConnection {
2233
2251
  this.followAbort = null;
2234
2252
  try {
2235
2253
  this.tts?.stopAll();
2254
+ this.edge?.stopAll();
2236
2255
  } catch {
2237
2256
  /* 语音已停 */
2238
2257
  }
@@ -2286,6 +2305,7 @@ class BridgeConnection {
2286
2305
  if (got === this.opts.token) {
2287
2306
  this.authed = true;
2288
2307
  this.send(FRAME.READY, { authed: true });
2308
+ this.send(FRAME.VOICE_LIST, { voices: EDGE_VOICES });
2289
2309
  this.opts.log(`认证通过 App=${payload?.appVersion ?? '未知版本'}`);
2290
2310
  } else {
2291
2311
  // 长度和前几位足够定位问题:是少字符、多空格,还是完全另一个值
@@ -0,0 +1,86 @@
1
+ import { MsEdgeTTS, OUTPUT_FORMAT } from 'msedge-tts';
2
+
3
+ export const EDGE_VOICES = [
4
+ { id: 'zh-CN-XiaoxiaoNeural', name: '晓晓', gender: '女声', note: '温暖自然' },
5
+ { id: 'zh-CN-XiaoyiNeural', name: '晓伊', gender: '女声', note: '活泼' },
6
+ { id: 'zh-CN-XiaoxuanNeural', name: '晓萱', gender: '女声', note: '知性' },
7
+ { id: 'zh-CN-XiaochenNeural', name: '晓辰', gender: '女声', note: '温柔' },
8
+ { id: 'zh-CN-XiaohanNeural', name: '晓涵', gender: '女声', note: '亲和' },
9
+ { id: 'zh-CN-XiaomengNeural', name: '晓梦', gender: '女声', note: '甜' },
10
+ { id: 'zh-CN-XiaomoNeural', name: '晓墨', gender: '女声', note: '沉稳' },
11
+ { id: 'zh-CN-XiaoruiNeural', name: '晓睿', gender: '女声', note: '成熟' },
12
+ { id: 'zh-CN-YunxiNeural', name: '云希', gender: '男声', note: '阳光' },
13
+ { id: 'zh-CN-YunyangNeural', name: '云扬', gender: '男声', note: '专业播报' },
14
+ { id: 'zh-CN-YunjianNeural', name: '云健', gender: '男声', note: '浑厚' },
15
+ { id: 'zh-CN-YunxiaNeural', name: '云夏', gender: '男声', note: '少年' },
16
+ { id: 'zh-CN-YunzeNeural', name: '云泽', gender: '男声', note: '稳重' },
17
+ { id: 'zh-CN-liaoning-XiaobeiNeural', name: '晓北', gender: '女声', note: '东北话' },
18
+ { id: 'zh-CN-shaanxi-XiaoniNeural', name: '晓妮', gender: '女声', note: '陕西话' },
19
+ ];
20
+
21
+ export const DEFAULT_EDGE_VOICE = 'zh-CN-XiaoxiaoNeural';
22
+
23
+ const MP3 = OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3;
24
+
25
+ function voiceOf(id) {
26
+ return EDGE_VOICES.some((v) => v.id === id) ? id : DEFAULT_EDGE_VOICE;
27
+ }
28
+
29
+ export function createEdgeTts({ log }) {
30
+ const sessions = new Map();
31
+
32
+ async function synthesize({ id, text, voice, onChunk }) {
33
+ const body = String(text ?? '');
34
+ if (body.trim() === '') return { ok: false, message: '没有可朗读的文本' };
35
+ const tts = new MsEdgeTTS({ connectionTimeoutMs: 10_000, synthesisTimeoutMs: 120_000 });
36
+ try {
37
+ await tts.setMetadata(voiceOf(voice), MP3);
38
+ } catch (err) {
39
+ log?.(`[edge-tts] 元数据失败: ${err?.message ?? err}`);
40
+ return { ok: false, message: '微软语音服务连接失败' };
41
+ }
42
+ return await new Promise((resolve) => {
43
+ let seq = 0;
44
+ let bytes = 0;
45
+ let settled = false;
46
+ const { audioStream } = tts.toStream(body);
47
+ sessions.set(id, { close: () => audioStream.destroy() });
48
+ audioStream.on('data', (data) => {
49
+ if (settled) return;
50
+ const chunk = Buffer.from(data);
51
+ bytes += chunk.length;
52
+ onChunk?.({ id, seq: seq++, data: chunk.toString('base64'), codec: 'mp3' });
53
+ });
54
+ audioStream.on('close', () => {
55
+ if (settled) return;
56
+ settled = true;
57
+ sessions.delete(id);
58
+ resolve(bytes > 0 ? { ok: true, bytes } : { ok: false, message: '微软语音没有返回音频' });
59
+ });
60
+ audioStream.on('error', (err) => {
61
+ if (settled) return;
62
+ settled = true;
63
+ sessions.delete(id);
64
+ log?.(`[edge-tts] 合成失败: ${err?.message ?? err}`);
65
+ resolve({ ok: false, message: '微软语音合成失败' });
66
+ });
67
+ });
68
+ }
69
+
70
+ function stop(id) {
71
+ const session = sessions.get(id);
72
+ if (!session) return;
73
+ sessions.delete(id);
74
+ try {
75
+ session.close();
76
+ } catch {
77
+ /* 已关闭 */
78
+ }
79
+ }
80
+
81
+ function stopAll() {
82
+ for (const id of [...sessions.keys()]) stop(id);
83
+ }
84
+
85
+ return { synthesize, stop, stopAll, voices: EDGE_VOICES };
86
+ }
package/lib/protocol.js CHANGED
@@ -128,6 +128,10 @@ export const FRAME = {
128
128
 
129
129
  TTS_CMD: 0x7d,
130
130
 
131
+ VOICE_LIST_REQ: 0x3f,
132
+
133
+ VOICE_LIST: 0x42,
134
+
131
135
  TTS_AUDIO: 0x7e,
132
136
 
133
137
  PING: 0x40,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.154",
3
+ "version": "1.1.156",
4
4
  "type": "module",
5
5
  "description": "鲸聊 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [
@@ -52,6 +52,7 @@
52
52
  "prepack": "node scripts/build-vendor.mjs"
53
53
  },
54
54
  "dependencies": {
55
+ "msedge-tts": "^2.1.1",
55
56
  "ws": "^8.18.0"
56
57
  }
57
58
  }