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