@streamoji/aitwin 0.3.7 → 0.3.8
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/dist/aitwin.cjs +3 -3
- package/dist/aitwin.js +1555 -1527
- package/package.json +1 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
import { jsxs as yr, jsx as yn } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as _r, useRef as
|
|
2
|
+
import { forwardRef as _r, useRef as U, useState as ot, useEffect as Le, useCallback as ke, useMemo as _n, useImperativeHandle as Sr } from "react";
|
|
3
3
|
import { PipecatClient as kr } from "@pipecat-ai/client-js";
|
|
4
|
-
import { WebSocketTransport as
|
|
4
|
+
import { WebSocketTransport as vr, DailyMediaManager as br, ProtobufFrameSerializer as Er } from "@pipecat-ai/websocket-transport";
|
|
5
5
|
const Tr = "https://aitwin.bubu.social", Wn = {
|
|
6
6
|
publicBase: Tr
|
|
7
|
-
}, Ar = "0.3.
|
|
7
|
+
}, Ar = "0.3.8", Ir = {
|
|
8
8
|
version: Ar
|
|
9
|
-
}, Mr = {},
|
|
9
|
+
}, Mr = {}, ft = "https://ai.aitwin.me", zt = `${Wn.publicBase}/custom-faces`, Pr = `${Wn.publicBase}/aitwin-workers/v${Ir.version}/visemeDiffPreview.worker.js`;
|
|
10
10
|
function Rr(e) {
|
|
11
11
|
if (e) return e;
|
|
12
12
|
const t = typeof import.meta < "u" ? Mr?.VITE_AITWIN_WORKER_URL : void 0;
|
|
13
13
|
return t?.trim() ? t.trim() : Pr;
|
|
14
14
|
}
|
|
15
|
-
const Dr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin",
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const Dr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Ft = 3e3, lt = 16, Sn = 3e3, xr = 4e3, Cr = 0.85, Br = 8, Yt = 400, Hn = "eng_a7f2b9c1", Jt = "eng_d4e8f3a2", Qe = "eng_c9b1e6d4", ze = Qe, $n = /* @__PURE__ */ new Set([
|
|
16
|
+
Jt,
|
|
17
|
+
Qe
|
|
18
18
|
]), qn = {
|
|
19
19
|
[Hn]: "oculus_direct",
|
|
20
|
-
[
|
|
21
|
-
[
|
|
20
|
+
[Qe]: "oculus_direct",
|
|
21
|
+
[Jt]: "inworld_word"
|
|
22
22
|
}, kn = {
|
|
23
23
|
google: Hn,
|
|
24
|
-
inworld:
|
|
25
|
-
cartesia:
|
|
24
|
+
inworld: Jt,
|
|
25
|
+
cartesia: Qe
|
|
26
26
|
};
|
|
27
27
|
function Fr(e) {
|
|
28
28
|
return qn[e];
|
|
29
29
|
}
|
|
30
|
-
function Lr(e) {
|
|
31
|
-
return e === Xe;
|
|
32
|
-
}
|
|
33
30
|
function Or(e) {
|
|
31
|
+
return e === Qe;
|
|
32
|
+
}
|
|
33
|
+
function Lr(e) {
|
|
34
34
|
if (e.ttsEngineId && e.ttsEngineId in qn)
|
|
35
35
|
return e.ttsEngineId;
|
|
36
36
|
const t = e.tts?.toLowerCase();
|
|
37
|
-
return t && t in kn ? kn[t] :
|
|
37
|
+
return t && t in kn ? kn[t] : ze;
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class Vt extends Error {
|
|
40
40
|
constructor(t = "AI twin not found") {
|
|
41
41
|
super(t), this.name = "AiTwinNotFoundError";
|
|
42
42
|
}
|
|
@@ -46,21 +46,21 @@ async function Nr(e, t = Dr) {
|
|
|
46
46
|
n.searchParams.set("id", e);
|
|
47
47
|
const r = await fetch(n.toString());
|
|
48
48
|
if (r.status === 404)
|
|
49
|
-
throw new
|
|
49
|
+
throw new Vt();
|
|
50
50
|
if (!r.ok)
|
|
51
51
|
throw new Error(`getAiTwin failed (${r.status})`);
|
|
52
52
|
const s = await r.json();
|
|
53
53
|
if (!s.success)
|
|
54
|
-
throw new
|
|
55
|
-
const { tts: i, token: a, ...o } = s.data,
|
|
54
|
+
throw new Vt(s.error ?? "AI twin not found");
|
|
55
|
+
const { tts: i, token: a, ...o } = s.data, d = String(o.authToken ?? a ?? "").trim() || void 0;
|
|
56
56
|
return {
|
|
57
57
|
...o,
|
|
58
|
-
ttsEngineId:
|
|
59
|
-
authToken:
|
|
58
|
+
ttsEngineId: Lr(s.data),
|
|
59
|
+
authToken: d
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
const Ur = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Vr = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Wr = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hr = "6TNvp3SCs4Og0a1ijm9TommXLql1", $r = "Swaraj Mali";
|
|
63
|
-
async function
|
|
63
|
+
async function Ot() {
|
|
64
64
|
const e = await fetch(Ur, {
|
|
65
65
|
method: "POST",
|
|
66
66
|
headers: {
|
|
@@ -80,7 +80,7 @@ async function Ft() {
|
|
|
80
80
|
throw new Error("getAuthToken returned no token");
|
|
81
81
|
return n;
|
|
82
82
|
}
|
|
83
|
-
async function qr(e, t =
|
|
83
|
+
async function qr(e, t = ft) {
|
|
84
84
|
const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
85
85
|
headers: { Authorization: `Bearer ${e}` }
|
|
86
86
|
});
|
|
@@ -98,7 +98,7 @@ function Kr(e) {
|
|
|
98
98
|
n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
|
|
99
99
|
return n;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function yt(e) {
|
|
102
102
|
return Uint8Array.from(e);
|
|
103
103
|
}
|
|
104
104
|
function Gr(e, t) {
|
|
@@ -109,7 +109,7 @@ async function jr(e, t) {
|
|
|
109
109
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
110
110
|
if (e.byteLength < 28)
|
|
111
111
|
throw new Error("Encrypted payload too small");
|
|
112
|
-
const n = new Uint8Array(e), r =
|
|
112
|
+
const n = new Uint8Array(e), r = yt(n.subarray(0, 12)), s = yt(n.subarray(12, 28)), i = yt(n.subarray(28)), a = yt(Gr(i, s)), o = await crypto.subtle.importKey(
|
|
113
113
|
"raw",
|
|
114
114
|
Kr(t),
|
|
115
115
|
{ name: "AES-GCM" },
|
|
@@ -122,22 +122,22 @@ async function jr(e, t) {
|
|
|
122
122
|
a
|
|
123
123
|
);
|
|
124
124
|
}
|
|
125
|
-
let
|
|
126
|
-
const
|
|
127
|
-
function
|
|
125
|
+
let Wt = null;
|
|
126
|
+
const Ht = /* @__PURE__ */ new Set();
|
|
127
|
+
function _t(e) {
|
|
128
128
|
return e.includes("/custom-faces/");
|
|
129
129
|
}
|
|
130
130
|
function bt(e) {
|
|
131
131
|
const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
|
|
132
|
-
if (!(e.encrypted ||
|
|
132
|
+
if (!(e.encrypted || _t(t) || _t(n)))
|
|
133
133
|
return { twinBase: n, binBase: t, encrypted: !1 };
|
|
134
|
-
const s =
|
|
134
|
+
const s = _t(t) ? t : _t(n) ? n : t;
|
|
135
135
|
return { twinBase: s, binBase: s, encrypted: !0 };
|
|
136
136
|
}
|
|
137
|
-
function
|
|
137
|
+
function Ze(e) {
|
|
138
138
|
return bt(e).encrypted;
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function vn(e, t = zt) {
|
|
141
141
|
const n = `${t.replace(/\/$/, "")}/${e}`;
|
|
142
142
|
return { twinBase: n, binBase: n, encrypted: !0 };
|
|
143
143
|
}
|
|
@@ -145,8 +145,8 @@ function zr(e, t) {
|
|
|
145
145
|
return (e ?? t)?.trim() || void 0;
|
|
146
146
|
}
|
|
147
147
|
function Yr(e) {
|
|
148
|
-
|
|
149
|
-
for (const t of
|
|
148
|
+
Wt = bt(e);
|
|
149
|
+
for (const t of Ht) t();
|
|
150
150
|
}
|
|
151
151
|
function Jr(e, t) {
|
|
152
152
|
const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
@@ -164,36 +164,36 @@ function Jr(e, t) {
|
|
|
164
164
|
encrypted: e.encrypted
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
|
-
function
|
|
168
|
-
if (!
|
|
167
|
+
function He() {
|
|
168
|
+
if (!Wt)
|
|
169
169
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
170
|
-
return
|
|
170
|
+
return Wt;
|
|
171
171
|
}
|
|
172
172
|
function Xr(e) {
|
|
173
|
-
return
|
|
173
|
+
return Ht.add(e), () => Ht.delete(e);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
176
|
-
const e =
|
|
177
|
-
return
|
|
175
|
+
function bn() {
|
|
176
|
+
const e = He();
|
|
177
|
+
return Ze(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
178
178
|
}
|
|
179
179
|
function Qr() {
|
|
180
|
-
const e =
|
|
181
|
-
return
|
|
180
|
+
const e = He();
|
|
181
|
+
return Ze(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
182
182
|
}
|
|
183
183
|
function Zr() {
|
|
184
|
-
const e =
|
|
185
|
-
return
|
|
184
|
+
const e = He();
|
|
185
|
+
return Ze(e) ? e.binBase : e.twinBase;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
188
|
-
return
|
|
187
|
+
function Mt() {
|
|
188
|
+
return Ze(He());
|
|
189
189
|
}
|
|
190
190
|
function es() {
|
|
191
|
-
const e =
|
|
192
|
-
return
|
|
191
|
+
const e = He();
|
|
192
|
+
return Ze(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
193
193
|
}
|
|
194
194
|
function ts() {
|
|
195
|
-
const e =
|
|
196
|
-
return
|
|
195
|
+
const e = He();
|
|
196
|
+
return Ze(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
197
197
|
}
|
|
198
198
|
function Kn(e) {
|
|
199
199
|
const t = e.split(/\r?\n/);
|
|
@@ -258,16 +258,16 @@ function os(e, t) {
|
|
|
258
258
|
const s = Math.max(0, Math.min(1, (t - e.wtime) / r));
|
|
259
259
|
return Math.min(n - 1, Math.floor(s * n));
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function Ye(e, t) {
|
|
262
262
|
const n = Math.max(0, Math.min(e.length - 1, t));
|
|
263
263
|
return e[n] ?? "";
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function Xt(e, t) {
|
|
266
266
|
const n = e.toLowerCase().replace(/[^a-z']/g, "");
|
|
267
|
-
return !n ||
|
|
267
|
+
return !n || Ye(n, t) !== "w" || t > 0 && Ye(n, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(n);
|
|
268
268
|
}
|
|
269
269
|
function cs(e, t) {
|
|
270
|
-
const n = e.toLowerCase(), r =
|
|
270
|
+
const n = e.toLowerCase(), r = Ye(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
|
|
271
271
|
return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
|
|
272
272
|
}
|
|
273
273
|
function us(e, t) {
|
|
@@ -276,22 +276,22 @@ function us(e, t) {
|
|
|
276
276
|
Math.min(n.length, t + 3)
|
|
277
277
|
);
|
|
278
278
|
if (/oo|ou|uw/.test(r)) return "U";
|
|
279
|
-
if (
|
|
280
|
-
const s =
|
|
279
|
+
if (Xt(n, t)) return "FF";
|
|
280
|
+
const s = Ye(n, t);
|
|
281
281
|
return s === "u" || s === "w" ? "U" : "O";
|
|
282
282
|
}
|
|
283
283
|
function ls(e, t) {
|
|
284
284
|
const n = e.toLowerCase();
|
|
285
|
-
if (
|
|
285
|
+
if (Xt(n, t)) return "FF";
|
|
286
286
|
const r = n.slice(Math.max(0, t - 2), t + 1);
|
|
287
287
|
if (/qu/.test(r)) return "U";
|
|
288
288
|
const s = n.slice(
|
|
289
289
|
Math.max(0, t - 1),
|
|
290
290
|
Math.min(n.length, t + 3)
|
|
291
291
|
);
|
|
292
|
-
return /wo|wh/.test(s) ||
|
|
292
|
+
return /wo|wh/.test(s) || Ye(n, t) === "o" ? "O" : "U";
|
|
293
293
|
}
|
|
294
|
-
const
|
|
294
|
+
const St = {
|
|
295
295
|
d: "DD",
|
|
296
296
|
t: "DD",
|
|
297
297
|
n: "DD",
|
|
@@ -304,11 +304,11 @@ const _t = {
|
|
|
304
304
|
j: "CH"
|
|
305
305
|
};
|
|
306
306
|
function fs(e, t) {
|
|
307
|
-
const n = e.toLowerCase(), r =
|
|
308
|
-
if (
|
|
307
|
+
const n = e.toLowerCase(), r = Ye(n, t);
|
|
308
|
+
if (St[r]) return St[r];
|
|
309
309
|
for (let s = 0; s < n.length; s++) {
|
|
310
310
|
const i = n[s];
|
|
311
|
-
if (
|
|
311
|
+
if (St[i]) return St[i];
|
|
312
312
|
}
|
|
313
313
|
return "DD";
|
|
314
314
|
}
|
|
@@ -350,9 +350,9 @@ function jn(e) {
|
|
|
350
350
|
function hs(e) {
|
|
351
351
|
return zn(e).find((n) => n.viseme !== "sil") ?? null;
|
|
352
352
|
}
|
|
353
|
-
function
|
|
353
|
+
function Ne(e) {
|
|
354
354
|
const t = Gn(e);
|
|
355
|
-
return jn(e) ? t +
|
|
355
|
+
return jn(e) ? t + Yt : t;
|
|
356
356
|
}
|
|
357
357
|
function ps(e) {
|
|
358
358
|
const t = [], n = hs(e);
|
|
@@ -367,7 +367,7 @@ function ps(e) {
|
|
|
367
367
|
from: r.viseme,
|
|
368
368
|
to: "sil",
|
|
369
369
|
fromVtime: s,
|
|
370
|
-
toVtime: s +
|
|
370
|
+
toVtime: s + Yt
|
|
371
371
|
}), t;
|
|
372
372
|
}
|
|
373
373
|
function zn(e) {
|
|
@@ -402,10 +402,10 @@ function Yn(e, t) {
|
|
|
402
402
|
const n = Math.max(0, t - e), r = n > 0 ? Math.max(n, ms) : 0, s = e, i = e + r;
|
|
403
403
|
return { gapMs: n, effectiveGapMs: r, holdEnd: e, transStart: s, transEnd: i };
|
|
404
404
|
}
|
|
405
|
-
const
|
|
405
|
+
const Qt = 16e3;
|
|
406
406
|
function Jn(e) {
|
|
407
407
|
const t = Number(e);
|
|
408
|
-
return Number.isFinite(t) && t > 0 ? t :
|
|
408
|
+
return Number.isFinite(t) && t > 0 ? t : Qt;
|
|
409
409
|
}
|
|
410
410
|
function _s(e) {
|
|
411
411
|
let t = e.trim();
|
|
@@ -417,7 +417,7 @@ function _s(e) {
|
|
|
417
417
|
function Ss(e) {
|
|
418
418
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
419
419
|
}
|
|
420
|
-
function En(e, t, n =
|
|
420
|
+
function En(e, t, n = Qt) {
|
|
421
421
|
const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
|
|
422
422
|
r.buffer,
|
|
423
423
|
r.byteOffset,
|
|
@@ -434,7 +434,7 @@ function ks(e) {
|
|
|
434
434
|
r[s] = n.charCodeAt(s);
|
|
435
435
|
return r;
|
|
436
436
|
}
|
|
437
|
-
async function
|
|
437
|
+
async function vs(e, t, n = Qt) {
|
|
438
438
|
const r = ks(t), s = Jn(n);
|
|
439
439
|
if (Ss(r)) {
|
|
440
440
|
const i = r.buffer.slice(
|
|
@@ -461,7 +461,7 @@ function Tn(e) {
|
|
|
461
461
|
t = Math.max(t, n.vtime + n.vduration);
|
|
462
462
|
return t;
|
|
463
463
|
}
|
|
464
|
-
function
|
|
464
|
+
function bs(e, t) {
|
|
465
465
|
for (const n of e)
|
|
466
466
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
467
467
|
return n;
|
|
@@ -469,292 +469,312 @@ function vs(e, t) {
|
|
|
469
469
|
}
|
|
470
470
|
function Xn(e, t) {
|
|
471
471
|
const n = [], r = [];
|
|
472
|
-
let s = null, i = !1, a = !1, o = !1,
|
|
473
|
-
const
|
|
474
|
-
|
|
475
|
-
},
|
|
472
|
+
let s = null, i = !1, a = !1, o = !1, d = !1, m = 0, c = 0, u = 0, f = 0, w = null, b = 1, p = t, P = !1, E = null, _ = 0, h = 0, A = !1, O = !1, B = 0;
|
|
473
|
+
const G = [], C = () => {
|
|
474
|
+
O = !1, B = 0, G.length = 0;
|
|
475
|
+
}, k = () => {
|
|
476
476
|
w != null && (clearTimeout(w), w = null);
|
|
477
|
-
},
|
|
478
|
-
for (const
|
|
477
|
+
}, I = () => {
|
|
478
|
+
for (const g of r) {
|
|
479
479
|
try {
|
|
480
|
-
|
|
480
|
+
g.onended = null, g.stop(0);
|
|
481
481
|
} catch {
|
|
482
482
|
}
|
|
483
483
|
try {
|
|
484
|
-
|
|
484
|
+
g.disconnect();
|
|
485
485
|
} catch {
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
r.length = 0;
|
|
489
489
|
}, M = () => {
|
|
490
|
-
for (const
|
|
491
|
-
|
|
492
|
-
},
|
|
493
|
-
if (!(
|
|
494
|
-
if (o && s &&
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
497
|
-
|
|
498
|
-
const
|
|
490
|
+
for (const g of r)
|
|
491
|
+
g.playbackRate.value = b;
|
|
492
|
+
}, Q = () => Math.max(_, h), x = () => {
|
|
493
|
+
if (!(P || !d || i || r.length > 0 || n.length > 0)) {
|
|
494
|
+
if (o && s && c > 0) {
|
|
495
|
+
const g = (s.currentTime - c) * 1e3, S = Q();
|
|
496
|
+
if (g < S) {
|
|
497
|
+
k();
|
|
498
|
+
const L = b > 0 ? (S - g) / b : S - g;
|
|
499
499
|
w = setTimeout(() => {
|
|
500
|
-
|
|
501
|
-
}, Math.max(0,
|
|
500
|
+
P || (a = !1, w = null, e.onSpeakingDone(), e.onNotify());
|
|
501
|
+
}, Math.max(0, L));
|
|
502
502
|
return;
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
|
-
a = !1,
|
|
505
|
+
a = !1, k(), e.onSpeakingDone(), e.onNotify();
|
|
506
506
|
}
|
|
507
|
-
},
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
507
|
+
}, z = (g) => {
|
|
508
|
+
const S = Ne(g);
|
|
509
|
+
if (S <= 0) {
|
|
510
510
|
e.onSpeakingDone(), e.onNotify();
|
|
511
511
|
return;
|
|
512
512
|
}
|
|
513
|
-
a = !0,
|
|
514
|
-
const
|
|
513
|
+
a = !0, m = performance.now(), e.onSpeakingStart(), e.onNotify(), k();
|
|
514
|
+
const L = b > 0 ? S / b : S;
|
|
515
515
|
w = setTimeout(() => {
|
|
516
|
-
|
|
517
|
-
},
|
|
518
|
-
},
|
|
519
|
-
|
|
520
|
-
const
|
|
521
|
-
if (!
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
word:
|
|
525
|
-
wtime:
|
|
526
|
-
wduration:
|
|
527
|
-
queueIndex:
|
|
528
|
-
gesture:
|
|
529
|
-
emphasis:
|
|
516
|
+
P || (a = !1, w = null, e.onSpeakingDone(), e.onNotify());
|
|
517
|
+
}, L);
|
|
518
|
+
}, J = (g, S, L, W) => {
|
|
519
|
+
S.length !== 0 && (W && (u = L), S.forEach((D) => {
|
|
520
|
+
const T = String(D.word ?? "").trim();
|
|
521
|
+
if (!T) return;
|
|
522
|
+
const Z = Math.round((D.start ?? 0) * 1e3), ae = D.duration != null ? Math.round(D.duration * 1e3) : D.end != null ? Math.max(1, Math.round((D.end - (D.start ?? 0)) * 1e3)) : 0;
|
|
523
|
+
g.push({
|
|
524
|
+
word: T,
|
|
525
|
+
wtime: u + Z,
|
|
526
|
+
wduration: ae,
|
|
527
|
+
queueIndex: g.length,
|
|
528
|
+
gesture: D.gesture ?? null,
|
|
529
|
+
emphasis: D.emphasis === !0
|
|
530
530
|
});
|
|
531
531
|
}));
|
|
532
|
-
},
|
|
533
|
-
|
|
534
|
-
const
|
|
535
|
-
if (!
|
|
536
|
-
const
|
|
537
|
-
let
|
|
538
|
-
Fr(
|
|
539
|
-
|
|
532
|
+
}, ie = (g, S, L, W, D, R) => {
|
|
533
|
+
L.length !== 0 && (D && (u = W), L.forEach((T) => {
|
|
534
|
+
const Z = String(T.symbol ?? T.viseme ?? "").trim();
|
|
535
|
+
if (!Z) return;
|
|
536
|
+
const ae = Math.round((T.start ?? 0) * 1e3), te = Math.max(1, Math.round((T.duration ?? 0) * 1e3)), ue = u + ae, me = bs(S, ue), ge = me ? os(me, ue) : 0;
|
|
537
|
+
let Ae;
|
|
538
|
+
Fr(R) === "oculus_direct" ? (Ae = ss(Z), Ae === "U" && me && Xt(me.word, ge) && (Ae = "FF")) : Ae = ds(
|
|
539
|
+
Z,
|
|
540
540
|
me?.word ?? "",
|
|
541
|
-
|
|
542
|
-
),
|
|
543
|
-
viseme:
|
|
541
|
+
ge
|
|
542
|
+
), g.push({
|
|
543
|
+
viseme: Ae,
|
|
544
544
|
weight: 1,
|
|
545
|
-
vtime:
|
|
546
|
-
vduration:
|
|
545
|
+
vtime: ue,
|
|
546
|
+
vduration: te
|
|
547
547
|
});
|
|
548
548
|
}), e.onNotify());
|
|
549
|
-
},
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
549
|
+
}, X = (g, S, L, W, D, R, T) => {
|
|
550
|
+
J(S, W, D, R), ie(
|
|
551
|
+
g,
|
|
552
|
+
S,
|
|
553
|
+
L,
|
|
554
|
+
D,
|
|
555
|
+
R,
|
|
556
|
+
T
|
|
557
557
|
);
|
|
558
|
-
},
|
|
558
|
+
}, he = (g, S) => {
|
|
559
559
|
if (!s) return;
|
|
560
|
-
const
|
|
561
|
-
let
|
|
562
|
-
const
|
|
563
|
-
|
|
564
|
-
const
|
|
565
|
-
if (
|
|
560
|
+
const L = s, W = L.currentTime;
|
|
561
|
+
let D = S?.startTime ?? f;
|
|
562
|
+
const R = S?.isFirstAudio ?? !a;
|
|
563
|
+
D < W && (D = W + 0.1), f = D + g.duration;
|
|
564
|
+
const T = L.createBufferSource();
|
|
565
|
+
if (T.buffer = g, T.playbackRate.value = b, T.connect(L.destination), E && T.connect(E), r.push(T), P) {
|
|
566
566
|
r.pop();
|
|
567
567
|
return;
|
|
568
568
|
}
|
|
569
|
-
if (
|
|
570
|
-
a = !0, e.onSpeakingStart(),
|
|
571
|
-
const
|
|
572
|
-
|
|
569
|
+
if (R) {
|
|
570
|
+
a = !0, e.onSpeakingStart(), S?.isFirstOfStream ? (c = D, u = 0, S.onNewStream?.()) : c <= 0 && (c = D);
|
|
571
|
+
const Z = (D - W) * 1e3;
|
|
572
|
+
m = performance.now() + Z;
|
|
573
573
|
}
|
|
574
|
-
|
|
575
|
-
const
|
|
576
|
-
|
|
577
|
-
},
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
574
|
+
T.onended = () => {
|
|
575
|
+
const Z = r.indexOf(T);
|
|
576
|
+
Z >= 0 && r.splice(Z, 1), x(), e.onNotify();
|
|
577
|
+
}, T.start(D), c > 0 && (h = Math.max(
|
|
578
|
+
h,
|
|
579
|
+
(f - c) * 1e3
|
|
580
|
+
));
|
|
581
|
+
}, fe = () => {
|
|
582
|
+
if (!O || G.length === 0) return;
|
|
583
|
+
O = !1;
|
|
584
|
+
const g = G.splice(0);
|
|
585
|
+
B = 0;
|
|
586
|
+
for (let S = 0; S < g.length; S++)
|
|
587
|
+
he(g[S].audioBuffer, {
|
|
588
|
+
isFirstAudio: S === 0 && !a,
|
|
589
|
+
isFirstOfStream: S === 0
|
|
587
590
|
});
|
|
588
591
|
e.onNotify();
|
|
589
|
-
}, de = async (
|
|
590
|
-
if (
|
|
591
|
-
const
|
|
592
|
-
if (!
|
|
593
|
-
if (
|
|
594
|
-
|
|
595
|
-
let
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
592
|
+
}, de = async (g, S, L, W, D, R, T) => {
|
|
593
|
+
if (P) return;
|
|
594
|
+
const Z = Jn(T?.sampleRate), ae = T?.newStream === !0;
|
|
595
|
+
if (!L?.trim()) {
|
|
596
|
+
if (W.length === 0 && D.length === 0) return;
|
|
597
|
+
ae && (u = 0, _ = 0, h = 0, g.length = 0, S.length = 0, T?.onNewStream?.());
|
|
598
|
+
let te = T?.audioOffsetMs != null ? T.audioOffsetMs : u;
|
|
599
|
+
T?.audioOffsetMs == null && R && g.length > 0 && !ae && (te = Tn(g));
|
|
600
|
+
const ue = T?.audioOffsetMs != null ? !0 : R;
|
|
601
|
+
X(
|
|
602
|
+
g,
|
|
603
|
+
S,
|
|
604
|
+
W,
|
|
605
|
+
D,
|
|
606
|
+
te,
|
|
607
|
+
ue,
|
|
608
|
+
p
|
|
609
|
+
), _ = Math.max(_, Ne(g)), !a && _ > 0 && z(g), e.onNotify();
|
|
605
610
|
return;
|
|
606
611
|
}
|
|
607
612
|
if (i) {
|
|
608
613
|
n.push({
|
|
609
|
-
audio:
|
|
610
|
-
visemes:
|
|
611
|
-
words:
|
|
612
|
-
isNewSegment:
|
|
613
|
-
sampleRate:
|
|
614
|
-
newStream:
|
|
614
|
+
audio: L,
|
|
615
|
+
visemes: W,
|
|
616
|
+
words: D,
|
|
617
|
+
isNewSegment: R,
|
|
618
|
+
sampleRate: Z,
|
|
619
|
+
newStream: ae,
|
|
620
|
+
audioOffsetMs: T?.audioOffsetMs
|
|
615
621
|
});
|
|
616
622
|
return;
|
|
617
623
|
}
|
|
618
624
|
i = !0;
|
|
619
625
|
try {
|
|
620
|
-
const
|
|
621
|
-
s || (s = new
|
|
622
|
-
const
|
|
623
|
-
|
|
624
|
-
const me = await
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
626
|
+
const te = window.AudioContext || window.webkitAudioContext;
|
|
627
|
+
s || (s = new te());
|
|
628
|
+
const ue = s;
|
|
629
|
+
ue.state === "suspended" && await ue.resume(), E || (E = ue.createMediaStreamDestination());
|
|
630
|
+
const me = await vs(
|
|
631
|
+
ue,
|
|
632
|
+
L,
|
|
633
|
+
Z
|
|
628
634
|
);
|
|
629
635
|
o = !0;
|
|
630
|
-
const
|
|
631
|
-
if (
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
636
|
+
const ge = !a;
|
|
637
|
+
if (A && (e.shouldHoldForWarmup?.() ?? !1) && (O || ge && ae)) {
|
|
638
|
+
O || (O = !0, B = 0, G.length = 0, ae && (u = 0, _ = 0, h = 0, g.length = 0, S.length = 0, T?.onNewStream?.()));
|
|
639
|
+
const v = T?.audioOffsetMs != null ? T.audioOffsetMs : B, N = T?.audioOffsetMs != null ? !0 : R;
|
|
640
|
+
X(
|
|
641
|
+
g,
|
|
642
|
+
S,
|
|
643
|
+
W,
|
|
644
|
+
D,
|
|
645
|
+
v,
|
|
637
646
|
N,
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
), N += Math.round(me.duration * 1e3), F.push({ audioBuffer: me }), _ = Math.max(_, Fe(y)), e.onNotify();
|
|
647
|
+
p
|
|
648
|
+
), T?.audioOffsetMs == null && (B += Math.round(me.duration * 1e3)), G.push({ audioBuffer: me }), _ = Math.max(_, Ne(g)), e.onNotify();
|
|
641
649
|
return;
|
|
642
650
|
}
|
|
643
|
-
|
|
644
|
-
const
|
|
645
|
-
let
|
|
646
|
-
|
|
647
|
-
const
|
|
648
|
-
|
|
649
|
-
startTime:
|
|
650
|
-
isFirstAudio:
|
|
651
|
-
isFirstOfStream:
|
|
652
|
-
}),
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
), _ = Math.max(_,
|
|
661
|
-
} catch (
|
|
662
|
-
console.error("[avatarChunkPlayback] audio chunk failed:",
|
|
651
|
+
ge && ae && (_ = 0, h = 0, g.length = 0, S.length = 0, u = 0, T?.onNewStream?.());
|
|
652
|
+
const Fe = ue.currentTime;
|
|
653
|
+
let De = f;
|
|
654
|
+
De < Fe && (De = Fe + 0.1);
|
|
655
|
+
const dt = T?.audioOffsetMs ?? (ge && ae ? 0 : c > 0 ? Math.max(0, (De - c) * 1e3) : 0), l = T?.audioOffsetMs != null ? !0 : R;
|
|
656
|
+
he(me, {
|
|
657
|
+
startTime: De,
|
|
658
|
+
isFirstAudio: ge,
|
|
659
|
+
isFirstOfStream: ge && ae
|
|
660
|
+
}), X(
|
|
661
|
+
g,
|
|
662
|
+
S,
|
|
663
|
+
W,
|
|
664
|
+
D,
|
|
665
|
+
dt,
|
|
666
|
+
l,
|
|
667
|
+
p
|
|
668
|
+
), _ = Math.max(_, Ne(g));
|
|
669
|
+
} catch (te) {
|
|
670
|
+
console.error("[avatarChunkPlayback] audio chunk failed:", te);
|
|
663
671
|
} finally {
|
|
664
|
-
if (i = !1,
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
672
|
+
if (i = !1, P) return;
|
|
673
|
+
const te = n.shift();
|
|
674
|
+
te ? await de(
|
|
675
|
+
g,
|
|
676
|
+
S,
|
|
677
|
+
te.audio,
|
|
678
|
+
te.visemes,
|
|
679
|
+
te.words,
|
|
680
|
+
te.isNewSegment,
|
|
673
681
|
{
|
|
674
|
-
sampleRate:
|
|
675
|
-
newStream:
|
|
676
|
-
|
|
682
|
+
sampleRate: te.sampleRate,
|
|
683
|
+
newStream: te.newStream,
|
|
684
|
+
audioOffsetMs: te.audioOffsetMs,
|
|
685
|
+
onNewStream: T?.onNewStream
|
|
677
686
|
}
|
|
678
|
-
) :
|
|
687
|
+
) : x();
|
|
679
688
|
}
|
|
680
689
|
};
|
|
681
690
|
return {
|
|
682
|
-
setStreamTtsEngineId: (
|
|
683
|
-
|
|
691
|
+
setStreamTtsEngineId: (g) => {
|
|
692
|
+
p = g;
|
|
684
693
|
},
|
|
685
|
-
setPlaybackSpeed: (
|
|
686
|
-
b = Math.max(0.1, Math.min(1,
|
|
694
|
+
setPlaybackSpeed: (g) => {
|
|
695
|
+
b = Math.max(0.1, Math.min(1, g)), M();
|
|
687
696
|
},
|
|
688
697
|
getPlaybackSpeed: () => b,
|
|
689
|
-
setLipsyncWarmupHoldEnabled: (
|
|
690
|
-
|
|
698
|
+
setLipsyncWarmupHoldEnabled: (g) => {
|
|
699
|
+
A = g, g || C();
|
|
691
700
|
},
|
|
692
|
-
isWarmingUp: () =>
|
|
693
|
-
releaseWarmupHold:
|
|
694
|
-
resetForNewStream: (
|
|
695
|
-
|
|
701
|
+
isWarmingUp: () => O,
|
|
702
|
+
releaseWarmupHold: fe,
|
|
703
|
+
resetForNewStream: (g) => {
|
|
704
|
+
P = !1, d = !1, p = g, _ = 0, h = 0;
|
|
696
705
|
},
|
|
697
706
|
/** Next sentence in the same bot turn — keep viseme tail, allow more chunks. */
|
|
698
707
|
resumeBotStream: () => {
|
|
699
|
-
|
|
708
|
+
P = !1, d = !1;
|
|
700
709
|
},
|
|
701
710
|
/** After interrupt — allow the next utterance to queue/play again. */
|
|
702
711
|
clearAborted: () => {
|
|
703
|
-
|
|
712
|
+
P = !1;
|
|
704
713
|
},
|
|
705
714
|
/** Call from a user gesture before bot audio (connect / unlock). */
|
|
706
715
|
primeAudioContext: async () => {
|
|
707
|
-
const
|
|
708
|
-
s || (s = new
|
|
716
|
+
const g = window.AudioContext || window.webkitAudioContext;
|
|
717
|
+
s || (s = new g()), s.state === "suspended" && await s.resume(), s && !E && (E = s.createMediaStreamDestination());
|
|
709
718
|
},
|
|
710
719
|
stop: () => {
|
|
711
|
-
|
|
720
|
+
P = !0, k(), I(), n.length = 0, i = !1, a = !1, o = !1, d = !1, u = 0, f = 0, c = 0, m = 0, _ = 0, h = 0, C();
|
|
712
721
|
},
|
|
713
|
-
markStreamComplete: (
|
|
714
|
-
if (_ = Math.max(_,
|
|
715
|
-
|
|
722
|
+
markStreamComplete: (g) => {
|
|
723
|
+
if (_ = Math.max(_, Ne(g)), d = !0, !o && g.length > 0) {
|
|
724
|
+
z(g);
|
|
716
725
|
return;
|
|
717
726
|
}
|
|
718
|
-
|
|
727
|
+
x();
|
|
719
728
|
},
|
|
720
729
|
playAudioChunk: de,
|
|
721
|
-
queueTimingsOnly: (
|
|
722
|
-
if (
|
|
723
|
-
let
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
730
|
+
queueTimingsOnly: (g, S, L, W, D, R) => {
|
|
731
|
+
if (P) return;
|
|
732
|
+
let T = R ?? u;
|
|
733
|
+
R == null && D && g.length > 0 && (T = Tn(g));
|
|
734
|
+
const Z = R != null ? !0 : D;
|
|
735
|
+
X(
|
|
736
|
+
g,
|
|
737
|
+
S,
|
|
738
|
+
L,
|
|
739
|
+
W,
|
|
740
|
+
T,
|
|
741
|
+
Z,
|
|
742
|
+
p
|
|
743
|
+
), _ = Math.max(_, Ne(g));
|
|
744
|
+
},
|
|
745
|
+
getPlaybackElapsedMs: () => o && s && c > 0 ? Math.max(
|
|
735
746
|
0,
|
|
736
|
-
(s.currentTime -
|
|
737
|
-
) : a ? Math.max(0, (performance.now() -
|
|
738
|
-
isSpeaking: () => a ? !0 : !o || !s ||
|
|
747
|
+
(s.currentTime - c) * 1e3
|
|
748
|
+
) : a ? Math.max(0, (performance.now() - m) * b) : 0,
|
|
749
|
+
isSpeaking: () => a ? !0 : !o || !s || c <= 0 ? !1 : (s.currentTime - c) * 1e3 < Q(),
|
|
739
750
|
getVoiceStream: () => E ? E.stream : null,
|
|
740
|
-
getPlaybackStartPerf: () =>
|
|
751
|
+
getPlaybackStartPerf: () => m,
|
|
741
752
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
742
753
|
bargeIn: () => {
|
|
743
|
-
|
|
754
|
+
P = !0, d = !1, k(), I(), n.length = 0, i = !1, a = !1, o = !1, u = 0, f = 0, c = 0, m = 0, _ = 0, h = 0, C();
|
|
744
755
|
},
|
|
745
756
|
interrupt: () => {
|
|
746
|
-
|
|
757
|
+
P = !0, d = !1, k(), I(), n.length = 0, i = !1, a = !1, o = !1, u = 0, f = 0, c = 0, m = 0, _ = 0, h = 0, C();
|
|
747
758
|
}
|
|
748
759
|
};
|
|
749
760
|
}
|
|
750
|
-
function
|
|
761
|
+
function Pt(e, t) {
|
|
751
762
|
let n = null;
|
|
752
763
|
for (const r of e)
|
|
753
764
|
t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
|
|
754
|
-
|
|
765
|
+
if (!n) {
|
|
766
|
+
let r = null, s = -1;
|
|
767
|
+
for (const i of e) {
|
|
768
|
+
if (i.viseme === "sil") continue;
|
|
769
|
+
const a = i.vtime + i.vduration;
|
|
770
|
+
a <= t && a >= s && (r = i, s = a);
|
|
771
|
+
}
|
|
772
|
+
return r?.viseme ?? "sil";
|
|
773
|
+
}
|
|
774
|
+
return n.viseme;
|
|
755
775
|
}
|
|
756
776
|
function Qn(e, t, n = 120) {
|
|
757
|
-
const r =
|
|
777
|
+
const r = Pt(e, t);
|
|
758
778
|
if (r !== "sil") return r;
|
|
759
779
|
let s = null;
|
|
760
780
|
for (const i of e) {
|
|
@@ -788,203 +808,204 @@ function Ts(e, t) {
|
|
|
788
808
|
return null;
|
|
789
809
|
}
|
|
790
810
|
}
|
|
791
|
-
const
|
|
792
|
-
function An(e, t =
|
|
811
|
+
const Zt = 0.5, en = 1.5, Zn = "Olivia", er = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Rt = 0.85;
|
|
812
|
+
function An(e, t = ft, n = {}) {
|
|
793
813
|
const r = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], a = [], o = [];
|
|
794
|
-
let
|
|
795
|
-
const
|
|
814
|
+
let d = "", m = "neutral", c = "", u = ze;
|
|
815
|
+
const f = /* @__PURE__ */ new Set();
|
|
796
816
|
let w = 0, b = null;
|
|
797
|
-
const
|
|
798
|
-
let
|
|
817
|
+
const p = () => f.forEach((C) => C());
|
|
818
|
+
let P = () => !1;
|
|
799
819
|
const E = Xn(
|
|
800
820
|
{
|
|
801
821
|
onSpeakingStart: () => e("speaking"),
|
|
802
822
|
onSpeakingDone: () => e("done"),
|
|
803
|
-
onNotify:
|
|
804
|
-
shouldHoldForWarmup: () =>
|
|
823
|
+
onNotify: p,
|
|
824
|
+
shouldHoldForWarmup: () => P()
|
|
805
825
|
},
|
|
806
|
-
|
|
807
|
-
), _ = () => E.getPlaybackElapsedMs(),
|
|
826
|
+
ze
|
|
827
|
+
), _ = () => E.getPlaybackElapsedMs(), h = (C, k = d) => {
|
|
808
828
|
if (!n.onLipsyncDebug) return;
|
|
809
|
-
const
|
|
829
|
+
const I = _(), M = s;
|
|
810
830
|
n.onLipsyncDebug({
|
|
811
|
-
event:
|
|
812
|
-
spokenText:
|
|
813
|
-
mood:
|
|
831
|
+
event: C,
|
|
832
|
+
spokenText: k,
|
|
833
|
+
mood: m,
|
|
814
834
|
playbackAnchorPerf: E.getPlaybackStartPerf(),
|
|
815
|
-
playbackElapsedMs:
|
|
816
|
-
queueLength:
|
|
817
|
-
activeViseme:
|
|
818
|
-
segments: o.map((
|
|
819
|
-
...
|
|
820
|
-
visemes: [...
|
|
835
|
+
playbackElapsedMs: I,
|
|
836
|
+
queueLength: M.length,
|
|
837
|
+
activeViseme: Pt(M, I),
|
|
838
|
+
segments: o.map((Q) => ({
|
|
839
|
+
...Q,
|
|
840
|
+
visemes: [...Q.visemes]
|
|
821
841
|
}))
|
|
822
842
|
});
|
|
823
|
-
},
|
|
824
|
-
n.onLipsyncDebug && (b = { event:
|
|
843
|
+
}, A = (C, k) => {
|
|
844
|
+
n.onLipsyncDebug && (b = { event: C, spokenText: k }, w === 0 && (w = requestAnimationFrame(() => {
|
|
825
845
|
w = 0;
|
|
826
|
-
const
|
|
827
|
-
b = null,
|
|
846
|
+
const I = b;
|
|
847
|
+
b = null, I && h(I.event, I.spokenText);
|
|
828
848
|
})));
|
|
829
|
-
},
|
|
849
|
+
}, O = (C, k, I, M, Q) => {
|
|
830
850
|
if (!n.onLipsyncDebug) return;
|
|
831
|
-
const
|
|
832
|
-
(
|
|
851
|
+
const x = s.slice(k), z = I.filter(
|
|
852
|
+
(J) => String(J.symbol ?? J.viseme ?? "").trim()
|
|
833
853
|
);
|
|
834
854
|
o.push({
|
|
835
|
-
spokenText:
|
|
836
|
-
audioOffsetMs:
|
|
837
|
-
isNewSegment:
|
|
838
|
-
chunkDurationMs:
|
|
855
|
+
spokenText: C,
|
|
856
|
+
audioOffsetMs: x[0]?.vtime ?? 0,
|
|
857
|
+
isNewSegment: M,
|
|
858
|
+
chunkDurationMs: Q,
|
|
839
859
|
receivedAtMs: performance.now(),
|
|
840
|
-
visemes:
|
|
841
|
-
const
|
|
860
|
+
visemes: x.map((J, ie) => {
|
|
861
|
+
const X = z[ie];
|
|
842
862
|
return {
|
|
843
|
-
rawSymbol: String(
|
|
844
|
-
viseme:
|
|
845
|
-
startSec: Number(
|
|
846
|
-
durationSec: Number(
|
|
847
|
-
vtimeMs:
|
|
848
|
-
vdurationMs:
|
|
863
|
+
rawSymbol: String(X?.symbol ?? X?.viseme ?? J.viseme).trim(),
|
|
864
|
+
viseme: J.viseme,
|
|
865
|
+
startSec: Number(X?.start ?? 0),
|
|
866
|
+
durationSec: Number(X?.duration ?? 0),
|
|
867
|
+
vtimeMs: J.vtime,
|
|
868
|
+
vdurationMs: J.vduration
|
|
849
869
|
};
|
|
850
870
|
})
|
|
851
871
|
});
|
|
852
|
-
},
|
|
853
|
-
E.stop(), s.length = 0, i.length = 0, a.length = 0,
|
|
872
|
+
}, B = () => {
|
|
873
|
+
E.stop(), s.length = 0, i.length = 0, a.length = 0, m = "neutral", o.length = 0, d = "", e("idle"), A("reset"), p();
|
|
854
874
|
};
|
|
855
875
|
return {
|
|
856
|
-
setDeveloperToken: (
|
|
857
|
-
|
|
876
|
+
setDeveloperToken: (C) => {
|
|
877
|
+
c = C;
|
|
858
878
|
},
|
|
859
|
-
setTtsEngineId: (
|
|
860
|
-
|
|
879
|
+
setTtsEngineId: (C) => {
|
|
880
|
+
u = C;
|
|
861
881
|
},
|
|
862
|
-
getTtsEngineId: () =>
|
|
863
|
-
speak: async (
|
|
864
|
-
|
|
865
|
-
const
|
|
866
|
-
if (!
|
|
882
|
+
getTtsEngineId: () => u,
|
|
883
|
+
speak: async (C, k) => {
|
|
884
|
+
B(), e("loading"), d = C, o.length = 0;
|
|
885
|
+
const I = c.trim();
|
|
886
|
+
if (!I)
|
|
867
887
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
868
|
-
const
|
|
869
|
-
E.resetForNewStream(
|
|
870
|
-
const
|
|
871
|
-
|
|
872
|
-
Math.min(
|
|
873
|
-
),
|
|
874
|
-
user_query:
|
|
875
|
-
ttsEngineId:
|
|
876
|
-
speakingRate:
|
|
888
|
+
const M = k?.ttsEngineId ?? u ?? ze;
|
|
889
|
+
E.resetForNewStream(M), E.setStreamTtsEngineId(M), await E.primeAudioContext();
|
|
890
|
+
const Q = k?.voiceId ?? Zn, x = k?.speakingRate ?? Rt, z = Math.max(
|
|
891
|
+
Zt,
|
|
892
|
+
Math.min(en, x)
|
|
893
|
+
), J = {
|
|
894
|
+
user_query: C,
|
|
895
|
+
ttsEngineId: M,
|
|
896
|
+
speakingRate: z,
|
|
877
897
|
tenant: "aiTwin"
|
|
878
898
|
};
|
|
879
|
-
$n.has(
|
|
899
|
+
$n.has(M) && (J.voice_id = Q);
|
|
880
900
|
try {
|
|
881
|
-
const
|
|
901
|
+
const ie = await fetch(r, {
|
|
882
902
|
method: "POST",
|
|
883
903
|
headers: {
|
|
884
904
|
"Content-Type": "application/json",
|
|
885
|
-
Authorization: `Bearer ${
|
|
905
|
+
Authorization: `Bearer ${I}`
|
|
886
906
|
},
|
|
887
|
-
body: JSON.stringify(
|
|
907
|
+
body: JSON.stringify(J)
|
|
888
908
|
});
|
|
889
|
-
if (!
|
|
890
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
891
|
-
const
|
|
892
|
-
if (!
|
|
893
|
-
const
|
|
894
|
-
let
|
|
895
|
-
const
|
|
896
|
-
const
|
|
897
|
-
if (
|
|
898
|
-
if (
|
|
899
|
-
const
|
|
900
|
-
|
|
909
|
+
if (!ie.ok)
|
|
910
|
+
throw new Error(`avatar_ttsWithPoses failed (${ie.status})`);
|
|
911
|
+
const X = ie.body;
|
|
912
|
+
if (!X) throw new Error("No response body");
|
|
913
|
+
const he = X.getReader(), fe = new TextDecoder();
|
|
914
|
+
let de = "";
|
|
915
|
+
const ne = async (g) => {
|
|
916
|
+
const S = Kn(g);
|
|
917
|
+
if (S) {
|
|
918
|
+
if (S.event === "audio") {
|
|
919
|
+
const L = S.data.chunk, W = S.data.visemes ?? [], D = S.data.words ?? [], R = S.data.is_new_segment ?? !1, T = S.data.sample_rate, Z = Number(S.data.audio_offset_ms ?? 0), ae = s.length;
|
|
920
|
+
L ? (await E.playAudioChunk(
|
|
901
921
|
s,
|
|
902
922
|
i,
|
|
903
|
-
|
|
904
|
-
|
|
923
|
+
L,
|
|
924
|
+
W,
|
|
925
|
+
D,
|
|
926
|
+
R,
|
|
927
|
+
{ sampleRate: T, audioOffsetMs: Z }
|
|
928
|
+
), O(
|
|
905
929
|
C,
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
), N(
|
|
930
|
+
ae,
|
|
931
|
+
W,
|
|
909
932
|
R,
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
B,
|
|
913
|
-
Ts(P, Y)
|
|
914
|
-
), v("audio_chunk", R)) : ($.length > 0 || C.length > 0) && (E.queueTimingsOnly(
|
|
933
|
+
Ts(L, T)
|
|
934
|
+
), A("audio_chunk", C)) : (W.length > 0 || D.length > 0) && (E.queueTimingsOnly(
|
|
915
935
|
s,
|
|
916
936
|
i,
|
|
917
|
-
|
|
937
|
+
W,
|
|
938
|
+
D,
|
|
939
|
+
R,
|
|
940
|
+
Z
|
|
941
|
+
), O(
|
|
918
942
|
C,
|
|
919
|
-
|
|
920
|
-
|
|
943
|
+
ae,
|
|
944
|
+
W,
|
|
921
945
|
R,
|
|
922
|
-
ee,
|
|
923
|
-
$,
|
|
924
|
-
B,
|
|
925
946
|
null
|
|
926
|
-
),
|
|
927
|
-
} else if (
|
|
928
|
-
const
|
|
929
|
-
typeof
|
|
930
|
-
const
|
|
931
|
-
if (Array.isArray(
|
|
947
|
+
), A("audio_chunk", C));
|
|
948
|
+
} else if (S.event === "metadata") {
|
|
949
|
+
const L = S.data.mood;
|
|
950
|
+
typeof L == "string" && L.trim() && (m = L.trim());
|
|
951
|
+
const W = S.data.sentence_emotions;
|
|
952
|
+
if (Array.isArray(W)) {
|
|
932
953
|
a.length = 0;
|
|
933
|
-
for (const
|
|
934
|
-
if (!
|
|
935
|
-
const
|
|
954
|
+
for (const D of W) {
|
|
955
|
+
if (!D || typeof D != "object") continue;
|
|
956
|
+
const R = D;
|
|
936
957
|
a.push({
|
|
937
|
-
sentence_index: Number(
|
|
938
|
-
text: String(
|
|
939
|
-
sentiment: typeof
|
|
940
|
-
emotion: String(
|
|
941
|
-
start_word: Number(
|
|
942
|
-
end_word: Number(
|
|
958
|
+
sentence_index: Number(R.sentence_index ?? 0),
|
|
959
|
+
text: String(R.text ?? ""),
|
|
960
|
+
sentiment: typeof R.sentiment == "string" ? R.sentiment : void 0,
|
|
961
|
+
emotion: String(R.emotion ?? m),
|
|
962
|
+
start_word: Number(R.start_word ?? 0),
|
|
963
|
+
end_word: Number(R.end_word ?? 0)
|
|
943
964
|
});
|
|
944
965
|
}
|
|
945
966
|
}
|
|
946
|
-
|
|
947
|
-
} else if (
|
|
967
|
+
p(), A("metadata", C);
|
|
968
|
+
} else if (S.event === "error")
|
|
948
969
|
throw new Error(
|
|
949
|
-
String(
|
|
970
|
+
String(S.data.message ?? "avatar_ttsWithPoses stream error")
|
|
950
971
|
);
|
|
951
972
|
}
|
|
952
973
|
};
|
|
953
974
|
for (; ; ) {
|
|
954
|
-
const { done:
|
|
955
|
-
|
|
956
|
-
const
|
|
975
|
+
const { done: g, value: S } = await he.read();
|
|
976
|
+
S && (de += fe.decode(S, { stream: !0 }));
|
|
977
|
+
const L = de.split(`
|
|
957
978
|
|
|
958
979
|
`);
|
|
959
|
-
|
|
960
|
-
for (const
|
|
961
|
-
if (
|
|
962
|
-
|
|
980
|
+
de = L.pop() ?? "";
|
|
981
|
+
for (const W of L) await ne(W);
|
|
982
|
+
if (g) {
|
|
983
|
+
de.trim() && await ne(de.trim()), E.markStreamComplete(s), A("bot_stopped", C);
|
|
963
984
|
break;
|
|
964
985
|
}
|
|
965
986
|
}
|
|
966
|
-
} catch (
|
|
967
|
-
throw console.error("[avatarTtsLipsync]",
|
|
987
|
+
} catch (ie) {
|
|
988
|
+
throw console.error("[avatarTtsLipsync]", ie), B(), e("error"), ie;
|
|
968
989
|
}
|
|
969
990
|
},
|
|
970
|
-
stop:
|
|
991
|
+
stop: B,
|
|
971
992
|
getVisemeQueue: () => s,
|
|
972
993
|
getWordQueue: () => i,
|
|
973
994
|
getSentenceEmotions: () => a,
|
|
974
|
-
getStreamMood: () =>
|
|
995
|
+
getStreamMood: () => m,
|
|
975
996
|
getPlaybackElapsedMs: () => E.getPlaybackElapsedMs(),
|
|
976
997
|
isSpeaking: () => E.isSpeaking(),
|
|
977
998
|
isWarmingUp: () => E.isWarmingUp(),
|
|
978
999
|
releaseWarmupHold: () => E.releaseWarmupHold(),
|
|
979
|
-
setLipsyncWarmupHold: (
|
|
980
|
-
|
|
1000
|
+
setLipsyncWarmupHold: (C, k) => {
|
|
1001
|
+
k && (P = k), E.setLipsyncWarmupHoldEnabled(C);
|
|
981
1002
|
},
|
|
982
1003
|
getVoiceStream: () => E.getVoiceStream(),
|
|
983
|
-
setPlaybackSpeed: (
|
|
984
|
-
E.setPlaybackSpeed(
|
|
1004
|
+
setPlaybackSpeed: (C) => {
|
|
1005
|
+
E.setPlaybackSpeed(C);
|
|
985
1006
|
},
|
|
986
1007
|
getPlaybackSpeed: () => E.getPlaybackSpeed(),
|
|
987
|
-
subscribe: (
|
|
1008
|
+
subscribe: (C) => (f.add(C), () => f.delete(C))
|
|
988
1009
|
};
|
|
989
1010
|
}
|
|
990
1011
|
const tr = 16e3, nr = 16e3;
|
|
@@ -1000,7 +1021,7 @@ class As extends Er {
|
|
|
1000
1021
|
}
|
|
1001
1022
|
}
|
|
1002
1023
|
}
|
|
1003
|
-
class Is extends
|
|
1024
|
+
class Is extends br {
|
|
1004
1025
|
constructor() {
|
|
1005
1026
|
super(
|
|
1006
1027
|
!0,
|
|
@@ -1031,16 +1052,16 @@ function Ds(e) {
|
|
|
1031
1052
|
throw new Error(
|
|
1032
1053
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1033
1054
|
);
|
|
1034
|
-
const n = e.apiBase ??
|
|
1055
|
+
const n = e.apiBase ?? ft, r = new URL(`${Rs(n)}/ws/voice`);
|
|
1035
1056
|
r.searchParams.set("authToken", t), r.searchParams.set("tenant", "aiTwin");
|
|
1036
1057
|
const s = e.voiceId?.trim();
|
|
1037
1058
|
s && Ps(s) && r.searchParams.set("voiceId", s);
|
|
1038
1059
|
const i = e.personaId?.trim();
|
|
1039
1060
|
i && r.searchParams.set("personaId", i);
|
|
1040
|
-
const a = e.speakingRate ??
|
|
1061
|
+
const a = e.speakingRate ?? Rt;
|
|
1041
1062
|
return r.searchParams.set(
|
|
1042
1063
|
"speaking_rate",
|
|
1043
|
-
String(Math.max(
|
|
1064
|
+
String(Math.max(Zt, Math.min(en, a)))
|
|
1044
1065
|
), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
|
|
1045
1066
|
}
|
|
1046
1067
|
function Lt(e, t) {
|
|
@@ -1065,294 +1086,297 @@ function xs(e) {
|
|
|
1065
1086
|
type: String(r.type ?? t.type ?? "server-message")
|
|
1066
1087
|
};
|
|
1067
1088
|
}
|
|
1068
|
-
function
|
|
1089
|
+
function Nt(e) {
|
|
1069
1090
|
return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
|
|
1070
1091
|
}
|
|
1071
|
-
function
|
|
1092
|
+
function Cs(e) {
|
|
1072
1093
|
return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
|
|
1073
1094
|
}
|
|
1074
|
-
function
|
|
1095
|
+
function Bs(e, t = {}) {
|
|
1075
1096
|
const n = [], r = [], s = [], i = [];
|
|
1076
|
-
let a = "", o = "neutral",
|
|
1077
|
-
const
|
|
1078
|
-
let E = !1, _ = null,
|
|
1079
|
-
const
|
|
1080
|
-
let
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
},
|
|
1084
|
-
let
|
|
1085
|
-
const
|
|
1097
|
+
let a = "", o = "neutral", d = Qe, m = !1, c = null, u = null, f = { ...t }, w = 0, b = null;
|
|
1098
|
+
const p = /* @__PURE__ */ new Set(), P = [];
|
|
1099
|
+
let E = !1, _ = null, h = !0, A = "default";
|
|
1100
|
+
const O = /* @__PURE__ */ new Set();
|
|
1101
|
+
let B = null, G = 0, C = !1, k = null;
|
|
1102
|
+
const I = () => {
|
|
1103
|
+
k != null && (clearTimeout(k), k = null);
|
|
1104
|
+
}, M = () => p.forEach((l) => l());
|
|
1105
|
+
let Q = () => !1;
|
|
1106
|
+
const x = Xn(
|
|
1086
1107
|
{
|
|
1087
1108
|
onSpeakingStart: () => e("speaking"),
|
|
1088
1109
|
onSpeakingDone: () => e("done"),
|
|
1089
|
-
onNotify:
|
|
1090
|
-
shouldHoldForWarmup: () =>
|
|
1110
|
+
onNotify: M,
|
|
1111
|
+
shouldHoldForWarmup: () => Q()
|
|
1091
1112
|
},
|
|
1092
|
-
|
|
1093
|
-
),
|
|
1113
|
+
d
|
|
1114
|
+
), z = () => {
|
|
1094
1115
|
if (_) return _;
|
|
1095
1116
|
const l = new MessageChannel();
|
|
1096
1117
|
return l.port1.onmessage = () => {
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1118
|
+
const v = P.shift();
|
|
1119
|
+
v !== void 0 && ue(v), P.length > 0 ? l.port2.postMessage(null) : E = !1;
|
|
1099
1120
|
}, _ = l, l;
|
|
1100
|
-
},
|
|
1101
|
-
|
|
1102
|
-
},
|
|
1103
|
-
if (!
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1121
|
+
}, J = (l) => {
|
|
1122
|
+
P.push(l), !E && (E = !0, z().port2.postMessage(null));
|
|
1123
|
+
}, ie = () => x.getPlaybackElapsedMs(), X = (l, v = a) => {
|
|
1124
|
+
if (!f.onLipsyncDebug) return;
|
|
1125
|
+
const N = ie(), q = n;
|
|
1126
|
+
f.onLipsyncDebug({
|
|
1106
1127
|
event: l,
|
|
1107
|
-
spokenText:
|
|
1128
|
+
spokenText: v,
|
|
1108
1129
|
mood: o,
|
|
1109
|
-
playbackAnchorPerf:
|
|
1110
|
-
playbackElapsedMs:
|
|
1111
|
-
queueLength:
|
|
1112
|
-
activeViseme:
|
|
1113
|
-
segments: i.map((
|
|
1114
|
-
...
|
|
1115
|
-
visemes: [...
|
|
1130
|
+
playbackAnchorPerf: x.getPlaybackStartPerf(),
|
|
1131
|
+
playbackElapsedMs: N,
|
|
1132
|
+
queueLength: q.length,
|
|
1133
|
+
activeViseme: Pt(q, N),
|
|
1134
|
+
segments: i.map((re) => ({
|
|
1135
|
+
...re,
|
|
1136
|
+
visemes: [...re.visemes]
|
|
1116
1137
|
}))
|
|
1117
1138
|
});
|
|
1118
|
-
},
|
|
1119
|
-
|
|
1139
|
+
}, he = (l, v) => {
|
|
1140
|
+
f.onLipsyncDebug && (b = { event: l, spokenText: v }, w === 0 && (w = requestAnimationFrame(() => {
|
|
1120
1141
|
w = 0;
|
|
1121
|
-
const
|
|
1122
|
-
b = null,
|
|
1142
|
+
const N = b;
|
|
1143
|
+
b = null, N && X(N.event, N.spokenText);
|
|
1123
1144
|
})));
|
|
1124
|
-
},
|
|
1125
|
-
|
|
1126
|
-
},
|
|
1127
|
-
const l =
|
|
1145
|
+
}, fe = () => {
|
|
1146
|
+
h = !0, O.clear(), x.clearAborted();
|
|
1147
|
+
}, de = () => {
|
|
1148
|
+
const l = Cs(c);
|
|
1128
1149
|
if (l) {
|
|
1129
|
-
|
|
1150
|
+
A = `bot-${Date.now()}`, l.interruptedTrackIds = { [A]: !0 };
|
|
1130
1151
|
try {
|
|
1131
1152
|
l.interrupt?.();
|
|
1132
1153
|
} catch {
|
|
1133
1154
|
}
|
|
1134
1155
|
}
|
|
1135
|
-
const
|
|
1156
|
+
const v = u;
|
|
1136
1157
|
try {
|
|
1137
|
-
|
|
1158
|
+
v?.interrupt?.();
|
|
1138
1159
|
} catch {
|
|
1139
1160
|
}
|
|
1140
|
-
},
|
|
1141
|
-
const
|
|
1142
|
-
return
|
|
1143
|
-
},
|
|
1144
|
-
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1147
|
-
},
|
|
1161
|
+
}, ne = (l) => {
|
|
1162
|
+
const v = l.context_id?.trim();
|
|
1163
|
+
return v && O.has(v) ? !0 : h ? !1 : !(l.type === "avatar_metadata" || Nt(l));
|
|
1164
|
+
}, g = (l) => {
|
|
1165
|
+
h = !1;
|
|
1166
|
+
const v = l.context_id?.trim();
|
|
1167
|
+
v && O.add(v), I(), C = !1, P.length = 0, E = !1, B?.abort(), B = null, G += 1, de(), x.bargeIn(), S(), e("idle"), he("interrupt"), M();
|
|
1168
|
+
}, S = () => {
|
|
1148
1169
|
n.length = 0, r.length = 0, i.length = 0, a = "", o = "neutral", s.length = 0;
|
|
1149
|
-
},
|
|
1150
|
-
|
|
1151
|
-
},
|
|
1152
|
-
|
|
1153
|
-
},
|
|
1154
|
-
typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), Array.isArray(l.sentence_emotions) && l.sentence_emotions.length > 0 && (
|
|
1170
|
+
}, L = () => {
|
|
1171
|
+
x.stop(), S(), he("reset"), M();
|
|
1172
|
+
}, W = () => {
|
|
1173
|
+
L(), e("idle"), M();
|
|
1174
|
+
}, D = (l, v) => {
|
|
1175
|
+
typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), Array.isArray(l.sentence_emotions) && l.sentence_emotions.length > 0 && (v && (s.length = 0), s.push(
|
|
1155
1176
|
...Lt(l.sentence_emotions, o)
|
|
1156
1177
|
));
|
|
1157
|
-
},
|
|
1158
|
-
if (
|
|
1178
|
+
}, R = (l) => {
|
|
1179
|
+
if (ne({ ...l, type: "avatar_metadata" }))
|
|
1159
1180
|
return;
|
|
1160
|
-
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1181
|
+
fe(), C = !0;
|
|
1182
|
+
const v = String(l.spoken_text ?? l.text ?? "").trim();
|
|
1183
|
+
v && (a = v), x.resetForNewStream(d), typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), s.length = 0, s.push(
|
|
1163
1184
|
...Lt(l.sentence_emotions, o)
|
|
1164
|
-
), Array.isArray(l.gestures) && l.gestures,
|
|
1165
|
-
},
|
|
1166
|
-
if (!
|
|
1167
|
-
const
|
|
1168
|
-
(
|
|
1185
|
+
), Array.isArray(l.gestures) && l.gestures, he("metadata", v), M();
|
|
1186
|
+
}, T = (l, v, N, q) => {
|
|
1187
|
+
if (!f.onLipsyncDebug) return;
|
|
1188
|
+
const re = n.slice(N), xe = q.filter(
|
|
1189
|
+
(oe) => String(oe.symbol ?? oe.viseme ?? "").trim()
|
|
1169
1190
|
);
|
|
1170
1191
|
i.push({
|
|
1171
|
-
spokenText:
|
|
1172
|
-
audioOffsetMs:
|
|
1192
|
+
spokenText: v,
|
|
1193
|
+
audioOffsetMs: re[0]?.vtime ?? 0,
|
|
1173
1194
|
isNewSegment: !!l.is_new_segment,
|
|
1174
1195
|
chunkDurationMs: l.chunk_duration_ms != null ? Number(l.chunk_duration_ms) : null,
|
|
1175
1196
|
receivedAtMs: performance.now(),
|
|
1176
|
-
visemes:
|
|
1177
|
-
const
|
|
1197
|
+
visemes: re.map((oe, Ce) => {
|
|
1198
|
+
const _e = xe[Ce];
|
|
1178
1199
|
return {
|
|
1179
|
-
rawSymbol: String(
|
|
1180
|
-
viseme:
|
|
1181
|
-
startSec: Number(
|
|
1182
|
-
durationSec: Number(
|
|
1183
|
-
vtimeMs:
|
|
1184
|
-
vdurationMs:
|
|
1200
|
+
rawSymbol: String(_e?.symbol ?? _e?.viseme ?? oe.viseme).trim(),
|
|
1201
|
+
viseme: oe.viseme,
|
|
1202
|
+
startSec: Number(_e?.start ?? 0),
|
|
1203
|
+
durationSec: Number(_e?.duration ?? 0),
|
|
1204
|
+
vtimeMs: oe.vtime,
|
|
1205
|
+
vdurationMs: oe.vduration
|
|
1185
1206
|
};
|
|
1186
1207
|
})
|
|
1187
1208
|
});
|
|
1188
|
-
},
|
|
1189
|
-
if (
|
|
1190
|
-
|
|
1191
|
-
const
|
|
1192
|
-
|
|
1193
|
-
const
|
|
1194
|
-
|
|
1209
|
+
}, Z = (l) => {
|
|
1210
|
+
if (ne(l)) return;
|
|
1211
|
+
I(), Nt(l) && fe();
|
|
1212
|
+
const v = String(l.spoken_text ?? l.text ?? "").trim(), N = Nt(l), q = l.visemes ?? [], re = l.words ?? [], xe = String(l.chunk ?? "").trim(), oe = C;
|
|
1213
|
+
oe && (C = !1), v && (a = v), D(l, N), oe ? x.resetForNewStream(d) : N && x.resumeBotStream();
|
|
1214
|
+
const Ce = n.length;
|
|
1215
|
+
x.playAudioChunk(
|
|
1195
1216
|
n,
|
|
1196
1217
|
r,
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1218
|
+
xe,
|
|
1219
|
+
q,
|
|
1220
|
+
re,
|
|
1221
|
+
N,
|
|
1201
1222
|
{
|
|
1202
1223
|
sampleRate: l.sample_rate,
|
|
1203
|
-
newStream:
|
|
1224
|
+
newStream: oe,
|
|
1225
|
+
audioOffsetMs: l.audio_offset_ms != null ? Number(l.audio_offset_ms) : void 0,
|
|
1204
1226
|
onNewStream: () => {
|
|
1205
1227
|
i.length = 0;
|
|
1206
1228
|
}
|
|
1207
1229
|
}
|
|
1208
1230
|
).then(() => {
|
|
1209
|
-
|
|
1231
|
+
T(l, v, Ce, q), he("audio_chunk", v);
|
|
1210
1232
|
});
|
|
1211
|
-
},
|
|
1212
|
-
if (
|
|
1213
|
-
(l.is_new_segment || Number(l.audio_offset_ms ?? -1) === 0) &&
|
|
1233
|
+
}, ae = (l) => {
|
|
1234
|
+
if (ne(l)) return;
|
|
1235
|
+
(l.is_new_segment || Number(l.audio_offset_ms ?? -1) === 0) && fe(), console.warn(
|
|
1214
1236
|
"[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
|
|
1215
1237
|
);
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
const
|
|
1219
|
-
|
|
1238
|
+
const v = String(l.spoken_text ?? l.text ?? "").trim();
|
|
1239
|
+
v && (a = v), D(l, !!l.is_new_segment);
|
|
1240
|
+
const N = n.length;
|
|
1241
|
+
x.queueTimingsOnly(
|
|
1220
1242
|
n,
|
|
1221
1243
|
r,
|
|
1222
1244
|
l.visemes ?? [],
|
|
1223
1245
|
l.words ?? [],
|
|
1224
|
-
!!l.is_new_segment
|
|
1225
|
-
|
|
1246
|
+
!!l.is_new_segment,
|
|
1247
|
+
l.audio_offset_ms != null ? Number(l.audio_offset_ms) : void 0
|
|
1248
|
+
), T(
|
|
1226
1249
|
l,
|
|
1227
|
-
|
|
1228
|
-
|
|
1250
|
+
v,
|
|
1251
|
+
N,
|
|
1229
1252
|
l.visemes ?? []
|
|
1230
|
-
),
|
|
1231
|
-
},
|
|
1232
|
-
const
|
|
1233
|
-
if (!
|
|
1234
|
-
const
|
|
1235
|
-
if (!
|
|
1253
|
+
), he("lipsync", v), M();
|
|
1254
|
+
}, te = async (l) => {
|
|
1255
|
+
const v = String(l.text ?? "").trim();
|
|
1256
|
+
if (!v) return;
|
|
1257
|
+
const N = f.authToken?.trim();
|
|
1258
|
+
if (!N) {
|
|
1236
1259
|
console.error("[realtimeVoice] avatar_speak requires authToken");
|
|
1237
1260
|
return;
|
|
1238
1261
|
}
|
|
1239
|
-
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1242
|
-
const
|
|
1243
|
-
|
|
1244
|
-
const
|
|
1245
|
-
|
|
1246
|
-
Math.min(
|
|
1247
|
-
),
|
|
1248
|
-
user_query:
|
|
1249
|
-
ttsEngineId:
|
|
1250
|
-
speakingRate:
|
|
1262
|
+
B?.abort();
|
|
1263
|
+
const q = new AbortController();
|
|
1264
|
+
B = q;
|
|
1265
|
+
const re = ++G;
|
|
1266
|
+
fe(), x.resetForNewStream(d), await x.primeAudioContext(), a = v;
|
|
1267
|
+
const oe = `${(f.apiBase ?? ft).replace(/\/$/, "")}/avatar_ttsWithPoses`, Ce = f.voiceId?.trim() || er, _e = f.speakingRate ?? Rt, et = Math.max(
|
|
1268
|
+
Zt,
|
|
1269
|
+
Math.min(en, _e)
|
|
1270
|
+
), tt = {
|
|
1271
|
+
user_query: v,
|
|
1272
|
+
ttsEngineId: d,
|
|
1273
|
+
speakingRate: et,
|
|
1251
1274
|
tenant: "aiTwin"
|
|
1252
1275
|
};
|
|
1253
|
-
$n.has(
|
|
1276
|
+
$n.has(d) && (tt.voice_id = Ce);
|
|
1254
1277
|
try {
|
|
1255
|
-
const
|
|
1278
|
+
const se = await fetch(oe, {
|
|
1256
1279
|
method: "POST",
|
|
1257
1280
|
headers: {
|
|
1258
1281
|
"Content-Type": "application/json",
|
|
1259
|
-
Authorization: `Bearer ${
|
|
1282
|
+
Authorization: `Bearer ${N}`
|
|
1260
1283
|
},
|
|
1261
|
-
body: JSON.stringify(
|
|
1262
|
-
signal:
|
|
1284
|
+
body: JSON.stringify(tt),
|
|
1285
|
+
signal: q.signal
|
|
1263
1286
|
});
|
|
1264
|
-
if (!
|
|
1265
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
1266
|
-
const
|
|
1267
|
-
if (!
|
|
1268
|
-
const
|
|
1287
|
+
if (!se.ok)
|
|
1288
|
+
throw new Error(`avatar_ttsWithPoses failed (${se.status})`);
|
|
1289
|
+
const nt = se.body;
|
|
1290
|
+
if (!nt) throw new Error("No response body");
|
|
1291
|
+
const mt = nt.getReader(), ht = new TextDecoder();
|
|
1269
1292
|
let be = "";
|
|
1270
|
-
const
|
|
1271
|
-
if (
|
|
1293
|
+
const rt = async (Ee) => {
|
|
1294
|
+
if (re !== G || q.signal.aborted || !h)
|
|
1272
1295
|
return;
|
|
1273
|
-
const
|
|
1274
|
-
if (
|
|
1275
|
-
if (
|
|
1276
|
-
const
|
|
1277
|
-
|
|
1296
|
+
const ce = Kn(Ee);
|
|
1297
|
+
if (ce) {
|
|
1298
|
+
if (ce.event === "audio") {
|
|
1299
|
+
const le = ce.data.chunk, pe = ce.data.visemes ?? [], j = ce.data.words ?? [], Y = ce.data.is_new_segment ?? !1, pt = ce.data.sample_rate, we = Number(ce.data.audio_offset_ms ?? 0);
|
|
1300
|
+
le ? await x.playAudioChunk(
|
|
1278
1301
|
n,
|
|
1279
1302
|
r,
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
{ sampleRate:
|
|
1285
|
-
) : (
|
|
1303
|
+
le,
|
|
1304
|
+
pe,
|
|
1305
|
+
j,
|
|
1306
|
+
Y,
|
|
1307
|
+
{ sampleRate: pt, audioOffsetMs: we }
|
|
1308
|
+
) : (pe.length > 0 || j.length > 0) && x.queueTimingsOnly(
|
|
1286
1309
|
n,
|
|
1287
1310
|
r,
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1311
|
+
pe,
|
|
1312
|
+
j,
|
|
1313
|
+
Y,
|
|
1314
|
+
we
|
|
1291
1315
|
);
|
|
1292
|
-
} else if (
|
|
1293
|
-
const
|
|
1294
|
-
typeof
|
|
1295
|
-
const
|
|
1296
|
-
Array.isArray(
|
|
1297
|
-
...Lt(
|
|
1298
|
-
)),
|
|
1299
|
-
} else if (
|
|
1316
|
+
} else if (ce.event === "metadata") {
|
|
1317
|
+
const le = ce.data.mood;
|
|
1318
|
+
typeof le == "string" && le.trim() && (o = le.trim());
|
|
1319
|
+
const pe = ce.data.sentence_emotions;
|
|
1320
|
+
Array.isArray(pe) && (s.length = 0, s.push(
|
|
1321
|
+
...Lt(pe, o)
|
|
1322
|
+
)), M();
|
|
1323
|
+
} else if (ce.event === "error")
|
|
1300
1324
|
throw new Error(
|
|
1301
|
-
String(
|
|
1325
|
+
String(ce.data.message ?? "avatar_ttsWithPoses stream error")
|
|
1302
1326
|
);
|
|
1303
1327
|
}
|
|
1304
1328
|
};
|
|
1305
|
-
for (; !(
|
|
1306
|
-
const { done:
|
|
1307
|
-
|
|
1308
|
-
const
|
|
1329
|
+
for (; !(re !== G || q.signal.aborted || !h); ) {
|
|
1330
|
+
const { done: Ee, value: ce } = await mt.read();
|
|
1331
|
+
ce && (be += ht.decode(ce, { stream: !0 }));
|
|
1332
|
+
const le = be.split(`
|
|
1309
1333
|
|
|
1310
1334
|
`);
|
|
1311
|
-
be =
|
|
1312
|
-
for (const
|
|
1313
|
-
if (
|
|
1314
|
-
be.trim() && await
|
|
1335
|
+
be = le.pop() ?? "";
|
|
1336
|
+
for (const pe of le) await rt(pe);
|
|
1337
|
+
if (Ee) {
|
|
1338
|
+
be.trim() && await rt(be.trim()), re === G && !q.signal.aborted && h && x.markStreamComplete(n);
|
|
1315
1339
|
break;
|
|
1316
1340
|
}
|
|
1317
1341
|
}
|
|
1318
|
-
} catch (
|
|
1319
|
-
if (
|
|
1320
|
-
console.error("[realtimeVoice] avatar_speak failed:",
|
|
1342
|
+
} catch (se) {
|
|
1343
|
+
if (q.signal.aborted || !h) return;
|
|
1344
|
+
console.error("[realtimeVoice] avatar_speak failed:", se), e("error"), M();
|
|
1321
1345
|
} finally {
|
|
1322
|
-
|
|
1346
|
+
B === q && (B = null);
|
|
1323
1347
|
}
|
|
1324
|
-
},
|
|
1325
|
-
const
|
|
1326
|
-
if (!
|
|
1348
|
+
}, ue = (l) => {
|
|
1349
|
+
const v = xs(l);
|
|
1350
|
+
if (!v) {
|
|
1327
1351
|
console.warn("[realtimeVoice] server message with no payload", l);
|
|
1328
1352
|
return;
|
|
1329
1353
|
}
|
|
1330
|
-
const
|
|
1331
|
-
switch (
|
|
1354
|
+
const N = String(v.type ?? "unknown");
|
|
1355
|
+
switch (N !== "avatar_metadata" && N !== "avatar_audio_chunk" && N !== "avatar_lipsync" && N !== "avatar_interrupt" && N !== "error" && console.debug("[realtimeVoice] server message", N, v), N) {
|
|
1332
1356
|
case "avatar_metadata":
|
|
1333
|
-
|
|
1357
|
+
R(v);
|
|
1334
1358
|
break;
|
|
1335
1359
|
case "avatar_audio_chunk":
|
|
1336
|
-
|
|
1360
|
+
Z(v);
|
|
1337
1361
|
break;
|
|
1338
1362
|
case "avatar_lipsync":
|
|
1339
|
-
|
|
1363
|
+
ae(v);
|
|
1340
1364
|
break;
|
|
1341
1365
|
case "avatar_interrupt":
|
|
1342
|
-
|
|
1366
|
+
g(v);
|
|
1343
1367
|
break;
|
|
1344
1368
|
case "error": {
|
|
1345
|
-
const
|
|
1346
|
-
console.error("[realtimeVoice] server error:",
|
|
1369
|
+
const q = String(v.message ?? "Voice session error");
|
|
1370
|
+
console.error("[realtimeVoice] server error:", q), e("error"), M();
|
|
1347
1371
|
break;
|
|
1348
1372
|
}
|
|
1349
1373
|
case "avatar_speak":
|
|
1350
|
-
|
|
1374
|
+
te(v);
|
|
1351
1375
|
break;
|
|
1352
1376
|
}
|
|
1353
|
-
},
|
|
1354
|
-
transport: new
|
|
1355
|
-
mediaManager:
|
|
1377
|
+
}, me = () => c || (u = new Is(), c = new kr({
|
|
1378
|
+
transport: new vr({
|
|
1379
|
+
mediaManager: u,
|
|
1356
1380
|
serializer: new As(),
|
|
1357
1381
|
recorderSampleRate: tr,
|
|
1358
1382
|
playerSampleRate: nr
|
|
@@ -1361,109 +1385,109 @@ function Cs(e, t = {}) {
|
|
|
1361
1385
|
enableMic: !0,
|
|
1362
1386
|
callbacks: {
|
|
1363
1387
|
onBotReady: () => {
|
|
1364
|
-
|
|
1388
|
+
m = !0, e("idle"), M();
|
|
1365
1389
|
},
|
|
1366
1390
|
onDisconnected: () => {
|
|
1367
|
-
|
|
1391
|
+
m = !1, W();
|
|
1368
1392
|
},
|
|
1369
1393
|
onError: (l) => {
|
|
1370
|
-
const
|
|
1371
|
-
console.error("[realtimeVoice]",
|
|
1394
|
+
const v = typeof l == "object" && l !== null && "data" in l ? String(l.data ?? l) : String(l);
|
|
1395
|
+
console.error("[realtimeVoice]", v, l), e("error"), M();
|
|
1372
1396
|
},
|
|
1373
1397
|
onTransportStateChanged: (l) => {
|
|
1374
|
-
l === "error" && (e("error"),
|
|
1398
|
+
l === "error" && (e("error"), M());
|
|
1375
1399
|
},
|
|
1376
1400
|
onServerMessage: (l) => {
|
|
1377
|
-
|
|
1401
|
+
J(l);
|
|
1378
1402
|
},
|
|
1379
1403
|
onUserStartedSpeaking: () => {
|
|
1380
|
-
|
|
1404
|
+
g({});
|
|
1381
1405
|
},
|
|
1382
1406
|
onBotStartedSpeaking: () => {
|
|
1383
|
-
|
|
1407
|
+
fe(), he("bot_started");
|
|
1384
1408
|
},
|
|
1385
1409
|
onBotStoppedSpeaking: () => {
|
|
1386
|
-
|
|
1387
|
-
|
|
1410
|
+
h && (I(), k = setTimeout(() => {
|
|
1411
|
+
k = null, h && (x.markStreamComplete(n), he("bot_stopped"));
|
|
1388
1412
|
}, 450));
|
|
1389
1413
|
},
|
|
1390
1414
|
onUserTranscript: (l) => {
|
|
1391
|
-
|
|
1415
|
+
f.onUserTranscript?.(l.text, !!l.final);
|
|
1392
1416
|
},
|
|
1393
1417
|
onBotOutput: (l) => {
|
|
1394
|
-
|
|
1418
|
+
f.onBotOutput?.(l.text);
|
|
1395
1419
|
}
|
|
1396
1420
|
}
|
|
1397
|
-
}),
|
|
1421
|
+
}), c);
|
|
1398
1422
|
return {
|
|
1399
1423
|
setDeveloperToken: (l) => {
|
|
1400
1424
|
},
|
|
1401
1425
|
setTtsEngineId: (l) => {
|
|
1402
|
-
|
|
1426
|
+
d = l, x.setStreamTtsEngineId(l);
|
|
1403
1427
|
},
|
|
1404
|
-
getTtsEngineId: () =>
|
|
1405
|
-
speak: async (l,
|
|
1406
|
-
const
|
|
1407
|
-
if (
|
|
1408
|
-
if (!
|
|
1428
|
+
getTtsEngineId: () => d,
|
|
1429
|
+
speak: async (l, v) => {
|
|
1430
|
+
const N = l.trim();
|
|
1431
|
+
if (N) {
|
|
1432
|
+
if (!c || !m)
|
|
1409
1433
|
throw new Error(
|
|
1410
1434
|
"Realtime voice is not connected. Call connect() first."
|
|
1411
1435
|
);
|
|
1412
|
-
|
|
1436
|
+
L(), await c.sendText(N);
|
|
1413
1437
|
}
|
|
1414
1438
|
},
|
|
1415
1439
|
stop: () => {
|
|
1416
|
-
|
|
1440
|
+
B?.abort(), B = null, G += 1, fe(), L(), e("idle"), M();
|
|
1417
1441
|
},
|
|
1418
1442
|
connect: async (l) => {
|
|
1419
|
-
if (l && (
|
|
1443
|
+
if (l && (f = { ...f, ...l }), !f.authToken?.trim())
|
|
1420
1444
|
throw new Error(
|
|
1421
1445
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1422
1446
|
);
|
|
1423
1447
|
e("loading");
|
|
1424
|
-
const
|
|
1425
|
-
await
|
|
1426
|
-
const
|
|
1427
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1448
|
+
const v = me();
|
|
1449
|
+
await v.initDevices();
|
|
1450
|
+
const N = Ds(f);
|
|
1451
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", N);
|
|
1428
1452
|
try {
|
|
1429
|
-
await
|
|
1430
|
-
} catch (
|
|
1431
|
-
|
|
1432
|
-
const
|
|
1433
|
-
throw new Error(`${
|
|
1453
|
+
await v.connect({ wsUrl: N });
|
|
1454
|
+
} catch (q) {
|
|
1455
|
+
m = !1, e("error"), M();
|
|
1456
|
+
const re = q instanceof Error ? q.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
|
|
1457
|
+
throw new Error(`${re} — ${N}`);
|
|
1434
1458
|
}
|
|
1435
|
-
|
|
1459
|
+
m = !0, e("idle"), M();
|
|
1436
1460
|
},
|
|
1437
1461
|
disconnect: async () => {
|
|
1438
|
-
if (
|
|
1462
|
+
if (I(), C = !1, P.length = 0, E = !1, B?.abort(), B = null, G += 1, fe(), c)
|
|
1439
1463
|
try {
|
|
1440
|
-
await
|
|
1464
|
+
await c.disconnect();
|
|
1441
1465
|
} catch (l) {
|
|
1442
1466
|
console.error("[realtimeVoice] disconnect failed:", l);
|
|
1443
1467
|
}
|
|
1444
|
-
|
|
1468
|
+
m = !1, W();
|
|
1445
1469
|
},
|
|
1446
|
-
isConnected: () =>
|
|
1470
|
+
isConnected: () => m,
|
|
1447
1471
|
unlockAudio: async () => {
|
|
1448
|
-
await
|
|
1472
|
+
await x.primeAudioContext();
|
|
1449
1473
|
},
|
|
1450
1474
|
getVisemeQueue: () => n,
|
|
1451
1475
|
getWordQueue: () => r,
|
|
1452
1476
|
getSentenceEmotions: () => s,
|
|
1453
1477
|
getStreamMood: () => o,
|
|
1454
|
-
getPlaybackElapsedMs:
|
|
1455
|
-
isSpeaking: () =>
|
|
1456
|
-
isWarmingUp: () =>
|
|
1457
|
-
releaseWarmupHold: () =>
|
|
1458
|
-
setLipsyncWarmupHold: (l,
|
|
1459
|
-
|
|
1460
|
-
},
|
|
1461
|
-
getVoiceStream: () =>
|
|
1478
|
+
getPlaybackElapsedMs: ie,
|
|
1479
|
+
isSpeaking: () => x.isSpeaking(),
|
|
1480
|
+
isWarmingUp: () => x.isWarmingUp(),
|
|
1481
|
+
releaseWarmupHold: () => x.releaseWarmupHold(),
|
|
1482
|
+
setLipsyncWarmupHold: (l, v) => {
|
|
1483
|
+
v && (Q = v), x.setLipsyncWarmupHoldEnabled(l);
|
|
1484
|
+
},
|
|
1485
|
+
getVoiceStream: () => x.getVoiceStream(),
|
|
1462
1486
|
setPlaybackSpeed: (l) => {
|
|
1463
|
-
|
|
1487
|
+
x.setPlaybackSpeed(l);
|
|
1464
1488
|
},
|
|
1465
|
-
getPlaybackSpeed: () =>
|
|
1466
|
-
subscribe: (l) => (
|
|
1489
|
+
getPlaybackSpeed: () => x.getPlaybackSpeed(),
|
|
1490
|
+
subscribe: (l) => (p.add(l), () => p.delete(l))
|
|
1467
1491
|
};
|
|
1468
1492
|
}
|
|
1469
1493
|
function Fs(e, t, n) {
|
|
@@ -1472,7 +1496,7 @@ function Fs(e, t, n) {
|
|
|
1472
1496
|
height: e.crop?.source_height ?? n
|
|
1473
1497
|
};
|
|
1474
1498
|
}
|
|
1475
|
-
function
|
|
1499
|
+
function Os(e, t) {
|
|
1476
1500
|
const n = e.crop;
|
|
1477
1501
|
return {
|
|
1478
1502
|
x: t?.source_x ?? n?.x ?? 0,
|
|
@@ -1481,10 +1505,10 @@ function Ls(e, t) {
|
|
|
1481
1505
|
height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
|
|
1482
1506
|
};
|
|
1483
1507
|
}
|
|
1484
|
-
function
|
|
1508
|
+
function Ls(e) {
|
|
1485
1509
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
1486
1510
|
}
|
|
1487
|
-
async function
|
|
1511
|
+
async function Dt(e, t) {
|
|
1488
1512
|
const n = await fetch(e);
|
|
1489
1513
|
if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
|
|
1490
1514
|
const r = await n.arrayBuffer();
|
|
@@ -1492,7 +1516,7 @@ async function Rt(e, t) {
|
|
|
1492
1516
|
}
|
|
1493
1517
|
async function Ns(e, t) {
|
|
1494
1518
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
1495
|
-
const n = await
|
|
1519
|
+
const n = await Dt(e, t), r = new TextDecoder().decode(n);
|
|
1496
1520
|
return JSON.parse(r);
|
|
1497
1521
|
}
|
|
1498
1522
|
async function Us(e) {
|
|
@@ -1523,16 +1547,16 @@ function Ws(e) {
|
|
|
1523
1547
|
}
|
|
1524
1548
|
async function Hs(e) {
|
|
1525
1549
|
const t = Qr();
|
|
1526
|
-
if (!
|
|
1550
|
+
if (!Mt()) return t;
|
|
1527
1551
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
1528
|
-
const n = await
|
|
1552
|
+
const n = await Dt(t, e);
|
|
1529
1553
|
return Ws(n);
|
|
1530
1554
|
}
|
|
1531
|
-
function
|
|
1555
|
+
function tn(e, t) {
|
|
1532
1556
|
return `${e}/${t}_minus_sil.png`;
|
|
1533
1557
|
}
|
|
1534
1558
|
const rr = 5;
|
|
1535
|
-
function
|
|
1559
|
+
function nn(e) {
|
|
1536
1560
|
const t = e?.composite_threshold;
|
|
1537
1561
|
if (typeof t == "number" && t > 0) return t;
|
|
1538
1562
|
const n = e?.crop?.content_threshold;
|
|
@@ -1553,11 +1577,11 @@ const ta = [
|
|
|
1553
1577
|
"RR",
|
|
1554
1578
|
"kk",
|
|
1555
1579
|
"nn"
|
|
1556
|
-
],
|
|
1580
|
+
], $t = [
|
|
1557
1581
|
"t01_0.25",
|
|
1558
1582
|
"t02_0.50",
|
|
1559
1583
|
"t03_0.75"
|
|
1560
|
-
], $s =
|
|
1584
|
+
], $s = $t.length, In = /* @__PURE__ */ new Set([
|
|
1561
1585
|
"aa__kk",
|
|
1562
1586
|
"aa__nn",
|
|
1563
1587
|
"aa__sil",
|
|
@@ -1670,7 +1694,7 @@ function Mn(e, t) {
|
|
|
1670
1694
|
function Pn(e, t) {
|
|
1671
1695
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1672
1696
|
}
|
|
1673
|
-
function
|
|
1697
|
+
function Et(e) {
|
|
1674
1698
|
return `${e}_minus_sil.png`;
|
|
1675
1699
|
}
|
|
1676
1700
|
function sr(e, t) {
|
|
@@ -1679,28 +1703,28 @@ function sr(e, t) {
|
|
|
1679
1703
|
if (!n) return null;
|
|
1680
1704
|
const r = n[1].split("__")[1];
|
|
1681
1705
|
if (!r || r === "sil") return null;
|
|
1682
|
-
const s =
|
|
1706
|
+
const s = Et(r);
|
|
1683
1707
|
return t.has(s) ? s : null;
|
|
1684
1708
|
}
|
|
1685
1709
|
function ir(e, t) {
|
|
1686
1710
|
return e.filter((n) => t.has(n));
|
|
1687
1711
|
}
|
|
1688
1712
|
function qs(e, t, n) {
|
|
1689
|
-
const r =
|
|
1713
|
+
const r = rn(e, t);
|
|
1690
1714
|
return ir(r, n).length > 0;
|
|
1691
1715
|
}
|
|
1692
|
-
function
|
|
1716
|
+
function rn(e, t) {
|
|
1693
1717
|
if (e === t) return [];
|
|
1694
1718
|
const n = [], r = Mn(e, t);
|
|
1695
1719
|
if (In.has(r)) {
|
|
1696
|
-
for (const i of
|
|
1720
|
+
for (const i of $t)
|
|
1697
1721
|
n.push(Pn(r, i));
|
|
1698
1722
|
return n;
|
|
1699
1723
|
}
|
|
1700
1724
|
const s = Mn(t, e);
|
|
1701
1725
|
if (In.has(s)) {
|
|
1702
1726
|
for (let i = $s - 1; i >= 0; i--)
|
|
1703
|
-
n.push(Pn(s,
|
|
1727
|
+
n.push(Pn(s, $t[i]));
|
|
1704
1728
|
return n;
|
|
1705
1729
|
}
|
|
1706
1730
|
return [];
|
|
@@ -1732,7 +1756,7 @@ const Ys = [0.32, 0.24, 0.16, 0.08, 0], Js = Ys.map(
|
|
|
1732
1756
|
"eyes_0.16",
|
|
1733
1757
|
"eyes_0.08",
|
|
1734
1758
|
"eyes_0.00"
|
|
1735
|
-
], Rn = 2, Zs = -30,
|
|
1759
|
+
], Rn = 2, Zs = -30, qt = 20, ei = {
|
|
1736
1760
|
fear: -30,
|
|
1737
1761
|
anger: -20,
|
|
1738
1762
|
sad: -10,
|
|
@@ -1741,14 +1765,14 @@ const Ys = [0.32, 0.24, 0.16, 0.08, 0], Js = Ys.map(
|
|
|
1741
1765
|
happy: 0,
|
|
1742
1766
|
disgust: 20
|
|
1743
1767
|
};
|
|
1744
|
-
function
|
|
1768
|
+
function sn(e) {
|
|
1745
1769
|
return `brow_${e}`;
|
|
1746
1770
|
}
|
|
1747
|
-
function
|
|
1771
|
+
function an(e) {
|
|
1748
1772
|
return ei[e];
|
|
1749
1773
|
}
|
|
1750
|
-
function
|
|
1751
|
-
return Math.max(Zs, Math.min(
|
|
1774
|
+
function Ve(e) {
|
|
1775
|
+
return Math.max(Zs, Math.min(qt, e));
|
|
1752
1776
|
}
|
|
1753
1777
|
function ti(e, t) {
|
|
1754
1778
|
if (e === t) return [];
|
|
@@ -1781,19 +1805,19 @@ const ni = {
|
|
|
1781
1805
|
disgust: "disgust",
|
|
1782
1806
|
disgusted: "disgust"
|
|
1783
1807
|
};
|
|
1784
|
-
function
|
|
1808
|
+
function je(e, t = "neutral") {
|
|
1785
1809
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1786
1810
|
return n ? ni[n] ?? t : t;
|
|
1787
1811
|
}
|
|
1788
1812
|
function ar(e) {
|
|
1789
|
-
return e === 0 ? null :
|
|
1813
|
+
return e === 0 ? null : tn(sn(e), "eyes_standard");
|
|
1790
1814
|
}
|
|
1791
1815
|
function or(e) {
|
|
1792
|
-
return ar(
|
|
1816
|
+
return ar(an(e));
|
|
1793
1817
|
}
|
|
1794
1818
|
function Dn(e, t) {
|
|
1795
|
-
const n =
|
|
1796
|
-
return !t || t === "eyes_standard" ? or(e) : e === "neutral" && t === "eyes_standard" ? null :
|
|
1819
|
+
const n = sn(an(e));
|
|
1820
|
+
return !t || t === "eyes_standard" ? or(e) : e === "neutral" && t === "eyes_standard" ? null : tn(n, t);
|
|
1797
1821
|
}
|
|
1798
1822
|
function ri(e, t) {
|
|
1799
1823
|
const n = [];
|
|
@@ -1804,7 +1828,7 @@ function ri(e, t) {
|
|
|
1804
1828
|
return n.push(or(e)), n;
|
|
1805
1829
|
}
|
|
1806
1830
|
function si(e) {
|
|
1807
|
-
return e === 0 ? null :
|
|
1831
|
+
return e === 0 ? null : tn(sn(e), "eyes_standard");
|
|
1808
1832
|
}
|
|
1809
1833
|
function ii(e, t) {
|
|
1810
1834
|
return ti(e, t).map(si).filter((n) => n != null);
|
|
@@ -1817,11 +1841,11 @@ function oi(e, t) {
|
|
|
1817
1841
|
return null;
|
|
1818
1842
|
}
|
|
1819
1843
|
function ci(e) {
|
|
1820
|
-
const t =
|
|
1821
|
-
return t >=
|
|
1844
|
+
const t = Ve(e);
|
|
1845
|
+
return t >= qt ? qt : Ve(t + ai);
|
|
1822
1846
|
}
|
|
1823
1847
|
function ui(e, t, n) {
|
|
1824
|
-
const r =
|
|
1848
|
+
const r = Ve(n);
|
|
1825
1849
|
return oi(t, e)?.emphasis ? ci(r) : r;
|
|
1826
1850
|
}
|
|
1827
1851
|
function xn(e) {
|
|
@@ -1829,13 +1853,13 @@ function xn(e) {
|
|
|
1829
1853
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1830
1854
|
if (!t?.[1]) return null;
|
|
1831
1855
|
const n = Number.parseInt(t[1], 10);
|
|
1832
|
-
return Number.isFinite(n) ?
|
|
1856
|
+
return Number.isFinite(n) ? Ve(n) : null;
|
|
1833
1857
|
}
|
|
1834
|
-
function
|
|
1858
|
+
function ut(e, t) {
|
|
1835
1859
|
return e + Math.random() * (t - e);
|
|
1836
1860
|
}
|
|
1837
|
-
function
|
|
1838
|
-
return
|
|
1861
|
+
function kt() {
|
|
1862
|
+
return ut(14, 32);
|
|
1839
1863
|
}
|
|
1840
1864
|
function li(e = {}) {
|
|
1841
1865
|
const {
|
|
@@ -1846,127 +1870,127 @@ function li(e = {}) {
|
|
|
1846
1870
|
doubleBlinkGapMinMs: i = 120,
|
|
1847
1871
|
doubleBlinkGapMaxMs: a = 220,
|
|
1848
1872
|
fullBlinkChance: o = 0.75,
|
|
1849
|
-
postEmotionChangeDelayMs:
|
|
1850
|
-
minDwellMs:
|
|
1873
|
+
postEmotionChangeDelayMs: d = 380,
|
|
1874
|
+
minDwellMs: m = 550
|
|
1851
1875
|
} = e;
|
|
1852
|
-
let
|
|
1876
|
+
let c = "neutral", u = "neutral", f = 0, w = 0, b = 0, p = {
|
|
1853
1877
|
kind: "idle",
|
|
1854
1878
|
nextBlinkAt: performance.now() + t
|
|
1855
|
-
},
|
|
1856
|
-
function _(
|
|
1857
|
-
E = `${
|
|
1879
|
+
}, P = null, E = "__eyes_open__|neutral|brow:0";
|
|
1880
|
+
function _(k = c) {
|
|
1881
|
+
E = `${P ?? "__eyes_open__"}|${k}|brow:${w}`;
|
|
1858
1882
|
}
|
|
1859
|
-
function
|
|
1860
|
-
|
|
1861
|
-
const
|
|
1862
|
-
|
|
1883
|
+
function h(k, I = c) {
|
|
1884
|
+
P = k;
|
|
1885
|
+
const M = xn(k);
|
|
1886
|
+
M != null ? w = M : k == null && (w = 0), _(I);
|
|
1863
1887
|
}
|
|
1864
|
-
function
|
|
1865
|
-
return ar(
|
|
1888
|
+
function A(k) {
|
|
1889
|
+
return ar(k);
|
|
1866
1890
|
}
|
|
1867
|
-
function
|
|
1868
|
-
const
|
|
1869
|
-
if (
|
|
1870
|
-
|
|
1891
|
+
function O(k, I, M) {
|
|
1892
|
+
const Q = Ve(I), x = Ve(M);
|
|
1893
|
+
if (f = x, Q === x) {
|
|
1894
|
+
h(A(x));
|
|
1871
1895
|
return;
|
|
1872
1896
|
}
|
|
1873
|
-
const
|
|
1874
|
-
...ii(
|
|
1875
|
-
|
|
1897
|
+
const z = [
|
|
1898
|
+
...ii(Q, x),
|
|
1899
|
+
A(x)
|
|
1876
1900
|
];
|
|
1877
|
-
|
|
1901
|
+
p = {
|
|
1878
1902
|
kind: "browBlend",
|
|
1879
|
-
paths:
|
|
1903
|
+
paths: z,
|
|
1880
1904
|
index: 0,
|
|
1881
|
-
holdUntil:
|
|
1882
|
-
targetBrow:
|
|
1883
|
-
},
|
|
1905
|
+
holdUntil: k + kt(),
|
|
1906
|
+
targetBrow: x
|
|
1907
|
+
}, h(z[0] ?? null);
|
|
1884
1908
|
}
|
|
1885
|
-
function
|
|
1886
|
-
|
|
1909
|
+
function B(k, I) {
|
|
1910
|
+
p = {
|
|
1887
1911
|
kind: "idle",
|
|
1888
|
-
nextBlinkAt:
|
|
1889
|
-
},
|
|
1912
|
+
nextBlinkAt: k + ut(n, r)
|
|
1913
|
+
}, u = I, h(A(f), I);
|
|
1890
1914
|
}
|
|
1891
|
-
function
|
|
1892
|
-
const
|
|
1893
|
-
|
|
1915
|
+
function G(k, I, M) {
|
|
1916
|
+
const Q = M ? Xs : Math.random() < o ? Js : Qs;
|
|
1917
|
+
p = {
|
|
1894
1918
|
kind: "playing",
|
|
1895
|
-
paths: ri(
|
|
1919
|
+
paths: ri(I, Q),
|
|
1896
1920
|
index: 0,
|
|
1897
|
-
holdUntil:
|
|
1921
|
+
holdUntil: k + kt(),
|
|
1898
1922
|
after: "idle",
|
|
1899
|
-
blinkEmotion:
|
|
1900
|
-
},
|
|
1923
|
+
blinkEmotion: I
|
|
1924
|
+
}, u = I, h(p.paths[0] ?? null, I);
|
|
1901
1925
|
}
|
|
1902
|
-
function
|
|
1903
|
-
if (
|
|
1904
|
-
for (;
|
|
1905
|
-
|
|
1906
|
-
const
|
|
1907
|
-
|
|
1926
|
+
function C(k) {
|
|
1927
|
+
if (p.kind === "browBlend") {
|
|
1928
|
+
for (; k >= p.holdUntil && p.index < p.paths.length - 1; )
|
|
1929
|
+
p.index += 1, p.holdUntil = k + kt();
|
|
1930
|
+
const I = p.paths[p.index] ?? null;
|
|
1931
|
+
h(I), k >= p.holdUntil && p.index >= p.paths.length - 1 && (w = p.targetBrow, f = p.targetBrow, h(A(p.targetBrow)), p = {
|
|
1908
1932
|
kind: "idle",
|
|
1909
|
-
nextBlinkAt:
|
|
1933
|
+
nextBlinkAt: k + d
|
|
1910
1934
|
});
|
|
1911
1935
|
return;
|
|
1912
1936
|
}
|
|
1913
|
-
if (
|
|
1914
|
-
|
|
1937
|
+
if (p.kind === "idle") {
|
|
1938
|
+
h(A(f), u), k >= p.nextBlinkAt && G(k, u, !1);
|
|
1915
1939
|
return;
|
|
1916
1940
|
}
|
|
1917
|
-
if (
|
|
1918
|
-
|
|
1941
|
+
if (p.kind === "doublePause") {
|
|
1942
|
+
h(A(f), p.blinkEmotion), k >= p.resumeAt && G(k, p.blinkEmotion, !0);
|
|
1919
1943
|
return;
|
|
1920
1944
|
}
|
|
1921
|
-
if (
|
|
1922
|
-
for (;
|
|
1923
|
-
|
|
1924
|
-
if (p
|
|
1925
|
-
if (
|
|
1926
|
-
|
|
1945
|
+
if (p.kind === "playing") {
|
|
1946
|
+
for (; k >= p.holdUntil && p.index < p.paths.length - 1; )
|
|
1947
|
+
p.index += 1, p.holdUntil = k + kt();
|
|
1948
|
+
if (h(p.paths[p.index] ?? null, p.blinkEmotion), k >= p.holdUntil && p.index >= p.paths.length - 1) {
|
|
1949
|
+
if (p.after === "resumeIdle") {
|
|
1950
|
+
B(k + d, c);
|
|
1927
1951
|
return;
|
|
1928
1952
|
}
|
|
1929
|
-
if (
|
|
1930
|
-
|
|
1953
|
+
if (p.after === "doublePause") {
|
|
1954
|
+
p = {
|
|
1931
1955
|
kind: "doublePause",
|
|
1932
|
-
resumeAt:
|
|
1933
|
-
blinkEmotion:
|
|
1934
|
-
},
|
|
1956
|
+
resumeAt: k + ut(i, a),
|
|
1957
|
+
blinkEmotion: p.blinkEmotion
|
|
1958
|
+
}, h(A(f), p.blinkEmotion);
|
|
1935
1959
|
return;
|
|
1936
1960
|
}
|
|
1937
|
-
if (
|
|
1938
|
-
|
|
1961
|
+
if (p.after === "idle" && Math.random() < s) {
|
|
1962
|
+
p = {
|
|
1939
1963
|
kind: "doublePause",
|
|
1940
|
-
resumeAt:
|
|
1941
|
-
blinkEmotion:
|
|
1942
|
-
},
|
|
1964
|
+
resumeAt: k + ut(i, a),
|
|
1965
|
+
blinkEmotion: p.blinkEmotion
|
|
1966
|
+
}, h(A(f), p.blinkEmotion);
|
|
1943
1967
|
return;
|
|
1944
1968
|
}
|
|
1945
|
-
|
|
1969
|
+
B(k, p.blinkEmotion);
|
|
1946
1970
|
}
|
|
1947
1971
|
}
|
|
1948
1972
|
}
|
|
1949
1973
|
return {
|
|
1950
|
-
advance:
|
|
1951
|
-
setTargetEmotion(
|
|
1952
|
-
const
|
|
1953
|
-
if (
|
|
1954
|
-
const
|
|
1955
|
-
|
|
1956
|
-
},
|
|
1957
|
-
setTargetEyebrow(
|
|
1958
|
-
const
|
|
1959
|
-
if (
|
|
1960
|
-
const
|
|
1961
|
-
|
|
1962
|
-
},
|
|
1963
|
-
getTargetEmotion: () =>
|
|
1964
|
-
getTargetEyebrow: () =>
|
|
1965
|
-
getExpressionPath: () =>
|
|
1974
|
+
advance: C,
|
|
1975
|
+
setTargetEmotion(k) {
|
|
1976
|
+
const I = je(k, c);
|
|
1977
|
+
if (I === c) return;
|
|
1978
|
+
const M = performance.now();
|
|
1979
|
+
m > 0 && I !== c && !(c === "neutral" && I !== "neutral") && M - b < m || (c = I, u = I, b = M);
|
|
1980
|
+
},
|
|
1981
|
+
setTargetEyebrow(k) {
|
|
1982
|
+
const I = Ve(k);
|
|
1983
|
+
if (I === f) return;
|
|
1984
|
+
const M = performance.now(), Q = p.kind === "browBlend" ? xn(P) ?? w : w;
|
|
1985
|
+
f = I, !(I === Q && p.kind !== "browBlend") && (p.kind === "playing" || p.kind === "doublePause" || O(M, Q, I));
|
|
1986
|
+
},
|
|
1987
|
+
getTargetEmotion: () => c,
|
|
1988
|
+
getTargetEyebrow: () => f,
|
|
1989
|
+
getExpressionPath: () => P,
|
|
1966
1990
|
getDrawKey: () => E,
|
|
1967
1991
|
reset() {
|
|
1968
|
-
|
|
1969
|
-
performance.now() +
|
|
1992
|
+
c = "neutral", u = "neutral", f = 0, w = 0, b = 0, B(
|
|
1993
|
+
performance.now() + ut(n, r),
|
|
1970
1994
|
"neutral"
|
|
1971
1995
|
);
|
|
1972
1996
|
}
|
|
@@ -1982,15 +2006,15 @@ function fi() {
|
|
|
1982
2006
|
return {
|
|
1983
2007
|
async load(i) {
|
|
1984
2008
|
t && r === i || (s(), t = !1, r = i, i.startsWith("blob:") && (n = i), await new Promise((a, o) => {
|
|
1985
|
-
const
|
|
1986
|
-
const
|
|
1987
|
-
if (!Number.isFinite(
|
|
2009
|
+
const d = () => {
|
|
2010
|
+
const m = e.duration;
|
|
2011
|
+
if (!Number.isFinite(m) || m <= 0) {
|
|
1988
2012
|
o(new Error(`Idle video has invalid duration: ${i}`));
|
|
1989
2013
|
return;
|
|
1990
2014
|
}
|
|
1991
2015
|
t = !0, e.currentTime = 0, a();
|
|
1992
2016
|
};
|
|
1993
|
-
e.addEventListener("loadeddata",
|
|
2017
|
+
e.addEventListener("loadeddata", d, { once: !0 }), e.addEventListener(
|
|
1994
2018
|
"error",
|
|
1995
2019
|
() => o(new Error(`Failed to load idle video: ${i}`)),
|
|
1996
2020
|
{ once: !0 }
|
|
@@ -2041,92 +2065,92 @@ function hi(e, t) {
|
|
|
2041
2065
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
2042
2066
|
}
|
|
2043
2067
|
function pi(e, t, n, r = "neutral") {
|
|
2044
|
-
const s =
|
|
2068
|
+
const s = je(r);
|
|
2045
2069
|
if (t.length === 0) return s;
|
|
2046
2070
|
if (n.length === 0 || e < n[0].wtime)
|
|
2047
|
-
return
|
|
2071
|
+
return je(t[0]?.emotion, s);
|
|
2048
2072
|
const i = hi(t, n);
|
|
2049
2073
|
let a = null;
|
|
2050
|
-
for (const
|
|
2051
|
-
e >=
|
|
2074
|
+
for (const m of i)
|
|
2075
|
+
e >= m.startMs && e <= m.endMs && (a = m);
|
|
2052
2076
|
if (a)
|
|
2053
|
-
return
|
|
2054
|
-
const o = n[n.length - 1],
|
|
2055
|
-
return e >
|
|
2077
|
+
return je(a.sentence.emotion, s);
|
|
2078
|
+
const o = n[n.length - 1], d = o.wtime + o.wduration;
|
|
2079
|
+
return e > d + cr ? je(
|
|
2056
2080
|
t[t.length - 1]?.emotion,
|
|
2057
2081
|
s
|
|
2058
2082
|
) : s;
|
|
2059
2083
|
}
|
|
2060
|
-
function
|
|
2084
|
+
function on(e, t, n, r, s = rr) {
|
|
2061
2085
|
const i = new OffscreenCanvas(n, r), a = i.getContext("2d", { willReadFrequently: !0 });
|
|
2062
2086
|
a.drawImage(e, 0, 0, n, r);
|
|
2063
|
-
const o = a.getImageData(0, 0, n, r),
|
|
2064
|
-
|
|
2065
|
-
const
|
|
2066
|
-
for (const
|
|
2067
|
-
|
|
2068
|
-
const
|
|
2069
|
-
for (let w = 0; w <
|
|
2070
|
-
const b =
|
|
2071
|
-
Math.max(b,
|
|
2087
|
+
const o = a.getImageData(0, 0, n, r), d = a.createImageData(n, r);
|
|
2088
|
+
d.data.set(o.data);
|
|
2089
|
+
const c = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
|
|
2090
|
+
for (const u of t) {
|
|
2091
|
+
c.clearRect(0, 0, n, r), c.drawImage(u, 0, 0, n, r);
|
|
2092
|
+
const f = c.getImageData(0, 0, n, r);
|
|
2093
|
+
for (let w = 0; w < d.data.length; w += 4) {
|
|
2094
|
+
const b = f.data[w], p = f.data[w + 1], P = f.data[w + 2];
|
|
2095
|
+
Math.max(b, p, P) > s && (d.data[w] = b, d.data[w + 1] = p, d.data[w + 2] = P, d.data[w + 3] = 255);
|
|
2072
2096
|
}
|
|
2073
2097
|
}
|
|
2074
|
-
return a.putImageData(
|
|
2098
|
+
return a.putImageData(d, 0, 0), i;
|
|
2075
2099
|
}
|
|
2076
|
-
let
|
|
2077
|
-
const
|
|
2100
|
+
let Ue = null, Je = null;
|
|
2101
|
+
const Tt = /* @__PURE__ */ new Map();
|
|
2078
2102
|
function wi() {
|
|
2079
|
-
|
|
2103
|
+
Ue = null, Je = null, Tt.clear();
|
|
2080
2104
|
}
|
|
2081
2105
|
Xr(wi);
|
|
2082
2106
|
function gi(e) {
|
|
2083
|
-
return e ??
|
|
2107
|
+
return e ?? Je ?? void 0;
|
|
2084
2108
|
}
|
|
2085
|
-
function
|
|
2109
|
+
function cn(e) {
|
|
2086
2110
|
return new Promise((t, n) => {
|
|
2087
2111
|
const r = new Image();
|
|
2088
2112
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
2089
2113
|
});
|
|
2090
2114
|
}
|
|
2091
2115
|
async function yi(e) {
|
|
2092
|
-
return
|
|
2093
|
-
await
|
|
2094
|
-
) :
|
|
2095
|
-
}
|
|
2096
|
-
async function
|
|
2097
|
-
const s = n ? await Ns(e, r) : await fetch(e).then((
|
|
2098
|
-
if (!
|
|
2099
|
-
return
|
|
2116
|
+
return Mt() ? Vs(
|
|
2117
|
+
await Dt(bn(), e ?? "")
|
|
2118
|
+
) : cn(bn());
|
|
2119
|
+
}
|
|
2120
|
+
async function Cn(e, t, n, r) {
|
|
2121
|
+
const s = n ? await Ns(e, r) : await fetch(e).then((m) => {
|
|
2122
|
+
if (!m.ok) throw new Error(`Failed to load ${e}`);
|
|
2123
|
+
return m.json();
|
|
2100
2124
|
}), i = s.sheets?.[0];
|
|
2101
2125
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
2102
2126
|
const a = n ? await Us(
|
|
2103
|
-
await
|
|
2127
|
+
await Dt(
|
|
2104
2128
|
zs(t, i.path, n),
|
|
2105
2129
|
r ?? ""
|
|
2106
2130
|
)
|
|
2107
|
-
) : await
|
|
2108
|
-
for (const
|
|
2109
|
-
|
|
2110
|
-
const
|
|
2111
|
-
for (const
|
|
2112
|
-
|
|
2113
|
-
return { atlas: a, atlasMeta: s, cellByPath: o, sheetByIndex:
|
|
2114
|
-
}
|
|
2115
|
-
async function
|
|
2116
|
-
const t = gi(e), n =
|
|
2131
|
+
) : await cn(`${t}/${i.path}`), o = /* @__PURE__ */ new Map();
|
|
2132
|
+
for (const m of s.cells ?? [])
|
|
2133
|
+
m.path && o.set(m.path, m);
|
|
2134
|
+
const d = /* @__PURE__ */ new Map();
|
|
2135
|
+
for (const m of s.sheets ?? [])
|
|
2136
|
+
d.set(m.index, m);
|
|
2137
|
+
return { atlas: a, atlasMeta: s, cellByPath: o, sheetByIndex: d, diffBase: t };
|
|
2138
|
+
}
|
|
2139
|
+
async function Kt(e) {
|
|
2140
|
+
const t = gi(e), n = Mt();
|
|
2117
2141
|
if (n && !t)
|
|
2118
2142
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
2119
|
-
if (
|
|
2120
|
-
const i = await
|
|
2143
|
+
if (Ue && (!n || Je === (t ?? null))) {
|
|
2144
|
+
const i = await Ue;
|
|
2121
2145
|
return {
|
|
2122
|
-
...
|
|
2146
|
+
...Xe(i),
|
|
2123
2147
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
2124
2148
|
};
|
|
2125
2149
|
}
|
|
2126
|
-
|
|
2150
|
+
Je = t ?? null, Tt.clear();
|
|
2127
2151
|
const r = Zr();
|
|
2128
|
-
|
|
2129
|
-
const i = await yi(t), a = await
|
|
2152
|
+
Ue = (async () => {
|
|
2153
|
+
const i = await yi(t), a = await Cn(
|
|
2130
2154
|
es(),
|
|
2131
2155
|
r,
|
|
2132
2156
|
n,
|
|
@@ -2134,7 +2158,7 @@ async function qt(e) {
|
|
|
2134
2158
|
);
|
|
2135
2159
|
let o = null;
|
|
2136
2160
|
try {
|
|
2137
|
-
o = await
|
|
2161
|
+
o = await Cn(
|
|
2138
2162
|
ts(),
|
|
2139
2163
|
r,
|
|
2140
2164
|
n,
|
|
@@ -2145,14 +2169,14 @@ async function qt(e) {
|
|
|
2145
2169
|
}
|
|
2146
2170
|
return { sil: i, viseme: a, expression: o };
|
|
2147
2171
|
})();
|
|
2148
|
-
const s = await
|
|
2149
|
-
return { ...
|
|
2172
|
+
const s = await Ue;
|
|
2173
|
+
return { ...Xe(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
2150
2174
|
}
|
|
2151
|
-
async function
|
|
2152
|
-
if (await
|
|
2153
|
-
return
|
|
2175
|
+
async function un(e) {
|
|
2176
|
+
if (await Kt(e), !Ue) throw new Error("Assets not loaded");
|
|
2177
|
+
return Ue;
|
|
2154
2178
|
}
|
|
2155
|
-
function
|
|
2179
|
+
function Xe(e) {
|
|
2156
2180
|
return Fs(
|
|
2157
2181
|
e.viseme.atlasMeta,
|
|
2158
2182
|
e.sil.naturalWidth,
|
|
@@ -2163,115 +2187,115 @@ function _i(e, t) {
|
|
|
2163
2187
|
const n = document.createElement("canvas");
|
|
2164
2188
|
return n.width = t.w, n.height = t.h, n.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), n;
|
|
2165
2189
|
}
|
|
2166
|
-
async function
|
|
2167
|
-
const r = `${t.diffBase}::${n}`, s =
|
|
2190
|
+
async function At(e, t, n) {
|
|
2191
|
+
const r = `${t.diffBase}::${n}`, s = Tt.get(r);
|
|
2168
2192
|
if (s) return s;
|
|
2169
2193
|
const i = (async () => {
|
|
2170
2194
|
const a = t.cellByPath.get(n);
|
|
2171
2195
|
if (!a) throw new Error(`No atlas cell for path: ${n}`);
|
|
2172
|
-
const o =
|
|
2173
|
-
if (
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2176
|
-
const w =
|
|
2177
|
-
return w.fillStyle = "#000", w.fillRect(0, 0,
|
|
2196
|
+
const o = Os(t.atlasMeta, a), d = Xe(e);
|
|
2197
|
+
if (Ls(a)) {
|
|
2198
|
+
const u = _i(t, a), f = document.createElement("canvas");
|
|
2199
|
+
f.width = d.width, f.height = d.height;
|
|
2200
|
+
const w = f.getContext("2d");
|
|
2201
|
+
return w.fillStyle = "#000", w.fillRect(0, 0, d.width, d.height), w.drawImage(u, o.x, o.y), f;
|
|
2178
2202
|
}
|
|
2179
|
-
const
|
|
2180
|
-
if (
|
|
2181
|
-
return
|
|
2203
|
+
const m = `${t.diffBase}/${n}`, c = await cn(m);
|
|
2204
|
+
if (c.naturalWidth === d.width && c.naturalHeight === d.height)
|
|
2205
|
+
return c;
|
|
2182
2206
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
2183
2207
|
})();
|
|
2184
|
-
return
|
|
2208
|
+
return Tt.set(r, i), i;
|
|
2185
2209
|
}
|
|
2186
|
-
async function
|
|
2210
|
+
async function Bn(e, t, n, r, s, i) {
|
|
2187
2211
|
if (s) {
|
|
2188
2212
|
const { width: w, height: b } = s;
|
|
2189
2213
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
2190
2214
|
return;
|
|
2191
|
-
const
|
|
2192
|
-
|
|
2193
|
-
const
|
|
2194
|
-
if (
|
|
2215
|
+
const p = document.createElement("canvas");
|
|
2216
|
+
p.width = w, p.height = b;
|
|
2217
|
+
const P = p.getContext("2d");
|
|
2218
|
+
if (P.clearRect(0, 0, w, b), P.drawImage(t, 0, 0, w, b), i && !i()) return;
|
|
2195
2219
|
(e.width !== w || e.height !== b) && (e.width = w, e.height = b);
|
|
2196
2220
|
const E = e.getContext("2d");
|
|
2197
|
-
E.clearRect(0, 0, w, b), E.drawImage(
|
|
2221
|
+
E.clearRect(0, 0, w, b), E.drawImage(p, 0, 0);
|
|
2198
2222
|
return;
|
|
2199
2223
|
}
|
|
2200
|
-
const a = await
|
|
2201
|
-
(e.width !==
|
|
2202
|
-
const
|
|
2203
|
-
if (
|
|
2224
|
+
const a = await un(), o = nn(a.viseme.atlasMeta), { width: d, height: m } = Xe(a);
|
|
2225
|
+
(e.width !== d || e.height !== m) && (e.width = d, e.height = m);
|
|
2226
|
+
const c = [], u = e.getContext("2d");
|
|
2227
|
+
if (u.clearRect(0, 0, d, m), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
2204
2228
|
const w = a.sil;
|
|
2205
|
-
|
|
2229
|
+
u.drawImage(w, 0, 0, d, m);
|
|
2206
2230
|
return;
|
|
2207
2231
|
}
|
|
2208
|
-
if (
|
|
2209
|
-
|
|
2232
|
+
if (c.length === 0) {
|
|
2233
|
+
u.drawImage(t, 0, 0, d, m);
|
|
2210
2234
|
return;
|
|
2211
2235
|
}
|
|
2212
|
-
const
|
|
2213
|
-
|
|
2236
|
+
const f = on(t, c, d, m, o);
|
|
2237
|
+
u.drawImage(f, 0, 0);
|
|
2214
2238
|
}
|
|
2215
|
-
async function
|
|
2216
|
-
const r = await
|
|
2239
|
+
async function Gt(e, t, n) {
|
|
2240
|
+
const r = await un(Je ?? void 0), s = nn(r.viseme.atlasMeta), { width: i, height: a } = Xe(r);
|
|
2217
2241
|
(e.width !== i || e.height !== a) && (e.width = i, e.height = a);
|
|
2218
2242
|
const o = [];
|
|
2219
2243
|
if (t.mouthPath) {
|
|
2220
|
-
const
|
|
2221
|
-
|
|
2244
|
+
const c = new Set(r.viseme.cellByPath.keys()), u = sr(t.mouthPath, c) ?? (c.has(t.mouthPath) ? t.mouthPath : null);
|
|
2245
|
+
u && o.push(await At(r, r.viseme, u));
|
|
2222
2246
|
}
|
|
2223
2247
|
t.expressionPath && r.expression && o.push(
|
|
2224
|
-
await
|
|
2248
|
+
await At(r, r.expression, t.expressionPath)
|
|
2225
2249
|
);
|
|
2226
|
-
const
|
|
2227
|
-
if (
|
|
2228
|
-
|
|
2250
|
+
const d = e.getContext("2d");
|
|
2251
|
+
if (d.clearRect(0, 0, i, a), o.length === 0) {
|
|
2252
|
+
d.drawImage(r.sil, 0, 0, i, a);
|
|
2229
2253
|
return;
|
|
2230
2254
|
}
|
|
2231
|
-
const
|
|
2255
|
+
const m = on(
|
|
2232
2256
|
r.sil,
|
|
2233
2257
|
o,
|
|
2234
2258
|
i,
|
|
2235
2259
|
a,
|
|
2236
2260
|
s
|
|
2237
2261
|
);
|
|
2238
|
-
|
|
2262
|
+
d.drawImage(m, 0, 0);
|
|
2239
2263
|
}
|
|
2240
2264
|
async function Si(e, t) {
|
|
2241
|
-
const n = await
|
|
2265
|
+
const n = await un(Je ?? void 0), r = nn(n.viseme.atlasMeta), { width: s, height: i } = Xe(n), a = [];
|
|
2242
2266
|
if (e.mouthPath) {
|
|
2243
|
-
const
|
|
2244
|
-
|
|
2267
|
+
const c = new Set(n.viseme.cellByPath.keys()), u = sr(e.mouthPath, c) ?? (c.has(e.mouthPath) ? e.mouthPath : null);
|
|
2268
|
+
u && a.push(await At(n, n.viseme, u));
|
|
2245
2269
|
}
|
|
2246
2270
|
e.expressionPath && n.expression && a.push(
|
|
2247
|
-
await
|
|
2271
|
+
await At(n, n.expression, e.expressionPath)
|
|
2248
2272
|
);
|
|
2249
|
-
const o = new OffscreenCanvas(s, i),
|
|
2273
|
+
const o = new OffscreenCanvas(s, i), d = o.getContext("2d");
|
|
2250
2274
|
if (a.length === 0)
|
|
2251
|
-
return
|
|
2252
|
-
const
|
|
2275
|
+
return d.drawImage(n.sil, 0, 0, s, i), o.transferToImageBitmap();
|
|
2276
|
+
const m = on(
|
|
2253
2277
|
n.sil,
|
|
2254
2278
|
a,
|
|
2255
2279
|
s,
|
|
2256
2280
|
i,
|
|
2257
2281
|
r
|
|
2258
2282
|
);
|
|
2259
|
-
return
|
|
2283
|
+
return d.drawImage(m, 0, 0), o.transferToImageBitmap();
|
|
2260
2284
|
}
|
|
2261
2285
|
async function ki(e) {
|
|
2262
|
-
await
|
|
2286
|
+
await Gt(e, { mouthPath: null, expressionPath: null });
|
|
2263
2287
|
}
|
|
2264
2288
|
let ur = null;
|
|
2265
2289
|
function Fn(e) {
|
|
2266
2290
|
ur = e;
|
|
2267
2291
|
}
|
|
2268
|
-
function
|
|
2292
|
+
function We() {
|
|
2269
2293
|
return ur;
|
|
2270
2294
|
}
|
|
2271
|
-
function
|
|
2295
|
+
function vi(e) {
|
|
2272
2296
|
return `${e.from}→${e.to}@${e.fromVtime}`;
|
|
2273
2297
|
}
|
|
2274
|
-
function
|
|
2298
|
+
function On() {
|
|
2275
2299
|
return {
|
|
2276
2300
|
rafTicksSpeaking: 0,
|
|
2277
2301
|
rafTicksDeduped: 0,
|
|
@@ -2289,16 +2313,16 @@ function Ln() {
|
|
|
2289
2313
|
bufferPrefetched: 0
|
|
2290
2314
|
};
|
|
2291
2315
|
}
|
|
2292
|
-
function
|
|
2293
|
-
let e =
|
|
2316
|
+
function bi() {
|
|
2317
|
+
let e = On();
|
|
2294
2318
|
const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
2295
2319
|
let s = "", i = -1, a = "";
|
|
2296
2320
|
const o = () => {
|
|
2297
|
-
e =
|
|
2298
|
-
},
|
|
2299
|
-
t.add(
|
|
2300
|
-
},
|
|
2301
|
-
|
|
2321
|
+
e = On(), t.clear(), n.clear(), r.clear(), s = "", i = -1, a = "";
|
|
2322
|
+
}, d = (c) => {
|
|
2323
|
+
t.add(c);
|
|
2324
|
+
}, m = (c) => {
|
|
2325
|
+
c && r.add(c);
|
|
2302
2326
|
};
|
|
2303
2327
|
return {
|
|
2304
2328
|
reset: o,
|
|
@@ -2317,9 +2341,9 @@ function vi() {
|
|
|
2317
2341
|
onWorkerStale() {
|
|
2318
2342
|
e.workerStale += 1;
|
|
2319
2343
|
},
|
|
2320
|
-
onTransitionSample(
|
|
2321
|
-
const
|
|
2322
|
-
e.transitionFramesSampled += 1,
|
|
2344
|
+
onTransitionSample(c, u) {
|
|
2345
|
+
const f = vi(c);
|
|
2346
|
+
e.transitionFramesSampled += 1, f !== s && (s = f, i = -1, a !== f && (a = f, e.rifeFramesOmittedByGap += c.omittedByGap)), u && n.add(u), i >= 0 && c.frameIdx > i + 1 && (e.transitionFramesMissed += c.frameIdx - i - 1), i = c.frameIdx;
|
|
2323
2347
|
},
|
|
2324
2348
|
onBufferTick() {
|
|
2325
2349
|
e.bufferTicks += 1;
|
|
@@ -2335,60 +2359,60 @@ function vi() {
|
|
|
2335
2359
|
},
|
|
2336
2360
|
onBufferReset() {
|
|
2337
2361
|
},
|
|
2338
|
-
onDrawDisplayed(
|
|
2339
|
-
if (e.drawsDisplayed += 1,
|
|
2362
|
+
onDrawDisplayed(c, u) {
|
|
2363
|
+
if (e.drawsDisplayed += 1, c.transitionMeta) {
|
|
2340
2364
|
e.transitionFramesDisplayed += 1;
|
|
2341
|
-
const w =
|
|
2342
|
-
|
|
2365
|
+
const w = c.transitionMeta;
|
|
2366
|
+
d(w.fromVtime), d(w.toVtime), m(c.mouthPath);
|
|
2343
2367
|
return;
|
|
2344
2368
|
}
|
|
2345
|
-
if (
|
|
2369
|
+
if (c.label.includes("→")) {
|
|
2346
2370
|
e.transitionFramesDisplayed += 1;
|
|
2347
2371
|
return;
|
|
2348
2372
|
}
|
|
2349
|
-
const
|
|
2350
|
-
if (!(!
|
|
2351
|
-
for (const w of
|
|
2352
|
-
if (w.viseme ===
|
|
2353
|
-
|
|
2373
|
+
const f = c.label.trim();
|
|
2374
|
+
if (!(!f || f === "sil")) {
|
|
2375
|
+
for (const w of u)
|
|
2376
|
+
if (w.viseme === f && c.elapsedMs >= w.vtime && c.elapsedMs < w.vtime + w.vduration) {
|
|
2377
|
+
d(w.vtime);
|
|
2354
2378
|
break;
|
|
2355
2379
|
}
|
|
2356
2380
|
}
|
|
2357
2381
|
},
|
|
2358
|
-
snapshot(
|
|
2359
|
-
let
|
|
2360
|
-
for (const _ of
|
|
2382
|
+
snapshot(c, u) {
|
|
2383
|
+
let f = 0, w = 0;
|
|
2384
|
+
for (const _ of c)
|
|
2361
2385
|
if (_.viseme !== "sil") {
|
|
2362
|
-
if (_.vtime >=
|
|
2363
|
-
|
|
2386
|
+
if (_.vtime >= u) break;
|
|
2387
|
+
f += 1, t.has(_.vtime) && (w += 1);
|
|
2364
2388
|
}
|
|
2365
|
-
const b =
|
|
2389
|
+
const b = f > 0 ? Math.round(w / f * 100) : 100, p = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), P = f - w, E = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
|
|
2366
2390
|
return {
|
|
2367
2391
|
...e,
|
|
2368
2392
|
bufferHitRate: E,
|
|
2369
|
-
renderLoss:
|
|
2370
|
-
visemeSlotsTotal:
|
|
2393
|
+
renderLoss: p,
|
|
2394
|
+
visemeSlotsTotal: f,
|
|
2371
2395
|
visemeSlotsCovered: w,
|
|
2372
2396
|
visemeCoveragePct: b,
|
|
2373
2397
|
transitionFramesUniqueSampled: n.size,
|
|
2374
2398
|
transitionFramesUniquePainted: r.size,
|
|
2375
2399
|
drawsDeduped: e.rafTicksDeduped,
|
|
2376
|
-
renderSkips: e.rafTicksDeduped +
|
|
2400
|
+
renderSkips: e.rafTicksDeduped + p,
|
|
2377
2401
|
visemesShown: w,
|
|
2378
|
-
visemesSkipped:
|
|
2402
|
+
visemesSkipped: P,
|
|
2379
2403
|
rifeTransitionFramesSkipped: e.transitionFramesMissed
|
|
2380
2404
|
};
|
|
2381
2405
|
}
|
|
2382
2406
|
};
|
|
2383
2407
|
}
|
|
2384
|
-
const lr =
|
|
2408
|
+
const lr = Yt, Ei = 200, Ti = 100, Ai = 600, fr = "__sil__";
|
|
2385
2409
|
function Ii(e) {
|
|
2386
2410
|
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === fr : !1;
|
|
2387
2411
|
}
|
|
2388
|
-
function
|
|
2412
|
+
function ln() {
|
|
2389
2413
|
return { lastDrawnKey: "" };
|
|
2390
2414
|
}
|
|
2391
|
-
function
|
|
2415
|
+
function ve(e) {
|
|
2392
2416
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
2393
2417
|
}
|
|
2394
2418
|
function Mi(e, t) {
|
|
@@ -2410,100 +2434,100 @@ function Ri(e, t, n, r = 120) {
|
|
|
2410
2434
|
return s !== "sil" ? s : Pi(e, t);
|
|
2411
2435
|
}
|
|
2412
2436
|
function Di(e, t) {
|
|
2413
|
-
return e === "sil" ? !1 : t ? qs(e, "sil", t) :
|
|
2437
|
+
return e === "sil" ? !1 : t ? qs(e, "sil", t) : rn(e, "sil").length > 0;
|
|
2414
2438
|
}
|
|
2415
2439
|
function xi() {
|
|
2416
2440
|
return lr + Ai;
|
|
2417
2441
|
}
|
|
2418
|
-
function
|
|
2442
|
+
function It(e) {
|
|
2419
2443
|
return e ?? fr;
|
|
2420
2444
|
}
|
|
2421
|
-
function
|
|
2445
|
+
function fn(e, t, n, r, s = Ti) {
|
|
2422
2446
|
if (e.length === 0)
|
|
2423
2447
|
return { diffPath: null, label: "sil" };
|
|
2424
|
-
if (t >=
|
|
2448
|
+
if (t >= Ne(e))
|
|
2425
2449
|
return { diffPath: null, label: "sil" };
|
|
2426
2450
|
const i = Mi(e, r), a = ys(i, t);
|
|
2427
2451
|
if (a) {
|
|
2428
|
-
const
|
|
2429
|
-
if (t >=
|
|
2430
|
-
let
|
|
2431
|
-
n && (
|
|
2432
|
-
const
|
|
2433
|
-
if (
|
|
2434
|
-
const
|
|
2452
|
+
const d = Yn(a.fromVtime, a.toVtime);
|
|
2453
|
+
if (t >= d.transStart && t < d.transEnd) {
|
|
2454
|
+
let m = rn(a.from, a.to);
|
|
2455
|
+
n && (m = ir(m, n));
|
|
2456
|
+
const c = Gs(m, d.effectiveGapMs);
|
|
2457
|
+
if (c.length > 0) {
|
|
2458
|
+
const u = js(
|
|
2435
2459
|
t,
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2460
|
+
d.transStart,
|
|
2461
|
+
d.transEnd,
|
|
2462
|
+
c.length
|
|
2439
2463
|
);
|
|
2440
2464
|
return {
|
|
2441
|
-
diffPath: u
|
|
2465
|
+
diffPath: c[u] ?? c[c.length - 1],
|
|
2442
2466
|
label: `${a.from}→${a.to}`,
|
|
2443
2467
|
transitionMeta: {
|
|
2444
2468
|
from: a.from,
|
|
2445
2469
|
to: a.to,
|
|
2446
2470
|
fromVtime: a.fromVtime,
|
|
2447
2471
|
toVtime: a.toVtime,
|
|
2448
|
-
frameIdx:
|
|
2449
|
-
frameCount:
|
|
2450
|
-
fullFrameCount:
|
|
2451
|
-
omittedByGap: Math.max(0,
|
|
2472
|
+
frameIdx: u,
|
|
2473
|
+
frameCount: c.length,
|
|
2474
|
+
fullFrameCount: m.length,
|
|
2475
|
+
omittedByGap: Math.max(0, m.length - c.length)
|
|
2452
2476
|
}
|
|
2453
2477
|
};
|
|
2454
2478
|
}
|
|
2455
|
-
return { diffPath:
|
|
2479
|
+
return { diffPath: Et(a.to), label: a.to };
|
|
2456
2480
|
}
|
|
2457
2481
|
}
|
|
2458
2482
|
const o = Qn(e, t, s);
|
|
2459
|
-
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath:
|
|
2483
|
+
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Et(o), label: o };
|
|
2460
2484
|
}
|
|
2461
|
-
function
|
|
2462
|
-
const n = t ??
|
|
2463
|
-
return `${
|
|
2485
|
+
function dn(e, t) {
|
|
2486
|
+
const n = t ?? It(e.expressionPath);
|
|
2487
|
+
return `${It(e.mouthPath)}|${n}`;
|
|
2464
2488
|
}
|
|
2465
|
-
function
|
|
2466
|
-
const
|
|
2467
|
-
mouthPath:
|
|
2489
|
+
function Ci(e, t, n, r, s, i, a, o, d, m) {
|
|
2490
|
+
const c = fn(t, n, d, i), u = {
|
|
2491
|
+
mouthPath: c.diffPath,
|
|
2468
2492
|
expressionPath: r
|
|
2469
|
-
},
|
|
2470
|
-
if (
|
|
2493
|
+
}, f = dn(u, s), w = We();
|
|
2494
|
+
if (c.transitionMeta && w?.onTransitionSample(c.transitionMeta, c.diffPath), f === i.lastDrawnKey) {
|
|
2471
2495
|
w?.onDrawDeduped();
|
|
2472
2496
|
return;
|
|
2473
2497
|
}
|
|
2474
|
-
w?.onDrawRequested(), o(
|
|
2475
|
-
b ===
|
|
2498
|
+
w?.onDrawRequested(), o(c), i.lastDrawnKey = f, a(e, u, f, (b) => {
|
|
2499
|
+
b === f && (i.lastDrawnKey = f);
|
|
2476
2500
|
});
|
|
2477
2501
|
}
|
|
2478
|
-
function
|
|
2479
|
-
const o = { mouthPath: null, expressionPath: t },
|
|
2480
|
-
!(a != null) &&
|
|
2502
|
+
function Ln(e, t, n, r, s, i, a = null) {
|
|
2503
|
+
const o = { mouthPath: null, expressionPath: t }, d = a != null ? `|idle@${Math.round(a * 1e3)}` : "", m = dn(o, n) + d;
|
|
2504
|
+
!(a != null) && m === r.lastDrawnKey || (i(
|
|
2481
2505
|
a != null ? "idle" : "sil"
|
|
2482
|
-
), s(e, o,
|
|
2483
|
-
|
|
2506
|
+
), s(e, o, m, (u) => {
|
|
2507
|
+
u === m && (r.lastDrawnKey = m);
|
|
2484
2508
|
}));
|
|
2485
2509
|
}
|
|
2486
|
-
function dr(e, t, n, r, s =
|
|
2510
|
+
function dr(e, t, n, r, s = lt, i) {
|
|
2487
2511
|
if (n <= t || e.length === 0) return [];
|
|
2488
|
-
const a = i ??
|
|
2489
|
-
let
|
|
2490
|
-
for (let
|
|
2491
|
-
const
|
|
2512
|
+
const a = i ?? ln(), o = [];
|
|
2513
|
+
let d = "";
|
|
2514
|
+
for (let m = t; m < n; m += s) {
|
|
2515
|
+
const c = fn(
|
|
2492
2516
|
e,
|
|
2493
|
-
|
|
2517
|
+
m,
|
|
2494
2518
|
r,
|
|
2495
2519
|
a
|
|
2496
|
-
),
|
|
2497
|
-
|
|
2498
|
-
displayAtMs:
|
|
2499
|
-
mouthPath:
|
|
2500
|
-
mouthKey:
|
|
2501
|
-
label:
|
|
2520
|
+
), u = It(c.diffPath);
|
|
2521
|
+
u !== d && (d = u, o.push({
|
|
2522
|
+
displayAtMs: m,
|
|
2523
|
+
mouthPath: c.diffPath,
|
|
2524
|
+
mouthKey: u,
|
|
2525
|
+
label: c.label
|
|
2502
2526
|
}));
|
|
2503
2527
|
}
|
|
2504
2528
|
return o;
|
|
2505
2529
|
}
|
|
2506
|
-
const
|
|
2530
|
+
const Bi = 3;
|
|
2507
2531
|
function mr(e) {
|
|
2508
2532
|
let t = 0;
|
|
2509
2533
|
const n = [];
|
|
@@ -2513,8 +2537,8 @@ function mr(e) {
|
|
|
2513
2537
|
r = !0;
|
|
2514
2538
|
try {
|
|
2515
2539
|
for (; n.length > 0; ) {
|
|
2516
|
-
const o = n.shift(),
|
|
2517
|
-
await e(o.diffs,
|
|
2540
|
+
const o = n.shift(), d = ++t;
|
|
2541
|
+
await e(o.diffs, d, o) && d === t && o.onDisplayed?.(o.drawKey);
|
|
2518
2542
|
}
|
|
2519
2543
|
} finally {
|
|
2520
2544
|
r = !1, n.length > 0 && i();
|
|
@@ -2526,9 +2550,9 @@ function mr(e) {
|
|
|
2526
2550
|
}));
|
|
2527
2551
|
};
|
|
2528
2552
|
return {
|
|
2529
|
-
enqueue(o,
|
|
2530
|
-
const
|
|
2531
|
-
|
|
2553
|
+
enqueue(o, d, m) {
|
|
2554
|
+
const c = n.findIndex((u) => u.drawKey === d);
|
|
2555
|
+
c >= 0 ? n[c] = { diffs: o, drawKey: d, onDisplayed: m } : (n.length >= Bi && (n.shift(), We()?.onQueueSuperseded()), n.push({ diffs: o, drawKey: d, onDisplayed: m })), a();
|
|
2532
2556
|
},
|
|
2533
2557
|
reset() {
|
|
2534
2558
|
t += 1, n.length = 0;
|
|
@@ -2544,35 +2568,35 @@ function mr(e) {
|
|
|
2544
2568
|
function Fi(e, t = 2) {
|
|
2545
2569
|
const n = [], r = /* @__PURE__ */ new Set();
|
|
2546
2570
|
let s = 0, i = !1, a = 0;
|
|
2547
|
-
const o = (
|
|
2571
|
+
const o = (m, c) => `${m}|${c}`, d = async () => {
|
|
2548
2572
|
if (!i) {
|
|
2549
2573
|
i = !0;
|
|
2550
2574
|
try {
|
|
2551
2575
|
for (; s < t && n.length > 0; ) {
|
|
2552
|
-
const
|
|
2553
|
-
if (r.has(
|
|
2554
|
-
r.add(
|
|
2555
|
-
const
|
|
2576
|
+
const m = n.shift(), c = o(m.displayAtMs, m.drawKey);
|
|
2577
|
+
if (r.has(c)) continue;
|
|
2578
|
+
r.add(c), s += 1;
|
|
2579
|
+
const u = a;
|
|
2556
2580
|
try {
|
|
2557
|
-
await e(
|
|
2581
|
+
await e(m);
|
|
2558
2582
|
} finally {
|
|
2559
|
-
if (r.delete(
|
|
2583
|
+
if (r.delete(c), s -= 1, u !== a) return;
|
|
2560
2584
|
}
|
|
2561
2585
|
}
|
|
2562
2586
|
} finally {
|
|
2563
|
-
i = !1, n.length > 0 && s < t &&
|
|
2587
|
+
i = !1, n.length > 0 && s < t && d();
|
|
2564
2588
|
}
|
|
2565
2589
|
}
|
|
2566
2590
|
};
|
|
2567
2591
|
return {
|
|
2568
|
-
enqueue(
|
|
2569
|
-
const
|
|
2570
|
-
r.has(
|
|
2571
|
-
},
|
|
2572
|
-
isQueuedOrInflight(
|
|
2573
|
-
const
|
|
2574
|
-
return r.has(
|
|
2575
|
-
(
|
|
2592
|
+
enqueue(m) {
|
|
2593
|
+
const c = o(m.displayAtMs, m.drawKey);
|
|
2594
|
+
r.has(c) || n.some((u) => o(u.displayAtMs, u.drawKey) === c) || (n.push(m), d());
|
|
2595
|
+
},
|
|
2596
|
+
isQueuedOrInflight(m, c) {
|
|
2597
|
+
const u = o(m, c);
|
|
2598
|
+
return r.has(u) ? !0 : n.some(
|
|
2599
|
+
(f) => o(f.displayAtMs, f.drawKey) === u
|
|
2576
2600
|
);
|
|
2577
2601
|
},
|
|
2578
2602
|
reset() {
|
|
@@ -2583,7 +2607,7 @@ function Fi(e, t = 2) {
|
|
|
2583
2607
|
}
|
|
2584
2608
|
};
|
|
2585
2609
|
}
|
|
2586
|
-
function
|
|
2610
|
+
function Oi() {
|
|
2587
2611
|
const e = /* @__PURE__ */ new Map(), t = (n) => {
|
|
2588
2612
|
n.bitmap.close();
|
|
2589
2613
|
};
|
|
@@ -2618,129 +2642,129 @@ function Li() {
|
|
|
2618
2642
|
}
|
|
2619
2643
|
};
|
|
2620
2644
|
}
|
|
2621
|
-
function
|
|
2645
|
+
function Li(e, t, n, r, s, i) {
|
|
2622
2646
|
const a = dr(
|
|
2623
2647
|
t,
|
|
2624
2648
|
n,
|
|
2625
2649
|
r,
|
|
2626
2650
|
s,
|
|
2627
|
-
|
|
2651
|
+
lt,
|
|
2628
2652
|
i
|
|
2629
2653
|
);
|
|
2630
2654
|
if (a.length === 0) return { ready: 0, total: 0 };
|
|
2631
2655
|
let o = 0;
|
|
2632
|
-
for (const
|
|
2633
|
-
e.has(
|
|
2656
|
+
for (const d of a)
|
|
2657
|
+
e.has(d.displayAtMs, d.mouthKey) && (o += 1);
|
|
2634
2658
|
return { ready: o, total: a.length };
|
|
2635
2659
|
}
|
|
2636
2660
|
function Ni(e) {
|
|
2637
|
-
const t =
|
|
2661
|
+
const t = Oi(), n = ln(), r = /* @__PURE__ */ new Set();
|
|
2638
2662
|
let s = "", i = null;
|
|
2639
2663
|
const a = Fi(
|
|
2640
|
-
async (
|
|
2664
|
+
async (u) => {
|
|
2641
2665
|
try {
|
|
2642
2666
|
if (!e.supportsBufferedPlayback) return;
|
|
2643
|
-
const
|
|
2644
|
-
|
|
2645
|
-
|
|
2667
|
+
const f = await e.compositePrefetchFrame(
|
|
2668
|
+
u.diffs,
|
|
2669
|
+
u.mouthKey
|
|
2646
2670
|
);
|
|
2647
|
-
if (!
|
|
2671
|
+
if (!f) return;
|
|
2648
2672
|
t.markRendered(
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
),
|
|
2673
|
+
u.displayAtMs,
|
|
2674
|
+
u.mouthKey,
|
|
2675
|
+
u.label,
|
|
2676
|
+
u.mouthPath,
|
|
2677
|
+
f
|
|
2678
|
+
), We()?.onBufferPrefetched();
|
|
2655
2679
|
} finally {
|
|
2656
|
-
r.delete(
|
|
2680
|
+
r.delete(u.mouthKey);
|
|
2657
2681
|
}
|
|
2658
2682
|
},
|
|
2659
|
-
|
|
2660
|
-
), o = (
|
|
2661
|
-
for (const
|
|
2662
|
-
t.has(
|
|
2663
|
-
...
|
|
2683
|
+
Br
|
|
2684
|
+
), o = (u) => {
|
|
2685
|
+
for (const f of u)
|
|
2686
|
+
t.has(f.displayAtMs, f.mouthKey) || r.has(f.mouthKey) || a.isQueuedOrInflight(0, f.mouthKey) || (r.add(f.mouthKey), a.enqueue({
|
|
2687
|
+
...f,
|
|
2664
2688
|
displayAtMs: 0,
|
|
2665
|
-
drawKey:
|
|
2689
|
+
drawKey: f.mouthKey,
|
|
2666
2690
|
diffs: {
|
|
2667
|
-
mouthPath:
|
|
2691
|
+
mouthPath: f.mouthPath,
|
|
2668
2692
|
expressionPath: null
|
|
2669
2693
|
}
|
|
2670
2694
|
}));
|
|
2671
|
-
},
|
|
2695
|
+
}, d = (u, f, w, b = Ft) => {
|
|
2672
2696
|
if (!e.supportsBufferedPlayback) return;
|
|
2673
|
-
const
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2697
|
+
const p = Math.max(0, f - lt * 4), P = dr(
|
|
2698
|
+
u,
|
|
2699
|
+
p,
|
|
2700
|
+
f + b,
|
|
2677
2701
|
w,
|
|
2678
|
-
|
|
2702
|
+
lt,
|
|
2679
2703
|
n
|
|
2680
2704
|
);
|
|
2681
|
-
o(
|
|
2682
|
-
},
|
|
2683
|
-
s =
|
|
2684
|
-
},
|
|
2705
|
+
o(P);
|
|
2706
|
+
}, m = (u, f) => {
|
|
2707
|
+
s = u, i = f;
|
|
2708
|
+
}, c = (u, f) => !(s !== u || i !== f);
|
|
2685
2709
|
return {
|
|
2686
2710
|
reset() {
|
|
2687
|
-
t.reset(), a.reset(), r.clear(),
|
|
2711
|
+
t.reset(), a.reset(), r.clear(), ve(n), s = "", i = null, We()?.onBufferReset();
|
|
2688
2712
|
},
|
|
2689
|
-
markExternallyDisplayed(
|
|
2690
|
-
|
|
2713
|
+
markExternallyDisplayed(u, f) {
|
|
2714
|
+
m(u.split("|")[0] ?? u, f);
|
|
2691
2715
|
},
|
|
2692
|
-
warmupTick(
|
|
2693
|
-
e.supportsBufferedPlayback &&
|
|
2694
|
-
|
|
2716
|
+
warmupTick(u) {
|
|
2717
|
+
e.supportsBufferedPlayback && d(
|
|
2718
|
+
u.queue,
|
|
2695
2719
|
0,
|
|
2696
|
-
|
|
2697
|
-
Math.max(Sn,
|
|
2720
|
+
u.availablePaths,
|
|
2721
|
+
Math.max(Sn, Ft)
|
|
2698
2722
|
);
|
|
2699
2723
|
},
|
|
2700
|
-
isWarmupReady(
|
|
2724
|
+
isWarmupReady(u, f = Sn) {
|
|
2701
2725
|
if (!e.supportsBufferedPlayback) return !0;
|
|
2702
|
-
const { ready: w, total: b } =
|
|
2726
|
+
const { ready: w, total: b } = Li(
|
|
2703
2727
|
t,
|
|
2704
|
-
|
|
2728
|
+
u.queue,
|
|
2705
2729
|
0,
|
|
2706
|
-
|
|
2707
|
-
|
|
2730
|
+
f,
|
|
2731
|
+
u.availablePaths,
|
|
2708
2732
|
n
|
|
2709
2733
|
);
|
|
2710
|
-
return b === 0 ? !1 : w / b >=
|
|
2734
|
+
return b === 0 ? !1 : w / b >= Cr;
|
|
2711
2735
|
},
|
|
2712
2736
|
getBufferedFrameCount: () => t.size(),
|
|
2713
|
-
tick(
|
|
2714
|
-
const
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
), t.pruneBefore(
|
|
2720
|
-
const w =
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2737
|
+
tick(u) {
|
|
2738
|
+
const f = We();
|
|
2739
|
+
f?.onBufferTick(), d(
|
|
2740
|
+
u.queue,
|
|
2741
|
+
u.elapsedMs,
|
|
2742
|
+
u.availablePaths
|
|
2743
|
+
), t.pruneBefore(u.elapsedMs - Ft);
|
|
2744
|
+
const w = fn(
|
|
2745
|
+
u.queue,
|
|
2746
|
+
u.elapsedMs,
|
|
2747
|
+
u.availablePaths,
|
|
2724
2748
|
n
|
|
2725
|
-
), b =
|
|
2726
|
-
{ mouthPath: w.diffPath, expressionPath:
|
|
2727
|
-
|
|
2728
|
-
),
|
|
2729
|
-
if (
|
|
2730
|
-
return
|
|
2749
|
+
), b = It(w.diffPath), p = dn(
|
|
2750
|
+
{ mouthPath: w.diffPath, expressionPath: u.expressionPath },
|
|
2751
|
+
u.expressionDrawKey
|
|
2752
|
+
), P = () => (m(b, u.expressionPath), f?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
|
|
2753
|
+
if (c(b, u.expressionPath) || u.playbackState.lastDrawnKey === p)
|
|
2754
|
+
return P();
|
|
2731
2755
|
const E = t.findForMouthKey(
|
|
2732
2756
|
b,
|
|
2733
|
-
|
|
2734
|
-
|
|
2757
|
+
u.elapsedMs,
|
|
2758
|
+
lt
|
|
2735
2759
|
);
|
|
2736
|
-
return E &&
|
|
2760
|
+
return E && u.expressionPath != null ? (f?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : E ? (e.blitBitmap(u.canvas, E.bitmap), m(E.mouthKey, u.expressionPath), u.playbackState.lastDrawnKey = p, u.onStatus({
|
|
2737
2761
|
diffPath: E.mouthPath,
|
|
2738
2762
|
label: E.label
|
|
2739
|
-
}),
|
|
2763
|
+
}), u.onDisplayed(p, E.mouthPath, E.label), f?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !1 }) : (f?.onBufferUnderrun(), { usedBuffer: !1, underrun: !0, held: !1 });
|
|
2740
2764
|
}
|
|
2741
2765
|
};
|
|
2742
2766
|
}
|
|
2743
|
-
const Nn = -1,
|
|
2767
|
+
const Nn = -1, vt = 1e5, Un = /* @__PURE__ */ new Map();
|
|
2744
2768
|
async function Ui(e) {
|
|
2745
2769
|
let t = Un.get(e);
|
|
2746
2770
|
if (!t) {
|
|
@@ -2757,18 +2781,18 @@ async function Ui(e) {
|
|
|
2757
2781
|
function Vi() {
|
|
2758
2782
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
2759
2783
|
}
|
|
2760
|
-
function
|
|
2784
|
+
function jt(e, t) {
|
|
2761
2785
|
(e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
|
|
2762
2786
|
const n = e.getContext("2d");
|
|
2763
2787
|
n && n.drawImage(t, 0, 0);
|
|
2764
2788
|
}
|
|
2765
2789
|
function Vn(e, t) {
|
|
2766
2790
|
let n = 0, r = null;
|
|
2767
|
-
const s = mr(async (i, a) => (await
|
|
2791
|
+
const s = mr(async (i, a) => (await Kt(), await Gt(e, i), s.isLatestSeq(a)));
|
|
2768
2792
|
return {
|
|
2769
2793
|
usesWorker: !1,
|
|
2770
2794
|
async loadAssets(i) {
|
|
2771
|
-
const a = await
|
|
2795
|
+
const a = await Kt(i);
|
|
2772
2796
|
return r = a.visemePaths ? new Set(a.visemePaths) : null, a;
|
|
2773
2797
|
},
|
|
2774
2798
|
getVisemeAtlasPaths() {
|
|
@@ -2777,8 +2801,8 @@ function Vn(e, t) {
|
|
|
2777
2801
|
async renderSilOnly() {
|
|
2778
2802
|
n += 1, s.reset(), await ki(e);
|
|
2779
2803
|
},
|
|
2780
|
-
drawLiveFrame(i, a, o,
|
|
2781
|
-
s.enqueue(a, o,
|
|
2804
|
+
drawLiveFrame(i, a, o, d) {
|
|
2805
|
+
s.enqueue(a, o, d);
|
|
2782
2806
|
},
|
|
2783
2807
|
async compositePrefetchFrame(i, a) {
|
|
2784
2808
|
try {
|
|
@@ -2788,14 +2812,14 @@ function Vn(e, t) {
|
|
|
2788
2812
|
}
|
|
2789
2813
|
},
|
|
2790
2814
|
blitBitmap(i, a) {
|
|
2791
|
-
|
|
2815
|
+
jt(i, a);
|
|
2792
2816
|
},
|
|
2793
2817
|
supportsBufferedPlayback: !0,
|
|
2794
2818
|
async renderViseme(i, a) {
|
|
2795
2819
|
n += 1;
|
|
2796
2820
|
const o = n;
|
|
2797
|
-
t.onStatus?.(a), await
|
|
2798
|
-
mouthPath:
|
|
2821
|
+
t.onStatus?.(a), await Gt(i, {
|
|
2822
|
+
mouthPath: Et(a),
|
|
2799
2823
|
expressionPath: null
|
|
2800
2824
|
});
|
|
2801
2825
|
},
|
|
@@ -2805,106 +2829,106 @@ function Vn(e, t) {
|
|
|
2805
2829
|
};
|
|
2806
2830
|
}
|
|
2807
2831
|
function Wi(e, t, n) {
|
|
2808
|
-
let r = null, s = 1, i = 0, a = !1, o = !1,
|
|
2809
|
-
const
|
|
2810
|
-
let
|
|
2811
|
-
const
|
|
2812
|
-
drawKey:
|
|
2813
|
-
onDisplayed:
|
|
2814
|
-
}), await
|
|
2832
|
+
let r = null, s = 1, i = 0, a = !1, o = !1, d = null;
|
|
2833
|
+
const m = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
|
|
2834
|
+
let u = vt;
|
|
2835
|
+
const f = mr(async (_, h, A) => (m.set(h, {
|
|
2836
|
+
drawKey: A.drawKey,
|
|
2837
|
+
onDisplayed: A.onDisplayed
|
|
2838
|
+
}), await P(
|
|
2815
2839
|
{
|
|
2816
2840
|
type: "drawFrame",
|
|
2817
2841
|
diffPath: _.mouthPath,
|
|
2818
2842
|
expressionDiffPath: _.expressionPath,
|
|
2819
|
-
liveSeq:
|
|
2843
|
+
liveSeq: h
|
|
2820
2844
|
},
|
|
2821
2845
|
void 0,
|
|
2822
2846
|
!0
|
|
2823
2847
|
), !1)), w = (_) => {
|
|
2824
2848
|
if (_ === Nn) {
|
|
2825
|
-
let
|
|
2826
|
-
for (const [
|
|
2827
|
-
|
|
2828
|
-
|
|
2849
|
+
let O = -1, B;
|
|
2850
|
+
for (const [G, C] of m)
|
|
2851
|
+
G >= O && (O = G, B = C);
|
|
2852
|
+
O >= 0 && m.delete(O), B?.onDisplayed?.(B.drawKey);
|
|
2829
2853
|
return;
|
|
2830
2854
|
}
|
|
2831
|
-
const
|
|
2832
|
-
|
|
2833
|
-
}, b = /* @__PURE__ */ new Map(),
|
|
2855
|
+
const h = -_, A = m.get(h);
|
|
2856
|
+
m.delete(h), A?.onDisplayed?.(A.drawKey);
|
|
2857
|
+
}, b = /* @__PURE__ */ new Map(), p = (_, h) => {
|
|
2834
2858
|
o || !r || r.postMessage(_, []);
|
|
2835
|
-
},
|
|
2859
|
+
}, P = (_, h, A = !1) => {
|
|
2836
2860
|
if (o) return Promise.resolve();
|
|
2837
|
-
const
|
|
2838
|
-
return new Promise((
|
|
2839
|
-
b.set(
|
|
2840
|
-
resolve: (
|
|
2841
|
-
reject:
|
|
2861
|
+
const O = s++;
|
|
2862
|
+
return new Promise((B, G) => {
|
|
2863
|
+
b.set(O, {
|
|
2864
|
+
resolve: (C) => B(C),
|
|
2865
|
+
reject: G,
|
|
2842
2866
|
generation: typeof _.generation == "number" ? _.generation : void 0,
|
|
2843
|
-
expectRenderDone:
|
|
2844
|
-
}),
|
|
2867
|
+
expectRenderDone: A
|
|
2868
|
+
}), p({ ..._, requestId: O });
|
|
2845
2869
|
});
|
|
2846
2870
|
}, E = (async () => {
|
|
2847
2871
|
r = await Ui(n), r.onmessage = (_) => {
|
|
2848
2872
|
if (o) return;
|
|
2849
|
-
const
|
|
2850
|
-
if (
|
|
2851
|
-
t.onStatus?.(
|
|
2873
|
+
const h = _.data;
|
|
2874
|
+
if (h.type === "status") {
|
|
2875
|
+
t.onStatus?.(h.label);
|
|
2852
2876
|
return;
|
|
2853
2877
|
}
|
|
2854
|
-
if (
|
|
2855
|
-
if (
|
|
2856
|
-
const
|
|
2857
|
-
|
|
2878
|
+
if (h.type === "frame") {
|
|
2879
|
+
if (h.generation <= -vt) {
|
|
2880
|
+
const B = -h.generation, G = c.get(B);
|
|
2881
|
+
c.delete(B), G?.resolve(h.bitmap);
|
|
2858
2882
|
return;
|
|
2859
2883
|
}
|
|
2860
|
-
const
|
|
2861
|
-
if (!
|
|
2862
|
-
|
|
2884
|
+
const O = h.generation < 0;
|
|
2885
|
+
if (!O && h.generation !== i) {
|
|
2886
|
+
h.bitmap.close();
|
|
2863
2887
|
return;
|
|
2864
2888
|
}
|
|
2865
|
-
if (
|
|
2866
|
-
const
|
|
2867
|
-
if (!
|
|
2868
|
-
|
|
2889
|
+
if (O && !(h.generation === Nn)) {
|
|
2890
|
+
const G = -h.generation;
|
|
2891
|
+
if (!f.isLatestSeq(G)) {
|
|
2892
|
+
We()?.onWorkerStale(), h.bitmap.close();
|
|
2869
2893
|
return;
|
|
2870
2894
|
}
|
|
2871
2895
|
}
|
|
2872
|
-
if (
|
|
2873
|
-
|
|
2896
|
+
if (O && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
2897
|
+
We()?.onWorkerStale(), h.bitmap.close();
|
|
2874
2898
|
return;
|
|
2875
2899
|
}
|
|
2876
|
-
|
|
2900
|
+
jt(e, h.bitmap), h.bitmap.close(), O && w(h.generation);
|
|
2877
2901
|
return;
|
|
2878
2902
|
}
|
|
2879
|
-
const
|
|
2880
|
-
if (
|
|
2881
|
-
switch (
|
|
2903
|
+
const A = b.get(h.requestId);
|
|
2904
|
+
if (A)
|
|
2905
|
+
switch (h.type) {
|
|
2882
2906
|
case "ready":
|
|
2883
|
-
b.delete(
|
|
2907
|
+
b.delete(h.requestId), A.resolve();
|
|
2884
2908
|
break;
|
|
2885
2909
|
case "loadAssetsDone":
|
|
2886
|
-
b.delete(
|
|
2910
|
+
b.delete(h.requestId), d = h.visemePaths?.length ? new Set(h.visemePaths) : null, A.resolve({ width: h.width, height: h.height, visemePaths: h.visemePaths });
|
|
2887
2911
|
break;
|
|
2888
2912
|
case "renderDone":
|
|
2889
|
-
if (
|
|
2913
|
+
if (A.expectRenderDone && A.generation != null && h.generation !== A.generation)
|
|
2890
2914
|
return;
|
|
2891
|
-
b.delete(
|
|
2915
|
+
b.delete(h.requestId), A.resolve();
|
|
2892
2916
|
break;
|
|
2893
2917
|
case "renderAborted":
|
|
2894
|
-
b.delete(
|
|
2918
|
+
b.delete(h.requestId), A.resolve();
|
|
2895
2919
|
break;
|
|
2896
2920
|
case "error":
|
|
2897
|
-
b.delete(
|
|
2921
|
+
b.delete(h.requestId), t.onError?.(h.message), A.reject(new Error(h.message));
|
|
2898
2922
|
break;
|
|
2899
2923
|
}
|
|
2900
2924
|
}, r.onerror = (_) => {
|
|
2901
2925
|
if (o) return;
|
|
2902
|
-
const
|
|
2903
|
-
t.onError?.(
|
|
2904
|
-
for (const [,
|
|
2905
|
-
|
|
2926
|
+
const h = _.message || "Worker error";
|
|
2927
|
+
t.onError?.(h);
|
|
2928
|
+
for (const [, A] of b)
|
|
2929
|
+
A.reject(new Error(h));
|
|
2906
2930
|
b.clear();
|
|
2907
|
-
}, await
|
|
2931
|
+
}, await P({ type: "init" }), a = !0;
|
|
2908
2932
|
})();
|
|
2909
2933
|
return {
|
|
2910
2934
|
usesWorker: !0,
|
|
@@ -2912,80 +2936,80 @@ function Wi(e, t, n) {
|
|
|
2912
2936
|
if (o) return { width: 842, height: 1264 };
|
|
2913
2937
|
if (await E, o) return { width: 842, height: 1264 };
|
|
2914
2938
|
if (!a) throw new Error("Worker init failed");
|
|
2915
|
-
return await
|
|
2939
|
+
return await P({
|
|
2916
2940
|
type: "loadAssets",
|
|
2917
2941
|
keyHex: _,
|
|
2918
|
-
urls: Jr(
|
|
2942
|
+
urls: Jr(He())
|
|
2919
2943
|
}) ?? { width: 842, height: 1264 };
|
|
2920
2944
|
},
|
|
2921
2945
|
getVisemeAtlasPaths() {
|
|
2922
|
-
return
|
|
2946
|
+
return d;
|
|
2923
2947
|
},
|
|
2924
2948
|
async renderSilOnly() {
|
|
2925
2949
|
if (o || (await E, o)) return;
|
|
2926
|
-
i += 1,
|
|
2950
|
+
i += 1, f.reset(), m.clear(), c.forEach(({ resolve: h }) => h(null)), c.clear(), u = vt;
|
|
2927
2951
|
const _ = i;
|
|
2928
|
-
await
|
|
2952
|
+
await P({ type: "cancelLiveDraws" }), await P(
|
|
2929
2953
|
{ type: "renderSil", generation: _ },
|
|
2930
2954
|
void 0,
|
|
2931
2955
|
!0
|
|
2932
2956
|
);
|
|
2933
2957
|
},
|
|
2934
|
-
drawLiveFrame(_,
|
|
2958
|
+
drawLiveFrame(_, h, A, O) {
|
|
2935
2959
|
o || E.then(() => {
|
|
2936
|
-
o ||
|
|
2960
|
+
o || f.enqueue(h, A, O);
|
|
2937
2961
|
});
|
|
2938
2962
|
},
|
|
2939
|
-
compositePrefetchFrame(_,
|
|
2963
|
+
compositePrefetchFrame(_, h) {
|
|
2940
2964
|
return o ? Promise.resolve(null) : E.then(() => {
|
|
2941
2965
|
if (o) return null;
|
|
2942
|
-
const
|
|
2943
|
-
return new Promise((
|
|
2944
|
-
|
|
2966
|
+
const A = ++u;
|
|
2967
|
+
return new Promise((O) => {
|
|
2968
|
+
c.set(A, { resolve: O }), P(
|
|
2945
2969
|
{
|
|
2946
2970
|
type: "drawFrame",
|
|
2947
2971
|
diffPath: _.mouthPath,
|
|
2948
2972
|
expressionDiffPath: _.expressionPath,
|
|
2949
|
-
liveSeq:
|
|
2973
|
+
liveSeq: A
|
|
2950
2974
|
},
|
|
2951
2975
|
void 0,
|
|
2952
2976
|
!0
|
|
2953
2977
|
).catch(() => {
|
|
2954
|
-
|
|
2978
|
+
c.delete(A), O(null);
|
|
2955
2979
|
});
|
|
2956
2980
|
});
|
|
2957
2981
|
});
|
|
2958
2982
|
},
|
|
2959
|
-
blitBitmap(_,
|
|
2960
|
-
|
|
2983
|
+
blitBitmap(_, h) {
|
|
2984
|
+
jt(_, h);
|
|
2961
2985
|
},
|
|
2962
2986
|
supportsBufferedPlayback: !0,
|
|
2963
|
-
async renderViseme(_,
|
|
2987
|
+
async renderViseme(_, h, A = {}) {
|
|
2964
2988
|
if (o || (await E, o)) return;
|
|
2965
|
-
i += 1,
|
|
2966
|
-
const
|
|
2989
|
+
i += 1, f.reset(), m.clear();
|
|
2990
|
+
const O = i;
|
|
2967
2991
|
try {
|
|
2968
|
-
await
|
|
2992
|
+
await P({ type: "cancelLiveDraws" }), await P(
|
|
2969
2993
|
{
|
|
2970
2994
|
type: "renderViseme",
|
|
2971
|
-
generation:
|
|
2972
|
-
to:
|
|
2973
|
-
from:
|
|
2974
|
-
transitionDurationMs:
|
|
2975
|
-
gapMs:
|
|
2976
|
-
threshold:
|
|
2995
|
+
generation: O,
|
|
2996
|
+
to: h,
|
|
2997
|
+
from: A.from,
|
|
2998
|
+
transitionDurationMs: A.transitionDurationMs,
|
|
2999
|
+
gapMs: A.gapMs,
|
|
3000
|
+
threshold: A.threshold
|
|
2977
3001
|
},
|
|
2978
3002
|
void 0,
|
|
2979
3003
|
!0
|
|
2980
3004
|
);
|
|
2981
|
-
} catch (
|
|
2982
|
-
if (
|
|
2983
|
-
throw
|
|
3005
|
+
} catch (B) {
|
|
3006
|
+
if (B?.name === "AbortError") return;
|
|
3007
|
+
throw B;
|
|
2984
3008
|
}
|
|
2985
3009
|
},
|
|
2986
3010
|
dispose() {
|
|
2987
3011
|
if (!o) {
|
|
2988
|
-
o = !0, i += 1,
|
|
3012
|
+
o = !0, i += 1, f.reset(), m.clear(), c.forEach(({ resolve: _ }) => _(null)), c.clear(), u = vt;
|
|
2989
3013
|
for (const [, _] of b)
|
|
2990
3014
|
_.resolve();
|
|
2991
3015
|
b.clear(), r?.terminate(), r = null;
|
|
@@ -3008,7 +3032,7 @@ class $i extends Error {
|
|
|
3008
3032
|
super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
3009
3033
|
}
|
|
3010
3034
|
}
|
|
3011
|
-
function
|
|
3035
|
+
function Ut(e, t, n) {
|
|
3012
3036
|
return new Promise((r, s) => {
|
|
3013
3037
|
const i = globalThis.setTimeout(() => {
|
|
3014
3038
|
s(new $i(n, t));
|
|
@@ -3043,10 +3067,10 @@ const qi = {
|
|
|
3043
3067
|
fontSize: "0.875rem",
|
|
3044
3068
|
textAlign: "center"
|
|
3045
3069
|
};
|
|
3046
|
-
function
|
|
3047
|
-
return
|
|
3070
|
+
function ct(e) {
|
|
3071
|
+
return Or(e) ? er : Zn;
|
|
3048
3072
|
}
|
|
3049
|
-
function
|
|
3073
|
+
function Re(e, t) {
|
|
3050
3074
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
3051
3075
|
}
|
|
3052
3076
|
const na = _r(function({
|
|
@@ -3056,556 +3080,560 @@ const na = _r(function({
|
|
|
3056
3080
|
assets: s,
|
|
3057
3081
|
authToken: i,
|
|
3058
3082
|
apiBase: a,
|
|
3059
|
-
ttsEngineId: o =
|
|
3060
|
-
voiceId:
|
|
3061
|
-
speakingRate:
|
|
3062
|
-
className:
|
|
3063
|
-
style:
|
|
3064
|
-
canvasStyle:
|
|
3083
|
+
ttsEngineId: o = ze,
|
|
3084
|
+
voiceId: d,
|
|
3085
|
+
speakingRate: m = Rt,
|
|
3086
|
+
className: c,
|
|
3087
|
+
style: u,
|
|
3088
|
+
canvasStyle: f,
|
|
3065
3089
|
onStatusChange: w,
|
|
3066
3090
|
onDisplayStatus: b,
|
|
3067
|
-
onError:
|
|
3068
|
-
onReady:
|
|
3091
|
+
onError: p,
|
|
3092
|
+
onReady: P,
|
|
3069
3093
|
showErrorOverlay: E = !0,
|
|
3070
3094
|
onUserTranscript: _,
|
|
3071
|
-
onBotOutput:
|
|
3072
|
-
onRealtimeLipsyncDebug:
|
|
3073
|
-
onFrameRenderStats:
|
|
3074
|
-
lipsyncBufferedPlayback:
|
|
3075
|
-
lipsyncPlaybackWarmupMs:
|
|
3076
|
-
},
|
|
3077
|
-
const
|
|
3078
|
-
|
|
3079
|
-
const
|
|
3095
|
+
onBotOutput: h,
|
|
3096
|
+
onRealtimeLipsyncDebug: A,
|
|
3097
|
+
onFrameRenderStats: O,
|
|
3098
|
+
lipsyncBufferedPlayback: B = !0,
|
|
3099
|
+
lipsyncPlaybackWarmupMs: G = 1500
|
|
3100
|
+
}, C) {
|
|
3101
|
+
const k = U(null), I = U(null), M = U(null), Q = U(B);
|
|
3102
|
+
Q.current = B;
|
|
3103
|
+
const x = U(0), z = U(ln()), J = U(li()), ie = U(0), X = U(0), he = U(0), fe = U(null), de = U(null), ne = U(!1), g = U(!1), S = U(!1), L = U("sil"), W = U(0), D = U(!1), R = U(
|
|
3080
3104
|
null
|
|
3081
|
-
),
|
|
3082
|
-
|
|
3083
|
-
const
|
|
3084
|
-
return Fn(
|
|
3105
|
+
), T = U(!1), [Z, ae] = ot("idle"), [te, ue] = ot(null), [me, ge] = ot(!1), [Ae, Fe] = ot(!1), [De, dt] = ot({ width: 842, height: 1264 }), l = U(i ?? null), v = a?.trim() || ft, N = U(null), q = U(null), re = U(!1), xe = U({ width: 842, height: 1264 }), oe = U(null), Ce = U("sil"), _e = U(void 0), et = U(/* @__PURE__ */ new Map()), tt = U(P), se = U(b), nt = U(p), mt = U(_), ht = U(h), be = U(A), rt = U(O), Ee = U(bi());
|
|
3106
|
+
tt.current = P, se.current = b, nt.current = p, mt.current = _, ht.current = h, be.current = A, rt.current = O, Le(() => {
|
|
3107
|
+
const y = Ee.current;
|
|
3108
|
+
return Fn(y), () => Fn(null);
|
|
3085
3109
|
}, []);
|
|
3086
|
-
const
|
|
3087
|
-
(
|
|
3088
|
-
const
|
|
3089
|
-
return { ttsEngineId:
|
|
3090
|
-
},
|
|
3091
|
-
[o,
|
|
3092
|
-
),
|
|
3093
|
-
|
|
3094
|
-
}, []),
|
|
3095
|
-
(
|
|
3096
|
-
|
|
3110
|
+
const ce = ke(
|
|
3111
|
+
(y) => {
|
|
3112
|
+
const F = y?.ttsEngineId ?? o ?? q.current?.ttsEngineId ?? ze, V = y?.voiceId ?? d ?? q.current?.voiceId ?? ct(F);
|
|
3113
|
+
return { ttsEngineId: F, voiceId: V };
|
|
3114
|
+
},
|
|
3115
|
+
[o, d]
|
|
3116
|
+
), le = ke((y) => {
|
|
3117
|
+
ue(y), nt.current?.(y);
|
|
3118
|
+
}, []), pe = ke(
|
|
3119
|
+
(y) => {
|
|
3120
|
+
ae(y), w?.(y);
|
|
3097
3121
|
},
|
|
3098
3122
|
[w]
|
|
3099
|
-
),
|
|
3100
|
-
An(
|
|
3101
|
-
onLipsyncDebug: (
|
|
3123
|
+
), j = U(
|
|
3124
|
+
An(pe, v, {
|
|
3125
|
+
onLipsyncDebug: (y) => be.current?.(y)
|
|
3102
3126
|
})
|
|
3103
|
-
),
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3127
|
+
), Y = U(null);
|
|
3128
|
+
Le(() => (j.current = An(
|
|
3129
|
+
pe,
|
|
3130
|
+
v,
|
|
3107
3131
|
{
|
|
3108
|
-
onLipsyncDebug: (
|
|
3132
|
+
onLipsyncDebug: (y) => be.current?.(y)
|
|
3109
3133
|
}
|
|
3110
|
-
), i &&
|
|
3111
|
-
|
|
3112
|
-
const
|
|
3113
|
-
|
|
3114
|
-
}), [
|
|
3115
|
-
const
|
|
3116
|
-
|
|
3134
|
+
), i && j.current.setDeveloperToken(i), j.current.setTtsEngineId(o), () => {
|
|
3135
|
+
j.current.stop();
|
|
3136
|
+
const y = Y.current;
|
|
3137
|
+
y && (y.disconnect(), Y.current = null);
|
|
3138
|
+
}), [pe, i, o, v]);
|
|
3139
|
+
const pt = ke(() => (Y.current || (Y.current = Bs(
|
|
3140
|
+
pe,
|
|
3117
3141
|
{
|
|
3118
|
-
speakingRate:
|
|
3119
|
-
onUserTranscript: (
|
|
3120
|
-
onBotOutput: (
|
|
3121
|
-
onLipsyncDebug: (
|
|
3142
|
+
speakingRate: m,
|
|
3143
|
+
onUserTranscript: (y, F) => mt.current?.(y, F),
|
|
3144
|
+
onBotOutput: (y) => ht.current?.(y),
|
|
3145
|
+
onLipsyncDebug: (y) => be.current?.(y)
|
|
3122
3146
|
}
|
|
3123
|
-
),
|
|
3124
|
-
|
|
3125
|
-
}, []),
|
|
3126
|
-
|
|
3127
|
-
}, []), mn =
|
|
3128
|
-
!
|
|
3129
|
-
if (
|
|
3130
|
-
|
|
3131
|
-
|
|
3147
|
+
), Y.current.setTtsEngineId(o)), Y.current), [pe, m, o]), we = ke(() => {
|
|
3148
|
+
fe.current != null && (clearTimeout(fe.current), fe.current = null);
|
|
3149
|
+
}, []), Ie = ke(() => {
|
|
3150
|
+
de.current != null && (clearTimeout(de.current), de.current = null), S.current = !1;
|
|
3151
|
+
}, []), mn = ke(() => {
|
|
3152
|
+
!T.current || !R.current || (Ie(), S.current = !0, de.current = setTimeout(() => {
|
|
3153
|
+
if (de.current = null, Re(
|
|
3154
|
+
j.current,
|
|
3155
|
+
Y.current
|
|
3132
3156
|
).isSpeaking()) {
|
|
3133
|
-
|
|
3157
|
+
S.current = !1;
|
|
3134
3158
|
return;
|
|
3135
3159
|
}
|
|
3136
|
-
if (
|
|
3137
|
-
|
|
3160
|
+
if (ne.current) {
|
|
3161
|
+
S.current = !1;
|
|
3138
3162
|
return;
|
|
3139
3163
|
}
|
|
3140
|
-
const
|
|
3141
|
-
if (!
|
|
3142
|
-
|
|
3164
|
+
const y = R.current;
|
|
3165
|
+
if (!y) {
|
|
3166
|
+
S.current = !1;
|
|
3143
3167
|
return;
|
|
3144
3168
|
}
|
|
3145
|
-
|
|
3146
|
-
const
|
|
3147
|
-
let
|
|
3148
|
-
const
|
|
3149
|
-
|
|
3150
|
-
},
|
|
3151
|
-
|
|
3169
|
+
y.restart(), y.setActive(!0);
|
|
3170
|
+
const F = y.getVideo();
|
|
3171
|
+
let V = !1;
|
|
3172
|
+
const K = () => {
|
|
3173
|
+
V || (V = !0, F.removeEventListener("playing", H), S.current = !1);
|
|
3174
|
+
}, H = () => {
|
|
3175
|
+
K();
|
|
3152
3176
|
};
|
|
3153
|
-
if (
|
|
3154
|
-
|
|
3177
|
+
if (F.addEventListener("playing", H, { once: !0 }), F.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !F.paused) {
|
|
3178
|
+
K();
|
|
3155
3179
|
return;
|
|
3156
3180
|
}
|
|
3157
|
-
setTimeout(
|
|
3181
|
+
setTimeout(K, 300);
|
|
3158
3182
|
}, Ei));
|
|
3159
|
-
}, [
|
|
3160
|
-
if (
|
|
3161
|
-
|
|
3183
|
+
}, [Ie]), $e = ke(() => {
|
|
3184
|
+
if (we(), se.current?.("sil"), ne.current = !1, !T.current || !R.current) {
|
|
3185
|
+
S.current = !1;
|
|
3162
3186
|
return;
|
|
3163
3187
|
}
|
|
3164
3188
|
mn();
|
|
3165
|
-
}, [
|
|
3166
|
-
async (
|
|
3167
|
-
const
|
|
3168
|
-
|
|
3189
|
+
}, [we, mn]), xt = ke(
|
|
3190
|
+
async (y) => {
|
|
3191
|
+
const F = X.current, V = I.current, K = k.current, H = () => {
|
|
3192
|
+
y?.fallbackOnly || (ne.current = !1);
|
|
3169
3193
|
};
|
|
3170
|
-
if (!
|
|
3171
|
-
|
|
3194
|
+
if (!V || !K || !re.current) {
|
|
3195
|
+
H();
|
|
3172
3196
|
return;
|
|
3173
3197
|
}
|
|
3174
|
-
if (
|
|
3175
|
-
|
|
3176
|
-
|
|
3198
|
+
if (Re(
|
|
3199
|
+
j.current,
|
|
3200
|
+
Y.current
|
|
3177
3201
|
).isSpeaking()) {
|
|
3178
|
-
|
|
3202
|
+
H();
|
|
3179
3203
|
return;
|
|
3180
3204
|
}
|
|
3181
|
-
if (
|
|
3182
|
-
if (!
|
|
3183
|
-
|
|
3184
|
-
|
|
3205
|
+
if (y?.fallbackOnly) {
|
|
3206
|
+
if (!ne.current || (ve(z.current), await V.renderSilOnly(), F !== X.current) || Re(
|
|
3207
|
+
j.current,
|
|
3208
|
+
Y.current
|
|
3185
3209
|
).isSpeaking())
|
|
3186
3210
|
return;
|
|
3187
|
-
|
|
3211
|
+
$e();
|
|
3188
3212
|
return;
|
|
3189
3213
|
}
|
|
3190
|
-
if (Ii(
|
|
3191
|
-
|
|
3214
|
+
if (Ii(z.current)) {
|
|
3215
|
+
ve(z.current), $e();
|
|
3192
3216
|
return;
|
|
3193
3217
|
}
|
|
3194
|
-
if (
|
|
3195
|
-
if (
|
|
3196
|
-
|
|
3197
|
-
|
|
3218
|
+
if (Q.current && V.supportsBufferedPlayback && !y?.fallbackOnly) {
|
|
3219
|
+
if (ve(z.current), M.current?.reset(), await V.renderSilOnly(), F !== X.current || Re(
|
|
3220
|
+
j.current,
|
|
3221
|
+
Y.current
|
|
3198
3222
|
).isSpeaking())
|
|
3199
3223
|
return;
|
|
3200
|
-
|
|
3224
|
+
$e();
|
|
3201
3225
|
return;
|
|
3202
3226
|
}
|
|
3203
|
-
const
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3227
|
+
const Se = Ri(
|
|
3228
|
+
Re(
|
|
3229
|
+
j.current,
|
|
3230
|
+
Y.current
|
|
3207
3231
|
).getVisemeQueue(),
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
),
|
|
3211
|
-
|
|
3212
|
-
|
|
3232
|
+
W.current,
|
|
3233
|
+
L.current
|
|
3234
|
+
), wt = Di(
|
|
3235
|
+
Se,
|
|
3236
|
+
oe.current
|
|
3213
3237
|
);
|
|
3214
|
-
if (
|
|
3215
|
-
if (await
|
|
3216
|
-
|
|
3217
|
-
|
|
3238
|
+
if (ve(z.current), !wt) {
|
|
3239
|
+
if (await V.renderSilOnly(), F !== X.current || Re(
|
|
3240
|
+
j.current,
|
|
3241
|
+
Y.current
|
|
3218
3242
|
).isSpeaking())
|
|
3219
3243
|
return;
|
|
3220
|
-
|
|
3244
|
+
$e();
|
|
3221
3245
|
return;
|
|
3222
3246
|
}
|
|
3223
3247
|
try {
|
|
3224
|
-
await
|
|
3225
|
-
from:
|
|
3248
|
+
await V.renderViseme(K, "sil", {
|
|
3249
|
+
from: Se,
|
|
3226
3250
|
transitionDurationMs: lr
|
|
3227
3251
|
});
|
|
3228
|
-
} catch (
|
|
3229
|
-
if (
|
|
3230
|
-
throw
|
|
3252
|
+
} catch (Be) {
|
|
3253
|
+
if (Be?.name !== "AbortError")
|
|
3254
|
+
throw Be;
|
|
3231
3255
|
}
|
|
3232
|
-
if (
|
|
3233
|
-
|
|
3256
|
+
if (F !== X.current) {
|
|
3257
|
+
H();
|
|
3234
3258
|
return;
|
|
3235
3259
|
}
|
|
3236
|
-
if (
|
|
3237
|
-
|
|
3238
|
-
|
|
3260
|
+
if (Re(
|
|
3261
|
+
j.current,
|
|
3262
|
+
Y.current
|
|
3239
3263
|
).isSpeaking()) {
|
|
3240
|
-
|
|
3264
|
+
H();
|
|
3241
3265
|
return;
|
|
3242
3266
|
}
|
|
3243
|
-
|
|
3244
|
-
},
|
|
3245
|
-
[
|
|
3246
|
-
),
|
|
3247
|
-
if (
|
|
3248
|
-
|
|
3249
|
-
const
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
}),
|
|
3253
|
-
|
|
3267
|
+
$e();
|
|
3268
|
+
},
|
|
3269
|
+
[me, $e]
|
|
3270
|
+
), st = ke(() => {
|
|
3271
|
+
if (g.current || ne.current) return;
|
|
3272
|
+
g.current = !0, ne.current = !0, we();
|
|
3273
|
+
const y = X.current;
|
|
3274
|
+
xt().finally(() => {
|
|
3275
|
+
g.current = !1;
|
|
3276
|
+
}), fe.current = setTimeout(() => {
|
|
3277
|
+
fe.current = null, y === X.current && xt({ fallbackOnly: !0 });
|
|
3254
3278
|
}, xi());
|
|
3255
|
-
}, [
|
|
3256
|
-
const
|
|
3257
|
-
if (
|
|
3258
|
-
return
|
|
3259
|
-
const
|
|
3260
|
-
l.current =
|
|
3261
|
-
const
|
|
3262
|
-
return
|
|
3263
|
-
key:
|
|
3264
|
-
expiresAt:
|
|
3265
|
-
},
|
|
3266
|
-
}, [
|
|
3267
|
-
|
|
3268
|
-
i && (l.current = i,
|
|
3269
|
-
}, [i]),
|
|
3270
|
-
|
|
3271
|
-
}, [o]),
|
|
3272
|
-
const
|
|
3273
|
-
|
|
3274
|
-
}, [
|
|
3275
|
-
const
|
|
3279
|
+
}, [we, xt]), hn = ke(async () => {
|
|
3280
|
+
const y = Math.floor(Date.now() / 1e3);
|
|
3281
|
+
if (N.current && y < N.current.expiresAt - 60)
|
|
3282
|
+
return N.current.key;
|
|
3283
|
+
const F = l.current ?? await Ot();
|
|
3284
|
+
l.current = F, j.current.setDeveloperToken(F);
|
|
3285
|
+
const V = await qr(F, v);
|
|
3286
|
+
return N.current = {
|
|
3287
|
+
key: V.value,
|
|
3288
|
+
expiresAt: V.expiresAt
|
|
3289
|
+
}, V.value;
|
|
3290
|
+
}, [v]);
|
|
3291
|
+
Le(() => {
|
|
3292
|
+
i && (l.current = i, j.current.setDeveloperToken(i));
|
|
3293
|
+
}, [i]), Le(() => {
|
|
3294
|
+
j.current.setTtsEngineId(o), Y.current?.setTtsEngineId(o), q.current && (q.current.ttsEngineId = o);
|
|
3295
|
+
}, [o]), Le(() => {
|
|
3296
|
+
const y = d ?? ct(o);
|
|
3297
|
+
q.current && (q.current.voiceId = y);
|
|
3298
|
+
}, [d, o]);
|
|
3299
|
+
const Oe = _n(
|
|
3276
3300
|
() => zr(n, r),
|
|
3277
3301
|
[n, r]
|
|
3278
|
-
), hr = _n(() => s ? JSON.stringify(s) :
|
|
3279
|
-
return
|
|
3280
|
-
if (!t && !s && !
|
|
3281
|
-
|
|
3302
|
+
), hr = _n(() => s ? JSON.stringify(s) : Oe ? `face:${Oe}` : `id:${t ?? ""}`, [s, Oe, t]);
|
|
3303
|
+
return Le(() => {
|
|
3304
|
+
if (!t && !s && !Oe) {
|
|
3305
|
+
le("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
3282
3306
|
return;
|
|
3283
3307
|
}
|
|
3284
|
-
let
|
|
3285
|
-
|
|
3286
|
-
const
|
|
3287
|
-
if (!
|
|
3288
|
-
let
|
|
3308
|
+
let y = !1;
|
|
3309
|
+
re.current = !1, ge(!1), Fe(!1), ue(null), q.current = null, R.current = null, T.current = !1;
|
|
3310
|
+
const F = k.current;
|
|
3311
|
+
if (!F) return;
|
|
3312
|
+
let V = null;
|
|
3289
3313
|
return (async () => {
|
|
3290
3314
|
try {
|
|
3291
|
-
let
|
|
3315
|
+
let K, H, ye, Se;
|
|
3292
3316
|
if (s)
|
|
3293
|
-
|
|
3294
|
-
else if (
|
|
3295
|
-
|
|
3317
|
+
K = s, H = o, ye = d ?? ct(H);
|
|
3318
|
+
else if (Oe)
|
|
3319
|
+
se.current?.("loadFace"), K = vn(Oe), H = o, ye = d ?? ct(H);
|
|
3296
3320
|
else {
|
|
3297
|
-
|
|
3298
|
-
const
|
|
3321
|
+
se.current?.("getAiTwin");
|
|
3322
|
+
const $ = await Ut(
|
|
3299
3323
|
Nr(t),
|
|
3300
3324
|
3e4,
|
|
3301
3325
|
"getAiTwin"
|
|
3302
3326
|
);
|
|
3303
|
-
if (
|
|
3304
|
-
if (
|
|
3327
|
+
if (y) return;
|
|
3328
|
+
if (!$.faceId?.trim())
|
|
3305
3329
|
throw new Error("getAiTwin returned no faceId");
|
|
3306
|
-
|
|
3330
|
+
H = $.ttsEngineId, ye = d ?? $.voiceId ?? ct(H), Se = $.knowledgeContextId?.trim() || void 0, K = vn($.faceId);
|
|
3307
3331
|
}
|
|
3308
|
-
|
|
3309
|
-
onStatus: (
|
|
3310
|
-
|
|
3332
|
+
q.current = { ttsEngineId: H, voiceId: ye, personaId: Se }, Yr(K), R.current = fi(), V = Hi(F, {
|
|
3333
|
+
onStatus: ($) => {
|
|
3334
|
+
y || se.current?.($);
|
|
3311
3335
|
},
|
|
3312
|
-
onError: (
|
|
3313
|
-
|
|
3336
|
+
onError: ($) => {
|
|
3337
|
+
y || le($);
|
|
3314
3338
|
},
|
|
3315
|
-
shouldAcceptLiveFrame: () =>
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
).isSpeaking() && !
|
|
3319
|
-
}),
|
|
3320
|
-
const
|
|
3321
|
-
|
|
3322
|
-
})(!0),
|
|
3323
|
-
const
|
|
3324
|
-
if (
|
|
3325
|
-
l.current =
|
|
3326
|
-
const
|
|
3327
|
-
if (
|
|
3328
|
-
|
|
3329
|
-
const
|
|
3330
|
-
|
|
3339
|
+
shouldAcceptLiveFrame: () => Re(
|
|
3340
|
+
j.current,
|
|
3341
|
+
Y.current
|
|
3342
|
+
).isSpeaking() && !ne.current
|
|
3343
|
+
}), I.current = V, M.current = Ni(V), (($) => {
|
|
3344
|
+
const ee = () => $ && B && (I.current?.supportsBufferedPlayback ?? !1) && G > 0;
|
|
3345
|
+
j.current.setLipsyncWarmupHold($, ee), Y.current?.setLipsyncWarmupHold($, ee);
|
|
3346
|
+
})(!0), se.current?.("auth");
|
|
3347
|
+
const Be = l.current ?? i ?? await Ut(Ot(), 3e4, "getAuthToken");
|
|
3348
|
+
if (y) return;
|
|
3349
|
+
l.current = Be, j.current.setDeveloperToken(Be), j.current.setTtsEngineId(H);
|
|
3350
|
+
const it = Mt() ? await hn() : void 0;
|
|
3351
|
+
if (y) return;
|
|
3352
|
+
se.current?.("loadAssets");
|
|
3353
|
+
const qe = await Ut(
|
|
3354
|
+
V.loadAssets(it),
|
|
3331
3355
|
18e4,
|
|
3332
3356
|
"load face assets"
|
|
3333
3357
|
);
|
|
3334
|
-
if (!
|
|
3335
|
-
|
|
3336
|
-
|
|
3358
|
+
if (!y && qe.width > 0 && qe.height > 0 && (xe.current = qe, dt(qe)), y) return;
|
|
3359
|
+
oe.current = V.getVisemeAtlasPaths(), re.current = !0, ge(!0), requestAnimationFrame(() => {
|
|
3360
|
+
requestAnimationFrame(() => {
|
|
3361
|
+
tt.current?.();
|
|
3362
|
+
});
|
|
3363
|
+
}), V.renderSilOnly().then(() => {
|
|
3364
|
+
y || se.current?.("sil");
|
|
3337
3365
|
}), (async () => {
|
|
3338
3366
|
try {
|
|
3339
|
-
const
|
|
3340
|
-
if (await
|
|
3341
|
-
|
|
3342
|
-
const
|
|
3343
|
-
await
|
|
3344
|
-
|
|
3345
|
-
|
|
3367
|
+
const $ = await Hs(it);
|
|
3368
|
+
if (await R.current.load($), y) return;
|
|
3369
|
+
T.current = !0, Fe(!0), ve(z.current), R.current.setActive(!0);
|
|
3370
|
+
const ee = R.current.getVideo();
|
|
3371
|
+
await Bn(
|
|
3372
|
+
F,
|
|
3373
|
+
ee,
|
|
3346
3374
|
null,
|
|
3347
3375
|
void 0,
|
|
3348
|
-
|
|
3349
|
-
),
|
|
3350
|
-
} catch (
|
|
3351
|
-
if (
|
|
3352
|
-
|
|
3376
|
+
xe.current
|
|
3377
|
+
), y || se.current?.("idle");
|
|
3378
|
+
} catch ($) {
|
|
3379
|
+
if (y) return;
|
|
3380
|
+
T.current = !1, Fe(!1), console.warn("[AiTwin] Idle video unavailable:", $);
|
|
3353
3381
|
}
|
|
3354
3382
|
})();
|
|
3355
|
-
} catch (
|
|
3356
|
-
if (
|
|
3357
|
-
if (
|
|
3358
|
-
|
|
3383
|
+
} catch (K) {
|
|
3384
|
+
if (y) return;
|
|
3385
|
+
if (K instanceof Vt) {
|
|
3386
|
+
le(K.message);
|
|
3359
3387
|
return;
|
|
3360
3388
|
}
|
|
3361
|
-
|
|
3389
|
+
le(K instanceof Error ? K.message : "Failed to load AI twin");
|
|
3362
3390
|
}
|
|
3363
3391
|
})(), () => {
|
|
3364
|
-
|
|
3392
|
+
y = !0, R.current?.dispose(), V?.dispose(), I.current = null;
|
|
3365
3393
|
};
|
|
3366
|
-
}, [hr, s,
|
|
3367
|
-
const
|
|
3368
|
-
const
|
|
3369
|
-
|
|
3370
|
-
|
|
3394
|
+
}, [hr, s, Oe, t, o, d, i, hn, le]), Le(() => {
|
|
3395
|
+
const y = { current: !1 }, F = () => {
|
|
3396
|
+
const V = k.current, K = I.current, H = Re(
|
|
3397
|
+
j.current,
|
|
3398
|
+
Y.current
|
|
3371
3399
|
);
|
|
3372
|
-
if (!
|
|
3373
|
-
|
|
3400
|
+
if (!V || !K || !re.current) {
|
|
3401
|
+
ie.current = requestAnimationFrame(F);
|
|
3374
3402
|
return;
|
|
3375
3403
|
}
|
|
3376
|
-
const
|
|
3377
|
-
|
|
3378
|
-
const
|
|
3379
|
-
if (
|
|
3380
|
-
|
|
3381
|
-
const
|
|
3382
|
-
|
|
3383
|
-
const
|
|
3384
|
-
queue:
|
|
3404
|
+
const ye = H.isSpeaking(), Se = H.isWarmingUp(), wt = ye && !D.current, Be = D.current && !ye;
|
|
3405
|
+
wt && (we(), Ie(), ne.current = !1, g.current = !1, ve(z.current), (M.current?.getBufferedFrameCount() ?? 0) === 0 && M.current?.reset(), Ee.current.reset(), _e.current = void 0, he.current = 0, L.current = "sil", W.current = 0, R.current?.setActive(!1)), Be && (J.current.reset(), R.current?.setActive(!1), st());
|
|
3406
|
+
const it = Be || ne.current || S.current, qe = B && K.supportsBufferedPlayback;
|
|
3407
|
+
if (Se && qe && M.current) {
|
|
3408
|
+
T.current && R.current?.setActive(!1);
|
|
3409
|
+
const $ = H.getVisemeQueue();
|
|
3410
|
+
$.length > 0 && x.current === 0 && (x.current = performance.now()), J.current.advance(performance.now());
|
|
3411
|
+
const ee = J.current.getExpressionPath(), Te = J.current.getDrawKey(), Me = {
|
|
3412
|
+
queue: $,
|
|
3385
3413
|
elapsedMs: 0,
|
|
3386
|
-
expressionPath:
|
|
3387
|
-
expressionDrawKey:
|
|
3388
|
-
availablePaths:
|
|
3414
|
+
expressionPath: ee,
|
|
3415
|
+
expressionDrawKey: Te,
|
|
3416
|
+
availablePaths: oe.current
|
|
3389
3417
|
};
|
|
3390
|
-
|
|
3391
|
-
const
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
),
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
), (
|
|
3418
|
+
M.current.warmupTick(Me);
|
|
3419
|
+
const Pe = M.current.isWarmupReady(
|
|
3420
|
+
Me,
|
|
3421
|
+
G
|
|
3422
|
+
), Ke = x.current > 0 && performance.now() - x.current > xr;
|
|
3423
|
+
se.current?.(
|
|
3424
|
+
Pe ? "buffer ready" : "buffering lipsync…"
|
|
3425
|
+
), (Pe || Ke) && (x.current = 0, H.releaseWarmupHold()), D.current = H.isSpeaking(), ie.current = requestAnimationFrame(F);
|
|
3398
3426
|
return;
|
|
3399
3427
|
}
|
|
3400
|
-
if (
|
|
3401
|
-
|
|
3402
|
-
const
|
|
3403
|
-
Es(
|
|
3404
|
-
const
|
|
3405
|
-
|
|
3406
|
-
const
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3428
|
+
if (ye) {
|
|
3429
|
+
T.current && R.current?.setActive(!1);
|
|
3430
|
+
const $ = H.getVisemeQueue(), ee = H.getPlaybackElapsedMs();
|
|
3431
|
+
Es($, ee), W.current = ee;
|
|
3432
|
+
const Te = $.length > 0 ? Pt($, ee) : "sil";
|
|
3433
|
+
Te !== "sil" && (L.current = Te);
|
|
3434
|
+
const Me = pi(
|
|
3435
|
+
ee,
|
|
3436
|
+
H.getSentenceEmotions(),
|
|
3437
|
+
H.getWordQueue(),
|
|
3438
|
+
H.getStreamMood()
|
|
3411
3439
|
);
|
|
3412
|
-
|
|
3440
|
+
J.current.setTargetEmotion(Me), J.current.setTargetEyebrow(
|
|
3413
3441
|
ui(
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3442
|
+
ee,
|
|
3443
|
+
H.getWordQueue(),
|
|
3444
|
+
an(Me)
|
|
3417
3445
|
)
|
|
3418
|
-
),
|
|
3419
|
-
const
|
|
3446
|
+
), J.current.advance(performance.now());
|
|
3447
|
+
const Pe = J.current.getExpressionPath(), Ke = J.current.getDrawKey(), pr = (Ge, Ct, at, Bt) => {
|
|
3420
3448
|
const gn = {
|
|
3421
|
-
label:
|
|
3422
|
-
elapsedMs:
|
|
3423
|
-
mouthPath:
|
|
3424
|
-
transitionMeta:
|
|
3449
|
+
label: Ce.current,
|
|
3450
|
+
elapsedMs: ee,
|
|
3451
|
+
mouthPath: Ct.mouthPath,
|
|
3452
|
+
transitionMeta: _e.current
|
|
3425
3453
|
};
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
),
|
|
3430
|
-
const gr =
|
|
3431
|
-
|
|
3454
|
+
et.current.set(at, gn), M.current?.markExternallyDisplayed(
|
|
3455
|
+
at,
|
|
3456
|
+
Pe
|
|
3457
|
+
), K.drawLiveFrame(Ge, Ct, at, (gt) => {
|
|
3458
|
+
const gr = et.current.get(gt) ?? gn;
|
|
3459
|
+
et.current.delete(gt), Ee.current.onDrawDisplayed(
|
|
3432
3460
|
gr,
|
|
3433
|
-
|
|
3434
|
-
),
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
), Bt?.(
|
|
3461
|
+
$
|
|
3462
|
+
), M.current?.markExternallyDisplayed(
|
|
3463
|
+
gt,
|
|
3464
|
+
Pe
|
|
3465
|
+
), Bt?.(gt);
|
|
3438
3466
|
});
|
|
3439
|
-
}, pn = (
|
|
3440
|
-
|
|
3441
|
-
}, wr =
|
|
3467
|
+
}, pn = (Ge) => {
|
|
3468
|
+
Ce.current = Ge.label, _e.current = Ge.transitionMeta, se.current?.(Ge.label);
|
|
3469
|
+
}, wr = B && K.supportsBufferedPlayback;
|
|
3442
3470
|
let wn = !1;
|
|
3443
|
-
wr &&
|
|
3444
|
-
canvas:
|
|
3445
|
-
queue:
|
|
3446
|
-
elapsedMs:
|
|
3447
|
-
expressionPath:
|
|
3448
|
-
expressionDrawKey:
|
|
3449
|
-
playbackState:
|
|
3450
|
-
availablePaths:
|
|
3471
|
+
wr && M.current && (wn = M.current.tick({
|
|
3472
|
+
canvas: V,
|
|
3473
|
+
queue: $,
|
|
3474
|
+
elapsedMs: ee,
|
|
3475
|
+
expressionPath: Pe,
|
|
3476
|
+
expressionDrawKey: Ke,
|
|
3477
|
+
playbackState: z.current,
|
|
3478
|
+
availablePaths: oe.current,
|
|
3451
3479
|
onStatus: pn,
|
|
3452
|
-
onDisplayed: (
|
|
3453
|
-
|
|
3480
|
+
onDisplayed: (Ct, at, Bt) => {
|
|
3481
|
+
Ee.current.onDrawDisplayed(
|
|
3454
3482
|
{
|
|
3455
3483
|
label: Bt,
|
|
3456
|
-
elapsedMs:
|
|
3457
|
-
mouthPath:
|
|
3458
|
-
transitionMeta:
|
|
3484
|
+
elapsedMs: ee,
|
|
3485
|
+
mouthPath: at,
|
|
3486
|
+
transitionMeta: _e.current
|
|
3459
3487
|
},
|
|
3460
|
-
|
|
3488
|
+
$
|
|
3461
3489
|
);
|
|
3462
3490
|
}
|
|
3463
|
-
}).usedBuffer), wn ||
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3491
|
+
}).usedBuffer), wn || Ci(
|
|
3492
|
+
V,
|
|
3493
|
+
$,
|
|
3494
|
+
ee,
|
|
3495
|
+
Pe,
|
|
3496
|
+
Ke,
|
|
3497
|
+
z.current,
|
|
3470
3498
|
pr,
|
|
3471
3499
|
pn,
|
|
3472
|
-
|
|
3473
|
-
),
|
|
3474
|
-
|
|
3500
|
+
oe.current
|
|
3501
|
+
), Ee.current.onRafTickSpeaking(), rt.current?.(
|
|
3502
|
+
Ee.current.snapshot($, ee)
|
|
3475
3503
|
);
|
|
3476
|
-
} else if (!
|
|
3477
|
-
const
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3504
|
+
} else if (!it && T.current && R.current) {
|
|
3505
|
+
const $ = R.current, ee = $.getVideo();
|
|
3506
|
+
ee.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? ($.setActive(!0), y.current || (y.current = !0, Bn(
|
|
3507
|
+
V,
|
|
3508
|
+
ee,
|
|
3481
3509
|
null,
|
|
3482
3510
|
void 0,
|
|
3483
|
-
|
|
3484
|
-
() => !
|
|
3485
|
-
).then(() =>
|
|
3486
|
-
|
|
3487
|
-
}))) :
|
|
3488
|
-
|
|
3511
|
+
xe.current,
|
|
3512
|
+
() => !H.isSpeaking() && !ne.current && !S.current
|
|
3513
|
+
).then(() => se.current?.("idle")).finally(() => {
|
|
3514
|
+
y.current = !1;
|
|
3515
|
+
}))) : Ln(
|
|
3516
|
+
V,
|
|
3489
3517
|
null,
|
|
3490
3518
|
"__sil__",
|
|
3491
|
-
|
|
3492
|
-
(
|
|
3493
|
-
(
|
|
3519
|
+
z.current,
|
|
3520
|
+
(Te, Me, Pe, Ke) => K.drawLiveFrame(Te, Me, Pe, Ke),
|
|
3521
|
+
(Te) => se.current?.(Te)
|
|
3494
3522
|
);
|
|
3495
|
-
} else
|
|
3496
|
-
|
|
3523
|
+
} else it || Ln(
|
|
3524
|
+
V,
|
|
3497
3525
|
null,
|
|
3498
3526
|
"__sil__",
|
|
3499
|
-
|
|
3500
|
-
(
|
|
3501
|
-
(
|
|
3527
|
+
z.current,
|
|
3528
|
+
($, ee, Te, Me) => K.drawLiveFrame($, ee, Te, Me),
|
|
3529
|
+
($) => se.current?.($)
|
|
3502
3530
|
);
|
|
3503
|
-
|
|
3531
|
+
D.current = ye, ie.current = requestAnimationFrame(F);
|
|
3504
3532
|
};
|
|
3505
|
-
return
|
|
3506
|
-
cancelAnimationFrame(
|
|
3533
|
+
return ie.current = requestAnimationFrame(F), () => {
|
|
3534
|
+
cancelAnimationFrame(ie.current), we(), Ie(), j.current.stop(), Y.current?.stop();
|
|
3507
3535
|
};
|
|
3508
3536
|
}, [
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3537
|
+
me,
|
|
3538
|
+
Ae,
|
|
3539
|
+
st,
|
|
3540
|
+
we,
|
|
3541
|
+
Ie
|
|
3514
3542
|
]), Sr(
|
|
3515
|
-
|
|
3543
|
+
C,
|
|
3516
3544
|
() => ({
|
|
3517
|
-
speakText: async (
|
|
3518
|
-
const
|
|
3519
|
-
if (!
|
|
3520
|
-
const
|
|
3521
|
-
if (!
|
|
3545
|
+
speakText: async (y, F) => {
|
|
3546
|
+
const V = y.trim();
|
|
3547
|
+
if (!V) return;
|
|
3548
|
+
const K = I.current;
|
|
3549
|
+
if (!K || !re.current && !me)
|
|
3522
3550
|
throw new Error("AI twin is not ready");
|
|
3523
|
-
const { ttsEngineId:
|
|
3524
|
-
|
|
3551
|
+
const { ttsEngineId: H, voiceId: ye } = ce(F);
|
|
3552
|
+
ue(null), X.current += 1, we(), Ie(), ne.current = !1, g.current = !1, L.current = "sil", W.current = 0, ve(z.current), J.current.reset(), D.current = !1;
|
|
3525
3553
|
try {
|
|
3526
|
-
|
|
3527
|
-
voiceId:
|
|
3528
|
-
speakingRate:
|
|
3529
|
-
ttsEngineId:
|
|
3554
|
+
T.current ? (R.current?.setActive(!1), R.current?.restart(), ve(z.current)) : await K.renderSilOnly(), await j.current.speak(V, {
|
|
3555
|
+
voiceId: ye,
|
|
3556
|
+
speakingRate: F?.speakingRate ?? m,
|
|
3557
|
+
ttsEngineId: H
|
|
3530
3558
|
});
|
|
3531
|
-
} catch (
|
|
3532
|
-
throw
|
|
3559
|
+
} catch (Se) {
|
|
3560
|
+
throw le(Se instanceof Error ? Se.message : "TTS failed"), Se;
|
|
3533
3561
|
}
|
|
3534
3562
|
},
|
|
3535
3563
|
stop: () => {
|
|
3536
|
-
|
|
3564
|
+
X.current += 1, we(), Ie(), ne.current = !1, g.current = !1, j.current.stop(), Y.current?.stop(), ve(z.current), M.current?.reset(), x.current = 0, D.current = !1, st();
|
|
3537
3565
|
},
|
|
3538
|
-
setTtsEngineId: (
|
|
3539
|
-
|
|
3566
|
+
setTtsEngineId: (y) => {
|
|
3567
|
+
j.current.setTtsEngineId(y), Y.current?.setTtsEngineId(y), q.current && (q.current.ttsEngineId = y);
|
|
3540
3568
|
},
|
|
3541
|
-
renderViseme: async (
|
|
3542
|
-
const
|
|
3543
|
-
if (!
|
|
3569
|
+
renderViseme: async (y, F) => {
|
|
3570
|
+
const V = I.current, K = k.current;
|
|
3571
|
+
if (!V || !K || !re.current)
|
|
3544
3572
|
throw new Error("AI twin is not ready");
|
|
3545
|
-
await
|
|
3546
|
-
from:
|
|
3547
|
-
transitionDurationMs:
|
|
3548
|
-
gapMs:
|
|
3549
|
-
onStatus: (
|
|
3573
|
+
await V.renderViseme(K, y, {
|
|
3574
|
+
from: F?.from,
|
|
3575
|
+
transitionDurationMs: F?.transitionDurationMs,
|
|
3576
|
+
gapMs: F?.gapMs,
|
|
3577
|
+
onStatus: (H) => se.current?.(H)
|
|
3550
3578
|
});
|
|
3551
3579
|
},
|
|
3552
|
-
isReady: () =>
|
|
3553
|
-
getStatus: () =>
|
|
3554
|
-
connect: async (
|
|
3555
|
-
|
|
3580
|
+
isReady: () => re.current,
|
|
3581
|
+
getStatus: () => Z,
|
|
3582
|
+
connect: async (y = {}) => {
|
|
3583
|
+
ue(null);
|
|
3556
3584
|
try {
|
|
3557
|
-
let
|
|
3558
|
-
|
|
3559
|
-
const
|
|
3560
|
-
await
|
|
3561
|
-
...
|
|
3562
|
-
apiBase:
|
|
3563
|
-
authToken:
|
|
3564
|
-
voiceId:
|
|
3565
|
-
personaId:
|
|
3566
|
-
speakingRate:
|
|
3585
|
+
let F = y.authToken?.trim();
|
|
3586
|
+
F || (F = l.current ?? i ?? await Ot(), l.current = F);
|
|
3587
|
+
const V = y.voiceId?.trim() ?? d ?? q.current?.voiceId, K = y.personaId?.trim() ?? q.current?.personaId, H = pt();
|
|
3588
|
+
await H.unlockAudio(), await H.connect({
|
|
3589
|
+
...y,
|
|
3590
|
+
apiBase: y.apiBase?.trim() || v,
|
|
3591
|
+
authToken: F,
|
|
3592
|
+
voiceId: V,
|
|
3593
|
+
personaId: K,
|
|
3594
|
+
speakingRate: y.speakingRate ?? m
|
|
3567
3595
|
});
|
|
3568
|
-
} catch (
|
|
3569
|
-
throw
|
|
3570
|
-
|
|
3571
|
-
),
|
|
3596
|
+
} catch (F) {
|
|
3597
|
+
throw le(
|
|
3598
|
+
F instanceof Error ? F.message : "Voice connect failed"
|
|
3599
|
+
), F;
|
|
3572
3600
|
}
|
|
3573
3601
|
},
|
|
3574
3602
|
disconnect: async () => {
|
|
3575
|
-
const
|
|
3576
|
-
|
|
3603
|
+
const y = Y.current;
|
|
3604
|
+
y && (X.current += 1, we(), Ie(), ne.current = !1, g.current = !1, ve(z.current), M.current?.reset(), x.current = 0, D.current = !1, await y.disconnect(), st());
|
|
3577
3605
|
},
|
|
3578
|
-
isConnected: () =>
|
|
3579
|
-
getVoiceStream: () =>
|
|
3606
|
+
isConnected: () => Y.current?.isConnected() ?? !1,
|
|
3607
|
+
getVoiceStream: () => Y.current?.getVoiceStream() ?? j.current?.getVoiceStream() ?? null
|
|
3580
3608
|
}),
|
|
3581
3609
|
[
|
|
3582
|
-
|
|
3583
|
-
|
|
3610
|
+
me,
|
|
3611
|
+
m,
|
|
3584
3612
|
i,
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3613
|
+
d,
|
|
3614
|
+
we,
|
|
3615
|
+
Ie,
|
|
3616
|
+
st,
|
|
3617
|
+
le,
|
|
3589
3618
|
ce,
|
|
3590
|
-
|
|
3591
|
-
|
|
3592
|
-
ee
|
|
3619
|
+
pt,
|
|
3620
|
+
Z
|
|
3593
3621
|
]
|
|
3594
|
-
), /* @__PURE__ */ yr("div", { className:
|
|
3622
|
+
), /* @__PURE__ */ yr("div", { className: c, style: { ...qi, ...u }, children: [
|
|
3595
3623
|
/* @__PURE__ */ yn(
|
|
3596
3624
|
"canvas",
|
|
3597
3625
|
{
|
|
3598
|
-
ref:
|
|
3599
|
-
width:
|
|
3600
|
-
height:
|
|
3601
|
-
style: { ...Ki, ...
|
|
3626
|
+
ref: k,
|
|
3627
|
+
width: De.width,
|
|
3628
|
+
height: De.height,
|
|
3629
|
+
style: { ...Ki, ...f },
|
|
3602
3630
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
3603
3631
|
}
|
|
3604
3632
|
),
|
|
3605
|
-
E &&
|
|
3633
|
+
E && te ? /* @__PURE__ */ yn("div", { style: Gi, children: te }) : null
|
|
3606
3634
|
] });
|
|
3607
3635
|
}), ji = "thumbnail.webp";
|
|
3608
|
-
function ra(e, t =
|
|
3636
|
+
function ra(e, t = zt) {
|
|
3609
3637
|
const n = e.trim();
|
|
3610
3638
|
if (!n)
|
|
3611
3639
|
throw new Error("faceId is required");
|
|
@@ -3616,7 +3644,7 @@ function Yi(e = ".png") {
|
|
|
3616
3644
|
const t = e.toLowerCase();
|
|
3617
3645
|
return zi.has(t) ? `source${t}` : "source.png";
|
|
3618
3646
|
}
|
|
3619
|
-
function sa(e, t =
|
|
3647
|
+
function sa(e, t = zt, n = ".png") {
|
|
3620
3648
|
const r = e.trim();
|
|
3621
3649
|
if (!r)
|
|
3622
3650
|
throw new Error("faceId is required");
|
|
@@ -3625,32 +3653,32 @@ function sa(e, t = jt, n = ".png") {
|
|
|
3625
3653
|
export {
|
|
3626
3654
|
ji as AI_TWIN_THUMBNAIL_FILENAME,
|
|
3627
3655
|
na as AiTwin,
|
|
3628
|
-
|
|
3629
|
-
|
|
3656
|
+
Vt as AiTwinNotFoundError,
|
|
3657
|
+
ze as DEFAULT_TTS_ENGINE_ID,
|
|
3630
3658
|
tr as MIC_SAMPLE_RATE,
|
|
3631
3659
|
ns as OCULUS_VISEME_IDS,
|
|
3632
3660
|
nr as PLAYBACK_SAMPLE_RATE,
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3661
|
+
en as SPEAKING_RATE_MAX,
|
|
3662
|
+
Zt as SPEAKING_RATE_MIN,
|
|
3663
|
+
Qe as TTS_ENGINE_CARTESIA,
|
|
3636
3664
|
Hn as TTS_ENGINE_GOOGLE,
|
|
3637
|
-
|
|
3665
|
+
Jt as TTS_ENGINE_INWORLD,
|
|
3638
3666
|
ta as VISEME_IDS,
|
|
3639
3667
|
er as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
3640
|
-
|
|
3668
|
+
Rt as VISEME_TEST_SPEAKING_RATE,
|
|
3641
3669
|
Zn as VISEME_TEST_VOICE_ID,
|
|
3642
3670
|
Yi as aiTwinSourceFilename,
|
|
3643
3671
|
Ds as buildVoiceWebSocketUrl,
|
|
3644
3672
|
An as createAvatarTtsLipsyncController,
|
|
3645
|
-
|
|
3646
|
-
|
|
3673
|
+
Bs as createRealtimeVoiceLipsyncController,
|
|
3674
|
+
vn as faceAssetUrls,
|
|
3647
3675
|
Nr as fetchAiTwin,
|
|
3648
|
-
|
|
3676
|
+
Ot as fetchDevAuthToken,
|
|
3649
3677
|
sa as getAiTwinSourceUrl,
|
|
3650
3678
|
ra as getAiTwinThumbnailUrl,
|
|
3651
3679
|
ss as normalizeOculusViseme,
|
|
3652
3680
|
zr as resolveDirectFaceId,
|
|
3653
|
-
|
|
3681
|
+
Pt as resolveVisemeAtTime,
|
|
3654
3682
|
ea as resolveWordAtTime,
|
|
3655
3683
|
Yr as setActiveTwinAssets
|
|
3656
3684
|
};
|