jbc-dssi 1.1.150 → 1.1.151
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/lib/tts.js +14 -1
- package/package.json +1 -1
package/lib/tts.js
CHANGED
|
@@ -41,8 +41,18 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
|
|
|
41
41
|
onError?.({ id, error: normalizeError('busy') });
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
+
const early = [];
|
|
45
|
+
let earlyEnd = false;
|
|
46
|
+
sessions.set(id, {
|
|
47
|
+
early,
|
|
48
|
+
sendText: (text) => early.push(text),
|
|
49
|
+
end: () => {
|
|
50
|
+
earlyEnd = true;
|
|
51
|
+
},
|
|
52
|
+
});
|
|
44
53
|
const key = await resolveKey();
|
|
45
54
|
if (!key) {
|
|
55
|
+
sessions.delete(id);
|
|
46
56
|
onError?.({ id, error: normalizeError('no_key') });
|
|
47
57
|
return;
|
|
48
58
|
}
|
|
@@ -51,12 +61,14 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
|
|
|
51
61
|
try {
|
|
52
62
|
ws = new WebSocketImpl(url, { headers: { Authorization: `Bearer ${key}` } });
|
|
53
63
|
} catch (err) {
|
|
64
|
+
sessions.delete(id);
|
|
54
65
|
onError?.({ id, error: normalizeError('network', `语音连接失败:${err?.message ?? err}`) });
|
|
55
66
|
return;
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
const mux = createOggOpusStream();
|
|
59
70
|
const session = {
|
|
71
|
+
pendingFinish: earlyEnd,
|
|
60
72
|
ws,
|
|
61
73
|
mux,
|
|
62
74
|
settled: false,
|
|
@@ -173,7 +185,8 @@ export function createTtsEngine({ log, resolveKey, WebSocketImpl = WebSocket })
|
|
|
173
185
|
function end(id) {
|
|
174
186
|
const session = sessions.get(id);
|
|
175
187
|
if (!session) return;
|
|
176
|
-
session.finish();
|
|
188
|
+
if (typeof session.finish === 'function') session.finish();
|
|
189
|
+
else if (typeof session.end === 'function') session.end();
|
|
177
190
|
}
|
|
178
191
|
|
|
179
192
|
function stop(id) {
|