jbc-dssi 1.1.163 → 1.1.164

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
@@ -27,6 +27,7 @@ import { createScheduleEngine } from './lib/schedules.js';
27
27
  import { createProcEngine } from './lib/proc-commands.js';
28
28
  import { createTtsEngine } from './lib/tts.js';
29
29
  import { createEdgeTts, EDGE_VOICES } from './lib/edge-tts.js';
30
+ import { createEdgeStream } from './lib/edge-stream.js';
30
31
  import { createAppReleaseWatch } from './lib/app-release-watch.js';
31
32
  import { PLUGIN_FEATURES } from './lib/plugin-features.js';
32
33
  import { MAX_FILE_BYTES, mimeOfFile, mimeOfImage, resolveWorkspaceFilePath } from './lib/workspace-bytes.js';
@@ -2229,14 +2230,19 @@ class BridgeConnection {
2229
2230
  if (op === 'stop') {
2230
2231
  this.tts.stop(id);
2231
2232
  this.edge?.stop(id);
2233
+ this.edgeStream?.stop(id);
2232
2234
  return;
2233
2235
  }
2234
2236
  if (op === 'voices') {
2235
2237
  this.send(FRAME.VOICE_LIST, { voices: EDGE_VOICES });
2236
2238
  return;
2237
2239
  }
2240
+ this.edge ??= createEdgeTts({ log: (message) => this.opts.log(message) });
2241
+ this.edgeStream ??= createEdgeStream({
2242
+ edge: this.edge,
2243
+ send: (frame) => this.send(FRAME.TTS_AUDIO, frame),
2244
+ });
2238
2245
  if (op === 'player') {
2239
- this.edge ??= createEdgeTts({ log: (message) => this.opts.log(message) });
2240
2246
  const result = await this.edge.synthesize({
2241
2247
  id,
2242
2248
  text: payload?.text,
@@ -2248,6 +2254,11 @@ class BridgeConnection {
2248
2254
  return;
2249
2255
  }
2250
2256
  if (op === 'open') {
2257
+ const voice = typeof payload?.voice === 'string' ? payload.voice : '';
2258
+ if (EDGE_VOICES.some((v) => v.id === voice)) {
2259
+ this.edgeStream.open(id, voice);
2260
+ return;
2261
+ }
2251
2262
  await this.tts.open({
2252
2263
  id,
2253
2264
  voice: payload?.voice,
@@ -2258,11 +2269,13 @@ class BridgeConnection {
2258
2269
  return;
2259
2270
  }
2260
2271
  if (op === 'text') {
2261
- this.tts.text(id, payload?.text);
2272
+ if (this.edgeStream?.has(id)) this.edgeStream.text(id, payload?.text);
2273
+ else this.tts.text(id, payload?.text);
2262
2274
  return;
2263
2275
  }
2264
2276
  if (op === 'end') {
2265
- this.tts.end(id);
2277
+ if (this.edgeStream?.has(id)) this.edgeStream.end(id);
2278
+ else this.tts.end(id);
2266
2279
  }
2267
2280
  }
2268
2281
 
@@ -0,0 +1,79 @@
1
+ export function createEdgeStream({ edge, send }) {
2
+ const sessions = new Map();
3
+
4
+ function open(id, voice) {
5
+ sessions.set(id, { voice, queue: [], busy: false, done: false, cancelled: false });
6
+ }
7
+
8
+ function has(id) {
9
+ return sessions.has(id);
10
+ }
11
+
12
+ function text(id, text) {
13
+ const s = sessions.get(id);
14
+ if (!s || s.cancelled) return;
15
+ const body = typeof text === 'string' ? text : '';
16
+ if (body.trim() === '') return;
17
+ s.queue.push(body);
18
+ pump(id);
19
+ }
20
+
21
+ function end(id) {
22
+ const s = sessions.get(id);
23
+ if (!s) return;
24
+ s.done = true;
25
+ if (!s.busy && s.queue.length === 0) finish(id);
26
+ }
27
+
28
+ function finish(id) {
29
+ const s = sessions.get(id);
30
+ if (!s) return;
31
+ sessions.delete(id);
32
+ if (!s.cancelled) send({ id, done: true, codec: 'mp3' });
33
+ }
34
+
35
+ async function pump(id) {
36
+ const s = sessions.get(id);
37
+ if (!s || s.busy || s.cancelled) return;
38
+ s.busy = true;
39
+ try {
40
+ while (s.queue.length > 0 && !s.cancelled) {
41
+ const body = s.queue.shift();
42
+ const result = await edge.synthesize({
43
+ id,
44
+ text: body,
45
+ voice: s.voice,
46
+ onChunk: (frame) => {
47
+ if (!s.cancelled) send(frame);
48
+ },
49
+ });
50
+ if (!result?.ok) {
51
+ const current = sessions.get(id);
52
+ if (current) {
53
+ sessions.delete(id);
54
+ send({ id, error: { code: 'edge', message: result?.message ?? '语音合成失败' } });
55
+ }
56
+ return;
57
+ }
58
+ }
59
+ } finally {
60
+ s.busy = false;
61
+ }
62
+ if (s.done && s.queue.length === 0) finish(id);
63
+ }
64
+
65
+ function stop(id) {
66
+ const s = sessions.get(id);
67
+ if (!s) return;
68
+ s.cancelled = true;
69
+ s.queue.length = 0;
70
+ sessions.delete(id);
71
+ edge.stop(id);
72
+ }
73
+
74
+ function stopAll() {
75
+ for (const id of [...sessions.keys()]) stop(id);
76
+ }
77
+
78
+ return { open, has, text, end, stop, stopAll };
79
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.163",
3
+ "version": "1.1.164",
4
4
  "type": "module",
5
5
  "description": "鲸聊 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [