@streamoji/aitwin 0.2.5 → 0.2.6
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 +2 -2
- package/dist/aitwin.js +870 -884
- package/package.json +1 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import { jsxs as kn, jsx as
|
|
2
|
-
import { forwardRef as vn, useRef as
|
|
1
|
+
import { jsxs as kn, jsx as It } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as vn, useRef as F, useState as Le, useCallback as oe, useEffect as ke, useMemo as Rt, useImperativeHandle as bn } from "react";
|
|
3
3
|
import { PipecatClient as Tn } from "@pipecat-ai/client-js";
|
|
4
4
|
import { WebSocketTransport as An, DailyMediaManager as In } from "@pipecat-ai/websocket-transport";
|
|
5
|
-
const Rn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev",
|
|
5
|
+
const Rn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", Jt = {
|
|
6
6
|
publicBase: Rn
|
|
7
|
-
}, Dn = "0.2.
|
|
7
|
+
}, Dn = "0.2.6", Mn = {
|
|
8
8
|
version: Dn
|
|
9
|
-
},
|
|
9
|
+
}, Cn = {}, be = "https://ai.streamoji.com", ut = `${Jt.publicBase}/custom-faces`, xn = `${Jt.publicBase}/aitwin-workers/v${Mn.version}/visemeDiffPreview.worker.js`;
|
|
10
10
|
function Pn(e) {
|
|
11
11
|
if (e) return e;
|
|
12
|
-
const t = typeof import.meta < "u" ?
|
|
12
|
+
const t = typeof import.meta < "u" ? Cn?.VITE_AITWIN_WORKER_URL : void 0;
|
|
13
13
|
return t?.trim() ? t.trim() : xn;
|
|
14
14
|
}
|
|
15
|
-
const Bn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
]),
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
},
|
|
23
|
-
google:
|
|
24
|
-
inworld:
|
|
25
|
-
cartesia:
|
|
15
|
+
const Bn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Qt = "eng_a7f2b9c1", lt = "eng_d4e8f3a2", Ae = "eng_c9b1e6d4", Te = Ae, Ln = /* @__PURE__ */ new Set([
|
|
16
|
+
lt,
|
|
17
|
+
Ae
|
|
18
|
+
]), Xt = {
|
|
19
|
+
[Qt]: "oculus_direct",
|
|
20
|
+
[Ae]: "oculus_direct",
|
|
21
|
+
[lt]: "inworld_word"
|
|
22
|
+
}, Dt = {
|
|
23
|
+
google: Qt,
|
|
24
|
+
inworld: lt,
|
|
25
|
+
cartesia: Ae
|
|
26
26
|
};
|
|
27
27
|
function On(e) {
|
|
28
|
-
return
|
|
28
|
+
return Xt[e];
|
|
29
29
|
}
|
|
30
30
|
function Fn(e) {
|
|
31
|
-
return e ===
|
|
31
|
+
return e === Ae;
|
|
32
32
|
}
|
|
33
33
|
function Un(e) {
|
|
34
|
-
if (e.ttsEngineId && e.ttsEngineId in
|
|
34
|
+
if (e.ttsEngineId && e.ttsEngineId in Xt)
|
|
35
35
|
return e.ttsEngineId;
|
|
36
36
|
const t = e.tts?.toLowerCase();
|
|
37
|
-
return t && t in
|
|
37
|
+
return t && t in Dt ? Dt[t] : Te;
|
|
38
38
|
}
|
|
39
|
-
class
|
|
39
|
+
class nt extends Error {
|
|
40
40
|
constructor(t = "AI twin not found") {
|
|
41
41
|
super(t), this.name = "AiTwinNotFoundError";
|
|
42
42
|
}
|
|
@@ -46,12 +46,12 @@ async function Nn(e, t = Bn) {
|
|
|
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 nt();
|
|
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 nt(s.error ?? "AI twin not found");
|
|
55
55
|
const { tts: i, ...o } = s.data;
|
|
56
56
|
return {
|
|
57
57
|
...o,
|
|
@@ -59,7 +59,7 @@ async function Nn(e, t = Bn) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
const Vn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", $n = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Wn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hn = "6TNvp3SCs4Og0a1ijm9TommXLql1", qn = "Swaraj Mali";
|
|
62
|
-
async function
|
|
62
|
+
async function et() {
|
|
63
63
|
const e = await fetch(Vn, {
|
|
64
64
|
method: "POST",
|
|
65
65
|
headers: {
|
|
@@ -79,7 +79,7 @@ async function nt() {
|
|
|
79
79
|
throw new Error("getAuthToken returned no token");
|
|
80
80
|
return n;
|
|
81
81
|
}
|
|
82
|
-
async function Kn(e, t =
|
|
82
|
+
async function Kn(e, t = be) {
|
|
83
83
|
const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
84
84
|
headers: { Authorization: `Bearer ${e}` }
|
|
85
85
|
});
|
|
@@ -97,7 +97,7 @@ function jn(e) {
|
|
|
97
97
|
n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
|
|
98
98
|
return n;
|
|
99
99
|
}
|
|
100
|
-
function
|
|
100
|
+
function Ve(e) {
|
|
101
101
|
return Uint8Array.from(e);
|
|
102
102
|
}
|
|
103
103
|
function Gn(e, t) {
|
|
@@ -108,7 +108,7 @@ async function zn(e, t) {
|
|
|
108
108
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
109
109
|
if (e.byteLength < 28)
|
|
110
110
|
throw new Error("Encrypted payload too small");
|
|
111
|
-
const n = new Uint8Array(e), r =
|
|
111
|
+
const n = new Uint8Array(e), r = Ve(n.subarray(0, 12)), s = Ve(n.subarray(12, 28)), i = Ve(n.subarray(28)), o = Ve(Gn(i, s)), a = await crypto.subtle.importKey(
|
|
112
112
|
"raw",
|
|
113
113
|
jn(t),
|
|
114
114
|
{ name: "AES-GCM" },
|
|
@@ -121,22 +121,22 @@ async function zn(e, t) {
|
|
|
121
121
|
o
|
|
122
122
|
);
|
|
123
123
|
}
|
|
124
|
-
let
|
|
125
|
-
const
|
|
126
|
-
function
|
|
124
|
+
let rt = null;
|
|
125
|
+
const st = /* @__PURE__ */ new Set();
|
|
126
|
+
function $e(e) {
|
|
127
127
|
return e.includes("/custom-faces/");
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function qe(e) {
|
|
130
130
|
const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
|
|
131
|
-
if (!(e.encrypted ||
|
|
131
|
+
if (!(e.encrypted || $e(t) || $e(n)))
|
|
132
132
|
return { twinBase: n, binBase: t, encrypted: !1 };
|
|
133
|
-
const s =
|
|
133
|
+
const s = $e(t) ? t : $e(n) ? n : t;
|
|
134
134
|
return { twinBase: s, binBase: s, encrypted: !0 };
|
|
135
135
|
}
|
|
136
|
-
function
|
|
137
|
-
return
|
|
136
|
+
function Ie(e) {
|
|
137
|
+
return qe(e).encrypted;
|
|
138
138
|
}
|
|
139
|
-
function Mt(e, t =
|
|
139
|
+
function Mt(e, t = ut) {
|
|
140
140
|
const n = `${t.replace(/\/$/, "")}/${e}`;
|
|
141
141
|
return { twinBase: n, binBase: n, encrypted: !0 };
|
|
142
142
|
}
|
|
@@ -144,12 +144,12 @@ function Yn(e, t) {
|
|
|
144
144
|
return (e ?? t)?.trim() || void 0;
|
|
145
145
|
}
|
|
146
146
|
function Jn(e) {
|
|
147
|
-
|
|
148
|
-
for (const t of
|
|
147
|
+
rt = qe(e);
|
|
148
|
+
for (const t of st) t();
|
|
149
149
|
}
|
|
150
150
|
function Qn(e, t) {
|
|
151
151
|
const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
152
|
-
if (!n) return
|
|
152
|
+
if (!n) return qe(e);
|
|
153
153
|
const r = (s) => {
|
|
154
154
|
try {
|
|
155
155
|
return new URL(s, n).href.replace(/\/$/, "");
|
|
@@ -157,42 +157,42 @@ function Qn(e, t) {
|
|
|
157
157
|
return s;
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
|
-
return
|
|
160
|
+
return qe({
|
|
161
161
|
twinBase: r(e.twinBase),
|
|
162
162
|
binBase: r(e.binBase),
|
|
163
163
|
encrypted: e.encrypted
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
function
|
|
167
|
-
if (!
|
|
166
|
+
function Ee() {
|
|
167
|
+
if (!rt)
|
|
168
168
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
169
|
-
return
|
|
169
|
+
return rt;
|
|
170
170
|
}
|
|
171
171
|
function Xn(e) {
|
|
172
|
-
return
|
|
172
|
+
return st.add(e), () => st.delete(e);
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
const e =
|
|
176
|
-
return
|
|
174
|
+
function Ct() {
|
|
175
|
+
const e = Ee();
|
|
176
|
+
return Ie(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
177
177
|
}
|
|
178
178
|
function Zn() {
|
|
179
|
-
const e =
|
|
180
|
-
return
|
|
179
|
+
const e = Ee();
|
|
180
|
+
return Ie(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
181
181
|
}
|
|
182
182
|
function er() {
|
|
183
|
-
const e =
|
|
184
|
-
return
|
|
183
|
+
const e = Ee();
|
|
184
|
+
return Ie(e) ? e.binBase : e.twinBase;
|
|
185
185
|
}
|
|
186
|
-
function
|
|
187
|
-
return
|
|
186
|
+
function Ge() {
|
|
187
|
+
return Ie(Ee());
|
|
188
188
|
}
|
|
189
189
|
function tr() {
|
|
190
|
-
const e =
|
|
191
|
-
return
|
|
190
|
+
const e = Ee();
|
|
191
|
+
return Ie(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
192
192
|
}
|
|
193
193
|
function nr() {
|
|
194
|
-
const e =
|
|
195
|
-
return
|
|
194
|
+
const e = Ee();
|
|
195
|
+
return Ie(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
196
196
|
}
|
|
197
197
|
function rr(e) {
|
|
198
198
|
const t = e.split(/\r?\n/);
|
|
@@ -257,12 +257,12 @@ function ur(e, t) {
|
|
|
257
257
|
const s = Math.max(0, Math.min(1, (t - e.wtime) / r));
|
|
258
258
|
return Math.min(n - 1, Math.floor(s * n));
|
|
259
259
|
}
|
|
260
|
-
function
|
|
260
|
+
function ze(e, t) {
|
|
261
261
|
const n = Math.max(0, Math.min(e.length - 1, t));
|
|
262
262
|
return e[n] ?? "";
|
|
263
263
|
}
|
|
264
264
|
function lr(e, t) {
|
|
265
|
-
const n = e.toLowerCase(), r =
|
|
265
|
+
const n = e.toLowerCase(), r = ze(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
|
|
266
266
|
return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
|
|
267
267
|
}
|
|
268
268
|
function fr(e, t) {
|
|
@@ -271,7 +271,7 @@ function fr(e, t) {
|
|
|
271
271
|
Math.min(n.length, t + 3)
|
|
272
272
|
);
|
|
273
273
|
if (/oo|ou|uw/.test(r)) return "U";
|
|
274
|
-
const s =
|
|
274
|
+
const s = ze(n, t);
|
|
275
275
|
return s === "u" || s === "w" ? "U" : "O";
|
|
276
276
|
}
|
|
277
277
|
function dr(e, t) {
|
|
@@ -281,9 +281,9 @@ function dr(e, t) {
|
|
|
281
281
|
Math.max(0, t - 1),
|
|
282
282
|
Math.min(n.length, t + 3)
|
|
283
283
|
);
|
|
284
|
-
return /wo|wh/.test(s) ||
|
|
284
|
+
return /wo|wh/.test(s) || ze(n, t) === "o" ? "O" : "U";
|
|
285
285
|
}
|
|
286
|
-
const
|
|
286
|
+
const We = {
|
|
287
287
|
d: "DD",
|
|
288
288
|
t: "DD",
|
|
289
289
|
n: "DD",
|
|
@@ -296,11 +296,11 @@ const $e = {
|
|
|
296
296
|
j: "CH"
|
|
297
297
|
};
|
|
298
298
|
function hr(e, t) {
|
|
299
|
-
const n = e.toLowerCase(), r =
|
|
300
|
-
if (
|
|
299
|
+
const n = e.toLowerCase(), r = ze(n, t);
|
|
300
|
+
if (We[r]) return We[r];
|
|
301
301
|
for (let s = 0; s < n.length; s++) {
|
|
302
302
|
const i = n[s];
|
|
303
|
-
if (
|
|
303
|
+
if (We[i]) return We[i];
|
|
304
304
|
}
|
|
305
305
|
return "DD";
|
|
306
306
|
}
|
|
@@ -334,7 +334,7 @@ function gr(e) {
|
|
|
334
334
|
function _r(e) {
|
|
335
335
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
336
336
|
}
|
|
337
|
-
function
|
|
337
|
+
function xt(e, t, n = wr) {
|
|
338
338
|
const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
|
|
339
339
|
r.buffer,
|
|
340
340
|
r.byteOffset,
|
|
@@ -361,7 +361,7 @@ async function yr(e, t) {
|
|
|
361
361
|
return e.decodeAudioData(r);
|
|
362
362
|
}
|
|
363
363
|
if (n.length >= 2 && n.length % 2 === 0)
|
|
364
|
-
return
|
|
364
|
+
return xt(e, n);
|
|
365
365
|
try {
|
|
366
366
|
const r = n.buffer.slice(
|
|
367
367
|
n.byteOffset,
|
|
@@ -369,10 +369,10 @@ async function yr(e, t) {
|
|
|
369
369
|
);
|
|
370
370
|
return await e.decodeAudioData(r);
|
|
371
371
|
} catch {
|
|
372
|
-
return
|
|
372
|
+
return xt(e, n);
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
function
|
|
375
|
+
function Pt(e) {
|
|
376
376
|
let t = 0;
|
|
377
377
|
for (const n of e)
|
|
378
378
|
t = Math.max(t, n.vtime + n.vduration);
|
|
@@ -384,11 +384,11 @@ function Er(e, t) {
|
|
|
384
384
|
return n;
|
|
385
385
|
return null;
|
|
386
386
|
}
|
|
387
|
-
function
|
|
387
|
+
function Zt(e, t) {
|
|
388
388
|
const n = [], r = [];
|
|
389
|
-
let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, _ = 0, m = 0,
|
|
389
|
+
let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, _ = 0, m = 0, k = null, S = 1, u = t, p = !1;
|
|
390
390
|
const d = () => {
|
|
391
|
-
|
|
391
|
+
k != null && (clearTimeout(k), k = null);
|
|
392
392
|
}, I = () => {
|
|
393
393
|
for (const g of r)
|
|
394
394
|
try {
|
|
@@ -396,73 +396,73 @@ function en(e, t) {
|
|
|
396
396
|
} catch {
|
|
397
397
|
}
|
|
398
398
|
r.length = 0;
|
|
399
|
-
},
|
|
399
|
+
}, E = () => {
|
|
400
400
|
for (const g of r)
|
|
401
|
-
g.playbackRate.value =
|
|
401
|
+
g.playbackRate.value = S;
|
|
402
402
|
}, R = () => {
|
|
403
403
|
!f || i || r.length > 0 || n.length > 0 || (o = !1, d(), e.onSpeakingDone(), e.onNotify());
|
|
404
|
-
},
|
|
405
|
-
const
|
|
406
|
-
if (
|
|
404
|
+
}, H = (g) => {
|
|
405
|
+
const C = Pt(g);
|
|
406
|
+
if (C <= 0) {
|
|
407
407
|
e.onSpeakingDone(), e.onNotify();
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
410
410
|
o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), d();
|
|
411
|
-
const b =
|
|
412
|
-
|
|
413
|
-
p || (o = !1,
|
|
411
|
+
const b = S > 0 ? C / S : C;
|
|
412
|
+
k = setTimeout(() => {
|
|
413
|
+
p || (o = !1, k = null, e.onSpeakingDone(), e.onNotify());
|
|
414
414
|
}, b);
|
|
415
|
-
},
|
|
416
|
-
|
|
417
|
-
const
|
|
418
|
-
if (!
|
|
419
|
-
const W = Math.round((A.start ?? 0) * 1e3),
|
|
415
|
+
}, V = (g, C, b, D) => {
|
|
416
|
+
C.length !== 0 && (D && (_ = b), C.forEach((A) => {
|
|
417
|
+
const B = String(A.word ?? "").trim();
|
|
418
|
+
if (!B) return;
|
|
419
|
+
const W = Math.round((A.start ?? 0) * 1e3), U = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
|
|
420
420
|
g.push({
|
|
421
|
-
word:
|
|
421
|
+
word: B,
|
|
422
422
|
wtime: _ + W,
|
|
423
|
-
wduration:
|
|
423
|
+
wduration: U,
|
|
424
424
|
queueIndex: g.length,
|
|
425
425
|
gesture: A.gesture ?? null,
|
|
426
426
|
emphasis: A.emphasis === !0
|
|
427
427
|
});
|
|
428
428
|
}));
|
|
429
|
-
}, $ = (g,
|
|
430
|
-
b.length !== 0 && (A && (_ = D), b.forEach((
|
|
431
|
-
const W = String(
|
|
429
|
+
}, $ = (g, C, b, D, A, P) => {
|
|
430
|
+
b.length !== 0 && (A && (_ = D), b.forEach((B) => {
|
|
431
|
+
const W = String(B.symbol ?? B.viseme ?? "").trim();
|
|
432
432
|
if (!W) return;
|
|
433
|
-
const
|
|
434
|
-
let
|
|
433
|
+
const U = Math.round((B.start ?? 0) * 1e3), X = Math.max(1, Math.round((B.duration ?? 0) * 1e3)), se = _ + U;
|
|
434
|
+
let Z;
|
|
435
435
|
if (On(P) === "oculus_direct")
|
|
436
|
-
|
|
436
|
+
Z = or(W);
|
|
437
437
|
else {
|
|
438
|
-
const
|
|
439
|
-
|
|
438
|
+
const ce = Er(C, se), J = ce ? ur(ce, se) : 0;
|
|
439
|
+
Z = mr(
|
|
440
440
|
W,
|
|
441
|
-
|
|
442
|
-
|
|
441
|
+
ce?.word ?? "",
|
|
442
|
+
J
|
|
443
443
|
);
|
|
444
444
|
}
|
|
445
445
|
g.push({
|
|
446
|
-
viseme:
|
|
446
|
+
viseme: Z,
|
|
447
447
|
weight: 1,
|
|
448
|
-
vtime:
|
|
449
|
-
vduration:
|
|
448
|
+
vtime: se,
|
|
449
|
+
vduration: X
|
|
450
450
|
});
|
|
451
451
|
}), e.onNotify());
|
|
452
|
-
},
|
|
453
|
-
|
|
452
|
+
}, j = (g, C, b, D, A, P, B) => {
|
|
453
|
+
V(C, D, A, P), $(
|
|
454
454
|
g,
|
|
455
|
-
|
|
455
|
+
C,
|
|
456
456
|
b,
|
|
457
457
|
A,
|
|
458
458
|
P,
|
|
459
|
-
|
|
459
|
+
B
|
|
460
460
|
);
|
|
461
|
-
}, y = async (g,
|
|
461
|
+
}, y = async (g, C, b, D, A, P, B) => {
|
|
462
462
|
if (p || !b?.trim()) {
|
|
463
|
-
(D.length > 0 || A.length > 0) && !a &&
|
|
463
|
+
(D.length > 0 || A.length > 0) && !a && j(
|
|
464
464
|
g,
|
|
465
|
-
|
|
465
|
+
C,
|
|
466
466
|
D,
|
|
467
467
|
A,
|
|
468
468
|
_,
|
|
@@ -484,32 +484,32 @@ function en(e, t) {
|
|
|
484
484
|
try {
|
|
485
485
|
const W = window.AudioContext || window.webkitAudioContext;
|
|
486
486
|
s || (s = new W());
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
const
|
|
487
|
+
const U = s;
|
|
488
|
+
U.state === "suspended" && await U.resume();
|
|
489
|
+
const X = await yr(U, b);
|
|
490
490
|
a = !0;
|
|
491
|
-
const
|
|
492
|
-
let
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
const
|
|
496
|
-
if (
|
|
491
|
+
const se = U.currentTime;
|
|
492
|
+
let Z = m;
|
|
493
|
+
const ce = !o;
|
|
494
|
+
Z < se && (Z = se + 0.1), m = Z + X.duration;
|
|
495
|
+
const J = U.createBufferSource();
|
|
496
|
+
if (J.buffer = X, J.playbackRate.value = S, J.connect(U.destination), r.push(J), p) {
|
|
497
497
|
r.pop();
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
|
-
if (
|
|
501
|
-
o = !0, e.onSpeakingStart(), w =
|
|
502
|
-
const
|
|
503
|
-
l = performance.now() +
|
|
500
|
+
if (ce) {
|
|
501
|
+
o = !0, e.onSpeakingStart(), w = Z, _ = 0, g.length = 0, C.length = 0, B?.();
|
|
502
|
+
const v = (Z - se) * 1e3;
|
|
503
|
+
l = performance.now() + v;
|
|
504
504
|
}
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
},
|
|
509
|
-
const c = (
|
|
510
|
-
|
|
505
|
+
J.onended = () => {
|
|
506
|
+
const v = r.indexOf(J);
|
|
507
|
+
v >= 0 && r.splice(v, 1), R(), e.onNotify();
|
|
508
|
+
}, J.start(Z);
|
|
509
|
+
const c = (Z - w) * 1e3;
|
|
510
|
+
j(
|
|
511
511
|
g,
|
|
512
|
-
|
|
512
|
+
C,
|
|
513
513
|
D,
|
|
514
514
|
A,
|
|
515
515
|
c,
|
|
@@ -523,12 +523,12 @@ function en(e, t) {
|
|
|
523
523
|
const W = n.shift();
|
|
524
524
|
W ? await y(
|
|
525
525
|
g,
|
|
526
|
-
|
|
526
|
+
C,
|
|
527
527
|
W.audio,
|
|
528
528
|
W.visemes,
|
|
529
529
|
W.words,
|
|
530
530
|
W.isNewSegment,
|
|
531
|
-
|
|
531
|
+
B
|
|
532
532
|
) : R();
|
|
533
533
|
}
|
|
534
534
|
};
|
|
@@ -537,9 +537,9 @@ function en(e, t) {
|
|
|
537
537
|
u = g;
|
|
538
538
|
},
|
|
539
539
|
setPlaybackSpeed: (g) => {
|
|
540
|
-
|
|
540
|
+
S = Math.max(0.1, Math.min(1, g)), E();
|
|
541
541
|
},
|
|
542
|
-
getPlaybackSpeed: () =>
|
|
542
|
+
getPlaybackSpeed: () => S,
|
|
543
543
|
resetForNewStream: (g) => {
|
|
544
544
|
p = !1, f = !1, u = g;
|
|
545
545
|
},
|
|
@@ -553,17 +553,17 @@ function en(e, t) {
|
|
|
553
553
|
},
|
|
554
554
|
markStreamComplete: (g) => {
|
|
555
555
|
if (f = !0, !a && g.length > 0) {
|
|
556
|
-
|
|
556
|
+
H(g);
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
559
|
R();
|
|
560
560
|
},
|
|
561
561
|
playAudioChunk: y,
|
|
562
|
-
queueTimingsOnly: (g,
|
|
562
|
+
queueTimingsOnly: (g, C, b, D, A) => {
|
|
563
563
|
let P = _;
|
|
564
|
-
A && g.length > 0 && (P =
|
|
564
|
+
A && g.length > 0 && (P = Pt(g)), j(
|
|
565
565
|
g,
|
|
566
|
-
|
|
566
|
+
C,
|
|
567
567
|
b,
|
|
568
568
|
D,
|
|
569
569
|
P,
|
|
@@ -574,7 +574,7 @@ function en(e, t) {
|
|
|
574
574
|
getPlaybackElapsedMs: () => o ? a && s && w > 0 ? Math.max(
|
|
575
575
|
0,
|
|
576
576
|
(s.currentTime - w) * 1e3
|
|
577
|
-
) : Math.max(0, (performance.now() - l) *
|
|
577
|
+
) : Math.max(0, (performance.now() - l) * S) : 0,
|
|
578
578
|
isSpeaking: () => o,
|
|
579
579
|
getPlaybackStartPerf: () => l,
|
|
580
580
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
@@ -586,101 +586,90 @@ function en(e, t) {
|
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
588
|
}
|
|
589
|
-
function
|
|
589
|
+
function ft(e, t) {
|
|
590
590
|
let n = null;
|
|
591
591
|
for (const r of e)
|
|
592
592
|
t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
|
|
593
593
|
return n ? n.viseme : "sil";
|
|
594
594
|
}
|
|
595
|
-
function
|
|
596
|
-
const r = ze(e, t);
|
|
597
|
-
if (r !== "sil") return r;
|
|
598
|
-
let s = null;
|
|
599
|
-
for (const i of e) {
|
|
600
|
-
if (i.vtime > t) break;
|
|
601
|
-
const o = i.vtime + i.vduration;
|
|
602
|
-
o <= t && t - o <= n && (s = i);
|
|
603
|
-
}
|
|
604
|
-
return s?.viseme ?? "sil";
|
|
605
|
-
}
|
|
606
|
-
function zs(e, t) {
|
|
595
|
+
function js(e, t) {
|
|
607
596
|
for (const n of e)
|
|
608
597
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
609
598
|
return n;
|
|
610
599
|
return null;
|
|
611
600
|
}
|
|
612
|
-
const
|
|
613
|
-
function
|
|
601
|
+
const en = 0.5, tn = 1.5, nn = "Olivia", Sr = "f786b574-daa5-4673-aa0c-cbe3e8534c02", dt = 0.85;
|
|
602
|
+
function Bt(e, t = be) {
|
|
614
603
|
const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
|
|
615
|
-
let o = "neutral", a = "", f =
|
|
616
|
-
const l = /* @__PURE__ */ new Set(), w = () => l.forEach((
|
|
604
|
+
let o = "neutral", a = "", f = Te;
|
|
605
|
+
const l = /* @__PURE__ */ new Set(), w = () => l.forEach((S) => S()), _ = Zt(
|
|
617
606
|
{
|
|
618
607
|
onSpeakingStart: () => e("speaking"),
|
|
619
608
|
onSpeakingDone: () => e("done"),
|
|
620
609
|
onNotify: w
|
|
621
610
|
},
|
|
622
|
-
|
|
611
|
+
Te
|
|
623
612
|
), m = () => {
|
|
624
613
|
_.stop(), r.length = 0, s.length = 0, i.length = 0, o = "neutral", e("idle"), w();
|
|
625
614
|
};
|
|
626
615
|
return {
|
|
627
|
-
setDeveloperToken: (
|
|
628
|
-
a =
|
|
616
|
+
setDeveloperToken: (S) => {
|
|
617
|
+
a = S;
|
|
629
618
|
},
|
|
630
|
-
setTtsEngineId: (
|
|
631
|
-
f =
|
|
619
|
+
setTtsEngineId: (S) => {
|
|
620
|
+
f = S;
|
|
632
621
|
},
|
|
633
622
|
getTtsEngineId: () => f,
|
|
634
|
-
speak: async (
|
|
623
|
+
speak: async (S, u) => {
|
|
635
624
|
m(), e("loading");
|
|
636
625
|
const p = a.trim();
|
|
637
626
|
if (!p)
|
|
638
627
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
639
|
-
const d = u?.ttsEngineId ?? f ??
|
|
628
|
+
const d = u?.ttsEngineId ?? f ?? Te;
|
|
640
629
|
_.resetForNewStream(d), _.setStreamTtsEngineId(d);
|
|
641
|
-
const I = u?.voiceId ??
|
|
642
|
-
|
|
643
|
-
Math.min(
|
|
644
|
-
),
|
|
645
|
-
user_query:
|
|
630
|
+
const I = u?.voiceId ?? nn, E = u?.speakingRate ?? dt, R = Math.max(
|
|
631
|
+
en,
|
|
632
|
+
Math.min(tn, E)
|
|
633
|
+
), H = {
|
|
634
|
+
user_query: S,
|
|
646
635
|
ttsEngineId: d,
|
|
647
636
|
speakingRate: R,
|
|
648
637
|
tenant: "aiTwin"
|
|
649
638
|
};
|
|
650
|
-
Ln.has(d) && (
|
|
639
|
+
Ln.has(d) && (H.voice_id = I);
|
|
651
640
|
try {
|
|
652
|
-
const
|
|
641
|
+
const V = await fetch(n, {
|
|
653
642
|
method: "POST",
|
|
654
643
|
headers: {
|
|
655
644
|
"Content-Type": "application/json",
|
|
656
645
|
Authorization: `Bearer ${p}`
|
|
657
646
|
},
|
|
658
|
-
body: JSON.stringify(
|
|
647
|
+
body: JSON.stringify(H)
|
|
659
648
|
});
|
|
660
|
-
if (!
|
|
661
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
662
|
-
const $ =
|
|
649
|
+
if (!V.ok)
|
|
650
|
+
throw new Error(`avatar_ttsWithPoses failed (${V.status})`);
|
|
651
|
+
const $ = V.body;
|
|
663
652
|
if (!$) throw new Error("No response body");
|
|
664
|
-
const
|
|
653
|
+
const j = $.getReader(), y = new TextDecoder();
|
|
665
654
|
let T = "";
|
|
666
|
-
const g = async (
|
|
667
|
-
const b = rr(
|
|
655
|
+
const g = async (C) => {
|
|
656
|
+
const b = rr(C);
|
|
668
657
|
if (b) {
|
|
669
658
|
if (b.event === "audio") {
|
|
670
|
-
const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [],
|
|
659
|
+
const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], B = b.data.is_new_segment ?? !1;
|
|
671
660
|
D ? await _.playAudioChunk(
|
|
672
661
|
r,
|
|
673
662
|
s,
|
|
674
663
|
D,
|
|
675
664
|
A,
|
|
676
665
|
P,
|
|
677
|
-
|
|
666
|
+
B
|
|
678
667
|
) : (A.length > 0 || P.length > 0) && _.queueTimingsOnly(
|
|
679
668
|
r,
|
|
680
669
|
s,
|
|
681
670
|
A,
|
|
682
671
|
P,
|
|
683
|
-
|
|
672
|
+
B
|
|
684
673
|
);
|
|
685
674
|
} else if (b.event === "metadata") {
|
|
686
675
|
const D = b.data.mood;
|
|
@@ -690,14 +679,14 @@ function Lt(e, t = Ae) {
|
|
|
690
679
|
i.length = 0;
|
|
691
680
|
for (const P of A) {
|
|
692
681
|
if (!P || typeof P != "object") continue;
|
|
693
|
-
const
|
|
682
|
+
const B = P;
|
|
694
683
|
i.push({
|
|
695
|
-
sentence_index: Number(
|
|
696
|
-
text: String(
|
|
697
|
-
sentiment: typeof
|
|
698
|
-
emotion: String(
|
|
699
|
-
start_word: Number(
|
|
700
|
-
end_word: Number(
|
|
684
|
+
sentence_index: Number(B.sentence_index ?? 0),
|
|
685
|
+
text: String(B.text ?? ""),
|
|
686
|
+
sentiment: typeof B.sentiment == "string" ? B.sentiment : void 0,
|
|
687
|
+
emotion: String(B.emotion ?? o),
|
|
688
|
+
start_word: Number(B.start_word ?? 0),
|
|
689
|
+
end_word: Number(B.end_word ?? 0)
|
|
701
690
|
});
|
|
702
691
|
}
|
|
703
692
|
}
|
|
@@ -709,20 +698,20 @@ function Lt(e, t = Ae) {
|
|
|
709
698
|
}
|
|
710
699
|
};
|
|
711
700
|
for (; ; ) {
|
|
712
|
-
const { done:
|
|
701
|
+
const { done: C, value: b } = await j.read();
|
|
713
702
|
b && (T += y.decode(b, { stream: !0 }));
|
|
714
703
|
const D = T.split(`
|
|
715
704
|
|
|
716
705
|
`);
|
|
717
706
|
T = D.pop() ?? "";
|
|
718
707
|
for (const A of D) await g(A);
|
|
719
|
-
if (
|
|
708
|
+
if (C) {
|
|
720
709
|
T.trim() && await g(T.trim()), _.markStreamComplete(r);
|
|
721
710
|
break;
|
|
722
711
|
}
|
|
723
712
|
}
|
|
724
|
-
} catch (
|
|
725
|
-
throw console.error("[avatarTtsLipsync]",
|
|
713
|
+
} catch (V) {
|
|
714
|
+
throw console.error("[avatarTtsLipsync]", V), m(), e("error"), V;
|
|
726
715
|
}
|
|
727
716
|
},
|
|
728
717
|
stop: m,
|
|
@@ -732,15 +721,15 @@ function Lt(e, t = Ae) {
|
|
|
732
721
|
getStreamMood: () => o,
|
|
733
722
|
getPlaybackElapsedMs: () => _.getPlaybackElapsedMs(),
|
|
734
723
|
isSpeaking: () => _.isSpeaking(),
|
|
735
|
-
setPlaybackSpeed: (
|
|
736
|
-
_.setPlaybackSpeed(
|
|
724
|
+
setPlaybackSpeed: (S) => {
|
|
725
|
+
_.setPlaybackSpeed(S);
|
|
737
726
|
},
|
|
738
727
|
getPlaybackSpeed: () => _.getPlaybackSpeed(),
|
|
739
|
-
subscribe: (
|
|
728
|
+
subscribe: (S) => (l.add(S), () => l.delete(S))
|
|
740
729
|
};
|
|
741
730
|
}
|
|
742
|
-
const
|
|
743
|
-
class
|
|
731
|
+
const rn = 16e3, sn = 24e3;
|
|
732
|
+
class kr extends In {
|
|
744
733
|
constructor() {
|
|
745
734
|
super(
|
|
746
735
|
!0,
|
|
@@ -748,40 +737,40 @@ class vr extends In {
|
|
|
748
737
|
void 0,
|
|
749
738
|
void 0,
|
|
750
739
|
512,
|
|
751
|
-
|
|
752
|
-
|
|
740
|
+
rn,
|
|
741
|
+
sn
|
|
753
742
|
);
|
|
754
743
|
}
|
|
755
744
|
/** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
|
|
756
745
|
bufferBotAudio(t, n) {
|
|
757
746
|
}
|
|
758
747
|
}
|
|
759
|
-
const
|
|
760
|
-
function
|
|
761
|
-
return
|
|
748
|
+
const vr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
749
|
+
function br(e) {
|
|
750
|
+
return vr.test(e.trim());
|
|
762
751
|
}
|
|
763
|
-
function
|
|
752
|
+
function Tr(e) {
|
|
764
753
|
const t = e.replace(/\/$/, "");
|
|
765
754
|
return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
|
|
766
755
|
}
|
|
767
|
-
function
|
|
756
|
+
function Ar(e) {
|
|
768
757
|
if (e.wsUrl?.trim()) return e.wsUrl.trim();
|
|
769
758
|
const t = e.authToken?.trim();
|
|
770
759
|
if (!t)
|
|
771
760
|
throw new Error(
|
|
772
761
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
773
762
|
);
|
|
774
|
-
const n = e.apiBase ??
|
|
763
|
+
const n = e.apiBase ?? be, r = new URL(`${Tr(n)}/ws/voice`);
|
|
775
764
|
r.searchParams.set("authToken", t);
|
|
776
765
|
const s = e.voiceId?.trim();
|
|
777
|
-
s &&
|
|
778
|
-
const i = e.speakingRate ??
|
|
766
|
+
s && br(s) && r.searchParams.set("voiceId", s);
|
|
767
|
+
const i = e.speakingRate ?? dt;
|
|
779
768
|
return r.searchParams.set(
|
|
780
769
|
"speaking_rate",
|
|
781
|
-
String(Math.max(
|
|
770
|
+
String(Math.max(en, Math.min(tn, i)))
|
|
782
771
|
), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
|
|
783
772
|
}
|
|
784
|
-
function
|
|
773
|
+
function Lt(e, t) {
|
|
785
774
|
if (!Array.isArray(e)) return [];
|
|
786
775
|
const n = [];
|
|
787
776
|
for (const r of e)
|
|
@@ -795,116 +784,116 @@ function Ot(e, t) {
|
|
|
795
784
|
});
|
|
796
785
|
return n;
|
|
797
786
|
}
|
|
798
|
-
function
|
|
787
|
+
function Ir(e) {
|
|
799
788
|
if (!e || typeof e != "object") return null;
|
|
800
789
|
const t = e, n = t.data;
|
|
801
790
|
return n && typeof n == "object" ? n : t;
|
|
802
791
|
}
|
|
803
|
-
function
|
|
792
|
+
function Rr(e, t = {}) {
|
|
804
793
|
const n = [], r = [], s = [], i = [];
|
|
805
|
-
let o = "", a = "neutral", f =
|
|
794
|
+
let o = "", a = "neutral", f = Ae, l = !1, w = null, _ = null, m = { ...t }, k = 0, S = null;
|
|
806
795
|
const u = /* @__PURE__ */ new Set(), p = [];
|
|
807
796
|
let d = !1, I = null;
|
|
808
|
-
const
|
|
797
|
+
const E = () => u.forEach((c) => c()), R = Zt(
|
|
809
798
|
{
|
|
810
799
|
onSpeakingStart: () => e("speaking"),
|
|
811
800
|
onSpeakingDone: () => e("done"),
|
|
812
|
-
onNotify:
|
|
801
|
+
onNotify: E
|
|
813
802
|
},
|
|
814
803
|
f
|
|
815
|
-
),
|
|
804
|
+
), H = () => {
|
|
816
805
|
if (I) return I;
|
|
817
806
|
const c = new MessageChannel();
|
|
818
807
|
return c.port1.onmessage = () => {
|
|
819
|
-
const
|
|
820
|
-
|
|
808
|
+
const v = p.shift();
|
|
809
|
+
v !== void 0 && W(v), p.length > 0 ? c.port2.postMessage(null) : d = !1;
|
|
821
810
|
}, I = c, c;
|
|
822
|
-
},
|
|
823
|
-
p.push(c), !d && (d = !0,
|
|
824
|
-
}, $ = () => R.getPlaybackElapsedMs(),
|
|
811
|
+
}, V = (c) => {
|
|
812
|
+
p.push(c), !d && (d = !0, H().port2.postMessage(null));
|
|
813
|
+
}, $ = () => R.getPlaybackElapsedMs(), j = (c, v = o) => {
|
|
825
814
|
if (!m.onLipsyncDebug) return;
|
|
826
|
-
const
|
|
815
|
+
const L = $(), z = n;
|
|
827
816
|
m.onLipsyncDebug({
|
|
828
817
|
event: c,
|
|
829
|
-
spokenText:
|
|
818
|
+
spokenText: v,
|
|
830
819
|
mood: a,
|
|
831
820
|
playbackAnchorPerf: R.getPlaybackStartPerf(),
|
|
832
|
-
playbackElapsedMs:
|
|
833
|
-
queueLength:
|
|
834
|
-
activeViseme:
|
|
835
|
-
segments: i.map((
|
|
836
|
-
...
|
|
837
|
-
visemes: [...
|
|
821
|
+
playbackElapsedMs: L,
|
|
822
|
+
queueLength: z.length,
|
|
823
|
+
activeViseme: ft(z, L),
|
|
824
|
+
segments: i.map((ne) => ({
|
|
825
|
+
...ne,
|
|
826
|
+
visemes: [...ne.visemes]
|
|
838
827
|
}))
|
|
839
828
|
});
|
|
840
|
-
}, y = (c,
|
|
841
|
-
m.onLipsyncDebug && (
|
|
842
|
-
|
|
843
|
-
const
|
|
844
|
-
|
|
829
|
+
}, y = (c, v) => {
|
|
830
|
+
m.onLipsyncDebug && (S = { event: c, spokenText: v }, k === 0 && (k = requestAnimationFrame(() => {
|
|
831
|
+
k = 0;
|
|
832
|
+
const L = S;
|
|
833
|
+
S = null, L && j(L.event, L.spokenText);
|
|
845
834
|
})));
|
|
846
835
|
}, T = () => {
|
|
847
836
|
n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
|
|
848
837
|
}, g = () => {
|
|
849
|
-
R.stop(), T(), y("reset"),
|
|
850
|
-
},
|
|
851
|
-
g(), e("idle"),
|
|
852
|
-
}, b = (c,
|
|
853
|
-
typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (
|
|
854
|
-
...
|
|
838
|
+
R.stop(), T(), y("reset"), E();
|
|
839
|
+
}, C = () => {
|
|
840
|
+
g(), e("idle"), E();
|
|
841
|
+
}, b = (c, v) => {
|
|
842
|
+
typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (v && (s.length = 0), s.push(
|
|
843
|
+
...Lt(c.sentence_emotions, a)
|
|
855
844
|
));
|
|
856
845
|
}, D = (c) => {
|
|
857
|
-
const
|
|
858
|
-
|
|
859
|
-
...
|
|
860
|
-
), Array.isArray(c.gestures) && c.gestures, y("metadata",
|
|
861
|
-
}, A = (c,
|
|
846
|
+
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
847
|
+
v && (o = v), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
|
|
848
|
+
...Lt(c.sentence_emotions, a)
|
|
849
|
+
), Array.isArray(c.gestures) && c.gestures, y("metadata", v), E();
|
|
850
|
+
}, A = (c, v, L, z) => {
|
|
862
851
|
if (!m.onLipsyncDebug) return;
|
|
863
|
-
const
|
|
864
|
-
(
|
|
852
|
+
const ne = n.slice(L), Re = z.filter(
|
|
853
|
+
(G) => String(G.symbol ?? G.viseme ?? "").trim()
|
|
865
854
|
);
|
|
866
855
|
i.push({
|
|
867
|
-
spokenText:
|
|
868
|
-
audioOffsetMs:
|
|
856
|
+
spokenText: v,
|
|
857
|
+
audioOffsetMs: ne[0]?.vtime ?? 0,
|
|
869
858
|
isNewSegment: !!c.is_new_segment,
|
|
870
859
|
chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
|
|
871
860
|
receivedAtMs: performance.now(),
|
|
872
|
-
visemes:
|
|
873
|
-
const
|
|
861
|
+
visemes: ne.map((G, Se) => {
|
|
862
|
+
const Y = Re[Se];
|
|
874
863
|
return {
|
|
875
|
-
rawSymbol: String(
|
|
876
|
-
viseme:
|
|
877
|
-
startSec: Number(
|
|
878
|
-
durationSec: Number(
|
|
879
|
-
vtimeMs:
|
|
880
|
-
vdurationMs:
|
|
864
|
+
rawSymbol: String(Y?.symbol ?? Y?.viseme ?? G.viseme).trim(),
|
|
865
|
+
viseme: G.viseme,
|
|
866
|
+
startSec: Number(Y?.start ?? 0),
|
|
867
|
+
durationSec: Number(Y?.duration ?? 0),
|
|
868
|
+
vtimeMs: G.vtime,
|
|
869
|
+
vdurationMs: G.vduration
|
|
881
870
|
};
|
|
882
871
|
})
|
|
883
872
|
});
|
|
884
873
|
}, P = (c) => {
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
const
|
|
874
|
+
const v = String(c.spoken_text ?? c.text ?? "").trim(), L = !!c.is_new_segment || Number(c.chunk_index ?? -1) === 0, z = c.visemes ?? [], ne = c.words ?? [], Re = String(c.chunk ?? "").trim();
|
|
875
|
+
v && (o = v), b(c, L), L && R.resetForNewStream(f);
|
|
876
|
+
const G = n.length;
|
|
888
877
|
R.playAudioChunk(
|
|
889
878
|
n,
|
|
890
879
|
r,
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
880
|
+
Re,
|
|
881
|
+
z,
|
|
882
|
+
ne,
|
|
883
|
+
L,
|
|
895
884
|
() => {
|
|
896
885
|
i.length = 0;
|
|
897
886
|
}
|
|
898
887
|
).then(() => {
|
|
899
|
-
A(c,
|
|
888
|
+
A(c, v, G, z), y("audio_chunk", v);
|
|
900
889
|
});
|
|
901
|
-
},
|
|
890
|
+
}, B = (c) => {
|
|
902
891
|
console.warn(
|
|
903
892
|
"[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
|
|
904
893
|
);
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
const
|
|
894
|
+
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
895
|
+
v && (o = v), b(c, !!c.is_new_segment);
|
|
896
|
+
const L = n.length;
|
|
908
897
|
R.queueTimingsOnly(
|
|
909
898
|
n,
|
|
910
899
|
r,
|
|
@@ -913,66 +902,66 @@ function Dr(e, t = {}) {
|
|
|
913
902
|
!!c.is_new_segment
|
|
914
903
|
), A(
|
|
915
904
|
c,
|
|
916
|
-
|
|
917
|
-
|
|
905
|
+
v,
|
|
906
|
+
L,
|
|
918
907
|
c.visemes ?? []
|
|
919
|
-
), y("lipsync",
|
|
908
|
+
), y("lipsync", v), E();
|
|
920
909
|
}, W = (c) => {
|
|
921
|
-
const
|
|
922
|
-
if (!
|
|
910
|
+
const v = Ir(c);
|
|
911
|
+
if (!v) {
|
|
923
912
|
console.warn("[realtimeVoice] server message with no payload", c);
|
|
924
913
|
return;
|
|
925
914
|
}
|
|
926
|
-
const
|
|
927
|
-
switch (
|
|
915
|
+
const L = String(v.type ?? "unknown");
|
|
916
|
+
switch (L !== "avatar_metadata" && L !== "avatar_audio_chunk" && L !== "avatar_lipsync" && L !== "error" && console.debug("[realtimeVoice] server message", L, v), L) {
|
|
928
917
|
case "avatar_metadata":
|
|
929
|
-
D(
|
|
918
|
+
D(v);
|
|
930
919
|
break;
|
|
931
920
|
case "avatar_audio_chunk":
|
|
932
|
-
P(
|
|
921
|
+
P(v);
|
|
933
922
|
break;
|
|
934
923
|
case "avatar_lipsync":
|
|
935
|
-
|
|
924
|
+
B(v);
|
|
936
925
|
break;
|
|
937
926
|
case "error": {
|
|
938
|
-
const
|
|
939
|
-
console.error("[realtimeVoice] server error:",
|
|
927
|
+
const z = String(v.message ?? "Voice session error");
|
|
928
|
+
console.error("[realtimeVoice] server error:", z), e("error"), E();
|
|
940
929
|
break;
|
|
941
930
|
}
|
|
942
931
|
case "avatar_speak":
|
|
943
932
|
console.warn(
|
|
944
933
|
"[realtimeVoice] avatar_speak received; tts_stream=false Mode B is not wired yet:",
|
|
945
|
-
|
|
934
|
+
v.text
|
|
946
935
|
);
|
|
947
936
|
break;
|
|
948
937
|
}
|
|
949
|
-
},
|
|
938
|
+
}, U = () => w || (_ = new kr(), w = new Tn({
|
|
950
939
|
transport: new An({
|
|
951
940
|
mediaManager: _,
|
|
952
|
-
recorderSampleRate:
|
|
953
|
-
playerSampleRate:
|
|
941
|
+
recorderSampleRate: rn,
|
|
942
|
+
playerSampleRate: sn
|
|
954
943
|
}),
|
|
955
944
|
enableCam: !1,
|
|
956
945
|
enableMic: !0,
|
|
957
946
|
callbacks: {
|
|
958
947
|
onBotReady: () => {
|
|
959
|
-
l = !0, e("idle"),
|
|
948
|
+
l = !0, e("idle"), E();
|
|
960
949
|
},
|
|
961
950
|
onDisconnected: () => {
|
|
962
|
-
l = !1,
|
|
951
|
+
l = !1, C();
|
|
963
952
|
},
|
|
964
953
|
onError: (c) => {
|
|
965
|
-
const
|
|
966
|
-
console.error("[realtimeVoice]",
|
|
954
|
+
const v = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
|
|
955
|
+
console.error("[realtimeVoice]", v, c), e("error"), E();
|
|
967
956
|
},
|
|
968
957
|
onTransportStateChanged: (c) => {
|
|
969
|
-
c === "error" && (e("error"),
|
|
958
|
+
c === "error" && (e("error"), E());
|
|
970
959
|
},
|
|
971
960
|
onServerMessage: (c) => {
|
|
972
|
-
|
|
961
|
+
V(c);
|
|
973
962
|
},
|
|
974
963
|
onUserStartedSpeaking: () => {
|
|
975
|
-
R.bargeIn(), T(), e("idle"), y("user_started"),
|
|
964
|
+
R.bargeIn(), T(), e("idle"), y("user_started"), E();
|
|
976
965
|
},
|
|
977
966
|
onBotStartedSpeaking: () => {
|
|
978
967
|
y("bot_started");
|
|
@@ -995,18 +984,18 @@ function Dr(e, t = {}) {
|
|
|
995
984
|
f = c, R.setStreamTtsEngineId(c);
|
|
996
985
|
},
|
|
997
986
|
getTtsEngineId: () => f,
|
|
998
|
-
speak: async (c,
|
|
999
|
-
const
|
|
1000
|
-
if (
|
|
987
|
+
speak: async (c, v) => {
|
|
988
|
+
const L = c.trim();
|
|
989
|
+
if (L) {
|
|
1001
990
|
if (!w || !l)
|
|
1002
991
|
throw new Error(
|
|
1003
992
|
"Realtime voice is not connected. Call connect() first."
|
|
1004
993
|
);
|
|
1005
|
-
g(), await w.sendText(
|
|
994
|
+
g(), await w.sendText(L);
|
|
1006
995
|
}
|
|
1007
996
|
},
|
|
1008
997
|
stop: () => {
|
|
1009
|
-
g(), e("idle"),
|
|
998
|
+
g(), e("idle"), E();
|
|
1010
999
|
},
|
|
1011
1000
|
connect: async (c) => {
|
|
1012
1001
|
if (c && (m = { ...m, ...c }), !m.authToken?.trim())
|
|
@@ -1014,18 +1003,18 @@ function Dr(e, t = {}) {
|
|
|
1014
1003
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1015
1004
|
);
|
|
1016
1005
|
e("loading");
|
|
1017
|
-
const
|
|
1018
|
-
await
|
|
1019
|
-
const
|
|
1020
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1006
|
+
const v = U();
|
|
1007
|
+
await v.initDevices();
|
|
1008
|
+
const L = Ar(m);
|
|
1009
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", L);
|
|
1021
1010
|
try {
|
|
1022
|
-
await
|
|
1023
|
-
} catch (
|
|
1024
|
-
l = !1, e("error"),
|
|
1025
|
-
const
|
|
1026
|
-
throw new Error(`${
|
|
1011
|
+
await v.connect({ wsUrl: L });
|
|
1012
|
+
} catch (z) {
|
|
1013
|
+
l = !1, e("error"), E();
|
|
1014
|
+
const ne = z instanceof Error ? z.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
|
|
1015
|
+
throw new Error(`${ne} — ${L}`);
|
|
1027
1016
|
}
|
|
1028
|
-
l = !0, e("idle"),
|
|
1017
|
+
l = !0, e("idle"), E();
|
|
1029
1018
|
},
|
|
1030
1019
|
disconnect: async () => {
|
|
1031
1020
|
if (p.length = 0, d = !1, w)
|
|
@@ -1034,7 +1023,7 @@ function Dr(e, t = {}) {
|
|
|
1034
1023
|
} catch (c) {
|
|
1035
1024
|
console.error("[realtimeVoice] disconnect failed:", c);
|
|
1036
1025
|
}
|
|
1037
|
-
l = !1,
|
|
1026
|
+
l = !1, C();
|
|
1038
1027
|
},
|
|
1039
1028
|
isConnected: () => l,
|
|
1040
1029
|
unlockAudio: async () => {
|
|
@@ -1053,7 +1042,7 @@ function Dr(e, t = {}) {
|
|
|
1053
1042
|
subscribe: (c) => (u.add(c), () => u.delete(c))
|
|
1054
1043
|
};
|
|
1055
1044
|
}
|
|
1056
|
-
function
|
|
1045
|
+
function Dr(e, t, n) {
|
|
1057
1046
|
return {
|
|
1058
1047
|
width: e.crop?.source_width ?? t,
|
|
1059
1048
|
height: e.crop?.source_height ?? n
|
|
@@ -1068,7 +1057,7 @@ function Mr(e, t) {
|
|
|
1068
1057
|
height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
|
|
1069
1058
|
};
|
|
1070
1059
|
}
|
|
1071
|
-
function
|
|
1060
|
+
function Cr(e) {
|
|
1072
1061
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
1073
1062
|
}
|
|
1074
1063
|
async function Ye(e, t) {
|
|
@@ -1077,12 +1066,12 @@ async function Ye(e, t) {
|
|
|
1077
1066
|
const r = await n.arrayBuffer();
|
|
1078
1067
|
return zn(r, t);
|
|
1079
1068
|
}
|
|
1080
|
-
async function
|
|
1069
|
+
async function xr(e, t) {
|
|
1081
1070
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
1082
1071
|
const n = await Ye(e, t), r = new TextDecoder().decode(n);
|
|
1083
1072
|
return JSON.parse(r);
|
|
1084
1073
|
}
|
|
1085
|
-
async function
|
|
1074
|
+
async function Pr(e) {
|
|
1086
1075
|
const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
|
|
1087
1076
|
return new Promise((r, s) => {
|
|
1088
1077
|
const i = new Image();
|
|
@@ -1093,7 +1082,7 @@ async function Br(e) {
|
|
|
1093
1082
|
}, i.src = n;
|
|
1094
1083
|
});
|
|
1095
1084
|
}
|
|
1096
|
-
async function
|
|
1085
|
+
async function Br(e) {
|
|
1097
1086
|
const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
|
|
1098
1087
|
return new Promise((r, s) => {
|
|
1099
1088
|
const i = new Image();
|
|
@@ -1104,28 +1093,28 @@ async function Lr(e) {
|
|
|
1104
1093
|
}, i.src = n;
|
|
1105
1094
|
});
|
|
1106
1095
|
}
|
|
1107
|
-
function
|
|
1096
|
+
function Lr(e) {
|
|
1108
1097
|
const t = new Blob([e], { type: "video/mp4" });
|
|
1109
1098
|
return URL.createObjectURL(t);
|
|
1110
1099
|
}
|
|
1111
|
-
async function
|
|
1100
|
+
async function Or(e) {
|
|
1112
1101
|
const t = Zn();
|
|
1113
|
-
if (!
|
|
1102
|
+
if (!Ge()) return t;
|
|
1114
1103
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
1115
1104
|
const n = await Ye(t, e);
|
|
1116
|
-
return
|
|
1105
|
+
return Lr(n);
|
|
1117
1106
|
}
|
|
1118
|
-
function
|
|
1107
|
+
function ht(e, t) {
|
|
1119
1108
|
return `${e}/${t}_minus_sil.png`;
|
|
1120
1109
|
}
|
|
1121
|
-
const
|
|
1122
|
-
function
|
|
1110
|
+
const on = 5;
|
|
1111
|
+
function an(e) {
|
|
1123
1112
|
const t = e?.composite_threshold;
|
|
1124
1113
|
if (typeof t == "number" && t > 0) return t;
|
|
1125
1114
|
const n = e?.crop?.content_threshold;
|
|
1126
|
-
return typeof n == "number" && n > 0 ? n :
|
|
1115
|
+
return typeof n == "number" && n > 0 ? n : on;
|
|
1127
1116
|
}
|
|
1128
|
-
const
|
|
1117
|
+
const Gs = [
|
|
1129
1118
|
"aa",
|
|
1130
1119
|
"E",
|
|
1131
1120
|
"I",
|
|
@@ -1140,11 +1129,11 @@ const Ys = [
|
|
|
1140
1129
|
"RR",
|
|
1141
1130
|
"kk",
|
|
1142
1131
|
"nn"
|
|
1143
|
-
],
|
|
1132
|
+
], it = [
|
|
1144
1133
|
"t01_0.25",
|
|
1145
1134
|
"t02_0.50",
|
|
1146
1135
|
"t03_0.75"
|
|
1147
|
-
],
|
|
1136
|
+
], Fr = it.length, Ot = /* @__PURE__ */ new Set([
|
|
1148
1137
|
"aa__kk",
|
|
1149
1138
|
"aa__nn",
|
|
1150
1139
|
"aa__sil",
|
|
@@ -1251,75 +1240,75 @@ const Ys = [
|
|
|
1251
1240
|
"U__nn",
|
|
1252
1241
|
"U__sil"
|
|
1253
1242
|
]);
|
|
1254
|
-
function
|
|
1243
|
+
function Ft(e, t) {
|
|
1255
1244
|
return `${e}__${t}`;
|
|
1256
1245
|
}
|
|
1257
|
-
function
|
|
1246
|
+
function Ut(e, t) {
|
|
1258
1247
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1259
1248
|
}
|
|
1260
|
-
function
|
|
1249
|
+
function Ke(e) {
|
|
1261
1250
|
return `${e}_minus_sil.png`;
|
|
1262
1251
|
}
|
|
1263
|
-
function
|
|
1252
|
+
function Ur(e, t) {
|
|
1264
1253
|
if (t.has(e)) return e;
|
|
1265
1254
|
const n = /^pairs\/([^/]+)\//.exec(e);
|
|
1266
1255
|
if (!n) return null;
|
|
1267
1256
|
const r = n[1].split("__")[1];
|
|
1268
1257
|
if (!r || r === "sil") return null;
|
|
1269
|
-
const s =
|
|
1258
|
+
const s = Ke(r);
|
|
1270
1259
|
return t.has(s) ? s : null;
|
|
1271
1260
|
}
|
|
1272
|
-
function
|
|
1261
|
+
function cn(e, t) {
|
|
1273
1262
|
return e.filter((n) => t.has(n));
|
|
1274
1263
|
}
|
|
1275
|
-
function
|
|
1276
|
-
const r =
|
|
1277
|
-
return
|
|
1264
|
+
function Nr(e, t, n) {
|
|
1265
|
+
const r = mt(e, t);
|
|
1266
|
+
return cn(r, n).length > 0;
|
|
1278
1267
|
}
|
|
1279
|
-
function
|
|
1268
|
+
function mt(e, t) {
|
|
1280
1269
|
if (e === t) return [];
|
|
1281
|
-
const n = [], r =
|
|
1282
|
-
if (
|
|
1283
|
-
for (const i of
|
|
1284
|
-
n.push(
|
|
1270
|
+
const n = [], r = Ft(e, t);
|
|
1271
|
+
if (Ot.has(r)) {
|
|
1272
|
+
for (const i of it)
|
|
1273
|
+
n.push(Ut(r, i));
|
|
1285
1274
|
return n;
|
|
1286
1275
|
}
|
|
1287
|
-
const s =
|
|
1288
|
-
if (
|
|
1289
|
-
for (let i =
|
|
1290
|
-
n.push(
|
|
1276
|
+
const s = Ft(t, e);
|
|
1277
|
+
if (Ot.has(s)) {
|
|
1278
|
+
for (let i = Fr - 1; i >= 0; i--)
|
|
1279
|
+
n.push(Ut(s, it[i]));
|
|
1291
1280
|
return n;
|
|
1292
1281
|
}
|
|
1293
1282
|
return [];
|
|
1294
1283
|
}
|
|
1295
|
-
function
|
|
1284
|
+
function Vr(e) {
|
|
1296
1285
|
return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
|
|
1297
1286
|
}
|
|
1298
|
-
function
|
|
1299
|
-
return
|
|
1287
|
+
function $r(e, t) {
|
|
1288
|
+
return Vr(t).map((r) => e[r]).filter((r) => r != null);
|
|
1300
1289
|
}
|
|
1301
|
-
function
|
|
1290
|
+
function Wr(e, t, n, r) {
|
|
1302
1291
|
if (r <= 0) return 0;
|
|
1303
1292
|
const i = Math.max(1, n - t) / r, o = e - t, a = Math.floor(o / i);
|
|
1304
1293
|
return Math.min(r - 1, Math.max(0, a));
|
|
1305
1294
|
}
|
|
1306
|
-
function
|
|
1295
|
+
function Hr(e, t, n) {
|
|
1307
1296
|
if (!n) return `${e}/${t}`;
|
|
1308
1297
|
const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
|
|
1309
1298
|
return `${e}/${s}.bin`;
|
|
1310
1299
|
}
|
|
1311
|
-
const
|
|
1300
|
+
const qr = [0.32, 0.24, 0.16, 0.08, 0], Kr = qr.map(
|
|
1312
1301
|
(e) => `eyes_${e.toFixed(2)}`
|
|
1313
|
-
),
|
|
1302
|
+
), jr = [
|
|
1314
1303
|
"eyes_0.32",
|
|
1315
1304
|
"eyes_0.16",
|
|
1316
1305
|
"eyes_0.00"
|
|
1317
|
-
],
|
|
1306
|
+
], Gr = [
|
|
1318
1307
|
"eyes_0.32",
|
|
1319
1308
|
"eyes_0.16",
|
|
1320
1309
|
"eyes_0.08",
|
|
1321
1310
|
"eyes_0.00"
|
|
1322
|
-
],
|
|
1311
|
+
], Nt = 2, zr = -30, ot = 20, Yr = {
|
|
1323
1312
|
fear: -30,
|
|
1324
1313
|
anger: -20,
|
|
1325
1314
|
sad: -10,
|
|
@@ -1328,24 +1317,24 @@ const Kr = [0.32, 0.24, 0.16, 0.08, 0], jr = Kr.map(
|
|
|
1328
1317
|
happy: 0,
|
|
1329
1318
|
disgust: 20
|
|
1330
1319
|
};
|
|
1331
|
-
function
|
|
1320
|
+
function wt(e) {
|
|
1332
1321
|
return `brow_${e}`;
|
|
1333
1322
|
}
|
|
1334
|
-
function
|
|
1335
|
-
return
|
|
1323
|
+
function gt(e) {
|
|
1324
|
+
return Yr[e];
|
|
1336
1325
|
}
|
|
1337
|
-
function
|
|
1338
|
-
return Math.max(
|
|
1326
|
+
function ye(e) {
|
|
1327
|
+
return Math.max(zr, Math.min(ot, e));
|
|
1339
1328
|
}
|
|
1340
|
-
function
|
|
1329
|
+
function Jr(e, t) {
|
|
1341
1330
|
if (e === t) return [];
|
|
1342
|
-
const n = e < t ?
|
|
1331
|
+
const n = e < t ? Nt : -Nt, r = [];
|
|
1343
1332
|
let s = e;
|
|
1344
1333
|
for (; s !== t; )
|
|
1345
1334
|
s += n, r.push(s);
|
|
1346
1335
|
return r;
|
|
1347
1336
|
}
|
|
1348
|
-
const
|
|
1337
|
+
const Qr = {
|
|
1349
1338
|
fear: "fear",
|
|
1350
1339
|
afraid: "fear",
|
|
1351
1340
|
anxiety: "fear",
|
|
@@ -1368,63 +1357,63 @@ const Xr = {
|
|
|
1368
1357
|
disgust: "disgust",
|
|
1369
1358
|
disgusted: "disgust"
|
|
1370
1359
|
};
|
|
1371
|
-
function
|
|
1360
|
+
function ve(e, t = "neutral") {
|
|
1372
1361
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1373
|
-
return n ?
|
|
1362
|
+
return n ? Qr[n] ?? t : t;
|
|
1374
1363
|
}
|
|
1375
|
-
function
|
|
1376
|
-
return e === 0 ? null :
|
|
1364
|
+
function un(e) {
|
|
1365
|
+
return e === 0 ? null : ht(wt(e), "eyes_standard");
|
|
1377
1366
|
}
|
|
1378
|
-
function
|
|
1379
|
-
return
|
|
1367
|
+
function ln(e) {
|
|
1368
|
+
return un(gt(e));
|
|
1380
1369
|
}
|
|
1381
|
-
function
|
|
1382
|
-
const n = gt(
|
|
1383
|
-
return !t || t === "eyes_standard" ?
|
|
1370
|
+
function Vt(e, t) {
|
|
1371
|
+
const n = wt(gt(e));
|
|
1372
|
+
return !t || t === "eyes_standard" ? ln(e) : e === "neutral" && t === "eyes_standard" ? null : ht(n, t);
|
|
1384
1373
|
}
|
|
1385
|
-
function
|
|
1374
|
+
function Xr(e, t) {
|
|
1386
1375
|
const n = [];
|
|
1387
1376
|
for (const r of t)
|
|
1388
|
-
n.push(
|
|
1377
|
+
n.push(Vt(e, r));
|
|
1389
1378
|
for (let r = t.length - 2; r >= 0; r--)
|
|
1390
|
-
n.push(
|
|
1391
|
-
return n.push(
|
|
1379
|
+
n.push(Vt(e, t[r]));
|
|
1380
|
+
return n.push(ln(e)), n;
|
|
1392
1381
|
}
|
|
1393
|
-
function
|
|
1394
|
-
return e === 0 ? null :
|
|
1382
|
+
function Zr(e) {
|
|
1383
|
+
return e === 0 ? null : ht(wt(e), "eyes_standard");
|
|
1395
1384
|
}
|
|
1396
|
-
function
|
|
1397
|
-
return
|
|
1385
|
+
function es(e, t) {
|
|
1386
|
+
return Jr(e, t).map(Zr).filter((n) => n != null);
|
|
1398
1387
|
}
|
|
1399
|
-
const
|
|
1400
|
-
function
|
|
1388
|
+
const ts = 6;
|
|
1389
|
+
function ns(e, t) {
|
|
1401
1390
|
for (const n of e)
|
|
1402
1391
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
1403
1392
|
return n;
|
|
1404
1393
|
return null;
|
|
1405
1394
|
}
|
|
1406
|
-
function
|
|
1407
|
-
const t =
|
|
1408
|
-
return t >=
|
|
1395
|
+
function rs(e) {
|
|
1396
|
+
const t = ye(e);
|
|
1397
|
+
return t >= ot ? ot : ye(t + ts);
|
|
1409
1398
|
}
|
|
1410
|
-
function
|
|
1411
|
-
const r =
|
|
1412
|
-
return
|
|
1399
|
+
function ss(e, t, n) {
|
|
1400
|
+
const r = ye(n);
|
|
1401
|
+
return ns(t, e)?.emphasis ? rs(r) : r;
|
|
1413
1402
|
}
|
|
1414
|
-
function
|
|
1403
|
+
function $t(e) {
|
|
1415
1404
|
if (!e) return 0;
|
|
1416
1405
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1417
1406
|
if (!t?.[1]) return null;
|
|
1418
1407
|
const n = Number.parseInt(t[1], 10);
|
|
1419
|
-
return Number.isFinite(n) ?
|
|
1408
|
+
return Number.isFinite(n) ? ye(n) : null;
|
|
1420
1409
|
}
|
|
1421
|
-
function
|
|
1410
|
+
function Fe(e, t) {
|
|
1422
1411
|
return e + Math.random() * (t - e);
|
|
1423
1412
|
}
|
|
1424
|
-
function
|
|
1425
|
-
return
|
|
1413
|
+
function He() {
|
|
1414
|
+
return Fe(14, 32);
|
|
1426
1415
|
}
|
|
1427
|
-
function
|
|
1416
|
+
function is(e = {}) {
|
|
1428
1417
|
const {
|
|
1429
1418
|
initialDelayMs: t = 800 + Math.random() * 1200,
|
|
1430
1419
|
intervalMinMs: n = 2200,
|
|
@@ -1436,130 +1425,130 @@ function os(e = {}) {
|
|
|
1436
1425
|
postEmotionChangeDelayMs: f = 380,
|
|
1437
1426
|
minDwellMs: l = 550
|
|
1438
1427
|
} = e;
|
|
1439
|
-
let w = "neutral", _ = "neutral", m = 0,
|
|
1428
|
+
let w = "neutral", _ = "neutral", m = 0, k = 0, S = 0, u = {
|
|
1440
1429
|
kind: "idle",
|
|
1441
1430
|
nextBlinkAt: performance.now() + t
|
|
1442
1431
|
}, p = null, d = "__eyes_open__|neutral|brow:0";
|
|
1443
1432
|
function I(y = w) {
|
|
1444
|
-
d = `${p ?? "__eyes_open__"}|${y}|brow:${
|
|
1433
|
+
d = `${p ?? "__eyes_open__"}|${y}|brow:${k}`;
|
|
1445
1434
|
}
|
|
1446
|
-
function
|
|
1435
|
+
function E(y, T = w) {
|
|
1447
1436
|
p = y;
|
|
1448
|
-
const g =
|
|
1449
|
-
g != null ?
|
|
1437
|
+
const g = $t(y);
|
|
1438
|
+
g != null ? k = g : y == null && (k = 0), I(T);
|
|
1450
1439
|
}
|
|
1451
1440
|
function R(y) {
|
|
1452
|
-
return
|
|
1441
|
+
return un(y);
|
|
1453
1442
|
}
|
|
1454
|
-
function
|
|
1455
|
-
const
|
|
1456
|
-
if (m = b,
|
|
1457
|
-
|
|
1443
|
+
function H(y, T, g) {
|
|
1444
|
+
const C = ye(T), b = ye(g);
|
|
1445
|
+
if (m = b, C === b) {
|
|
1446
|
+
E(R(b));
|
|
1458
1447
|
return;
|
|
1459
1448
|
}
|
|
1460
1449
|
const D = [
|
|
1461
|
-
...
|
|
1450
|
+
...es(C, b),
|
|
1462
1451
|
R(b)
|
|
1463
1452
|
];
|
|
1464
1453
|
u = {
|
|
1465
1454
|
kind: "browBlend",
|
|
1466
1455
|
paths: D,
|
|
1467
1456
|
index: 0,
|
|
1468
|
-
holdUntil: y +
|
|
1457
|
+
holdUntil: y + He(),
|
|
1469
1458
|
targetBrow: b
|
|
1470
|
-
},
|
|
1459
|
+
}, E(D[0] ?? null);
|
|
1471
1460
|
}
|
|
1472
|
-
function
|
|
1461
|
+
function V(y, T) {
|
|
1473
1462
|
u = {
|
|
1474
1463
|
kind: "idle",
|
|
1475
|
-
nextBlinkAt: y +
|
|
1476
|
-
}, _ = T,
|
|
1464
|
+
nextBlinkAt: y + Fe(n, r)
|
|
1465
|
+
}, _ = T, E(R(m), T);
|
|
1477
1466
|
}
|
|
1478
1467
|
function $(y, T, g) {
|
|
1479
|
-
const
|
|
1468
|
+
const C = g ? jr : Math.random() < a ? Kr : Gr;
|
|
1480
1469
|
u = {
|
|
1481
1470
|
kind: "playing",
|
|
1482
|
-
paths:
|
|
1471
|
+
paths: Xr(T, C),
|
|
1483
1472
|
index: 0,
|
|
1484
|
-
holdUntil: y +
|
|
1473
|
+
holdUntil: y + He(),
|
|
1485
1474
|
after: "idle",
|
|
1486
1475
|
blinkEmotion: T
|
|
1487
|
-
}, _ = T,
|
|
1476
|
+
}, _ = T, E(u.paths[0] ?? null, T);
|
|
1488
1477
|
}
|
|
1489
|
-
function
|
|
1478
|
+
function j(y) {
|
|
1490
1479
|
if (u.kind === "browBlend") {
|
|
1491
1480
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1492
|
-
u.index += 1, u.holdUntil = y +
|
|
1481
|
+
u.index += 1, u.holdUntil = y + He();
|
|
1493
1482
|
const T = u.paths[u.index] ?? null;
|
|
1494
|
-
|
|
1483
|
+
E(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (k = u.targetBrow, m = u.targetBrow, E(R(u.targetBrow)), u = {
|
|
1495
1484
|
kind: "idle",
|
|
1496
1485
|
nextBlinkAt: y + f
|
|
1497
1486
|
});
|
|
1498
1487
|
return;
|
|
1499
1488
|
}
|
|
1500
1489
|
if (u.kind === "idle") {
|
|
1501
|
-
|
|
1490
|
+
E(R(m), _), y >= u.nextBlinkAt && $(y, _, !1);
|
|
1502
1491
|
return;
|
|
1503
1492
|
}
|
|
1504
1493
|
if (u.kind === "doublePause") {
|
|
1505
|
-
|
|
1494
|
+
E(R(m), u.blinkEmotion), y >= u.resumeAt && $(y, u.blinkEmotion, !0);
|
|
1506
1495
|
return;
|
|
1507
1496
|
}
|
|
1508
1497
|
if (u.kind === "playing") {
|
|
1509
1498
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1510
|
-
u.index += 1, u.holdUntil = y +
|
|
1511
|
-
if (
|
|
1499
|
+
u.index += 1, u.holdUntil = y + He();
|
|
1500
|
+
if (E(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
|
|
1512
1501
|
if (u.after === "resumeIdle") {
|
|
1513
|
-
|
|
1502
|
+
V(y + f, w);
|
|
1514
1503
|
return;
|
|
1515
1504
|
}
|
|
1516
1505
|
if (u.after === "doublePause") {
|
|
1517
1506
|
u = {
|
|
1518
1507
|
kind: "doublePause",
|
|
1519
|
-
resumeAt: y +
|
|
1508
|
+
resumeAt: y + Fe(i, o),
|
|
1520
1509
|
blinkEmotion: u.blinkEmotion
|
|
1521
|
-
},
|
|
1510
|
+
}, E(R(m), u.blinkEmotion);
|
|
1522
1511
|
return;
|
|
1523
1512
|
}
|
|
1524
1513
|
if (u.after === "idle" && Math.random() < s) {
|
|
1525
1514
|
u = {
|
|
1526
1515
|
kind: "doublePause",
|
|
1527
|
-
resumeAt: y +
|
|
1516
|
+
resumeAt: y + Fe(i, o),
|
|
1528
1517
|
blinkEmotion: u.blinkEmotion
|
|
1529
|
-
},
|
|
1518
|
+
}, E(R(m), u.blinkEmotion);
|
|
1530
1519
|
return;
|
|
1531
1520
|
}
|
|
1532
|
-
|
|
1521
|
+
V(y, u.blinkEmotion);
|
|
1533
1522
|
}
|
|
1534
1523
|
}
|
|
1535
1524
|
}
|
|
1536
1525
|
return {
|
|
1537
|
-
advance:
|
|
1526
|
+
advance: j,
|
|
1538
1527
|
setTargetEmotion(y) {
|
|
1539
|
-
const T =
|
|
1528
|
+
const T = ve(y, w);
|
|
1540
1529
|
if (T === w) return;
|
|
1541
1530
|
const g = performance.now();
|
|
1542
|
-
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g -
|
|
1531
|
+
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g - S < l || (w = T, _ = T, S = g);
|
|
1543
1532
|
},
|
|
1544
1533
|
setTargetEyebrow(y) {
|
|
1545
|
-
const T =
|
|
1534
|
+
const T = ye(y);
|
|
1546
1535
|
if (T === m && u.kind !== "browBlend") return;
|
|
1547
|
-
const g = performance.now(),
|
|
1548
|
-
m = T, !(T ===
|
|
1536
|
+
const g = performance.now(), C = u.kind === "browBlend" ? $t(p) ?? k : k;
|
|
1537
|
+
m = T, !(T === C && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || H(g, C, T));
|
|
1549
1538
|
},
|
|
1550
1539
|
getTargetEmotion: () => w,
|
|
1551
1540
|
getTargetEyebrow: () => m,
|
|
1552
1541
|
getExpressionPath: () => p,
|
|
1553
1542
|
getDrawKey: () => d,
|
|
1554
1543
|
reset() {
|
|
1555
|
-
w = "neutral", _ = "neutral", m = 0,
|
|
1556
|
-
performance.now() +
|
|
1544
|
+
w = "neutral", _ = "neutral", m = 0, k = 0, S = 0, V(
|
|
1545
|
+
performance.now() + Fe(n, r),
|
|
1557
1546
|
"neutral"
|
|
1558
1547
|
);
|
|
1559
1548
|
}
|
|
1560
1549
|
};
|
|
1561
1550
|
}
|
|
1562
|
-
function
|
|
1551
|
+
function os() {
|
|
1563
1552
|
const e = document.createElement("video");
|
|
1564
1553
|
e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
|
|
1565
1554
|
let t = !1, n = null, r = "";
|
|
@@ -1602,17 +1591,17 @@ function as() {
|
|
|
1602
1591
|
}
|
|
1603
1592
|
};
|
|
1604
1593
|
}
|
|
1605
|
-
const
|
|
1606
|
-
function
|
|
1594
|
+
const as = 50, fn = 400;
|
|
1595
|
+
function cs(e, t, n) {
|
|
1607
1596
|
return e.filter((r) => {
|
|
1608
1597
|
const s = r.queueIndex ?? -1;
|
|
1609
1598
|
return s >= t && s <= n;
|
|
1610
1599
|
});
|
|
1611
1600
|
}
|
|
1612
|
-
function
|
|
1601
|
+
function us(e, t) {
|
|
1613
1602
|
const n = [];
|
|
1614
1603
|
for (const r of e) {
|
|
1615
|
-
const s =
|
|
1604
|
+
const s = cs(
|
|
1616
1605
|
t,
|
|
1617
1606
|
r.start_word,
|
|
1618
1607
|
r.end_word
|
|
@@ -1621,30 +1610,30 @@ function ls(e, t) {
|
|
|
1621
1610
|
const i = s[0], o = s[s.length - 1];
|
|
1622
1611
|
n.push({
|
|
1623
1612
|
sentence: r,
|
|
1624
|
-
startMs: Math.max(0, i.wtime -
|
|
1625
|
-
endMs: o.wtime + o.wduration +
|
|
1613
|
+
startMs: Math.max(0, i.wtime - as),
|
|
1614
|
+
endMs: o.wtime + o.wduration + fn
|
|
1626
1615
|
});
|
|
1627
1616
|
}
|
|
1628
1617
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
1629
1618
|
}
|
|
1630
|
-
function
|
|
1631
|
-
const s =
|
|
1619
|
+
function ls(e, t, n, r = "neutral") {
|
|
1620
|
+
const s = ve(r);
|
|
1632
1621
|
if (t.length === 0) return s;
|
|
1633
1622
|
if (n.length === 0 || e < n[0].wtime)
|
|
1634
|
-
return
|
|
1635
|
-
const i =
|
|
1623
|
+
return ve(t[0]?.emotion, s);
|
|
1624
|
+
const i = us(t, n);
|
|
1636
1625
|
let o = null;
|
|
1637
1626
|
for (const l of i)
|
|
1638
1627
|
e >= l.startMs && e <= l.endMs && (o = l);
|
|
1639
1628
|
if (o)
|
|
1640
|
-
return
|
|
1629
|
+
return ve(o.sentence.emotion, s);
|
|
1641
1630
|
const a = n[n.length - 1], f = a.wtime + a.wduration;
|
|
1642
|
-
return e > f +
|
|
1631
|
+
return e > f + fn ? ve(
|
|
1643
1632
|
t[t.length - 1]?.emotion,
|
|
1644
1633
|
s
|
|
1645
1634
|
) : s;
|
|
1646
1635
|
}
|
|
1647
|
-
function
|
|
1636
|
+
function dn(e, t, n, r, s = on) {
|
|
1648
1637
|
const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
|
|
1649
1638
|
o.drawImage(e, 0, 0, n, r);
|
|
1650
1639
|
const a = o.getImageData(0, 0, n, r), f = o.createImageData(n, r);
|
|
@@ -1653,45 +1642,45 @@ function hn(e, t, n, r, s = an) {
|
|
|
1653
1642
|
for (const _ of t) {
|
|
1654
1643
|
w.clearRect(0, 0, n, r), w.drawImage(_, 0, 0, n, r);
|
|
1655
1644
|
const m = w.getImageData(0, 0, n, r);
|
|
1656
|
-
for (let
|
|
1657
|
-
const
|
|
1658
|
-
Math.max(
|
|
1645
|
+
for (let k = 0; k < f.data.length; k += 4) {
|
|
1646
|
+
const S = m.data[k], u = m.data[k + 1], p = m.data[k + 2];
|
|
1647
|
+
Math.max(S, u, p) > s && (f.data[k] = S, f.data[k + 1] = u, f.data[k + 2] = p, f.data[k + 3] = 255);
|
|
1659
1648
|
}
|
|
1660
1649
|
}
|
|
1661
1650
|
return o.putImageData(f, 0, 0), i;
|
|
1662
1651
|
}
|
|
1663
|
-
let
|
|
1664
|
-
const
|
|
1665
|
-
function
|
|
1666
|
-
|
|
1652
|
+
let pe = null, Ue = null;
|
|
1653
|
+
const je = /* @__PURE__ */ new Map();
|
|
1654
|
+
function fs() {
|
|
1655
|
+
pe = null, Ue = null, je.clear();
|
|
1667
1656
|
}
|
|
1668
|
-
Xn(
|
|
1669
|
-
function
|
|
1670
|
-
return e ??
|
|
1657
|
+
Xn(fs);
|
|
1658
|
+
function ds(e) {
|
|
1659
|
+
return e ?? Ue ?? void 0;
|
|
1671
1660
|
}
|
|
1672
|
-
function
|
|
1661
|
+
function _t(e) {
|
|
1673
1662
|
return new Promise((t, n) => {
|
|
1674
1663
|
const r = new Image();
|
|
1675
1664
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
1676
1665
|
});
|
|
1677
1666
|
}
|
|
1678
|
-
async function
|
|
1679
|
-
return
|
|
1680
|
-
await Ye(
|
|
1681
|
-
) :
|
|
1667
|
+
async function hs(e) {
|
|
1668
|
+
return Ge() ? Br(
|
|
1669
|
+
await Ye(Ct(), e ?? "")
|
|
1670
|
+
) : _t(Ct());
|
|
1682
1671
|
}
|
|
1683
|
-
async function
|
|
1684
|
-
const s = n ? await
|
|
1672
|
+
async function Wt(e, t, n, r) {
|
|
1673
|
+
const s = n ? await xr(e, r) : await fetch(e).then((l) => {
|
|
1685
1674
|
if (!l.ok) throw new Error(`Failed to load ${e}`);
|
|
1686
1675
|
return l.json();
|
|
1687
1676
|
}), i = s.sheets?.[0];
|
|
1688
1677
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
1689
|
-
const o = n ? await
|
|
1678
|
+
const o = n ? await Pr(
|
|
1690
1679
|
await Ye(
|
|
1691
|
-
|
|
1680
|
+
Hr(t, i.path, n),
|
|
1692
1681
|
r ?? ""
|
|
1693
1682
|
)
|
|
1694
|
-
) : await
|
|
1683
|
+
) : await _t(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
|
|
1695
1684
|
for (const l of s.cells ?? [])
|
|
1696
1685
|
l.path && a.set(l.path, l);
|
|
1697
1686
|
const f = /* @__PURE__ */ new Map();
|
|
@@ -1699,21 +1688,21 @@ async function Ht(e, t, n, r) {
|
|
|
1699
1688
|
f.set(l.index, l);
|
|
1700
1689
|
return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: f, diffBase: t };
|
|
1701
1690
|
}
|
|
1702
|
-
async function
|
|
1703
|
-
const t =
|
|
1691
|
+
async function at(e) {
|
|
1692
|
+
const t = ds(e), n = Ge();
|
|
1704
1693
|
if (n && !t)
|
|
1705
1694
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
1706
|
-
if (
|
|
1707
|
-
const i = await
|
|
1695
|
+
if (pe && (!n || Ue === (t ?? null))) {
|
|
1696
|
+
const i = await pe;
|
|
1708
1697
|
return {
|
|
1709
|
-
...
|
|
1698
|
+
...Ne(i),
|
|
1710
1699
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
1711
1700
|
};
|
|
1712
1701
|
}
|
|
1713
|
-
|
|
1702
|
+
Ue = t ?? null, je.clear();
|
|
1714
1703
|
const r = er();
|
|
1715
|
-
|
|
1716
|
-
const i = await
|
|
1704
|
+
pe = (async () => {
|
|
1705
|
+
const i = await hs(t), o = await Wt(
|
|
1717
1706
|
tr(),
|
|
1718
1707
|
r,
|
|
1719
1708
|
n,
|
|
@@ -1721,7 +1710,7 @@ async function ut(e) {
|
|
|
1721
1710
|
);
|
|
1722
1711
|
let a = null;
|
|
1723
1712
|
try {
|
|
1724
|
-
a = await
|
|
1713
|
+
a = await Wt(
|
|
1725
1714
|
nr(),
|
|
1726
1715
|
r,
|
|
1727
1716
|
n,
|
|
@@ -1732,90 +1721,90 @@ async function ut(e) {
|
|
|
1732
1721
|
}
|
|
1733
1722
|
return { sil: i, viseme: o, expression: a };
|
|
1734
1723
|
})();
|
|
1735
|
-
const s = await
|
|
1736
|
-
return { ...
|
|
1724
|
+
const s = await pe;
|
|
1725
|
+
return { ...Ne(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
1737
1726
|
}
|
|
1738
|
-
async function
|
|
1739
|
-
if (await
|
|
1740
|
-
return
|
|
1727
|
+
async function hn(e) {
|
|
1728
|
+
if (await at(e), !pe) throw new Error("Assets not loaded");
|
|
1729
|
+
return pe;
|
|
1741
1730
|
}
|
|
1742
|
-
function
|
|
1743
|
-
return
|
|
1731
|
+
function Ne(e) {
|
|
1732
|
+
return Dr(
|
|
1744
1733
|
e.viseme.atlasMeta,
|
|
1745
1734
|
e.sil.naturalWidth,
|
|
1746
1735
|
e.sil.naturalHeight
|
|
1747
1736
|
);
|
|
1748
1737
|
}
|
|
1749
|
-
function
|
|
1738
|
+
function ms(e, t) {
|
|
1750
1739
|
const n = document.createElement("canvas");
|
|
1751
1740
|
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;
|
|
1752
1741
|
}
|
|
1753
|
-
async function
|
|
1754
|
-
const r = `${t.diffBase}::${n}`, s =
|
|
1742
|
+
async function Ht(e, t, n) {
|
|
1743
|
+
const r = `${t.diffBase}::${n}`, s = je.get(r);
|
|
1755
1744
|
if (s) return s;
|
|
1756
1745
|
const i = (async () => {
|
|
1757
1746
|
const o = t.cellByPath.get(n);
|
|
1758
1747
|
if (!o) throw new Error(`No atlas cell for path: ${n}`);
|
|
1759
|
-
const a = Mr(t.atlasMeta, o), f =
|
|
1760
|
-
if (
|
|
1761
|
-
const _ =
|
|
1748
|
+
const a = Mr(t.atlasMeta, o), f = Ne(e);
|
|
1749
|
+
if (Cr(o)) {
|
|
1750
|
+
const _ = ms(t, o), m = document.createElement("canvas");
|
|
1762
1751
|
m.width = f.width, m.height = f.height;
|
|
1763
|
-
const
|
|
1764
|
-
return
|
|
1752
|
+
const k = m.getContext("2d");
|
|
1753
|
+
return k.fillStyle = "#000", k.fillRect(0, 0, f.width, f.height), k.drawImage(_, a.x, a.y), m;
|
|
1765
1754
|
}
|
|
1766
|
-
const l = `${t.diffBase}/${n}`, w = await
|
|
1755
|
+
const l = `${t.diffBase}/${n}`, w = await _t(l);
|
|
1767
1756
|
if (w.naturalWidth === f.width && w.naturalHeight === f.height)
|
|
1768
1757
|
return w;
|
|
1769
1758
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
1770
1759
|
})();
|
|
1771
|
-
return
|
|
1760
|
+
return je.set(r, i), i;
|
|
1772
1761
|
}
|
|
1773
|
-
async function
|
|
1762
|
+
async function qt(e, t, n, r, s, i) {
|
|
1774
1763
|
if (s) {
|
|
1775
|
-
const { width:
|
|
1764
|
+
const { width: k, height: S } = s;
|
|
1776
1765
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
1777
1766
|
return;
|
|
1778
1767
|
const u = document.createElement("canvas");
|
|
1779
|
-
u.width =
|
|
1768
|
+
u.width = k, u.height = S;
|
|
1780
1769
|
const p = u.getContext("2d");
|
|
1781
|
-
if (p.clearRect(0, 0,
|
|
1782
|
-
(e.width !==
|
|
1770
|
+
if (p.clearRect(0, 0, k, S), p.drawImage(t, 0, 0, k, S), i && !i()) return;
|
|
1771
|
+
(e.width !== k || e.height !== S) && (e.width = k, e.height = S);
|
|
1783
1772
|
const d = e.getContext("2d");
|
|
1784
|
-
d.clearRect(0, 0,
|
|
1773
|
+
d.clearRect(0, 0, k, S), d.drawImage(u, 0, 0);
|
|
1785
1774
|
return;
|
|
1786
1775
|
}
|
|
1787
|
-
const o = await
|
|
1776
|
+
const o = await hn(), a = an(o.viseme.atlasMeta), { width: f, height: l } = Ne(o);
|
|
1788
1777
|
(e.width !== f || e.height !== l) && (e.width = f, e.height = l);
|
|
1789
1778
|
const w = [], _ = e.getContext("2d");
|
|
1790
1779
|
if (_.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
1791
|
-
const
|
|
1792
|
-
_.drawImage(
|
|
1780
|
+
const k = o.sil;
|
|
1781
|
+
_.drawImage(k, 0, 0, f, l);
|
|
1793
1782
|
return;
|
|
1794
1783
|
}
|
|
1795
1784
|
if (w.length === 0) {
|
|
1796
1785
|
_.drawImage(t, 0, 0, f, l);
|
|
1797
1786
|
return;
|
|
1798
1787
|
}
|
|
1799
|
-
const m =
|
|
1788
|
+
const m = dn(t, w, f, l, a);
|
|
1800
1789
|
_.drawImage(m, 0, 0);
|
|
1801
1790
|
}
|
|
1802
|
-
async function
|
|
1803
|
-
const r = await
|
|
1791
|
+
async function ct(e, t, n) {
|
|
1792
|
+
const r = await hn(Ue ?? void 0), s = an(r.viseme.atlasMeta), { width: i, height: o } = Ne(r);
|
|
1804
1793
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
1805
1794
|
const a = [];
|
|
1806
1795
|
if (t.mouthPath) {
|
|
1807
|
-
const w = new Set(r.viseme.cellByPath.keys()), _ =
|
|
1808
|
-
_ && a.push(await
|
|
1796
|
+
const w = new Set(r.viseme.cellByPath.keys()), _ = Ur(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
|
|
1797
|
+
_ && a.push(await Ht(r, r.viseme, _));
|
|
1809
1798
|
}
|
|
1810
1799
|
t.expressionPath && r.expression && a.push(
|
|
1811
|
-
await
|
|
1800
|
+
await Ht(r, r.expression, t.expressionPath)
|
|
1812
1801
|
);
|
|
1813
1802
|
const f = e.getContext("2d");
|
|
1814
1803
|
if (f.clearRect(0, 0, i, o), a.length === 0) {
|
|
1815
1804
|
f.drawImage(r.sil, 0, 0, i, o);
|
|
1816
1805
|
return;
|
|
1817
1806
|
}
|
|
1818
|
-
const l =
|
|
1807
|
+
const l = dn(
|
|
1819
1808
|
r.sil,
|
|
1820
1809
|
a,
|
|
1821
1810
|
i,
|
|
@@ -1824,78 +1813,75 @@ async function lt(e, t, n) {
|
|
|
1824
1813
|
);
|
|
1825
1814
|
f.drawImage(l, 0, 0);
|
|
1826
1815
|
}
|
|
1827
|
-
async function
|
|
1828
|
-
await
|
|
1816
|
+
async function ws(e) {
|
|
1817
|
+
await ct(e, { mouthPath: null, expressionPath: null });
|
|
1829
1818
|
}
|
|
1830
|
-
function
|
|
1819
|
+
function gs(e) {
|
|
1831
1820
|
const t = /* @__PURE__ */ new Map();
|
|
1832
1821
|
for (const n of e)
|
|
1833
1822
|
t.has(n.vtime) || t.set(n.vtime, n);
|
|
1834
1823
|
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
1835
1824
|
}
|
|
1836
|
-
function
|
|
1837
|
-
const t =
|
|
1825
|
+
function _s(e) {
|
|
1826
|
+
const t = gs(e), n = [];
|
|
1838
1827
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1839
1828
|
const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
|
|
1840
1829
|
s === i || a <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: a });
|
|
1841
1830
|
}
|
|
1842
1831
|
return n;
|
|
1843
1832
|
}
|
|
1844
|
-
function
|
|
1833
|
+
function ps(e, t) {
|
|
1845
1834
|
let n = null;
|
|
1846
1835
|
for (const r of e)
|
|
1847
1836
|
t >= r.fromVtime && t < r.toVtime && (n = r);
|
|
1848
1837
|
return n;
|
|
1849
1838
|
}
|
|
1850
|
-
function
|
|
1839
|
+
function ys(e, t) {
|
|
1851
1840
|
return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
|
|
1852
1841
|
}
|
|
1853
|
-
const
|
|
1854
|
-
function
|
|
1842
|
+
const mn = 400, Es = 200, Ss = 600, wn = "__sil__";
|
|
1843
|
+
function ks(e) {
|
|
1844
|
+
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === wn : !1;
|
|
1845
|
+
}
|
|
1846
|
+
function vs() {
|
|
1855
1847
|
return { lastDrawnKey: "" };
|
|
1856
1848
|
}
|
|
1857
|
-
function
|
|
1849
|
+
function fe(e) {
|
|
1858
1850
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
1859
1851
|
}
|
|
1860
|
-
function
|
|
1852
|
+
function bs(e, t) {
|
|
1861
1853
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
1862
1854
|
return t.transitionCache.transitions;
|
|
1863
|
-
const n =
|
|
1855
|
+
const n = _s(e);
|
|
1864
1856
|
return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
|
|
1865
1857
|
}
|
|
1866
|
-
function
|
|
1867
|
-
let
|
|
1868
|
-
for (const
|
|
1869
|
-
|
|
1870
|
-
return
|
|
1871
|
-
}
|
|
1872
|
-
function Is(e, t, n, r = 120) {
|
|
1873
|
-
if (n !== "sil")
|
|
1874
|
-
return n;
|
|
1875
|
-
const s = Sr(e, t, r);
|
|
1876
|
-
return s !== "sil" ? s : As(e, t);
|
|
1858
|
+
function Ts(e) {
|
|
1859
|
+
let t = "sil";
|
|
1860
|
+
for (const n of e)
|
|
1861
|
+
n.viseme !== "sil" && (t = n.viseme);
|
|
1862
|
+
return t;
|
|
1877
1863
|
}
|
|
1878
|
-
function
|
|
1879
|
-
return e === "sil" ? !1 : t ?
|
|
1864
|
+
function As(e, t) {
|
|
1865
|
+
return e === "sil" ? !1 : t ? Nr(e, "sil", t) : mt(e, "sil").length > 0;
|
|
1880
1866
|
}
|
|
1881
|
-
function
|
|
1882
|
-
return
|
|
1867
|
+
function Is() {
|
|
1868
|
+
return mn + Ss;
|
|
1883
1869
|
}
|
|
1884
|
-
function
|
|
1885
|
-
return e ??
|
|
1870
|
+
function Kt(e) {
|
|
1871
|
+
return e ?? wn;
|
|
1886
1872
|
}
|
|
1887
|
-
function
|
|
1873
|
+
function Rs(e, t, n, r) {
|
|
1888
1874
|
if (e.length === 0)
|
|
1889
1875
|
return { diffPath: null, label: "sil" };
|
|
1890
|
-
const s =
|
|
1876
|
+
const s = bs(e, r), i = ps(s, t);
|
|
1891
1877
|
if (i) {
|
|
1892
|
-
const a = i.toVtime - i.fromVtime, f =
|
|
1878
|
+
const a = i.toVtime - i.fromVtime, f = ys(i.fromVtime, i.toVtime);
|
|
1893
1879
|
if (t >= f.transStart && t < i.toVtime) {
|
|
1894
|
-
let l =
|
|
1895
|
-
n && (l =
|
|
1896
|
-
const w =
|
|
1880
|
+
let l = mt(i.from, i.to);
|
|
1881
|
+
n && (l = cn(l, n));
|
|
1882
|
+
const w = $r(l, a);
|
|
1897
1883
|
if (w.length > 0) {
|
|
1898
|
-
const _ =
|
|
1884
|
+
const _ = Wr(
|
|
1899
1885
|
t,
|
|
1900
1886
|
f.transStart,
|
|
1901
1887
|
i.toVtime,
|
|
@@ -1903,26 +1889,26 @@ function Cs(e, t, n, r) {
|
|
|
1903
1889
|
);
|
|
1904
1890
|
return { diffPath: w[_] ?? w[w.length - 1], label: `${i.from}→${i.to}` };
|
|
1905
1891
|
}
|
|
1906
|
-
return { diffPath:
|
|
1892
|
+
return { diffPath: Ke(i.to), label: i.to };
|
|
1907
1893
|
}
|
|
1908
1894
|
}
|
|
1909
|
-
const o =
|
|
1910
|
-
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath:
|
|
1895
|
+
const o = ft(e, t);
|
|
1896
|
+
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Ke(o), label: o };
|
|
1911
1897
|
}
|
|
1912
1898
|
function gn(e, t) {
|
|
1913
|
-
const n = t ??
|
|
1914
|
-
return `${
|
|
1899
|
+
const n = t ?? Kt(e.expressionPath);
|
|
1900
|
+
return `${Kt(e.mouthPath)}|${n}`;
|
|
1915
1901
|
}
|
|
1916
|
-
function
|
|
1917
|
-
const w =
|
|
1902
|
+
function Ds(e, t, n, r, s, i, o, a, f, l) {
|
|
1903
|
+
const w = Rs(t, n, f, i), _ = {
|
|
1918
1904
|
mouthPath: w.diffPath,
|
|
1919
1905
|
expressionPath: r
|
|
1920
1906
|
}, m = gn(_, s);
|
|
1921
|
-
m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (
|
|
1922
|
-
|
|
1907
|
+
m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (k) => {
|
|
1908
|
+
k === m && (i.lastDrawnKey = m);
|
|
1923
1909
|
}));
|
|
1924
1910
|
}
|
|
1925
|
-
function
|
|
1911
|
+
function jt(e, t, n, r, s, i, o = null) {
|
|
1926
1912
|
const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = gn(a, n) + f;
|
|
1927
1913
|
!(o != null) && l === r.lastDrawnKey || (i(
|
|
1928
1914
|
o != null ? "idle" : "sil"
|
|
@@ -1966,9 +1952,9 @@ function _n(e) {
|
|
|
1966
1952
|
}
|
|
1967
1953
|
};
|
|
1968
1954
|
}
|
|
1969
|
-
const
|
|
1970
|
-
async function
|
|
1971
|
-
let t =
|
|
1955
|
+
const Gt = -1, zt = /* @__PURE__ */ new Map();
|
|
1956
|
+
async function Ms(e) {
|
|
1957
|
+
let t = zt.get(e);
|
|
1972
1958
|
if (!t) {
|
|
1973
1959
|
const n = await fetch(e);
|
|
1974
1960
|
if (!n.ok)
|
|
@@ -1976,32 +1962,32 @@ async function xs(e) {
|
|
|
1976
1962
|
`Failed to fetch worker script (${n.status}): ${e}`
|
|
1977
1963
|
);
|
|
1978
1964
|
const r = await n.blob();
|
|
1979
|
-
t = URL.createObjectURL(r),
|
|
1965
|
+
t = URL.createObjectURL(r), zt.set(e, t);
|
|
1980
1966
|
}
|
|
1981
1967
|
return new Worker(t, { name: "visemeDiffPreview" });
|
|
1982
1968
|
}
|
|
1983
|
-
function
|
|
1969
|
+
function Cs() {
|
|
1984
1970
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
1985
1971
|
}
|
|
1986
|
-
function
|
|
1972
|
+
function xs(e, t) {
|
|
1987
1973
|
(e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
|
|
1988
1974
|
const n = e.getContext("2d");
|
|
1989
1975
|
n && n.drawImage(t, 0, 0);
|
|
1990
1976
|
}
|
|
1991
|
-
function
|
|
1977
|
+
function Yt(e, t) {
|
|
1992
1978
|
let n = 0, r = null;
|
|
1993
|
-
const s = _n(async (i, o) => (await
|
|
1979
|
+
const s = _n(async (i, o) => (await at(), await ct(e, i), s.isLatestSeq(o)));
|
|
1994
1980
|
return {
|
|
1995
1981
|
usesWorker: !1,
|
|
1996
1982
|
async loadAssets(i) {
|
|
1997
|
-
const o = await
|
|
1983
|
+
const o = await at(i);
|
|
1998
1984
|
return r = o.visemePaths ? new Set(o.visemePaths) : null, o;
|
|
1999
1985
|
},
|
|
2000
1986
|
getVisemeAtlasPaths() {
|
|
2001
1987
|
return r;
|
|
2002
1988
|
},
|
|
2003
1989
|
async renderSilOnly() {
|
|
2004
|
-
n += 1, s.reset(), await
|
|
1990
|
+
n += 1, s.reset(), await ws(e);
|
|
2005
1991
|
},
|
|
2006
1992
|
drawLiveFrame(i, o, a, f) {
|
|
2007
1993
|
s.enqueue(o, a, f);
|
|
@@ -2009,8 +1995,8 @@ function Jt(e, t) {
|
|
|
2009
1995
|
async renderViseme(i, o) {
|
|
2010
1996
|
n += 1;
|
|
2011
1997
|
const a = n;
|
|
2012
|
-
t.onStatus?.(o), await
|
|
2013
|
-
mouthPath:
|
|
1998
|
+
t.onStatus?.(o), await ct(i, {
|
|
1999
|
+
mouthPath: Ke(o),
|
|
2014
2000
|
expressionPath: null
|
|
2015
2001
|
});
|
|
2016
2002
|
},
|
|
@@ -2019,12 +2005,12 @@ function Jt(e, t) {
|
|
|
2019
2005
|
}
|
|
2020
2006
|
};
|
|
2021
2007
|
}
|
|
2022
|
-
function
|
|
2008
|
+
function Ps(e, t, n) {
|
|
2023
2009
|
let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
|
|
2024
2010
|
const l = /* @__PURE__ */ new Map(), w = _n(async (p, d, I) => (l.set(d, {
|
|
2025
2011
|
drawKey: I.drawKey,
|
|
2026
2012
|
onDisplayed: I.onDisplayed
|
|
2027
|
-
}), await
|
|
2013
|
+
}), await S(
|
|
2028
2014
|
{
|
|
2029
2015
|
type: "drawFrame",
|
|
2030
2016
|
diffPath: p.mouthPath,
|
|
@@ -2034,30 +2020,30 @@ function Ls(e, t, n) {
|
|
|
2034
2020
|
void 0,
|
|
2035
2021
|
!0
|
|
2036
2022
|
), !1)), _ = (p) => {
|
|
2037
|
-
if (p ===
|
|
2038
|
-
let
|
|
2039
|
-
for (const [
|
|
2040
|
-
|
|
2041
|
-
|
|
2023
|
+
if (p === Gt) {
|
|
2024
|
+
let E = -1, R;
|
|
2025
|
+
for (const [H, V] of l)
|
|
2026
|
+
H >= E && (E = H, R = V);
|
|
2027
|
+
E >= 0 && l.delete(E), R?.onDisplayed?.(R.drawKey);
|
|
2042
2028
|
return;
|
|
2043
2029
|
}
|
|
2044
2030
|
const d = -p, I = l.get(d);
|
|
2045
2031
|
l.delete(d), I?.onDisplayed?.(I.drawKey);
|
|
2046
|
-
}, m = /* @__PURE__ */ new Map(),
|
|
2032
|
+
}, m = /* @__PURE__ */ new Map(), k = (p, d) => {
|
|
2047
2033
|
a || !r || r.postMessage(p, []);
|
|
2048
|
-
},
|
|
2034
|
+
}, S = (p, d, I = !1) => {
|
|
2049
2035
|
if (a) return Promise.resolve();
|
|
2050
|
-
const
|
|
2051
|
-
return new Promise((R,
|
|
2052
|
-
m.set(
|
|
2053
|
-
resolve: (
|
|
2054
|
-
reject:
|
|
2036
|
+
const E = s++;
|
|
2037
|
+
return new Promise((R, H) => {
|
|
2038
|
+
m.set(E, {
|
|
2039
|
+
resolve: (V) => R(V),
|
|
2040
|
+
reject: H,
|
|
2055
2041
|
generation: typeof p.generation == "number" ? p.generation : void 0,
|
|
2056
2042
|
expectRenderDone: I
|
|
2057
|
-
}),
|
|
2043
|
+
}), k({ ...p, requestId: E });
|
|
2058
2044
|
});
|
|
2059
2045
|
}, u = (async () => {
|
|
2060
|
-
r = await
|
|
2046
|
+
r = await Ms(n), r.onmessage = (p) => {
|
|
2061
2047
|
if (a) return;
|
|
2062
2048
|
const d = p.data;
|
|
2063
2049
|
if (d.type === "status") {
|
|
@@ -2065,23 +2051,23 @@ function Ls(e, t, n) {
|
|
|
2065
2051
|
return;
|
|
2066
2052
|
}
|
|
2067
2053
|
if (d.type === "frame") {
|
|
2068
|
-
const
|
|
2069
|
-
if (!
|
|
2054
|
+
const E = d.generation < 0;
|
|
2055
|
+
if (!E && d.generation !== i) {
|
|
2070
2056
|
d.bitmap.close();
|
|
2071
2057
|
return;
|
|
2072
2058
|
}
|
|
2073
|
-
if (
|
|
2074
|
-
const
|
|
2075
|
-
if (!w.isLatestSeq(
|
|
2059
|
+
if (E && !(d.generation === Gt)) {
|
|
2060
|
+
const H = -d.generation;
|
|
2061
|
+
if (!w.isLatestSeq(H)) {
|
|
2076
2062
|
d.bitmap.close();
|
|
2077
2063
|
return;
|
|
2078
2064
|
}
|
|
2079
2065
|
}
|
|
2080
|
-
if (
|
|
2066
|
+
if (E && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
2081
2067
|
d.bitmap.close();
|
|
2082
2068
|
return;
|
|
2083
2069
|
}
|
|
2084
|
-
|
|
2070
|
+
xs(e, d.bitmap), d.bitmap.close(), E && _(d.generation);
|
|
2085
2071
|
return;
|
|
2086
2072
|
}
|
|
2087
2073
|
const I = m.get(d.requestId);
|
|
@@ -2112,7 +2098,7 @@ function Ls(e, t, n) {
|
|
|
2112
2098
|
for (const [, I] of m)
|
|
2113
2099
|
I.reject(new Error(d));
|
|
2114
2100
|
m.clear();
|
|
2115
|
-
}, await
|
|
2101
|
+
}, await S({ type: "init" }), o = !0;
|
|
2116
2102
|
})();
|
|
2117
2103
|
return {
|
|
2118
2104
|
usesWorker: !0,
|
|
@@ -2120,10 +2106,10 @@ function Ls(e, t, n) {
|
|
|
2120
2106
|
if (a) return { width: 842, height: 1264 };
|
|
2121
2107
|
if (await u, a) return { width: 842, height: 1264 };
|
|
2122
2108
|
if (!o) throw new Error("Worker init failed");
|
|
2123
|
-
return await
|
|
2109
|
+
return await S({
|
|
2124
2110
|
type: "loadAssets",
|
|
2125
2111
|
keyHex: p,
|
|
2126
|
-
urls: Qn(
|
|
2112
|
+
urls: Qn(Ee())
|
|
2127
2113
|
}) ?? { width: 842, height: 1264 };
|
|
2128
2114
|
},
|
|
2129
2115
|
getVisemeAtlasPaths() {
|
|
@@ -2133,26 +2119,26 @@ function Ls(e, t, n) {
|
|
|
2133
2119
|
if (a || (await u, a)) return;
|
|
2134
2120
|
i += 1, w.reset(), l.clear();
|
|
2135
2121
|
const p = i;
|
|
2136
|
-
await
|
|
2122
|
+
await S({ type: "cancelLiveDraws" }), await S(
|
|
2137
2123
|
{ type: "renderSil", generation: p },
|
|
2138
2124
|
void 0,
|
|
2139
2125
|
!0
|
|
2140
2126
|
);
|
|
2141
2127
|
},
|
|
2142
|
-
drawLiveFrame(p, d, I,
|
|
2128
|
+
drawLiveFrame(p, d, I, E) {
|
|
2143
2129
|
a || u.then(() => {
|
|
2144
|
-
a || w.enqueue(d, I,
|
|
2130
|
+
a || w.enqueue(d, I, E);
|
|
2145
2131
|
});
|
|
2146
2132
|
},
|
|
2147
2133
|
async renderViseme(p, d, I = {}) {
|
|
2148
2134
|
if (a || (await u, a)) return;
|
|
2149
2135
|
i += 1, w.reset(), l.clear();
|
|
2150
|
-
const
|
|
2136
|
+
const E = i;
|
|
2151
2137
|
try {
|
|
2152
|
-
await
|
|
2138
|
+
await S({ type: "cancelLiveDraws" }), await S(
|
|
2153
2139
|
{
|
|
2154
2140
|
type: "renderViseme",
|
|
2155
|
-
generation:
|
|
2141
|
+
generation: E,
|
|
2156
2142
|
to: d,
|
|
2157
2143
|
from: I.from,
|
|
2158
2144
|
transitionDurationMs: I.transitionDurationMs,
|
|
@@ -2177,25 +2163,25 @@ function Ls(e, t, n) {
|
|
|
2177
2163
|
}
|
|
2178
2164
|
};
|
|
2179
2165
|
}
|
|
2180
|
-
function
|
|
2181
|
-
if (!
|
|
2182
|
-
return
|
|
2166
|
+
function Bs(e, t = {}) {
|
|
2167
|
+
if (!Cs())
|
|
2168
|
+
return Yt(e, t);
|
|
2183
2169
|
const n = Pn(t.workerScriptUrl);
|
|
2184
2170
|
try {
|
|
2185
|
-
return
|
|
2171
|
+
return Ps(e, t, n);
|
|
2186
2172
|
} catch {
|
|
2187
|
-
return
|
|
2173
|
+
return Yt(e, t);
|
|
2188
2174
|
}
|
|
2189
2175
|
}
|
|
2190
|
-
class
|
|
2176
|
+
class Ls extends Error {
|
|
2191
2177
|
constructor(t, n) {
|
|
2192
2178
|
super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
2193
2179
|
}
|
|
2194
2180
|
}
|
|
2195
|
-
function
|
|
2181
|
+
function tt(e, t, n) {
|
|
2196
2182
|
return new Promise((r, s) => {
|
|
2197
2183
|
const i = globalThis.setTimeout(() => {
|
|
2198
|
-
s(new
|
|
2184
|
+
s(new Ls(n, t));
|
|
2199
2185
|
}, t);
|
|
2200
2186
|
e.then(
|
|
2201
2187
|
(o) => {
|
|
@@ -2207,15 +2193,15 @@ function rt(e, t, n) {
|
|
|
2207
2193
|
);
|
|
2208
2194
|
});
|
|
2209
2195
|
}
|
|
2210
|
-
const
|
|
2196
|
+
const Os = {
|
|
2211
2197
|
position: "relative",
|
|
2212
2198
|
display: "inline-block",
|
|
2213
2199
|
lineHeight: 0
|
|
2214
|
-
},
|
|
2200
|
+
}, Fs = {
|
|
2215
2201
|
display: "block",
|
|
2216
2202
|
maxWidth: "100%",
|
|
2217
2203
|
height: "auto"
|
|
2218
|
-
},
|
|
2204
|
+
}, Us = {
|
|
2219
2205
|
position: "absolute",
|
|
2220
2206
|
inset: 0,
|
|
2221
2207
|
display: "flex",
|
|
@@ -2227,78 +2213,78 @@ const Us = {
|
|
|
2227
2213
|
fontSize: "0.875rem",
|
|
2228
2214
|
textAlign: "center"
|
|
2229
2215
|
};
|
|
2230
|
-
function
|
|
2231
|
-
return Fn(e) ?
|
|
2216
|
+
function Oe(e) {
|
|
2217
|
+
return Fn(e) ? Sr : nn;
|
|
2232
2218
|
}
|
|
2233
|
-
function
|
|
2219
|
+
function we(e, t) {
|
|
2234
2220
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
2235
2221
|
}
|
|
2236
|
-
const
|
|
2222
|
+
const zs = vn(function({
|
|
2237
2223
|
id: t,
|
|
2238
2224
|
avatarId: n,
|
|
2239
2225
|
faceId: r,
|
|
2240
2226
|
assets: s,
|
|
2241
2227
|
authToken: i,
|
|
2242
|
-
ttsEngineId: o =
|
|
2228
|
+
ttsEngineId: o = Te,
|
|
2243
2229
|
voiceId: a,
|
|
2244
|
-
speakingRate: f =
|
|
2230
|
+
speakingRate: f = dt,
|
|
2245
2231
|
className: l,
|
|
2246
2232
|
style: w,
|
|
2247
2233
|
canvasStyle: _,
|
|
2248
2234
|
onStatusChange: m,
|
|
2249
|
-
onDisplayStatus:
|
|
2250
|
-
onError:
|
|
2235
|
+
onDisplayStatus: k,
|
|
2236
|
+
onError: S,
|
|
2251
2237
|
onReady: u,
|
|
2252
2238
|
showErrorOverlay: p = !0,
|
|
2253
2239
|
onUserTranscript: d,
|
|
2254
2240
|
onBotOutput: I,
|
|
2255
|
-
onRealtimeLipsyncDebug:
|
|
2241
|
+
onRealtimeLipsyncDebug: E
|
|
2256
2242
|
}, R) {
|
|
2257
|
-
const
|
|
2243
|
+
const H = F(null), V = F(null), $ = F(vs()), j = F(is()), y = F(0), T = F(0), g = F(0), C = F(null), b = F(null), D = F(!1), A = F(!1), P = F(!1), B = F("sil"), W = F(!1), U = F(
|
|
2258
2244
|
null
|
|
2259
|
-
),
|
|
2260
|
-
|
|
2261
|
-
const
|
|
2245
|
+
), X = F(!1), [se, Z] = Le("idle"), [ce, J] = Le(null), [c, v] = Le(!1), [L, z] = Le(!1), [ne, Re] = Le({ width: 842, height: 1264 }), G = F(i ?? null), Se = F(null), Y = F(null), De = F(!1), Je = F({ width: 842, height: 1264 }), Qe = F(null), pt = F(u), ee = F(k), yt = F(S), Et = F(d), St = F(I), kt = F(E);
|
|
2246
|
+
pt.current = u, ee.current = k, yt.current = S, Et.current = d, St.current = I, kt.current = E;
|
|
2247
|
+
const vt = oe(
|
|
2262
2248
|
(h) => {
|
|
2263
|
-
const
|
|
2264
|
-
return { ttsEngineId:
|
|
2249
|
+
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, x = h?.voiceId ?? a ?? Y.current?.voiceId ?? Oe(M);
|
|
2250
|
+
return { ttsEngineId: M, voiceId: x };
|
|
2265
2251
|
},
|
|
2266
2252
|
[o, a]
|
|
2267
2253
|
), de = oe((h) => {
|
|
2268
|
-
|
|
2254
|
+
J(h), yt.current?.(h);
|
|
2269
2255
|
}, []), Me = oe(
|
|
2270
2256
|
(h) => {
|
|
2271
|
-
|
|
2257
|
+
Z(h), m?.(h);
|
|
2272
2258
|
},
|
|
2273
2259
|
[m]
|
|
2274
|
-
),
|
|
2275
|
-
|
|
2276
|
-
),
|
|
2277
|
-
|
|
2260
|
+
), q = F(
|
|
2261
|
+
Bt(Me, be)
|
|
2262
|
+
), K = F(null);
|
|
2263
|
+
ke(() => (q.current = Bt(
|
|
2278
2264
|
Me,
|
|
2279
|
-
|
|
2280
|
-
), i &&
|
|
2281
|
-
|
|
2282
|
-
const h =
|
|
2283
|
-
h && (h.disconnect(),
|
|
2265
|
+
be
|
|
2266
|
+
), i && q.current.setDeveloperToken(i), q.current.setTtsEngineId(o), () => {
|
|
2267
|
+
q.current.stop();
|
|
2268
|
+
const h = K.current;
|
|
2269
|
+
h && (h.disconnect(), K.current = null);
|
|
2284
2270
|
}), [Me, i, o]);
|
|
2285
|
-
const
|
|
2271
|
+
const bt = oe(() => (K.current || (K.current = Rr(
|
|
2286
2272
|
Me,
|
|
2287
2273
|
{
|
|
2288
2274
|
speakingRate: f,
|
|
2289
|
-
onUserTranscript: (h,
|
|
2290
|
-
onBotOutput: (h) =>
|
|
2291
|
-
onLipsyncDebug: (h) =>
|
|
2275
|
+
onUserTranscript: (h, M) => Et.current?.(h, M),
|
|
2276
|
+
onBotOutput: (h) => St.current?.(h),
|
|
2277
|
+
onLipsyncDebug: (h) => kt.current?.(h)
|
|
2292
2278
|
}
|
|
2293
|
-
),
|
|
2294
|
-
|
|
2295
|
-
}, []),
|
|
2279
|
+
), K.current.setTtsEngineId(o)), K.current), [Me, f, o]), ie = oe(() => {
|
|
2280
|
+
C.current != null && (clearTimeout(C.current), C.current = null);
|
|
2281
|
+
}, []), ue = oe(() => {
|
|
2296
2282
|
b.current != null && (clearTimeout(b.current), b.current = null), P.current = !1;
|
|
2297
|
-
}, []),
|
|
2298
|
-
!
|
|
2299
|
-
if (b.current = null,
|
|
2300
|
-
|
|
2301
|
-
|
|
2283
|
+
}, []), Tt = oe(() => {
|
|
2284
|
+
!X.current || !U.current || (ue(), P.current = !0, b.current = setTimeout(() => {
|
|
2285
|
+
if (b.current = null, we(
|
|
2286
|
+
q.current,
|
|
2287
|
+
K.current
|
|
2302
2288
|
).isSpeaking()) {
|
|
2303
2289
|
P.current = !1;
|
|
2304
2290
|
return;
|
|
@@ -2307,435 +2293,435 @@ const Js = vn(function({
|
|
|
2307
2293
|
P.current = !1;
|
|
2308
2294
|
return;
|
|
2309
2295
|
}
|
|
2310
|
-
const h =
|
|
2296
|
+
const h = U.current;
|
|
2311
2297
|
if (!h) {
|
|
2312
2298
|
P.current = !1;
|
|
2313
2299
|
return;
|
|
2314
2300
|
}
|
|
2315
2301
|
h.restart(), h.setActive(!0);
|
|
2316
|
-
const
|
|
2302
|
+
const M = h.getVideo();
|
|
2317
2303
|
let x = !1;
|
|
2318
|
-
const
|
|
2319
|
-
x || (x = !0,
|
|
2320
|
-
},
|
|
2321
|
-
|
|
2304
|
+
const O = () => {
|
|
2305
|
+
x || (x = !0, M.removeEventListener("playing", N), P.current = !1);
|
|
2306
|
+
}, N = () => {
|
|
2307
|
+
O();
|
|
2322
2308
|
};
|
|
2323
|
-
if (
|
|
2324
|
-
|
|
2309
|
+
if (M.addEventListener("playing", N, { once: !0 }), M.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !M.paused) {
|
|
2310
|
+
O();
|
|
2325
2311
|
return;
|
|
2326
2312
|
}
|
|
2327
|
-
setTimeout(
|
|
2328
|
-
},
|
|
2329
|
-
}, [
|
|
2330
|
-
if (ie(),
|
|
2313
|
+
setTimeout(O, 300);
|
|
2314
|
+
}, Es));
|
|
2315
|
+
}, [ue]), Ce = oe(() => {
|
|
2316
|
+
if (ie(), ee.current?.("sil"), D.current = !1, !X.current || !U.current) {
|
|
2331
2317
|
P.current = !1;
|
|
2332
2318
|
return;
|
|
2333
2319
|
}
|
|
2334
|
-
|
|
2335
|
-
}, [ie,
|
|
2320
|
+
Tt();
|
|
2321
|
+
}, [ie, Tt]), Xe = oe(
|
|
2336
2322
|
async (h) => {
|
|
2337
|
-
const
|
|
2323
|
+
const M = T.current, x = V.current, O = H.current, N = () => {
|
|
2338
2324
|
h?.fallbackOnly || (D.current = !1);
|
|
2339
2325
|
};
|
|
2340
|
-
if (!x || !
|
|
2341
|
-
|
|
2326
|
+
if (!x || !O || !c) {
|
|
2327
|
+
N();
|
|
2342
2328
|
return;
|
|
2343
2329
|
}
|
|
2344
|
-
if (
|
|
2345
|
-
|
|
2346
|
-
|
|
2330
|
+
if (we(
|
|
2331
|
+
q.current,
|
|
2332
|
+
K.current
|
|
2347
2333
|
).isSpeaking()) {
|
|
2348
|
-
|
|
2334
|
+
N();
|
|
2349
2335
|
return;
|
|
2350
2336
|
}
|
|
2351
2337
|
if (h?.fallbackOnly) {
|
|
2352
|
-
if (!D.current || (
|
|
2353
|
-
|
|
2354
|
-
|
|
2338
|
+
if (!D.current || (fe($.current), await x.renderSilOnly(), M !== T.current) || we(
|
|
2339
|
+
q.current,
|
|
2340
|
+
K.current
|
|
2355
2341
|
).isSpeaking())
|
|
2356
2342
|
return;
|
|
2357
|
-
|
|
2343
|
+
Ce();
|
|
2358
2344
|
return;
|
|
2359
2345
|
}
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2346
|
+
if (ks($.current)) {
|
|
2347
|
+
fe($.current), Ce();
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
const te = B.current !== "sil" ? B.current : Ts(
|
|
2351
|
+
we(
|
|
2352
|
+
q.current,
|
|
2353
|
+
K.current
|
|
2354
|
+
).getVisemeQueue()
|
|
2355
|
+
), ae = As(
|
|
2356
|
+
te,
|
|
2369
2357
|
Qe.current
|
|
2370
2358
|
);
|
|
2371
|
-
if (
|
|
2372
|
-
if (await x.renderSilOnly(),
|
|
2373
|
-
|
|
2374
|
-
|
|
2359
|
+
if (fe($.current), !ae) {
|
|
2360
|
+
if (await x.renderSilOnly(), M !== T.current || we(
|
|
2361
|
+
q.current,
|
|
2362
|
+
K.current
|
|
2375
2363
|
).isSpeaking())
|
|
2376
2364
|
return;
|
|
2377
|
-
|
|
2365
|
+
Ce();
|
|
2378
2366
|
return;
|
|
2379
2367
|
}
|
|
2380
2368
|
try {
|
|
2381
|
-
await x.renderViseme(
|
|
2382
|
-
from:
|
|
2383
|
-
transitionDurationMs:
|
|
2369
|
+
await x.renderViseme(O, "sil", {
|
|
2370
|
+
from: te,
|
|
2371
|
+
transitionDurationMs: mn
|
|
2384
2372
|
});
|
|
2385
2373
|
} catch (he) {
|
|
2386
2374
|
if (he?.name !== "AbortError")
|
|
2387
2375
|
throw he;
|
|
2388
2376
|
}
|
|
2389
|
-
if (
|
|
2390
|
-
|
|
2377
|
+
if (M !== T.current) {
|
|
2378
|
+
N();
|
|
2391
2379
|
return;
|
|
2392
2380
|
}
|
|
2393
|
-
if (
|
|
2394
|
-
|
|
2395
|
-
|
|
2381
|
+
if (we(
|
|
2382
|
+
q.current,
|
|
2383
|
+
K.current
|
|
2396
2384
|
).isSpeaking()) {
|
|
2397
|
-
|
|
2385
|
+
N();
|
|
2398
2386
|
return;
|
|
2399
2387
|
}
|
|
2400
|
-
|
|
2388
|
+
Ce();
|
|
2401
2389
|
},
|
|
2402
|
-
[
|
|
2390
|
+
[c, Ce]
|
|
2403
2391
|
), xe = oe(() => {
|
|
2404
2392
|
if (A.current || D.current) return;
|
|
2405
2393
|
A.current = !0, D.current = !0, ie();
|
|
2406
2394
|
const h = T.current;
|
|
2407
2395
|
Xe().finally(() => {
|
|
2408
2396
|
A.current = !1;
|
|
2409
|
-
}),
|
|
2410
|
-
|
|
2411
|
-
},
|
|
2412
|
-
}, [ie, Xe]),
|
|
2397
|
+
}), C.current = setTimeout(() => {
|
|
2398
|
+
C.current = null, h === T.current && Xe({ fallbackOnly: !0 });
|
|
2399
|
+
}, Is());
|
|
2400
|
+
}, [ie, Xe]), At = oe(async () => {
|
|
2413
2401
|
const h = Math.floor(Date.now() / 1e3);
|
|
2414
|
-
if (
|
|
2415
|
-
return
|
|
2416
|
-
const
|
|
2417
|
-
|
|
2418
|
-
const x = await Kn(
|
|
2419
|
-
return
|
|
2402
|
+
if (Se.current && h < Se.current.expiresAt - 60)
|
|
2403
|
+
return Se.current.key;
|
|
2404
|
+
const M = G.current ?? await et();
|
|
2405
|
+
G.current = M, q.current.setDeveloperToken(M);
|
|
2406
|
+
const x = await Kn(M, be);
|
|
2407
|
+
return Se.current = {
|
|
2420
2408
|
key: x.value,
|
|
2421
2409
|
expiresAt: x.expiresAt
|
|
2422
2410
|
}, x.value;
|
|
2423
2411
|
}, []);
|
|
2424
|
-
|
|
2425
|
-
i && (
|
|
2426
|
-
}, [i]),
|
|
2427
|
-
|
|
2428
|
-
}, [o]),
|
|
2429
|
-
const h = a ??
|
|
2430
|
-
|
|
2412
|
+
ke(() => {
|
|
2413
|
+
i && (G.current = i, q.current.setDeveloperToken(i));
|
|
2414
|
+
}, [i]), ke(() => {
|
|
2415
|
+
q.current.setTtsEngineId(o), K.current?.setTtsEngineId(o), Y.current && (Y.current.ttsEngineId = o);
|
|
2416
|
+
}, [o]), ke(() => {
|
|
2417
|
+
const h = a ?? Oe(o);
|
|
2418
|
+
Y.current && (Y.current.voiceId = h);
|
|
2431
2419
|
}, [a, o]);
|
|
2432
|
-
const
|
|
2420
|
+
const ge = Rt(
|
|
2433
2421
|
() => Yn(n, r),
|
|
2434
2422
|
[n, r]
|
|
2435
|
-
), pn =
|
|
2436
|
-
return
|
|
2437
|
-
if (!t && !s && !
|
|
2423
|
+
), pn = Rt(() => s ? JSON.stringify(s) : ge ? `face:${ge}` : `id:${t ?? ""}`, [s, ge, t]);
|
|
2424
|
+
return ke(() => {
|
|
2425
|
+
if (!t && !s && !ge) {
|
|
2438
2426
|
de("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
2439
2427
|
return;
|
|
2440
2428
|
}
|
|
2441
2429
|
let h = !1;
|
|
2442
|
-
|
|
2443
|
-
const
|
|
2444
|
-
if (!
|
|
2430
|
+
De.current = !1, v(!1), z(!1), J(null), Y.current = null, U.current = null, X.current = !1;
|
|
2431
|
+
const M = H.current;
|
|
2432
|
+
if (!M) return;
|
|
2445
2433
|
let x = null;
|
|
2446
2434
|
return (async () => {
|
|
2447
2435
|
try {
|
|
2448
|
-
let
|
|
2436
|
+
let O, N, te;
|
|
2449
2437
|
if (s)
|
|
2450
|
-
|
|
2451
|
-
else if (
|
|
2452
|
-
|
|
2438
|
+
O = s, N = o, te = a ?? Oe(N);
|
|
2439
|
+
else if (ge)
|
|
2440
|
+
ee.current?.("loadFace"), O = Mt(ge), N = o, te = a ?? Oe(N);
|
|
2453
2441
|
else {
|
|
2454
|
-
|
|
2455
|
-
const
|
|
2442
|
+
ee.current?.("getAiTwin");
|
|
2443
|
+
const Q = await tt(
|
|
2456
2444
|
Nn(t),
|
|
2457
2445
|
3e4,
|
|
2458
2446
|
"getAiTwin"
|
|
2459
2447
|
);
|
|
2460
2448
|
if (h) return;
|
|
2461
|
-
if (!
|
|
2449
|
+
if (!Q.faceId?.trim())
|
|
2462
2450
|
throw new Error("getAiTwin returned no faceId");
|
|
2463
|
-
|
|
2451
|
+
N = Q.ttsEngineId, te = a ?? Q.voiceId ?? Oe(N), O = Mt(Q.faceId);
|
|
2464
2452
|
}
|
|
2465
|
-
|
|
2466
|
-
onStatus: (
|
|
2467
|
-
h ||
|
|
2453
|
+
Y.current = { ttsEngineId: N, voiceId: te }, Jn(O), U.current = os(), x = Bs(M, {
|
|
2454
|
+
onStatus: (Q) => {
|
|
2455
|
+
h || ee.current?.(Q);
|
|
2468
2456
|
},
|
|
2469
|
-
onError: (
|
|
2470
|
-
h || de(
|
|
2457
|
+
onError: (Q) => {
|
|
2458
|
+
h || de(Q);
|
|
2471
2459
|
},
|
|
2472
|
-
shouldAcceptLiveFrame: () =>
|
|
2473
|
-
|
|
2474
|
-
|
|
2460
|
+
shouldAcceptLiveFrame: () => we(
|
|
2461
|
+
q.current,
|
|
2462
|
+
K.current
|
|
2475
2463
|
).isSpeaking() && !D.current
|
|
2476
|
-
}),
|
|
2477
|
-
const ae =
|
|
2464
|
+
}), V.current = x, ee.current?.("auth");
|
|
2465
|
+
const ae = G.current ?? i ?? await tt(et(), 3e4, "getAuthToken");
|
|
2478
2466
|
if (h) return;
|
|
2479
|
-
|
|
2480
|
-
const he =
|
|
2467
|
+
G.current = ae, q.current.setDeveloperToken(ae), q.current.setTtsEngineId(N);
|
|
2468
|
+
const he = Ge() ? await At() : void 0;
|
|
2481
2469
|
if (h) return;
|
|
2482
|
-
|
|
2483
|
-
const
|
|
2470
|
+
ee.current?.("loadAssets");
|
|
2471
|
+
const le = await tt(
|
|
2484
2472
|
x.loadAssets(he),
|
|
2485
2473
|
18e4,
|
|
2486
2474
|
"load face assets"
|
|
2487
2475
|
);
|
|
2488
|
-
if (!h &&
|
|
2489
|
-
Qe.current = x.getVisemeAtlasPaths(),
|
|
2490
|
-
h ||
|
|
2476
|
+
if (!h && le.width > 0 && le.height > 0 && (Je.current = le, Re(le)), h) return;
|
|
2477
|
+
Qe.current = x.getVisemeAtlasPaths(), De.current = !0, v(!0), pt.current?.(), x.renderSilOnly().then(() => {
|
|
2478
|
+
h || ee.current?.("sil");
|
|
2491
2479
|
}), (async () => {
|
|
2492
2480
|
try {
|
|
2493
|
-
const
|
|
2494
|
-
if (await
|
|
2495
|
-
|
|
2496
|
-
const
|
|
2497
|
-
await
|
|
2498
|
-
|
|
2499
|
-
|
|
2481
|
+
const Q = await Or(he);
|
|
2482
|
+
if (await U.current.load(Q), h) return;
|
|
2483
|
+
X.current = !0, z(!0), fe($.current), U.current.setActive(!0);
|
|
2484
|
+
const re = U.current.getVideo();
|
|
2485
|
+
await qt(
|
|
2486
|
+
M,
|
|
2487
|
+
re,
|
|
2500
2488
|
null,
|
|
2501
2489
|
void 0,
|
|
2502
2490
|
Je.current
|
|
2503
|
-
), h ||
|
|
2504
|
-
} catch (
|
|
2491
|
+
), h || ee.current?.("idle");
|
|
2492
|
+
} catch (Q) {
|
|
2505
2493
|
if (h) return;
|
|
2506
|
-
|
|
2494
|
+
X.current = !1, z(!1), console.warn("[AiTwin] Idle video unavailable:", Q);
|
|
2507
2495
|
}
|
|
2508
2496
|
})();
|
|
2509
|
-
} catch (
|
|
2497
|
+
} catch (O) {
|
|
2510
2498
|
if (h) return;
|
|
2511
|
-
if (
|
|
2512
|
-
de(
|
|
2499
|
+
if (O instanceof nt) {
|
|
2500
|
+
de(O.message);
|
|
2513
2501
|
return;
|
|
2514
2502
|
}
|
|
2515
|
-
de(
|
|
2503
|
+
de(O instanceof Error ? O.message : "Failed to load AI twin");
|
|
2516
2504
|
}
|
|
2517
2505
|
})(), () => {
|
|
2518
|
-
h = !0,
|
|
2506
|
+
h = !0, U.current?.dispose(), x?.dispose(), V.current = null;
|
|
2519
2507
|
};
|
|
2520
|
-
}, [pn, s,
|
|
2521
|
-
const h = { current: !1 },
|
|
2522
|
-
const x =
|
|
2523
|
-
|
|
2524
|
-
|
|
2508
|
+
}, [pn, s, ge, t, o, a, i, At, de]), ke(() => {
|
|
2509
|
+
const h = { current: !1 }, M = () => {
|
|
2510
|
+
const x = H.current, O = V.current, N = we(
|
|
2511
|
+
q.current,
|
|
2512
|
+
K.current
|
|
2525
2513
|
);
|
|
2526
|
-
if (!x || !
|
|
2527
|
-
y.current = requestAnimationFrame(
|
|
2514
|
+
if (!x || !O || !c) {
|
|
2515
|
+
y.current = requestAnimationFrame(M);
|
|
2528
2516
|
return;
|
|
2529
2517
|
}
|
|
2530
|
-
const
|
|
2531
|
-
ae && (ie(),
|
|
2532
|
-
const
|
|
2533
|
-
if (
|
|
2534
|
-
|
|
2535
|
-
const
|
|
2536
|
-
|
|
2537
|
-
const me =
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
U.getWordQueue(),
|
|
2543
|
-
U.getStreamMood()
|
|
2518
|
+
const te = N.isSpeaking(), ae = te && !W.current, he = W.current && !te;
|
|
2519
|
+
ae && (ie(), ue(), D.current = !1, A.current = !1, fe($.current), g.current = 0, B.current = "sil", U.current?.setActive(!1)), he && (j.current.reset(), U.current?.setActive(!1), xe());
|
|
2520
|
+
const le = N.getPlaybackElapsedMs(), Q = he || D.current || P.current;
|
|
2521
|
+
if (te) {
|
|
2522
|
+
X.current && U.current?.setActive(!1);
|
|
2523
|
+
const re = N.getVisemeQueue(), _e = re.length > 0 ? ft(re, le) : "sil";
|
|
2524
|
+
_e !== "sil" && (B.current = _e);
|
|
2525
|
+
const me = ls(
|
|
2526
|
+
le,
|
|
2527
|
+
N.getSentenceEmotions(),
|
|
2528
|
+
N.getWordQueue(),
|
|
2529
|
+
N.getStreamMood()
|
|
2544
2530
|
);
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2531
|
+
j.current.setTargetEmotion(me), j.current.setTargetEyebrow(
|
|
2532
|
+
ss(
|
|
2533
|
+
le,
|
|
2534
|
+
N.getWordQueue(),
|
|
2535
|
+
gt(me)
|
|
2550
2536
|
)
|
|
2551
|
-
),
|
|
2552
|
-
const
|
|
2553
|
-
|
|
2537
|
+
), j.current.advance(performance.now());
|
|
2538
|
+
const Pe = j.current.getExpressionPath(), Ze = j.current.getDrawKey();
|
|
2539
|
+
Ds(
|
|
2554
2540
|
x,
|
|
2555
|
-
|
|
2556
|
-
|
|
2541
|
+
re,
|
|
2542
|
+
le,
|
|
2543
|
+
Pe,
|
|
2557
2544
|
Ze,
|
|
2558
|
-
et,
|
|
2559
2545
|
$.current,
|
|
2560
|
-
(
|
|
2561
|
-
(
|
|
2546
|
+
(Be, yn, En, Sn) => O.drawLiveFrame(Be, yn, En, Sn),
|
|
2547
|
+
(Be) => ee.current?.(Be),
|
|
2562
2548
|
Qe.current
|
|
2563
2549
|
);
|
|
2564
|
-
} else if (!
|
|
2565
|
-
const
|
|
2566
|
-
|
|
2550
|
+
} else if (!Q && X.current && U.current) {
|
|
2551
|
+
const re = U.current, _e = re.getVideo();
|
|
2552
|
+
_e.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), h.current || (h.current = !0, qt(
|
|
2567
2553
|
x,
|
|
2568
|
-
|
|
2554
|
+
_e,
|
|
2569
2555
|
null,
|
|
2570
2556
|
void 0,
|
|
2571
2557
|
Je.current,
|
|
2572
|
-
() => !
|
|
2573
|
-
).then(() =>
|
|
2558
|
+
() => !N.isSpeaking() && !D.current && !P.current
|
|
2559
|
+
).then(() => ee.current?.("idle")).finally(() => {
|
|
2574
2560
|
h.current = !1;
|
|
2575
|
-
}))) :
|
|
2561
|
+
}))) : jt(
|
|
2576
2562
|
x,
|
|
2577
2563
|
null,
|
|
2578
2564
|
"__sil__",
|
|
2579
2565
|
$.current,
|
|
2580
|
-
(me,
|
|
2581
|
-
(me) =>
|
|
2566
|
+
(me, Pe, Ze, Be) => O.drawLiveFrame(me, Pe, Ze, Be),
|
|
2567
|
+
(me) => ee.current?.(me)
|
|
2582
2568
|
);
|
|
2583
|
-
} else
|
|
2569
|
+
} else Q || jt(
|
|
2584
2570
|
x,
|
|
2585
2571
|
null,
|
|
2586
2572
|
"__sil__",
|
|
2587
2573
|
$.current,
|
|
2588
|
-
(
|
|
2589
|
-
(
|
|
2574
|
+
(re, _e, me, Pe) => O.drawLiveFrame(re, _e, me, Pe),
|
|
2575
|
+
(re) => ee.current?.(re)
|
|
2590
2576
|
);
|
|
2591
|
-
|
|
2577
|
+
W.current = te, y.current = requestAnimationFrame(M);
|
|
2592
2578
|
};
|
|
2593
|
-
return y.current = requestAnimationFrame(
|
|
2594
|
-
cancelAnimationFrame(y.current), ie(),
|
|
2579
|
+
return y.current = requestAnimationFrame(M), () => {
|
|
2580
|
+
cancelAnimationFrame(y.current), ie(), ue(), q.current.stop(), K.current?.stop();
|
|
2595
2581
|
};
|
|
2596
2582
|
}, [
|
|
2597
|
-
|
|
2598
|
-
|
|
2583
|
+
c,
|
|
2584
|
+
L,
|
|
2599
2585
|
xe,
|
|
2600
2586
|
ie,
|
|
2601
|
-
|
|
2587
|
+
ue
|
|
2602
2588
|
]), bn(
|
|
2603
2589
|
R,
|
|
2604
2590
|
() => ({
|
|
2605
|
-
speakText: async (h,
|
|
2591
|
+
speakText: async (h, M) => {
|
|
2606
2592
|
const x = h.trim();
|
|
2607
2593
|
if (!x) return;
|
|
2608
|
-
const
|
|
2609
|
-
if (!
|
|
2594
|
+
const O = V.current;
|
|
2595
|
+
if (!O || !De.current && !c)
|
|
2610
2596
|
throw new Error("AI twin is not ready");
|
|
2611
|
-
const { ttsEngineId:
|
|
2612
|
-
|
|
2597
|
+
const { ttsEngineId: N, voiceId: te } = vt(M);
|
|
2598
|
+
J(null), T.current += 1, ie(), ue(), D.current = !1, A.current = !1, B.current = "sil", fe($.current), j.current.reset(), W.current = !1;
|
|
2613
2599
|
try {
|
|
2614
|
-
|
|
2615
|
-
voiceId:
|
|
2616
|
-
speakingRate:
|
|
2617
|
-
ttsEngineId:
|
|
2600
|
+
X.current ? (U.current?.setActive(!1), U.current?.restart(), fe($.current)) : await O.renderSilOnly(), await q.current.speak(x, {
|
|
2601
|
+
voiceId: te,
|
|
2602
|
+
speakingRate: M?.speakingRate ?? f,
|
|
2603
|
+
ttsEngineId: N
|
|
2618
2604
|
});
|
|
2619
2605
|
} catch (ae) {
|
|
2620
2606
|
throw de(ae instanceof Error ? ae.message : "TTS failed"), ae;
|
|
2621
2607
|
}
|
|
2622
2608
|
},
|
|
2623
2609
|
stop: () => {
|
|
2624
|
-
T.current += 1, ie(),
|
|
2610
|
+
T.current += 1, ie(), ue(), D.current = !1, A.current = !1, q.current.stop(), K.current?.stop(), fe($.current), W.current = !1, xe();
|
|
2625
2611
|
},
|
|
2626
2612
|
setTtsEngineId: (h) => {
|
|
2627
|
-
|
|
2613
|
+
q.current.setTtsEngineId(h), K.current?.setTtsEngineId(h), Y.current && (Y.current.ttsEngineId = h);
|
|
2628
2614
|
},
|
|
2629
|
-
renderViseme: async (h,
|
|
2630
|
-
const x =
|
|
2631
|
-
if (!x || !
|
|
2615
|
+
renderViseme: async (h, M) => {
|
|
2616
|
+
const x = V.current, O = H.current;
|
|
2617
|
+
if (!x || !O || !De.current)
|
|
2632
2618
|
throw new Error("AI twin is not ready");
|
|
2633
|
-
await x.renderViseme(
|
|
2634
|
-
from:
|
|
2635
|
-
transitionDurationMs:
|
|
2636
|
-
gapMs:
|
|
2637
|
-
onStatus: (
|
|
2619
|
+
await x.renderViseme(O, h, {
|
|
2620
|
+
from: M?.from,
|
|
2621
|
+
transitionDurationMs: M?.transitionDurationMs,
|
|
2622
|
+
gapMs: M?.gapMs,
|
|
2623
|
+
onStatus: (N) => ee.current?.(N)
|
|
2638
2624
|
});
|
|
2639
2625
|
},
|
|
2640
|
-
isReady: () =>
|
|
2641
|
-
getStatus: () =>
|
|
2626
|
+
isReady: () => De.current,
|
|
2627
|
+
getStatus: () => se,
|
|
2642
2628
|
connect: async (h = {}) => {
|
|
2643
|
-
|
|
2629
|
+
J(null);
|
|
2644
2630
|
try {
|
|
2645
|
-
let
|
|
2646
|
-
|
|
2647
|
-
const x = h.voiceId?.trim() ?? a ??
|
|
2648
|
-
await
|
|
2631
|
+
let M = h.authToken?.trim();
|
|
2632
|
+
M || (M = G.current ?? i ?? await et(), G.current = M);
|
|
2633
|
+
const x = h.voiceId?.trim() ?? a ?? Y.current?.voiceId, O = bt();
|
|
2634
|
+
await O.unlockAudio(), await O.connect({
|
|
2649
2635
|
...h,
|
|
2650
|
-
authToken:
|
|
2636
|
+
authToken: M,
|
|
2651
2637
|
voiceId: x,
|
|
2652
2638
|
speakingRate: h.speakingRate ?? f
|
|
2653
2639
|
});
|
|
2654
|
-
} catch (
|
|
2640
|
+
} catch (M) {
|
|
2655
2641
|
throw de(
|
|
2656
|
-
|
|
2657
|
-
),
|
|
2642
|
+
M instanceof Error ? M.message : "Voice connect failed"
|
|
2643
|
+
), M;
|
|
2658
2644
|
}
|
|
2659
2645
|
},
|
|
2660
2646
|
disconnect: async () => {
|
|
2661
|
-
const h =
|
|
2662
|
-
h && (T.current += 1, ie(),
|
|
2647
|
+
const h = K.current;
|
|
2648
|
+
h && (T.current += 1, ie(), ue(), D.current = !1, A.current = !1, fe($.current), W.current = !1, await h.disconnect(), xe());
|
|
2663
2649
|
},
|
|
2664
|
-
isConnected: () =>
|
|
2650
|
+
isConnected: () => K.current?.isConnected() ?? !1
|
|
2665
2651
|
}),
|
|
2666
2652
|
[
|
|
2667
|
-
|
|
2653
|
+
c,
|
|
2668
2654
|
f,
|
|
2669
2655
|
i,
|
|
2670
2656
|
a,
|
|
2671
2657
|
ie,
|
|
2672
|
-
|
|
2658
|
+
ue,
|
|
2673
2659
|
xe,
|
|
2674
2660
|
de,
|
|
2661
|
+
vt,
|
|
2675
2662
|
bt,
|
|
2676
|
-
|
|
2677
|
-
J
|
|
2663
|
+
se
|
|
2678
2664
|
]
|
|
2679
|
-
), /* @__PURE__ */ kn("div", { className: l, style: { ...
|
|
2680
|
-
/* @__PURE__ */
|
|
2665
|
+
), /* @__PURE__ */ kn("div", { className: l, style: { ...Os, ...w }, children: [
|
|
2666
|
+
/* @__PURE__ */ It(
|
|
2681
2667
|
"canvas",
|
|
2682
2668
|
{
|
|
2683
|
-
ref:
|
|
2684
|
-
width:
|
|
2685
|
-
height:
|
|
2686
|
-
style: { ...
|
|
2669
|
+
ref: H,
|
|
2670
|
+
width: ne.width,
|
|
2671
|
+
height: ne.height,
|
|
2672
|
+
style: { ...Fs, ..._ },
|
|
2687
2673
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
2688
2674
|
}
|
|
2689
2675
|
),
|
|
2690
|
-
p &&
|
|
2676
|
+
p && ce ? /* @__PURE__ */ It("div", { style: Us, children: ce }) : null
|
|
2691
2677
|
] });
|
|
2692
|
-
}),
|
|
2693
|
-
function
|
|
2678
|
+
}), Ns = "thumbnail.webp";
|
|
2679
|
+
function Ys(e, t = ut) {
|
|
2694
2680
|
const n = e.trim();
|
|
2695
2681
|
if (!n)
|
|
2696
2682
|
throw new Error("faceId is required");
|
|
2697
|
-
return `${t.replace(/\/$/, "")}/${n}/${
|
|
2683
|
+
return `${t.replace(/\/$/, "")}/${n}/${Ns}`;
|
|
2698
2684
|
}
|
|
2699
|
-
const
|
|
2700
|
-
function
|
|
2685
|
+
const Vs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
2686
|
+
function $s(e = ".png") {
|
|
2701
2687
|
const t = e.toLowerCase();
|
|
2702
|
-
return
|
|
2688
|
+
return Vs.has(t) ? `source${t}` : "source.png";
|
|
2703
2689
|
}
|
|
2704
|
-
function
|
|
2690
|
+
function Js(e, t = ut, n = ".png") {
|
|
2705
2691
|
const r = e.trim();
|
|
2706
2692
|
if (!r)
|
|
2707
2693
|
throw new Error("faceId is required");
|
|
2708
|
-
return `${t.replace(/\/$/, "")}/${r}/${
|
|
2694
|
+
return `${t.replace(/\/$/, "")}/${r}/${$s(n)}`;
|
|
2709
2695
|
}
|
|
2710
2696
|
export {
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2697
|
+
Ns as AI_TWIN_THUMBNAIL_FILENAME,
|
|
2698
|
+
zs as AiTwin,
|
|
2699
|
+
nt as AiTwinNotFoundError,
|
|
2700
|
+
Te as DEFAULT_TTS_ENGINE_ID,
|
|
2701
|
+
rn as MIC_SAMPLE_RATE,
|
|
2716
2702
|
sr as OCULUS_VISEME_IDS,
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2703
|
+
sn as PLAYBACK_SAMPLE_RATE,
|
|
2704
|
+
tn as SPEAKING_RATE_MAX,
|
|
2705
|
+
en as SPEAKING_RATE_MIN,
|
|
2706
|
+
Ae as TTS_ENGINE_CARTESIA,
|
|
2707
|
+
Qt as TTS_ENGINE_GOOGLE,
|
|
2708
|
+
lt as TTS_ENGINE_INWORLD,
|
|
2709
|
+
Gs as VISEME_IDS,
|
|
2710
|
+
Sr as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
2711
|
+
dt as VISEME_TEST_SPEAKING_RATE,
|
|
2712
|
+
nn as VISEME_TEST_VOICE_ID,
|
|
2713
|
+
$s as aiTwinSourceFilename,
|
|
2714
|
+
Ar as buildVoiceWebSocketUrl,
|
|
2715
|
+
Bt as createAvatarTtsLipsyncController,
|
|
2716
|
+
Rr as createRealtimeVoiceLipsyncController,
|
|
2731
2717
|
Mt as faceAssetUrls,
|
|
2732
2718
|
Nn as fetchAiTwin,
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2719
|
+
et as fetchDevAuthToken,
|
|
2720
|
+
Js as getAiTwinSourceUrl,
|
|
2721
|
+
Ys as getAiTwinThumbnailUrl,
|
|
2736
2722
|
or as normalizeOculusViseme,
|
|
2737
2723
|
Yn as resolveDirectFaceId,
|
|
2738
|
-
|
|
2739
|
-
|
|
2724
|
+
ft as resolveVisemeAtTime,
|
|
2725
|
+
js as resolveWordAtTime,
|
|
2740
2726
|
Jn as setActiveTwinAssets
|
|
2741
2727
|
};
|