@streamoji/aitwin 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/aitwin.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
const
|
|
4
|
-
publicBase:
|
|
5
|
-
},
|
|
6
|
-
version:
|
|
7
|
-
},
|
|
8
|
-
function
|
|
1
|
+
import { jsxs as Bt, jsx as it } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Nt, useRef as R, useState as ke, useCallback as ie, useEffect as Te, useMemo as Vt, useImperativeHandle as $t } from "react";
|
|
3
|
+
const Ht = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", St = {
|
|
4
|
+
publicBase: Ht
|
|
5
|
+
}, Wt = "0.1.8", qt = {
|
|
6
|
+
version: Wt
|
|
7
|
+
}, Kt = {}, Pe = "https://ai.streamoji.com", jt = `${St.publicBase}/custom-faces`, Gt = `${St.publicBase}/aitwin-workers/v${qt.version}/visemeDiffPreview.worker.js`;
|
|
8
|
+
function zt(e) {
|
|
9
9
|
if (e) return e;
|
|
10
|
-
const t = typeof import.meta < "u" ?
|
|
11
|
-
return t?.trim() ? t.trim() :
|
|
12
|
-
}
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]),
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
},
|
|
21
|
-
google:
|
|
22
|
-
inworld:
|
|
23
|
-
cartesia:
|
|
10
|
+
const t = typeof import.meta < "u" ? Kt?.VITE_AITWIN_WORKER_URL : void 0;
|
|
11
|
+
return t?.trim() ? t.trim() : Gt;
|
|
12
|
+
}
|
|
13
|
+
const Qt = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", kt = "eng_a7f2b9c1", Ze = "eng_d4e8f3a2", be = "eng_c9b1e6d4", pe = be, Jt = /* @__PURE__ */ new Set([
|
|
14
|
+
Ze,
|
|
15
|
+
be
|
|
16
|
+
]), Tt = {
|
|
17
|
+
[kt]: "oculus_direct",
|
|
18
|
+
[be]: "oculus_direct",
|
|
19
|
+
[Ze]: "inworld_word"
|
|
20
|
+
}, st = {
|
|
21
|
+
google: kt,
|
|
22
|
+
inworld: Ze,
|
|
23
|
+
cartesia: be
|
|
24
24
|
};
|
|
25
|
-
function
|
|
26
|
-
return
|
|
25
|
+
function Yt(e) {
|
|
26
|
+
return Tt[e];
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return e ===
|
|
28
|
+
function Xt(e) {
|
|
29
|
+
return e === be;
|
|
30
30
|
}
|
|
31
|
-
function
|
|
32
|
-
if (e.ttsEngineId && e.ttsEngineId in
|
|
31
|
+
function Zt(e) {
|
|
32
|
+
if (e.ttsEngineId && e.ttsEngineId in Tt)
|
|
33
33
|
return e.ttsEngineId;
|
|
34
34
|
const t = e.tts?.toLowerCase();
|
|
35
|
-
return t && t in
|
|
35
|
+
return t && t in st ? st[t] : pe;
|
|
36
36
|
}
|
|
37
|
-
class
|
|
37
|
+
class Ke extends Error {
|
|
38
38
|
constructor(t = "AI twin not found") {
|
|
39
39
|
super(t), this.name = "AiTwinNotFoundError";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
async function
|
|
42
|
+
async function en(e, t = Qt) {
|
|
43
43
|
const n = new URL(t);
|
|
44
44
|
n.searchParams.set("id", e);
|
|
45
45
|
const r = await fetch(n.toString());
|
|
46
46
|
if (r.status === 404)
|
|
47
|
-
throw new
|
|
47
|
+
throw new Ke();
|
|
48
48
|
if (!r.ok)
|
|
49
49
|
throw new Error(`getAiTwin failed (${r.status})`);
|
|
50
50
|
const i = await r.json();
|
|
51
51
|
if (!i.success)
|
|
52
|
-
throw new
|
|
53
|
-
const { tts: s, ...
|
|
52
|
+
throw new Ke(i.error ?? "AI twin not found");
|
|
53
|
+
const { tts: s, ...c } = i.data;
|
|
54
54
|
return {
|
|
55
|
-
...
|
|
56
|
-
ttsEngineId:
|
|
55
|
+
...c,
|
|
56
|
+
ttsEngineId: Zt(i.data)
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
const
|
|
60
|
-
async function
|
|
61
|
-
const e = await fetch(
|
|
59
|
+
const tn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", nn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", rn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", sn = "6TNvp3SCs4Og0a1ijm9TommXLql1", on = "Swaraj Mali";
|
|
60
|
+
async function ot() {
|
|
61
|
+
const e = await fetch(tn, {
|
|
62
62
|
method: "POST",
|
|
63
63
|
headers: {
|
|
64
64
|
"Content-Type": "application/json",
|
|
65
|
-
"Client-Id":
|
|
66
|
-
"Client-Secret":
|
|
65
|
+
"Client-Id": nn,
|
|
66
|
+
"Client-Secret": rn
|
|
67
67
|
},
|
|
68
68
|
body: JSON.stringify({
|
|
69
|
-
userId:
|
|
70
|
-
userName:
|
|
69
|
+
userId: sn,
|
|
70
|
+
userName: on
|
|
71
71
|
})
|
|
72
72
|
});
|
|
73
73
|
if (!e.ok)
|
|
@@ -77,7 +77,7 @@ async function Qe() {
|
|
|
77
77
|
throw new Error("getAuthToken returned no token");
|
|
78
78
|
return n;
|
|
79
79
|
}
|
|
80
|
-
async function
|
|
80
|
+
async function an(e, t = Pe) {
|
|
81
81
|
const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
82
82
|
headers: { Authorization: `Bearer ${e}` }
|
|
83
83
|
});
|
|
@@ -87,7 +87,7 @@ async function Kt(e, t = Re) {
|
|
|
87
87
|
if (!r.value) throw new Error("Session value response missing value");
|
|
88
88
|
return r;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
90
|
+
function cn(e) {
|
|
91
91
|
const t = e.trim();
|
|
92
92
|
if (t.length % 2 !== 0) throw new Error("Invalid hex key");
|
|
93
93
|
const n = new Uint8Array(t.length / 2);
|
|
@@ -95,41 +95,41 @@ function Gt(e) {
|
|
|
95
95
|
n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
|
|
96
96
|
return n;
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function Ce(e) {
|
|
99
99
|
return Uint8Array.from(e);
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function un(e, t) {
|
|
102
102
|
const n = new Uint8Array(e.length + t.length);
|
|
103
103
|
return n.set(e, 0), n.set(t, e.length), n;
|
|
104
104
|
}
|
|
105
|
-
async function
|
|
105
|
+
async function ln(e, t) {
|
|
106
106
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
107
107
|
if (e.byteLength < 28)
|
|
108
108
|
throw new Error("Encrypted payload too small");
|
|
109
|
-
const n = new Uint8Array(e), r =
|
|
109
|
+
const n = new Uint8Array(e), r = Ce(n.subarray(0, 12)), i = Ce(n.subarray(12, 28)), s = Ce(n.subarray(28)), c = Ce(un(s, i)), a = await crypto.subtle.importKey(
|
|
110
110
|
"raw",
|
|
111
|
-
|
|
111
|
+
cn(t),
|
|
112
112
|
{ name: "AES-GCM" },
|
|
113
113
|
!1,
|
|
114
114
|
["decrypt"]
|
|
115
115
|
);
|
|
116
116
|
return crypto.subtle.decrypt(
|
|
117
117
|
{ name: "AES-GCM", iv: r, tagLength: 128 },
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
a,
|
|
119
|
+
c
|
|
120
120
|
);
|
|
121
121
|
}
|
|
122
|
-
let
|
|
123
|
-
const
|
|
124
|
-
function
|
|
122
|
+
let je = null;
|
|
123
|
+
const Ge = /* @__PURE__ */ new Set();
|
|
124
|
+
function fn(e, t = jt) {
|
|
125
125
|
const n = `${t.replace(/\/$/, "")}/${e}`;
|
|
126
126
|
return { twinBase: n, binBase: n, encrypted: !0 };
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
for (const t of
|
|
128
|
+
function dn(e) {
|
|
129
|
+
je = e;
|
|
130
|
+
for (const t of Ge) t();
|
|
131
131
|
}
|
|
132
|
-
function
|
|
132
|
+
function hn(e, t) {
|
|
133
133
|
const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
134
134
|
if (!n) return e;
|
|
135
135
|
const r = (i) => {
|
|
@@ -145,36 +145,38 @@ function Yt(e, t) {
|
|
|
145
145
|
encrypted: e.encrypted
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
function
|
|
149
|
-
if (!
|
|
148
|
+
function he() {
|
|
149
|
+
if (!je)
|
|
150
150
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
151
|
-
return
|
|
151
|
+
return je;
|
|
152
152
|
}
|
|
153
|
-
function
|
|
154
|
-
return
|
|
153
|
+
function mn(e) {
|
|
154
|
+
return Ge.add(e), () => Ge.delete(e);
|
|
155
155
|
}
|
|
156
|
-
function
|
|
157
|
-
|
|
156
|
+
function at() {
|
|
157
|
+
const { encrypted: e, binBase: t, twinBase: n } = he();
|
|
158
|
+
return e ? `${t}/sil.bin` : `${n}/sil.png`;
|
|
158
159
|
}
|
|
159
|
-
function
|
|
160
|
-
|
|
160
|
+
function _n() {
|
|
161
|
+
const { encrypted: e, binBase: t, twinBase: n } = he();
|
|
162
|
+
return e ? `${t}/idle.bin` : `${n}/idle.mp4`;
|
|
161
163
|
}
|
|
162
|
-
function
|
|
163
|
-
const { encrypted: e, binBase: t, twinBase: n } =
|
|
164
|
+
function wn() {
|
|
165
|
+
const { encrypted: e, binBase: t, twinBase: n } = he();
|
|
164
166
|
return e ? t : n;
|
|
165
167
|
}
|
|
166
|
-
function
|
|
167
|
-
return
|
|
168
|
+
function Be() {
|
|
169
|
+
return he().encrypted;
|
|
168
170
|
}
|
|
169
|
-
function
|
|
170
|
-
const { binBase: e, twinBase: t, encrypted: n } =
|
|
171
|
+
function gn() {
|
|
172
|
+
const { binBase: e, twinBase: t, encrypted: n } = he();
|
|
171
173
|
return n ? `${e}/atlas.bin` : `${t}/atlas.json`;
|
|
172
174
|
}
|
|
173
|
-
function
|
|
174
|
-
const { binBase: e, twinBase: t, encrypted: n } =
|
|
175
|
+
function yn() {
|
|
176
|
+
const { binBase: e, twinBase: t, encrypted: n } = he();
|
|
175
177
|
return n ? `${e}/expression_atlas.bin` : `${t}/expression_atlas.json`;
|
|
176
178
|
}
|
|
177
|
-
function
|
|
179
|
+
function pn(e) {
|
|
178
180
|
const t = e.split(/\r?\n/);
|
|
179
181
|
let n = "", r = "";
|
|
180
182
|
for (const s of t)
|
|
@@ -189,7 +191,7 @@ function sn(e) {
|
|
|
189
191
|
}
|
|
190
192
|
return { event: n, data: i };
|
|
191
193
|
}
|
|
192
|
-
const
|
|
194
|
+
const En = [
|
|
193
195
|
"aa",
|
|
194
196
|
"CH",
|
|
195
197
|
"DD",
|
|
@@ -205,14 +207,14 @@ const on = [
|
|
|
205
207
|
"kk",
|
|
206
208
|
"nn",
|
|
207
209
|
"sil"
|
|
208
|
-
],
|
|
209
|
-
|
|
210
|
+
], Sn = new Map(
|
|
211
|
+
En.map((e) => [e.toLowerCase(), e])
|
|
210
212
|
);
|
|
211
|
-
function
|
|
213
|
+
function kn(e) {
|
|
212
214
|
const t = (e ?? "").trim();
|
|
213
|
-
return t ?
|
|
215
|
+
return t ? Sn.get(t.toLowerCase()) ?? "sil" : "sil";
|
|
214
216
|
}
|
|
215
|
-
const
|
|
217
|
+
const Tn = {
|
|
216
218
|
aei: ["aa", "E", "I"],
|
|
217
219
|
o: ["O", "U"],
|
|
218
220
|
ee: ["I"],
|
|
@@ -224,12 +226,12 @@ const un = {
|
|
|
224
226
|
qw: ["U", "O"],
|
|
225
227
|
cdgknstxyz: ["DD", "SS", "kk", "CH"]
|
|
226
228
|
};
|
|
227
|
-
function
|
|
229
|
+
function vn(e) {
|
|
228
230
|
if (!e) return ["sil"];
|
|
229
231
|
const t = e.toLowerCase();
|
|
230
|
-
return
|
|
232
|
+
return Tn[t] ?? ["sil"];
|
|
231
233
|
}
|
|
232
|
-
function
|
|
234
|
+
function In(e, t) {
|
|
233
235
|
const n = e.word.length;
|
|
234
236
|
if (n <= 0) return 0;
|
|
235
237
|
const r = e.wduration;
|
|
@@ -237,33 +239,33 @@ function fn(e, t) {
|
|
|
237
239
|
const i = Math.max(0, Math.min(1, (t - e.wtime) / r));
|
|
238
240
|
return Math.min(n - 1, Math.floor(i * n));
|
|
239
241
|
}
|
|
240
|
-
function
|
|
242
|
+
function Ne(e, t) {
|
|
241
243
|
const n = Math.max(0, Math.min(e.length - 1, t));
|
|
242
244
|
return e[n] ?? "";
|
|
243
245
|
}
|
|
244
|
-
function
|
|
245
|
-
const n = e.toLowerCase(), r =
|
|
246
|
+
function An(e, t) {
|
|
247
|
+
const n = e.toLowerCase(), r = Ne(n, t), i = n.slice(Math.max(0, t - 1), t + 2);
|
|
246
248
|
return r === "i" || r === "y" ? "I" : i.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
|
|
247
249
|
}
|
|
248
|
-
function
|
|
250
|
+
function bn(e, t) {
|
|
249
251
|
const n = e.toLowerCase(), r = n.slice(
|
|
250
252
|
Math.max(0, t - 1),
|
|
251
253
|
Math.min(n.length, t + 3)
|
|
252
254
|
);
|
|
253
255
|
if (/oo|ou|uw/.test(r)) return "U";
|
|
254
|
-
const i =
|
|
256
|
+
const i = Ne(n, t);
|
|
255
257
|
return i === "u" || i === "w" ? "U" : "O";
|
|
256
258
|
}
|
|
257
|
-
function
|
|
259
|
+
function Rn(e, t) {
|
|
258
260
|
const n = e.toLowerCase(), r = n.slice(Math.max(0, t - 2), t + 1);
|
|
259
261
|
if (/qu/.test(r)) return "U";
|
|
260
262
|
const i = n.slice(
|
|
261
263
|
Math.max(0, t - 1),
|
|
262
264
|
Math.min(n.length, t + 3)
|
|
263
265
|
);
|
|
264
|
-
return /wo|wh/.test(i) ||
|
|
266
|
+
return /wo|wh/.test(i) || Ne(n, t) === "o" ? "O" : "U";
|
|
265
267
|
}
|
|
266
|
-
const
|
|
268
|
+
const Fe = {
|
|
267
269
|
d: "DD",
|
|
268
270
|
t: "DD",
|
|
269
271
|
n: "DD",
|
|
@@ -275,65 +277,65 @@ const ve = {
|
|
|
275
277
|
x: "CH",
|
|
276
278
|
j: "CH"
|
|
277
279
|
};
|
|
278
|
-
function
|
|
279
|
-
const n = e.toLowerCase(), r =
|
|
280
|
-
if (
|
|
280
|
+
function Dn(e, t) {
|
|
281
|
+
const n = e.toLowerCase(), r = Ne(n, t);
|
|
282
|
+
if (Fe[r]) return Fe[r];
|
|
281
283
|
for (let i = 0; i < n.length; i++) {
|
|
282
284
|
const s = n[i];
|
|
283
|
-
if (
|
|
285
|
+
if (Fe[s]) return Fe[s];
|
|
284
286
|
}
|
|
285
287
|
return "DD";
|
|
286
288
|
}
|
|
287
|
-
function
|
|
288
|
-
const r =
|
|
289
|
+
function xn(e, t, n) {
|
|
290
|
+
const r = vn(e);
|
|
289
291
|
if (r.length === 1) return r[0];
|
|
290
292
|
const i = t.trim();
|
|
291
293
|
if (!i) return r[0];
|
|
292
|
-
const s = (e ?? "").toLowerCase(),
|
|
294
|
+
const s = (e ?? "").toLowerCase(), c = Math.max(0, n);
|
|
293
295
|
switch (s) {
|
|
294
296
|
case "aei":
|
|
295
|
-
return
|
|
297
|
+
return An(i, c);
|
|
296
298
|
case "o":
|
|
297
|
-
return
|
|
299
|
+
return bn(i, c);
|
|
298
300
|
case "qw":
|
|
299
|
-
return
|
|
301
|
+
return Rn(i, c);
|
|
300
302
|
case "cdgknstxyz":
|
|
301
|
-
return
|
|
303
|
+
return Dn(i, c);
|
|
302
304
|
default:
|
|
303
305
|
return r[0];
|
|
304
306
|
}
|
|
305
307
|
}
|
|
306
|
-
function
|
|
308
|
+
function Mn(e) {
|
|
307
309
|
let t = e.trim();
|
|
308
310
|
const n = t.indexOf(",");
|
|
309
311
|
t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
|
|
310
312
|
const r = t.length % 4;
|
|
311
313
|
return r !== 0 && (t += "=".repeat(4 - r)), t;
|
|
312
314
|
}
|
|
313
|
-
const
|
|
314
|
-
function
|
|
315
|
+
const Cn = 24e3;
|
|
316
|
+
function Fn(e) {
|
|
315
317
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
316
318
|
}
|
|
317
|
-
function
|
|
319
|
+
function ct(e, t, n = Cn) {
|
|
318
320
|
const r = t.byteOffset % 2 === 0 ? t : t.slice(), i = new Int16Array(
|
|
319
321
|
r.buffer,
|
|
320
322
|
r.byteOffset,
|
|
321
323
|
r.byteLength / 2
|
|
322
324
|
), s = new Float32Array(i.length);
|
|
323
|
-
for (let
|
|
324
|
-
s[
|
|
325
|
-
const
|
|
326
|
-
return
|
|
325
|
+
for (let a = 0; a < i.length; a++)
|
|
326
|
+
s[a] = i[a] >= 32768 ? -(65536 - i[a]) / 32768 : i[a] / 32767;
|
|
327
|
+
const c = e.createBuffer(1, s.length, n);
|
|
328
|
+
return c.copyToChannel(s, 0), c;
|
|
327
329
|
}
|
|
328
|
-
function
|
|
329
|
-
const t =
|
|
330
|
+
function Ln(e) {
|
|
331
|
+
const t = Mn(e), n = window.atob(t), r = new Uint8Array(n.length);
|
|
330
332
|
for (let i = 0; i < n.length; i++)
|
|
331
333
|
r[i] = n.charCodeAt(i);
|
|
332
334
|
return r;
|
|
333
335
|
}
|
|
334
|
-
async function
|
|
335
|
-
const n =
|
|
336
|
-
if (
|
|
336
|
+
async function On(e, t) {
|
|
337
|
+
const n = Ln(t);
|
|
338
|
+
if (Fn(n)) {
|
|
337
339
|
const r = n.buffer.slice(
|
|
338
340
|
n.byteOffset,
|
|
339
341
|
n.byteOffset + n.byteLength
|
|
@@ -341,7 +343,7 @@ async function kn(e, t) {
|
|
|
341
343
|
return e.decodeAudioData(r);
|
|
342
344
|
}
|
|
343
345
|
if (n.length >= 2 && n.length % 2 === 0)
|
|
344
|
-
return
|
|
346
|
+
return ct(e, n);
|
|
345
347
|
try {
|
|
346
348
|
const r = n.buffer.slice(
|
|
347
349
|
n.byteOffset,
|
|
@@ -349,288 +351,288 @@ async function kn(e, t) {
|
|
|
349
351
|
);
|
|
350
352
|
return await e.decodeAudioData(r);
|
|
351
353
|
} catch {
|
|
352
|
-
return
|
|
354
|
+
return ct(e, n);
|
|
353
355
|
}
|
|
354
356
|
}
|
|
355
|
-
function
|
|
357
|
+
function vt(e, t) {
|
|
356
358
|
let n = null;
|
|
357
359
|
for (const r of e)
|
|
358
360
|
t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
|
|
359
361
|
return n ? n.viseme : "sil";
|
|
360
362
|
}
|
|
361
|
-
function
|
|
363
|
+
function Pn(e, t) {
|
|
362
364
|
for (const n of e)
|
|
363
365
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
364
366
|
return n;
|
|
365
367
|
return null;
|
|
366
368
|
}
|
|
367
|
-
function
|
|
369
|
+
function ut(e) {
|
|
368
370
|
let t = 0;
|
|
369
371
|
for (const n of e)
|
|
370
372
|
t = Math.max(t, n.vtime + n.vduration);
|
|
371
373
|
return t;
|
|
372
374
|
}
|
|
373
|
-
const
|
|
374
|
-
function
|
|
375
|
+
const Un = 0.5, Bn = 1.5, It = "Olivia", Nn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", At = 0.85;
|
|
376
|
+
function Vn(e, t = Pe) {
|
|
375
377
|
const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], i = [], s = [];
|
|
376
|
-
let
|
|
377
|
-
const
|
|
378
|
-
let d = null,
|
|
379
|
-
const
|
|
380
|
-
for (const
|
|
381
|
-
|
|
382
|
-
},
|
|
383
|
-
|
|
384
|
-
},
|
|
385
|
-
for (const
|
|
378
|
+
let c = "neutral";
|
|
379
|
+
const a = [], l = [];
|
|
380
|
+
let d = null, _ = !1, m = !1, S = !1, o = !1, F = 0, w = 0, u = 0, g = 0, y = null, v = 1, H = "", h = pe, E = pe, D = !1;
|
|
381
|
+
const L = /* @__PURE__ */ new Set(), z = () => {
|
|
382
|
+
for (const p of l)
|
|
383
|
+
p.playbackRate.value = v;
|
|
384
|
+
}, U = () => L.forEach((p) => p()), ae = () => {
|
|
385
|
+
y != null && (clearTimeout(y), y = null);
|
|
386
|
+
}, me = () => {
|
|
387
|
+
for (const p of l)
|
|
386
388
|
try {
|
|
387
|
-
|
|
389
|
+
p.stop();
|
|
388
390
|
} catch {
|
|
389
391
|
}
|
|
390
392
|
l.length = 0;
|
|
393
|
+
}, N = () => {
|
|
394
|
+
D = !0, ae(), me(), a.length = 0, _ = !1, m = !1, S = !1, o = !1, r.length = 0, i.length = 0, s.length = 0, c = "neutral", u = 0, g = 0, w = 0, e("idle"), U();
|
|
391
395
|
}, X = () => {
|
|
392
|
-
|
|
393
|
-
},
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (h <= 0) {
|
|
398
|
-
e("done"), q();
|
|
396
|
+
!o || _ || l.length > 0 || a.length > 0 || (m = !1, ae(), e("done"), U());
|
|
397
|
+
}, Re = () => {
|
|
398
|
+
const p = ut(r);
|
|
399
|
+
if (p <= 0) {
|
|
400
|
+
e("done"), U();
|
|
399
401
|
return;
|
|
400
402
|
}
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
},
|
|
406
|
-
},
|
|
407
|
-
|
|
408
|
-
const
|
|
409
|
-
if (!
|
|
410
|
-
const Q = Math.round((
|
|
403
|
+
m = !0, F = performance.now(), e("speaking"), U(), ae();
|
|
404
|
+
const V = v > 0 ? p / v : p;
|
|
405
|
+
y = setTimeout(() => {
|
|
406
|
+
D || (m = !1, y = null, e("done"), U());
|
|
407
|
+
}, V);
|
|
408
|
+
}, He = (p, V, W) => {
|
|
409
|
+
p.length !== 0 && (W && (u = V), p.forEach((x) => {
|
|
410
|
+
const I = String(x.word ?? "").trim();
|
|
411
|
+
if (!I) return;
|
|
412
|
+
const Q = Math.round((x.start ?? 0) * 1e3), J = Math.round((x.duration ?? 0) * 1e3);
|
|
411
413
|
i.push({
|
|
412
|
-
word:
|
|
414
|
+
word: I,
|
|
413
415
|
wtime: u + Q,
|
|
414
|
-
wduration:
|
|
416
|
+
wduration: J,
|
|
415
417
|
queueIndex: i.length
|
|
416
418
|
});
|
|
417
419
|
}));
|
|
418
|
-
},
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
if (!
|
|
422
|
-
const Q = Math.round((
|
|
420
|
+
}, De = (p, V, W, x) => {
|
|
421
|
+
p.length !== 0 && (W && (u = V), p.forEach((M) => {
|
|
422
|
+
const I = String(M.symbol ?? "").trim();
|
|
423
|
+
if (!I) return;
|
|
424
|
+
const Q = Math.round((M.start ?? 0) * 1e3), J = Math.max(
|
|
423
425
|
1,
|
|
424
|
-
Math.round((
|
|
425
|
-
),
|
|
426
|
-
let
|
|
427
|
-
if (
|
|
428
|
-
|
|
426
|
+
Math.round((M.duration ?? 0) * 1e3)
|
|
427
|
+
), P = u + Q;
|
|
428
|
+
let O;
|
|
429
|
+
if (Yt(x) === "oculus_direct")
|
|
430
|
+
O = kn(I);
|
|
429
431
|
else {
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
432
|
+
const q = Pn(i, P), ce = q ? In(q, P) : 0;
|
|
433
|
+
O = xn(
|
|
434
|
+
I,
|
|
435
|
+
q?.word ?? "",
|
|
436
|
+
ce
|
|
435
437
|
);
|
|
436
438
|
}
|
|
437
439
|
r.push({
|
|
438
|
-
viseme:
|
|
440
|
+
viseme: O,
|
|
439
441
|
weight: 1,
|
|
440
|
-
vtime:
|
|
441
|
-
vduration:
|
|
442
|
+
vtime: P,
|
|
443
|
+
vduration: J
|
|
442
444
|
});
|
|
443
|
-
}),
|
|
444
|
-
},
|
|
445
|
-
|
|
446
|
-
},
|
|
447
|
-
if (
|
|
448
|
-
(
|
|
449
|
-
|
|
450
|
-
|
|
445
|
+
}), U());
|
|
446
|
+
}, ue = (p, V, W, x, M) => {
|
|
447
|
+
He(V, W, x), De(p, W, x, M);
|
|
448
|
+
}, se = async (p, V, W, x) => {
|
|
449
|
+
if (D || !p?.trim()) {
|
|
450
|
+
(V.length > 0 || W.length > 0) && !S && ue(
|
|
451
|
+
V,
|
|
452
|
+
W,
|
|
451
453
|
u,
|
|
452
|
-
|
|
454
|
+
x,
|
|
453
455
|
E
|
|
454
456
|
);
|
|
455
457
|
return;
|
|
456
458
|
}
|
|
457
|
-
if (
|
|
458
|
-
|
|
459
|
-
audio:
|
|
460
|
-
visemes:
|
|
461
|
-
words:
|
|
462
|
-
isNewSegment:
|
|
459
|
+
if (_) {
|
|
460
|
+
a.push({
|
|
461
|
+
audio: p,
|
|
462
|
+
visemes: V,
|
|
463
|
+
words: W,
|
|
464
|
+
isNewSegment: x
|
|
463
465
|
});
|
|
464
466
|
return;
|
|
465
467
|
}
|
|
466
|
-
|
|
468
|
+
_ = !0;
|
|
467
469
|
try {
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
const Q = await
|
|
470
|
+
const M = window.AudioContext || window.webkitAudioContext, I = d ?? new M();
|
|
471
|
+
I.state === "suspended" && await I.resume(), d = I;
|
|
472
|
+
const Q = await On(I, p);
|
|
471
473
|
S = !0;
|
|
472
|
-
const
|
|
473
|
-
let
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
const
|
|
477
|
-
if (
|
|
474
|
+
const J = I.currentTime;
|
|
475
|
+
let P = g;
|
|
476
|
+
const O = !m;
|
|
477
|
+
P < J && (P = J + 0.1), g = P + Q.duration;
|
|
478
|
+
const q = I.createBufferSource();
|
|
479
|
+
if (q.buffer = Q, q.playbackRate.value = v, q.connect(I.destination), l.push(q), D) {
|
|
478
480
|
l.pop();
|
|
479
481
|
return;
|
|
480
482
|
}
|
|
481
|
-
if (
|
|
482
|
-
|
|
483
|
-
const
|
|
484
|
-
|
|
483
|
+
if (O) {
|
|
484
|
+
m = !0, e("speaking"), w = P, u = 0, r.length = 0, i.length = 0;
|
|
485
|
+
const $ = (P - J) * 1e3;
|
|
486
|
+
F = performance.now() + $;
|
|
485
487
|
}
|
|
486
|
-
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
},
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
488
|
+
q.onended = () => {
|
|
489
|
+
const $ = l.indexOf(q);
|
|
490
|
+
$ >= 0 && l.splice($, 1), X(), U();
|
|
491
|
+
}, q.start(P);
|
|
492
|
+
const ce = (P - w) * 1e3;
|
|
493
|
+
ue(
|
|
494
|
+
V,
|
|
495
|
+
W,
|
|
496
|
+
ce,
|
|
497
|
+
x,
|
|
496
498
|
E
|
|
497
499
|
);
|
|
498
|
-
} catch (
|
|
499
|
-
console.error("[avatarTtsLipsync] audio chunk failed:",
|
|
500
|
+
} catch (M) {
|
|
501
|
+
console.error("[avatarTtsLipsync] audio chunk failed:", M);
|
|
500
502
|
} finally {
|
|
501
|
-
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
) :
|
|
503
|
+
_ = !1;
|
|
504
|
+
const M = a.shift();
|
|
505
|
+
M ? await se(
|
|
506
|
+
M.audio,
|
|
507
|
+
M.visemes,
|
|
508
|
+
M.words,
|
|
509
|
+
M.isNewSegment
|
|
510
|
+
) : X();
|
|
509
511
|
}
|
|
510
|
-
},
|
|
512
|
+
}, xe = () => {
|
|
511
513
|
if (o = !0, !S && r.length > 0) {
|
|
512
|
-
|
|
514
|
+
Re();
|
|
513
515
|
return;
|
|
514
516
|
}
|
|
515
|
-
|
|
517
|
+
X();
|
|
516
518
|
};
|
|
517
519
|
return {
|
|
518
|
-
setDeveloperToken: (
|
|
519
|
-
|
|
520
|
+
setDeveloperToken: (p) => {
|
|
521
|
+
H = p;
|
|
520
522
|
},
|
|
521
|
-
setTtsEngineId: (
|
|
522
|
-
|
|
523
|
+
setTtsEngineId: (p) => {
|
|
524
|
+
h = p;
|
|
523
525
|
},
|
|
524
|
-
getTtsEngineId: () =>
|
|
525
|
-
speak: async (
|
|
526
|
-
|
|
527
|
-
const
|
|
528
|
-
if (!
|
|
526
|
+
getTtsEngineId: () => h,
|
|
527
|
+
speak: async (p, V) => {
|
|
528
|
+
N(), D = !1, e("loading");
|
|
529
|
+
const W = H.trim();
|
|
530
|
+
if (!W)
|
|
529
531
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
530
|
-
const
|
|
531
|
-
E =
|
|
532
|
-
const
|
|
533
|
-
|
|
534
|
-
Math.min(
|
|
535
|
-
),
|
|
536
|
-
user_query:
|
|
537
|
-
ttsEngineId:
|
|
532
|
+
const x = V?.ttsEngineId ?? h ?? pe;
|
|
533
|
+
E = x;
|
|
534
|
+
const M = V?.voiceId ?? It, I = V?.speakingRate ?? At, Q = Math.max(
|
|
535
|
+
Un,
|
|
536
|
+
Math.min(Bn, I)
|
|
537
|
+
), J = {
|
|
538
|
+
user_query: p,
|
|
539
|
+
ttsEngineId: x,
|
|
538
540
|
speakingRate: Q
|
|
539
541
|
};
|
|
540
|
-
|
|
542
|
+
Jt.has(x) && (J.voice_id = M);
|
|
541
543
|
try {
|
|
542
|
-
const
|
|
544
|
+
const P = await fetch(n, {
|
|
543
545
|
method: "POST",
|
|
544
546
|
headers: {
|
|
545
547
|
"Content-Type": "application/json",
|
|
546
|
-
Authorization: `Bearer ${
|
|
548
|
+
Authorization: `Bearer ${W}`
|
|
547
549
|
},
|
|
548
|
-
body: JSON.stringify(
|
|
550
|
+
body: JSON.stringify(J)
|
|
549
551
|
});
|
|
550
|
-
if (!
|
|
551
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
552
|
-
const
|
|
553
|
-
if (!
|
|
554
|
-
const
|
|
555
|
-
let
|
|
556
|
-
const
|
|
557
|
-
const
|
|
558
|
-
if (
|
|
559
|
-
if (
|
|
560
|
-
const
|
|
561
|
-
if (
|
|
562
|
-
await
|
|
563
|
-
else if (
|
|
564
|
-
const
|
|
565
|
-
|
|
552
|
+
if (!P.ok)
|
|
553
|
+
throw new Error(`avatar_ttsWithPoses failed (${P.status})`);
|
|
554
|
+
const O = P.body;
|
|
555
|
+
if (!O) throw new Error("No response body");
|
|
556
|
+
const q = O.getReader(), ce = new TextDecoder();
|
|
557
|
+
let $ = "";
|
|
558
|
+
const Me = async (B) => {
|
|
559
|
+
const b = pn(B);
|
|
560
|
+
if (b) {
|
|
561
|
+
if (b.event === "audio") {
|
|
562
|
+
const K = b.data.chunk, te = b.data.visemes ?? [], Z = b.data.words ?? [], j = b.data.is_new_segment ?? !1;
|
|
563
|
+
if (K)
|
|
564
|
+
await se(K, te, Z, j);
|
|
565
|
+
else if (te.length > 0 || Z.length > 0) {
|
|
566
|
+
const _e = j && r.length > 0 ? ut(r) : u;
|
|
567
|
+
ue(te, Z, _e, j, x);
|
|
566
568
|
}
|
|
567
|
-
} else if (
|
|
568
|
-
const
|
|
569
|
-
typeof
|
|
570
|
-
const
|
|
571
|
-
if (Array.isArray(
|
|
569
|
+
} else if (b.event === "metadata") {
|
|
570
|
+
const K = b.data.mood;
|
|
571
|
+
typeof K == "string" && K.trim() && (c = K.trim());
|
|
572
|
+
const te = b.data.sentence_emotions;
|
|
573
|
+
if (Array.isArray(te)) {
|
|
572
574
|
s.length = 0;
|
|
573
|
-
for (const
|
|
574
|
-
if (!
|
|
575
|
-
const
|
|
575
|
+
for (const Z of te) {
|
|
576
|
+
if (!Z || typeof Z != "object") continue;
|
|
577
|
+
const j = Z;
|
|
576
578
|
s.push({
|
|
577
|
-
sentence_index: Number(
|
|
578
|
-
text: String(
|
|
579
|
-
sentiment: typeof
|
|
580
|
-
emotion: String(
|
|
581
|
-
start_word: Number(
|
|
582
|
-
end_word: Number(
|
|
579
|
+
sentence_index: Number(j.sentence_index ?? 0),
|
|
580
|
+
text: String(j.text ?? ""),
|
|
581
|
+
sentiment: typeof j.sentiment == "string" ? j.sentiment : void 0,
|
|
582
|
+
emotion: String(j.emotion ?? c),
|
|
583
|
+
start_word: Number(j.start_word ?? 0),
|
|
584
|
+
end_word: Number(j.end_word ?? 0)
|
|
583
585
|
});
|
|
584
586
|
}
|
|
585
587
|
}
|
|
586
|
-
|
|
587
|
-
} else if (
|
|
588
|
+
U();
|
|
589
|
+
} else if (b.event === "error")
|
|
588
590
|
throw new Error(
|
|
589
|
-
String(
|
|
591
|
+
String(b.data.message ?? "avatar_ttsWithPoses stream error")
|
|
590
592
|
);
|
|
591
593
|
}
|
|
592
594
|
};
|
|
593
595
|
for (; ; ) {
|
|
594
|
-
const { done:
|
|
595
|
-
|
|
596
|
-
const
|
|
596
|
+
const { done: B, value: b } = await q.read();
|
|
597
|
+
b && ($ += ce.decode(b, { stream: !0 }));
|
|
598
|
+
const K = $.split(`
|
|
597
599
|
|
|
598
600
|
`);
|
|
599
|
-
|
|
600
|
-
for (const
|
|
601
|
-
if (
|
|
602
|
-
|
|
601
|
+
$ = K.pop() ?? "";
|
|
602
|
+
for (const te of K) await Me(te);
|
|
603
|
+
if (B) {
|
|
604
|
+
$.trim() && await Me($.trim()), D || xe();
|
|
603
605
|
break;
|
|
604
606
|
}
|
|
605
607
|
}
|
|
606
|
-
} catch (
|
|
607
|
-
throw console.error("[avatarTtsLipsync]",
|
|
608
|
+
} catch (P) {
|
|
609
|
+
throw console.error("[avatarTtsLipsync]", P), N(), e("error"), P;
|
|
608
610
|
}
|
|
609
611
|
},
|
|
610
|
-
stop:
|
|
612
|
+
stop: N,
|
|
611
613
|
getVisemeQueue: () => r,
|
|
612
614
|
getWordQueue: () => i,
|
|
613
615
|
getSentenceEmotions: () => s,
|
|
614
|
-
getStreamMood: () =>
|
|
615
|
-
getPlaybackElapsedMs: () =>
|
|
616
|
+
getStreamMood: () => c,
|
|
617
|
+
getPlaybackElapsedMs: () => m ? S && d && w > 0 ? Math.max(
|
|
616
618
|
0,
|
|
617
619
|
(d.currentTime - w) * 1e3
|
|
618
|
-
) : Math.max(0, (performance.now() -
|
|
619
|
-
isSpeaking: () =>
|
|
620
|
-
setPlaybackSpeed: (
|
|
621
|
-
|
|
620
|
+
) : Math.max(0, (performance.now() - F) * v) : 0,
|
|
621
|
+
isSpeaking: () => m,
|
|
622
|
+
setPlaybackSpeed: (p) => {
|
|
623
|
+
v = Math.max(0.1, Math.min(1, p)), z();
|
|
622
624
|
},
|
|
623
|
-
getPlaybackSpeed: () =>
|
|
624
|
-
subscribe: (
|
|
625
|
+
getPlaybackSpeed: () => v,
|
|
626
|
+
subscribe: (p) => (L.add(p), () => L.delete(p))
|
|
625
627
|
};
|
|
626
628
|
}
|
|
627
|
-
function
|
|
629
|
+
function $n(e, t, n) {
|
|
628
630
|
return {
|
|
629
631
|
width: e.crop?.source_width ?? t,
|
|
630
632
|
height: e.crop?.source_height ?? n
|
|
631
633
|
};
|
|
632
634
|
}
|
|
633
|
-
function
|
|
635
|
+
function Hn(e, t) {
|
|
634
636
|
const n = e.crop;
|
|
635
637
|
return {
|
|
636
638
|
x: t?.source_x ?? n?.x ?? 0,
|
|
@@ -639,21 +641,21 @@ function Dn(e, t) {
|
|
|
639
641
|
height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
|
|
640
642
|
};
|
|
641
643
|
}
|
|
642
|
-
function
|
|
644
|
+
function Wn(e) {
|
|
643
645
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
644
646
|
}
|
|
645
|
-
async function
|
|
647
|
+
async function Ve(e, t) {
|
|
646
648
|
const n = await fetch(e);
|
|
647
649
|
if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
|
|
648
650
|
const r = await n.arrayBuffer();
|
|
649
|
-
return
|
|
651
|
+
return ln(r, t);
|
|
650
652
|
}
|
|
651
|
-
async function
|
|
653
|
+
async function qn(e, t) {
|
|
652
654
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
653
|
-
const n = await
|
|
655
|
+
const n = await Ve(e, t), r = new TextDecoder().decode(n);
|
|
654
656
|
return JSON.parse(r);
|
|
655
657
|
}
|
|
656
|
-
async function
|
|
658
|
+
async function Kn(e) {
|
|
657
659
|
const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
|
|
658
660
|
return new Promise((r, i) => {
|
|
659
661
|
const s = new Image();
|
|
@@ -664,10 +666,32 @@ async function Mn(e) {
|
|
|
664
666
|
}, s.src = n;
|
|
665
667
|
});
|
|
666
668
|
}
|
|
667
|
-
function
|
|
669
|
+
async function jn(e) {
|
|
670
|
+
const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
|
|
671
|
+
return new Promise((r, i) => {
|
|
672
|
+
const s = new Image();
|
|
673
|
+
s.decoding = "async", s.onload = () => {
|
|
674
|
+
URL.revokeObjectURL(n), r(s);
|
|
675
|
+
}, s.onerror = () => {
|
|
676
|
+
URL.revokeObjectURL(n), i(new Error("Failed to decode decrypted PNG"));
|
|
677
|
+
}, s.src = n;
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
function Gn(e) {
|
|
681
|
+
const t = new Blob([e], { type: "video/mp4" });
|
|
682
|
+
return URL.createObjectURL(t);
|
|
683
|
+
}
|
|
684
|
+
async function zn(e) {
|
|
685
|
+
const t = _n();
|
|
686
|
+
if (!Be()) return t;
|
|
687
|
+
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
688
|
+
const n = await Ve(t, e);
|
|
689
|
+
return Gn(n);
|
|
690
|
+
}
|
|
691
|
+
function bt(e, t) {
|
|
668
692
|
return `${e}/${t}_minus_sil.png`;
|
|
669
693
|
}
|
|
670
|
-
const
|
|
694
|
+
const et = 15, Gr = [
|
|
671
695
|
"aa",
|
|
672
696
|
"E",
|
|
673
697
|
"I",
|
|
@@ -682,13 +706,13 @@ const Ke = 15, Rr = [
|
|
|
682
706
|
"RR",
|
|
683
707
|
"kk",
|
|
684
708
|
"nn"
|
|
685
|
-
],
|
|
709
|
+
], ze = [
|
|
686
710
|
"t01_0.17",
|
|
687
711
|
"t02_0.33",
|
|
688
712
|
"t03_0.50",
|
|
689
713
|
"t04_0.67",
|
|
690
714
|
"t05_0.83"
|
|
691
|
-
],
|
|
715
|
+
], Qn = ze.length, lt = /* @__PURE__ */ new Set([
|
|
692
716
|
"aa__kk",
|
|
693
717
|
"aa__nn",
|
|
694
718
|
"aa__sil",
|
|
@@ -795,59 +819,59 @@ const Ke = 15, Rr = [
|
|
|
795
819
|
"U__nn",
|
|
796
820
|
"U__sil"
|
|
797
821
|
]);
|
|
798
|
-
function
|
|
822
|
+
function ft(e, t) {
|
|
799
823
|
return `${e}__${t}`;
|
|
800
824
|
}
|
|
801
|
-
function
|
|
825
|
+
function dt(e, t) {
|
|
802
826
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
803
827
|
}
|
|
804
|
-
function
|
|
828
|
+
function Qe(e) {
|
|
805
829
|
return `${e}_minus_sil.png`;
|
|
806
830
|
}
|
|
807
|
-
function
|
|
831
|
+
function Rt(e, t) {
|
|
808
832
|
if (e === t) return [];
|
|
809
|
-
const n = [], r =
|
|
810
|
-
if (
|
|
811
|
-
for (const s of
|
|
812
|
-
n.push(
|
|
833
|
+
const n = [], r = ft(e, t);
|
|
834
|
+
if (lt.has(r)) {
|
|
835
|
+
for (const s of ze)
|
|
836
|
+
n.push(dt(r, s));
|
|
813
837
|
return n;
|
|
814
838
|
}
|
|
815
|
-
const i =
|
|
816
|
-
if (
|
|
817
|
-
for (let s =
|
|
818
|
-
n.push(
|
|
839
|
+
const i = ft(t, e);
|
|
840
|
+
if (lt.has(i)) {
|
|
841
|
+
for (let s = Qn - 1; s >= 0; s--)
|
|
842
|
+
n.push(dt(i, ze[s]));
|
|
819
843
|
return n;
|
|
820
844
|
}
|
|
821
845
|
return [];
|
|
822
846
|
}
|
|
823
|
-
function
|
|
847
|
+
function Jn(e) {
|
|
824
848
|
return e < 16 ? [] : e < 35 ? [2] : e < 51 ? [0, 4] : e < 67 ? [0, 2, 4] : e < 83 ? [0, 1, 2, 3] : [0, 1, 2, 3, 4];
|
|
825
849
|
}
|
|
826
|
-
function
|
|
827
|
-
return
|
|
850
|
+
function Yn(e, t) {
|
|
851
|
+
return Jn(t).map((r) => e[r]).filter((r) => r != null);
|
|
828
852
|
}
|
|
829
|
-
function
|
|
853
|
+
function Xn(e, t, n, r) {
|
|
830
854
|
if (r <= 0) return 0;
|
|
831
|
-
const s = Math.max(1, n - t) / r,
|
|
832
|
-
return Math.min(r - 1, Math.max(0,
|
|
855
|
+
const s = Math.max(1, n - t) / r, c = e - t, a = Math.floor(c / s);
|
|
856
|
+
return Math.min(r - 1, Math.max(0, a));
|
|
833
857
|
}
|
|
834
|
-
function
|
|
858
|
+
function Zn(e, t, n) {
|
|
835
859
|
if (!n) return `${e}/${t}`;
|
|
836
860
|
const r = t.split("/").pop() ?? t, i = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
|
|
837
861
|
return `${e}/${i}.bin`;
|
|
838
862
|
}
|
|
839
|
-
const
|
|
863
|
+
const er = [0.32, 0.24, 0.16, 0.08, 0], $e = er.map(
|
|
840
864
|
(e) => `eyes_${e.toFixed(2)}`
|
|
841
|
-
),
|
|
865
|
+
), tr = [
|
|
842
866
|
"eyes_0.32",
|
|
843
867
|
"eyes_0.16",
|
|
844
868
|
"eyes_0.00"
|
|
845
|
-
],
|
|
869
|
+
], nr = [
|
|
846
870
|
"eyes_0.32",
|
|
847
871
|
"eyes_0.16",
|
|
848
872
|
"eyes_0.08",
|
|
849
873
|
"eyes_0.00"
|
|
850
|
-
],
|
|
874
|
+
], rr = {
|
|
851
875
|
fear: "fear",
|
|
852
876
|
afraid: "fear",
|
|
853
877
|
anxiety: "fear",
|
|
@@ -870,174 +894,174 @@ const Nn = [0.32, 0.24, 0.16, 0.08, 0], xe = Nn.map(
|
|
|
870
894
|
disgust: "disgust",
|
|
871
895
|
disgusted: "disgust"
|
|
872
896
|
};
|
|
873
|
-
function
|
|
897
|
+
function ye(e, t = "neutral") {
|
|
874
898
|
const n = String(e ?? "").trim().toLowerCase();
|
|
875
|
-
return n ?
|
|
899
|
+
return n ? rr[n] ?? t : t;
|
|
876
900
|
}
|
|
877
|
-
function
|
|
878
|
-
return e === "neutral" ? null :
|
|
901
|
+
function ee(e) {
|
|
902
|
+
return e === "neutral" ? null : bt(e, "eyes_standard");
|
|
879
903
|
}
|
|
880
|
-
function
|
|
881
|
-
return !t || t === "eyes_standard" ?
|
|
904
|
+
function Je(e, t) {
|
|
905
|
+
return !t || t === "eyes_standard" ? ee(e) : e === "neutral" && t === "eyes_standard" ? null : bt(e, t);
|
|
882
906
|
}
|
|
883
|
-
function
|
|
907
|
+
function ir(e) {
|
|
884
908
|
if (!e) return "open";
|
|
885
909
|
const t = e.match(/\/(eyes_[^/]+)_minus_sil\.png$/);
|
|
886
910
|
if (!t?.[1]) return "open";
|
|
887
911
|
const n = t[1];
|
|
888
|
-
return
|
|
912
|
+
return $e.includes(n) ? n : "open";
|
|
889
913
|
}
|
|
890
|
-
function
|
|
891
|
-
return e === "open" ? -1 :
|
|
914
|
+
function sr(e) {
|
|
915
|
+
return e === "open" ? -1 : $e.indexOf(e);
|
|
892
916
|
}
|
|
893
|
-
function
|
|
917
|
+
function or(e, t) {
|
|
894
918
|
const n = [];
|
|
895
919
|
for (const r of t)
|
|
896
|
-
n.push(
|
|
920
|
+
n.push(Je(e, r));
|
|
897
921
|
for (let r = t.length - 2; r >= 0; r--)
|
|
898
|
-
n.push(
|
|
899
|
-
return n.push(
|
|
922
|
+
n.push(Je(e, t[r]));
|
|
923
|
+
return n.push(ee(e)), n;
|
|
900
924
|
}
|
|
901
|
-
function
|
|
902
|
-
if (t === "open") return [
|
|
903
|
-
const n =
|
|
904
|
-
if (n < 0) return [
|
|
925
|
+
function ar(e, t) {
|
|
926
|
+
if (t === "open") return [ee(e)];
|
|
927
|
+
const n = sr(t);
|
|
928
|
+
if (n < 0) return [ee(e)];
|
|
905
929
|
const r = [];
|
|
906
930
|
for (let i = n; i >= 0; i--)
|
|
907
|
-
r.push(
|
|
908
|
-
return r.push(
|
|
931
|
+
r.push(Je(e, $e[i]));
|
|
932
|
+
return r.push(ee(e)), r;
|
|
909
933
|
}
|
|
910
|
-
const
|
|
934
|
+
const cr = [
|
|
911
935
|
"t01_0.20",
|
|
912
936
|
"t02_0.40",
|
|
913
937
|
"t03_0.60",
|
|
914
938
|
"t04_0.80"
|
|
915
939
|
];
|
|
916
|
-
function
|
|
940
|
+
function ur(e, t) {
|
|
917
941
|
return `${e}__${t}`;
|
|
918
942
|
}
|
|
919
|
-
function
|
|
920
|
-
return `pairs/${
|
|
943
|
+
function lr(e, t, n) {
|
|
944
|
+
return `pairs/${ur(e, t)}/${n}_minus_sil.png`;
|
|
921
945
|
}
|
|
922
|
-
function
|
|
923
|
-
return
|
|
924
|
-
(n) =>
|
|
946
|
+
function fr(e, t) {
|
|
947
|
+
return cr.map(
|
|
948
|
+
(n) => lr(e, t, n)
|
|
925
949
|
);
|
|
926
950
|
}
|
|
927
|
-
function
|
|
951
|
+
function ve(e, t) {
|
|
928
952
|
return e + Math.random() * (t - e);
|
|
929
953
|
}
|
|
930
|
-
function
|
|
931
|
-
return
|
|
954
|
+
function Le() {
|
|
955
|
+
return ve(14, 32);
|
|
932
956
|
}
|
|
933
|
-
function
|
|
957
|
+
function dr(e = {}) {
|
|
934
958
|
const {
|
|
935
959
|
initialDelayMs: t = 800 + Math.random() * 1200,
|
|
936
960
|
intervalMinMs: n = 2200,
|
|
937
961
|
intervalMaxMs: r = 5800,
|
|
938
962
|
doubleBlinkChance: i = 0.18,
|
|
939
963
|
doubleBlinkGapMinMs: s = 120,
|
|
940
|
-
doubleBlinkGapMaxMs:
|
|
941
|
-
fullBlinkChance:
|
|
964
|
+
doubleBlinkGapMaxMs: c = 220,
|
|
965
|
+
fullBlinkChance: a = 0.75,
|
|
942
966
|
postEmotionChangeDelayMs: l = 380,
|
|
943
967
|
minDwellMs: d = 550
|
|
944
968
|
} = e;
|
|
945
|
-
let
|
|
969
|
+
let _ = "neutral", m = "neutral", S = 0, o = {
|
|
946
970
|
kind: "idle",
|
|
947
971
|
nextBlinkAt: performance.now() + t
|
|
948
|
-
},
|
|
949
|
-
function u(
|
|
950
|
-
|
|
972
|
+
}, F = null, w = "__eyes_open__|neutral";
|
|
973
|
+
function u(h, E) {
|
|
974
|
+
F = h, w = `${h ?? "__eyes_open__"}|${E}`;
|
|
951
975
|
}
|
|
952
|
-
function g(
|
|
976
|
+
function g(h, E) {
|
|
953
977
|
o = {
|
|
954
978
|
kind: "idle",
|
|
955
|
-
nextBlinkAt:
|
|
956
|
-
},
|
|
979
|
+
nextBlinkAt: h + ve(n, r)
|
|
980
|
+
}, m = E, u(ee(E), E);
|
|
957
981
|
}
|
|
958
|
-
function
|
|
959
|
-
const
|
|
982
|
+
function y(h, E, D) {
|
|
983
|
+
const L = D ? tr : Math.random() < a ? $e : nr;
|
|
960
984
|
o = {
|
|
961
985
|
kind: "playing",
|
|
962
|
-
paths:
|
|
986
|
+
paths: or(E, L),
|
|
963
987
|
index: 0,
|
|
964
|
-
holdUntil:
|
|
988
|
+
holdUntil: h + Le(),
|
|
965
989
|
after: "idle",
|
|
966
990
|
blinkEmotion: E
|
|
967
|
-
},
|
|
991
|
+
}, m = E, u(o.paths[0] ?? null, E);
|
|
968
992
|
}
|
|
969
|
-
function
|
|
970
|
-
const
|
|
971
|
-
if (
|
|
972
|
-
const
|
|
973
|
-
|
|
993
|
+
function v(h, E, D) {
|
|
994
|
+
const L = ir(F), z = [];
|
|
995
|
+
if (L !== "open") {
|
|
996
|
+
const U = ar(E, L);
|
|
997
|
+
z.push(...U.slice(0, -1));
|
|
974
998
|
}
|
|
975
|
-
|
|
999
|
+
z.push(...fr(E, D)), z.push(ee(D)), o = {
|
|
976
1000
|
kind: "emotionBlend",
|
|
977
|
-
paths:
|
|
1001
|
+
paths: z,
|
|
978
1002
|
index: 0,
|
|
979
|
-
holdUntil:
|
|
980
|
-
thenEmotion:
|
|
981
|
-
}, u(
|
|
1003
|
+
holdUntil: h + Le(),
|
|
1004
|
+
thenEmotion: D
|
|
1005
|
+
}, u(z[0] ?? null, E);
|
|
982
1006
|
}
|
|
983
|
-
function
|
|
1007
|
+
function H(h) {
|
|
984
1008
|
if (o.kind === "emotionBlend") {
|
|
985
|
-
for (;
|
|
986
|
-
o.index += 1, o.holdUntil =
|
|
1009
|
+
for (; h >= o.holdUntil && o.index < o.paths.length - 1; )
|
|
1010
|
+
o.index += 1, o.holdUntil = h + Le();
|
|
987
1011
|
const E = o.paths[o.index] ?? null;
|
|
988
|
-
u(E, o.thenEmotion),
|
|
1012
|
+
u(E, o.thenEmotion), h >= o.holdUntil && o.index >= o.paths.length - 1 && (_ = o.thenEmotion, m = o.thenEmotion, u(ee(o.thenEmotion), o.thenEmotion), o = {
|
|
989
1013
|
kind: "idle",
|
|
990
|
-
nextBlinkAt:
|
|
1014
|
+
nextBlinkAt: h + l
|
|
991
1015
|
});
|
|
992
1016
|
return;
|
|
993
1017
|
}
|
|
994
1018
|
if (o.kind === "idle") {
|
|
995
|
-
u(
|
|
1019
|
+
u(ee(m), m), h >= o.nextBlinkAt && y(h, m, !1);
|
|
996
1020
|
return;
|
|
997
1021
|
}
|
|
998
1022
|
if (o.kind === "doublePause") {
|
|
999
|
-
u(
|
|
1023
|
+
u(ee(o.blinkEmotion), o.blinkEmotion), h >= o.resumeAt && y(h, o.blinkEmotion, !0);
|
|
1000
1024
|
return;
|
|
1001
1025
|
}
|
|
1002
1026
|
if (o.kind === "playing") {
|
|
1003
|
-
for (;
|
|
1004
|
-
o.index += 1, o.holdUntil =
|
|
1005
|
-
if (u(o.paths[o.index] ?? null, o.blinkEmotion),
|
|
1027
|
+
for (; h >= o.holdUntil && o.index < o.paths.length - 1; )
|
|
1028
|
+
o.index += 1, o.holdUntil = h + Le();
|
|
1029
|
+
if (u(o.paths[o.index] ?? null, o.blinkEmotion), h >= o.holdUntil && o.index >= o.paths.length - 1) {
|
|
1006
1030
|
if (o.after === "resumeIdle") {
|
|
1007
|
-
g(
|
|
1031
|
+
g(h + l, _);
|
|
1008
1032
|
return;
|
|
1009
1033
|
}
|
|
1010
1034
|
if (o.after === "doublePause") {
|
|
1011
1035
|
o = {
|
|
1012
1036
|
kind: "doublePause",
|
|
1013
|
-
resumeAt:
|
|
1037
|
+
resumeAt: h + ve(s, c),
|
|
1014
1038
|
blinkEmotion: o.blinkEmotion
|
|
1015
|
-
}, u(
|
|
1039
|
+
}, u(ee(o.blinkEmotion), o.blinkEmotion);
|
|
1016
1040
|
return;
|
|
1017
1041
|
}
|
|
1018
1042
|
if (o.after === "idle" && Math.random() < i) {
|
|
1019
1043
|
o = {
|
|
1020
1044
|
kind: "doublePause",
|
|
1021
|
-
resumeAt:
|
|
1045
|
+
resumeAt: h + ve(s, c),
|
|
1022
1046
|
blinkEmotion: o.blinkEmotion
|
|
1023
|
-
}, u(
|
|
1047
|
+
}, u(ee(o.blinkEmotion), o.blinkEmotion);
|
|
1024
1048
|
return;
|
|
1025
1049
|
}
|
|
1026
|
-
g(
|
|
1050
|
+
g(h, o.blinkEmotion);
|
|
1027
1051
|
}
|
|
1028
1052
|
}
|
|
1029
1053
|
}
|
|
1030
1054
|
return {
|
|
1031
|
-
advance:
|
|
1032
|
-
setTargetEmotion(
|
|
1033
|
-
const E =
|
|
1034
|
-
if (E ===
|
|
1035
|
-
const
|
|
1036
|
-
if (d > 0 && E !==
|
|
1055
|
+
advance: H,
|
|
1056
|
+
setTargetEmotion(h) {
|
|
1057
|
+
const E = ye(h, _);
|
|
1058
|
+
if (E === _ && o.kind !== "emotionBlend") return;
|
|
1059
|
+
const D = performance.now();
|
|
1060
|
+
if (d > 0 && E !== _ && o.kind !== "emotionBlend" && !(_ === "neutral" && E !== "neutral") && D - S < d)
|
|
1037
1061
|
return;
|
|
1038
|
-
const
|
|
1039
|
-
if (
|
|
1040
|
-
|
|
1062
|
+
const L = _;
|
|
1063
|
+
if (_ = E, S = D, o.kind === "playing") {
|
|
1064
|
+
v(D, m, E);
|
|
1041
1065
|
return;
|
|
1042
1066
|
}
|
|
1043
1067
|
if (o.kind === "emotionBlend") {
|
|
@@ -1047,385 +1071,408 @@ function Yn(e = {}) {
|
|
|
1047
1071
|
};
|
|
1048
1072
|
return;
|
|
1049
1073
|
}
|
|
1050
|
-
|
|
1074
|
+
v(D, L, E);
|
|
1051
1075
|
},
|
|
1052
|
-
getTargetEmotion: () =>
|
|
1053
|
-
getExpressionPath: () =>
|
|
1076
|
+
getTargetEmotion: () => _,
|
|
1077
|
+
getExpressionPath: () => F,
|
|
1054
1078
|
getDrawKey: () => w,
|
|
1055
1079
|
reset() {
|
|
1056
|
-
|
|
1057
|
-
performance.now() +
|
|
1080
|
+
_ = "neutral", m = "neutral", S = 0, g(
|
|
1081
|
+
performance.now() + ve(n, r),
|
|
1058
1082
|
"neutral"
|
|
1059
1083
|
);
|
|
1060
1084
|
}
|
|
1061
1085
|
};
|
|
1062
1086
|
}
|
|
1063
|
-
function
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
let
|
|
1087
|
+
function hr() {
|
|
1088
|
+
const e = document.createElement("video");
|
|
1089
|
+
e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
|
|
1090
|
+
let t = !1, n = null, r = "";
|
|
1091
|
+
const i = () => {
|
|
1092
|
+
n && (URL.revokeObjectURL(n), n = null);
|
|
1093
|
+
};
|
|
1067
1094
|
return {
|
|
1068
|
-
async load() {
|
|
1069
|
-
|
|
1070
|
-
const
|
|
1071
|
-
const
|
|
1072
|
-
if (!Number.isFinite(
|
|
1073
|
-
|
|
1095
|
+
async load(s) {
|
|
1096
|
+
t && r === s || (i(), t = !1, r = s, s.startsWith("blob:") && (n = s), await new Promise((c, a) => {
|
|
1097
|
+
const l = () => {
|
|
1098
|
+
const d = e.duration;
|
|
1099
|
+
if (!Number.isFinite(d) || d <= 0) {
|
|
1100
|
+
a(new Error(`Idle video has invalid duration: ${s}`));
|
|
1074
1101
|
return;
|
|
1075
1102
|
}
|
|
1076
|
-
|
|
1103
|
+
t = !0, e.currentTime = 0, c();
|
|
1077
1104
|
};
|
|
1078
|
-
|
|
1105
|
+
e.addEventListener("loadeddata", l, { once: !0 }), e.addEventListener(
|
|
1079
1106
|
"error",
|
|
1080
|
-
() =>
|
|
1107
|
+
() => a(new Error(`Failed to load idle video: ${s}`)),
|
|
1081
1108
|
{ once: !0 }
|
|
1082
|
-
),
|
|
1083
|
-
});
|
|
1109
|
+
), e.src = s, e.load();
|
|
1110
|
+
}));
|
|
1084
1111
|
},
|
|
1085
1112
|
isReady() {
|
|
1086
|
-
return
|
|
1113
|
+
return t;
|
|
1087
1114
|
},
|
|
1088
1115
|
getVideo() {
|
|
1089
|
-
return
|
|
1116
|
+
return e;
|
|
1090
1117
|
},
|
|
1091
|
-
setActive(
|
|
1092
|
-
|
|
1093
|
-
}) :
|
|
1118
|
+
setActive(s) {
|
|
1119
|
+
t && (s ? e.paused && e.play().catch(() => {
|
|
1120
|
+
}) : e.paused || e.pause());
|
|
1094
1121
|
},
|
|
1095
1122
|
restart() {
|
|
1096
|
-
|
|
1123
|
+
t && (e.currentTime = 0);
|
|
1124
|
+
},
|
|
1125
|
+
dispose() {
|
|
1126
|
+
e.pause(), e.removeAttribute("src"), e.load(), i(), t = !1, r = "";
|
|
1097
1127
|
}
|
|
1098
1128
|
};
|
|
1099
1129
|
}
|
|
1100
|
-
const
|
|
1101
|
-
function
|
|
1130
|
+
const mr = 50, Dt = 400;
|
|
1131
|
+
function _r(e, t, n) {
|
|
1102
1132
|
return e.filter((r) => {
|
|
1103
1133
|
const i = r.queueIndex ?? -1;
|
|
1104
1134
|
return i >= t && i <= n;
|
|
1105
1135
|
});
|
|
1106
1136
|
}
|
|
1107
|
-
function
|
|
1137
|
+
function wr(e, t) {
|
|
1108
1138
|
const n = [];
|
|
1109
1139
|
for (const r of e) {
|
|
1110
|
-
const i =
|
|
1140
|
+
const i = _r(
|
|
1111
1141
|
t,
|
|
1112
1142
|
r.start_word,
|
|
1113
1143
|
r.end_word
|
|
1114
1144
|
);
|
|
1115
1145
|
if (i.length === 0) continue;
|
|
1116
|
-
const s = i[0],
|
|
1146
|
+
const s = i[0], c = i[i.length - 1];
|
|
1117
1147
|
n.push({
|
|
1118
1148
|
sentence: r,
|
|
1119
|
-
startMs: Math.max(0, s.wtime -
|
|
1120
|
-
endMs:
|
|
1149
|
+
startMs: Math.max(0, s.wtime - mr),
|
|
1150
|
+
endMs: c.wtime + c.wduration + Dt
|
|
1121
1151
|
});
|
|
1122
1152
|
}
|
|
1123
1153
|
return n.sort((r, i) => r.startMs - i.startMs);
|
|
1124
1154
|
}
|
|
1125
|
-
function
|
|
1126
|
-
const i =
|
|
1155
|
+
function gr(e, t, n, r = "neutral") {
|
|
1156
|
+
const i = ye(r);
|
|
1127
1157
|
if (t.length === 0) return i;
|
|
1128
1158
|
if (n.length === 0 || e < n[0].wtime)
|
|
1129
|
-
return
|
|
1130
|
-
const s =
|
|
1131
|
-
let
|
|
1159
|
+
return ye(t[0]?.emotion, i);
|
|
1160
|
+
const s = wr(t, n);
|
|
1161
|
+
let c = null;
|
|
1132
1162
|
for (const d of s)
|
|
1133
|
-
e >= d.startMs && e <= d.endMs && (
|
|
1134
|
-
if (
|
|
1135
|
-
return
|
|
1136
|
-
const
|
|
1137
|
-
return e > l +
|
|
1163
|
+
e >= d.startMs && e <= d.endMs && (c = d);
|
|
1164
|
+
if (c)
|
|
1165
|
+
return ye(c.sentence.emotion, i);
|
|
1166
|
+
const a = n[n.length - 1], l = a.wtime + a.wduration;
|
|
1167
|
+
return e > l + Dt ? ye(
|
|
1138
1168
|
t[t.length - 1]?.emotion,
|
|
1139
1169
|
i
|
|
1140
1170
|
) : i;
|
|
1141
1171
|
}
|
|
1142
|
-
function
|
|
1143
|
-
const s = new OffscreenCanvas(n, r),
|
|
1144
|
-
|
|
1145
|
-
const
|
|
1146
|
-
l.data.set(
|
|
1147
|
-
const
|
|
1148
|
-
for (const
|
|
1149
|
-
|
|
1150
|
-
const S =
|
|
1172
|
+
function xt(e, t, n, r, i = et) {
|
|
1173
|
+
const s = new OffscreenCanvas(n, r), c = s.getContext("2d", { willReadFrequently: !0 });
|
|
1174
|
+
c.drawImage(e, 0, 0, n, r);
|
|
1175
|
+
const a = c.getImageData(0, 0, n, r), l = c.createImageData(n, r);
|
|
1176
|
+
l.data.set(a.data);
|
|
1177
|
+
const _ = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
|
|
1178
|
+
for (const m of t) {
|
|
1179
|
+
_.clearRect(0, 0, n, r), _.drawImage(m, 0, 0, n, r);
|
|
1180
|
+
const S = _.getImageData(0, 0, n, r);
|
|
1151
1181
|
for (let o = 0; o < l.data.length; o += 4) {
|
|
1152
|
-
const
|
|
1153
|
-
Math.max(
|
|
1182
|
+
const F = S.data[o], w = S.data[o + 1], u = S.data[o + 2];
|
|
1183
|
+
Math.max(F, w, u) > i && (l.data[o] = F, l.data[o + 1] = w, l.data[o + 2] = u, l.data[o + 3] = 255);
|
|
1154
1184
|
}
|
|
1155
1185
|
}
|
|
1156
|
-
return
|
|
1186
|
+
return c.putImageData(l, 0, 0), s;
|
|
1157
1187
|
}
|
|
1158
|
-
let
|
|
1159
|
-
const
|
|
1160
|
-
function
|
|
1161
|
-
|
|
1188
|
+
let de = null, Ie = null;
|
|
1189
|
+
const Ue = /* @__PURE__ */ new Map();
|
|
1190
|
+
function yr() {
|
|
1191
|
+
de = null, Ie = null, Ue.clear();
|
|
1162
1192
|
}
|
|
1163
|
-
|
|
1164
|
-
function
|
|
1165
|
-
return e ??
|
|
1193
|
+
mn(yr);
|
|
1194
|
+
function pr(e) {
|
|
1195
|
+
return e ?? Ie ?? void 0;
|
|
1166
1196
|
}
|
|
1167
|
-
function
|
|
1197
|
+
function tt(e) {
|
|
1168
1198
|
return new Promise((t, n) => {
|
|
1169
1199
|
const r = new Image();
|
|
1170
1200
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
1171
1201
|
});
|
|
1172
1202
|
}
|
|
1173
|
-
async function
|
|
1174
|
-
|
|
1203
|
+
async function Er(e) {
|
|
1204
|
+
return Be() ? jn(
|
|
1205
|
+
await Ve(at(), e ?? "")
|
|
1206
|
+
) : tt(at());
|
|
1207
|
+
}
|
|
1208
|
+
async function ht(e, t, n, r) {
|
|
1209
|
+
const i = n ? await qn(e, r) : await fetch(e).then((d) => {
|
|
1175
1210
|
if (!d.ok) throw new Error(`Failed to load ${e}`);
|
|
1176
1211
|
return d.json();
|
|
1177
1212
|
}), s = i.sheets?.[0];
|
|
1178
1213
|
if (!s?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
1179
|
-
const
|
|
1180
|
-
await
|
|
1181
|
-
|
|
1214
|
+
const c = n ? await Kn(
|
|
1215
|
+
await Ve(
|
|
1216
|
+
Zn(t, s.path, n),
|
|
1182
1217
|
r ?? ""
|
|
1183
1218
|
)
|
|
1184
|
-
) : await
|
|
1219
|
+
) : await tt(`${t}/${s.path}`), a = /* @__PURE__ */ new Map();
|
|
1185
1220
|
for (const d of i.cells ?? [])
|
|
1186
|
-
d.path &&
|
|
1221
|
+
d.path && a.set(d.path, d);
|
|
1187
1222
|
const l = /* @__PURE__ */ new Map();
|
|
1188
1223
|
for (const d of i.sheets ?? [])
|
|
1189
1224
|
l.set(d.index, d);
|
|
1190
|
-
return { atlas:
|
|
1225
|
+
return { atlas: c, atlasMeta: i, cellByPath: a, sheetByIndex: l, diffBase: t };
|
|
1191
1226
|
}
|
|
1192
|
-
async function
|
|
1193
|
-
const t =
|
|
1227
|
+
async function Ye(e) {
|
|
1228
|
+
const t = pr(e), n = Be();
|
|
1194
1229
|
if (n && !t)
|
|
1195
1230
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
1196
|
-
if (
|
|
1197
|
-
const s = await
|
|
1198
|
-
return
|
|
1231
|
+
if (de && (!n || Ie === (t ?? null))) {
|
|
1232
|
+
const s = await de;
|
|
1233
|
+
return Ae(s);
|
|
1199
1234
|
}
|
|
1200
|
-
|
|
1201
|
-
const r =
|
|
1202
|
-
|
|
1203
|
-
const s = await
|
|
1204
|
-
|
|
1235
|
+
Ie = t ?? null, Ue.clear();
|
|
1236
|
+
const r = wn();
|
|
1237
|
+
de = (async () => {
|
|
1238
|
+
const s = await Er(t), c = await ht(
|
|
1239
|
+
gn(),
|
|
1205
1240
|
r,
|
|
1206
1241
|
n,
|
|
1207
1242
|
t
|
|
1208
1243
|
);
|
|
1209
|
-
let
|
|
1244
|
+
let a = null;
|
|
1210
1245
|
try {
|
|
1211
|
-
|
|
1212
|
-
|
|
1246
|
+
a = await ht(
|
|
1247
|
+
yn(),
|
|
1213
1248
|
r,
|
|
1214
1249
|
n,
|
|
1215
1250
|
t
|
|
1216
1251
|
);
|
|
1217
1252
|
} catch {
|
|
1218
|
-
|
|
1253
|
+
a = null;
|
|
1219
1254
|
}
|
|
1220
|
-
return { sil: s, viseme:
|
|
1255
|
+
return { sil: s, viseme: c, expression: a };
|
|
1221
1256
|
})();
|
|
1222
|
-
const i = await
|
|
1223
|
-
return
|
|
1257
|
+
const i = await de;
|
|
1258
|
+
return Ae(i);
|
|
1224
1259
|
}
|
|
1225
|
-
async function
|
|
1226
|
-
if (await
|
|
1227
|
-
return
|
|
1260
|
+
async function Mt(e) {
|
|
1261
|
+
if (await Ye(e), !de) throw new Error("Assets not loaded");
|
|
1262
|
+
return de;
|
|
1228
1263
|
}
|
|
1229
|
-
function
|
|
1230
|
-
return
|
|
1264
|
+
function Ae(e) {
|
|
1265
|
+
return $n(
|
|
1231
1266
|
e.viseme.atlasMeta,
|
|
1232
1267
|
e.sil.naturalWidth,
|
|
1233
1268
|
e.sil.naturalHeight
|
|
1234
1269
|
);
|
|
1235
1270
|
}
|
|
1236
|
-
function
|
|
1271
|
+
function Sr(e, t) {
|
|
1237
1272
|
const n = document.createElement("canvas");
|
|
1238
1273
|
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;
|
|
1239
1274
|
}
|
|
1240
|
-
async function
|
|
1241
|
-
const r = `${t.diffBase}::${n}`, i =
|
|
1275
|
+
async function mt(e, t, n) {
|
|
1276
|
+
const r = `${t.diffBase}::${n}`, i = Ue.get(r);
|
|
1242
1277
|
if (i) return i;
|
|
1243
1278
|
const s = (async () => {
|
|
1244
|
-
const
|
|
1245
|
-
if (!
|
|
1246
|
-
const
|
|
1247
|
-
if (
|
|
1248
|
-
const
|
|
1279
|
+
const c = t.cellByPath.get(n);
|
|
1280
|
+
if (!c) throw new Error(`No atlas cell for path: ${n}`);
|
|
1281
|
+
const a = Hn(t.atlasMeta, c), l = Ae(e);
|
|
1282
|
+
if (Wn(c)) {
|
|
1283
|
+
const m = Sr(t, c), S = document.createElement("canvas");
|
|
1249
1284
|
S.width = l.width, S.height = l.height;
|
|
1250
1285
|
const o = S.getContext("2d");
|
|
1251
|
-
return o.fillStyle = "#000", o.fillRect(0, 0, l.width, l.height), o.drawImage(
|
|
1286
|
+
return o.fillStyle = "#000", o.fillRect(0, 0, l.width, l.height), o.drawImage(m, a.x, a.y), S;
|
|
1252
1287
|
}
|
|
1253
|
-
const d = `${t.diffBase}/${n}`,
|
|
1254
|
-
if (
|
|
1255
|
-
return
|
|
1288
|
+
const d = `${t.diffBase}/${n}`, _ = await tt(d);
|
|
1289
|
+
if (_.naturalWidth === l.width && _.naturalHeight === l.height)
|
|
1290
|
+
return _;
|
|
1256
1291
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
1257
1292
|
})();
|
|
1258
|
-
return
|
|
1293
|
+
return Ue.set(r, s), s;
|
|
1259
1294
|
}
|
|
1260
|
-
async function
|
|
1295
|
+
async function _t(e, t, n, r = et, i, s) {
|
|
1261
1296
|
if (i) {
|
|
1262
1297
|
const { width: S, height: o } = i;
|
|
1263
1298
|
if (s && !s() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
1264
1299
|
return;
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
const w =
|
|
1300
|
+
const F = document.createElement("canvas");
|
|
1301
|
+
F.width = S, F.height = o;
|
|
1302
|
+
const w = F.getContext("2d");
|
|
1268
1303
|
if (w.clearRect(0, 0, S, o), w.drawImage(t, 0, 0, S, o), s && !s()) return;
|
|
1269
1304
|
(e.width !== S || e.height !== o) && (e.width = S, e.height = o);
|
|
1270
1305
|
const u = e.getContext("2d");
|
|
1271
|
-
u.clearRect(0, 0, S, o), u.drawImage(
|
|
1306
|
+
u.clearRect(0, 0, S, o), u.drawImage(F, 0, 0);
|
|
1272
1307
|
return;
|
|
1273
1308
|
}
|
|
1274
|
-
const
|
|
1275
|
-
(e.width !==
|
|
1276
|
-
const d = [],
|
|
1277
|
-
if (
|
|
1278
|
-
const S =
|
|
1279
|
-
|
|
1309
|
+
const c = await Mt(), { width: a, height: l } = Ae(c);
|
|
1310
|
+
(e.width !== a || e.height !== l) && (e.width = a, e.height = l);
|
|
1311
|
+
const d = [], _ = e.getContext("2d");
|
|
1312
|
+
if (_.clearRect(0, 0, a, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
1313
|
+
const S = c.sil;
|
|
1314
|
+
_.drawImage(S, 0, 0, a, l);
|
|
1280
1315
|
return;
|
|
1281
1316
|
}
|
|
1282
1317
|
if (d.length === 0) {
|
|
1283
|
-
|
|
1318
|
+
_.drawImage(t, 0, 0, a, l);
|
|
1284
1319
|
return;
|
|
1285
1320
|
}
|
|
1286
|
-
const
|
|
1287
|
-
|
|
1321
|
+
const m = xt(t, d, a, l, r);
|
|
1322
|
+
_.drawImage(m, 0, 0);
|
|
1288
1323
|
}
|
|
1289
|
-
async function
|
|
1290
|
-
const r = await
|
|
1324
|
+
async function Xe(e, t, n = et) {
|
|
1325
|
+
const r = await Mt(Ie ?? void 0), { width: i, height: s } = Ae(r);
|
|
1291
1326
|
(e.width !== i || e.height !== s) && (e.width = i, e.height = s);
|
|
1292
|
-
const
|
|
1293
|
-
t.mouthPath &&
|
|
1294
|
-
await
|
|
1327
|
+
const c = [];
|
|
1328
|
+
t.mouthPath && c.push(await mt(r, r.viseme, t.mouthPath)), t.expressionPath && r.expression && c.push(
|
|
1329
|
+
await mt(r, r.expression, t.expressionPath)
|
|
1295
1330
|
);
|
|
1296
|
-
const
|
|
1297
|
-
if (
|
|
1298
|
-
|
|
1331
|
+
const a = e.getContext("2d");
|
|
1332
|
+
if (a.clearRect(0, 0, i, s), c.length === 0) {
|
|
1333
|
+
a.drawImage(r.sil, 0, 0, i, s);
|
|
1299
1334
|
return;
|
|
1300
1335
|
}
|
|
1301
|
-
const l =
|
|
1336
|
+
const l = xt(
|
|
1302
1337
|
r.sil,
|
|
1303
|
-
|
|
1338
|
+
c,
|
|
1304
1339
|
i,
|
|
1305
1340
|
s,
|
|
1306
1341
|
n
|
|
1307
1342
|
);
|
|
1308
|
-
|
|
1343
|
+
a.drawImage(l, 0, 0);
|
|
1309
1344
|
}
|
|
1310
|
-
async function
|
|
1311
|
-
await
|
|
1345
|
+
async function kr(e) {
|
|
1346
|
+
await Xe(e, { mouthPath: null, expressionPath: null });
|
|
1312
1347
|
}
|
|
1313
|
-
function
|
|
1348
|
+
function Tr(e) {
|
|
1314
1349
|
const t = /* @__PURE__ */ new Map();
|
|
1315
1350
|
for (const n of e)
|
|
1316
1351
|
t.has(n.vtime) || t.set(n.vtime, n);
|
|
1317
1352
|
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
1318
1353
|
}
|
|
1319
|
-
function
|
|
1320
|
-
const t =
|
|
1354
|
+
function vr(e) {
|
|
1355
|
+
const t = Tr(e), n = [];
|
|
1321
1356
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1322
|
-
const i = t[r].viseme, s = t[r + 1].viseme,
|
|
1323
|
-
i === s ||
|
|
1357
|
+
const i = t[r].viseme, s = t[r + 1].viseme, c = t[r].vtime, a = t[r + 1].vtime;
|
|
1358
|
+
i === s || a <= c || n.push({ from: i, to: s, fromVtime: c, toVtime: a });
|
|
1324
1359
|
}
|
|
1325
1360
|
return n;
|
|
1326
1361
|
}
|
|
1327
|
-
function
|
|
1362
|
+
function Ir(e, t) {
|
|
1328
1363
|
let n = null;
|
|
1329
1364
|
for (const r of e)
|
|
1330
1365
|
t >= r.fromVtime && t < r.toVtime && (n = r);
|
|
1331
1366
|
return n;
|
|
1332
1367
|
}
|
|
1333
|
-
function
|
|
1368
|
+
function Ar(e, t) {
|
|
1334
1369
|
return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
|
|
1335
1370
|
}
|
|
1336
|
-
const
|
|
1337
|
-
function
|
|
1371
|
+
const Ct = 400, br = 200, Rr = 600, Dr = "__sil__";
|
|
1372
|
+
function xr() {
|
|
1338
1373
|
return { lastDrawnKey: "" };
|
|
1339
1374
|
}
|
|
1340
|
-
function
|
|
1375
|
+
function ge(e) {
|
|
1341
1376
|
e.lastDrawnKey = "";
|
|
1342
1377
|
}
|
|
1343
|
-
function
|
|
1344
|
-
|
|
1378
|
+
function Mr(e) {
|
|
1379
|
+
let t = "sil";
|
|
1380
|
+
for (const n of e)
|
|
1381
|
+
n.viseme !== "sil" && (t = n.viseme);
|
|
1382
|
+
return t;
|
|
1345
1383
|
}
|
|
1346
|
-
function
|
|
1384
|
+
function Cr(e) {
|
|
1385
|
+
return e === "sil" ? !1 : Rt(e, "sil").length > 0;
|
|
1386
|
+
}
|
|
1387
|
+
function Fr() {
|
|
1388
|
+
return Ct + Rr;
|
|
1389
|
+
}
|
|
1390
|
+
function wt(e) {
|
|
1391
|
+
return e ?? Dr;
|
|
1392
|
+
}
|
|
1393
|
+
function Lr(e, t) {
|
|
1347
1394
|
if (e.length === 0)
|
|
1348
1395
|
return { diffPath: null, label: "sil" };
|
|
1349
|
-
const n =
|
|
1396
|
+
const n = vr(e), r = Ir(n, t);
|
|
1350
1397
|
if (r) {
|
|
1351
|
-
const s = r.toVtime - r.fromVtime,
|
|
1352
|
-
if (t >=
|
|
1353
|
-
const
|
|
1398
|
+
const s = r.toVtime - r.fromVtime, c = Ar(r.fromVtime, r.toVtime);
|
|
1399
|
+
if (t >= c.transStart && t < r.toVtime) {
|
|
1400
|
+
const a = Rt(r.from, r.to), l = Yn(a, s);
|
|
1354
1401
|
if (l.length > 0) {
|
|
1355
|
-
const d =
|
|
1402
|
+
const d = Xn(
|
|
1356
1403
|
t,
|
|
1357
|
-
|
|
1404
|
+
c.transStart,
|
|
1358
1405
|
r.toVtime,
|
|
1359
1406
|
l.length
|
|
1360
1407
|
);
|
|
1361
1408
|
return { diffPath: l[d] ?? l[l.length - 1], label: `${r.from}→${r.to}` };
|
|
1362
1409
|
}
|
|
1363
|
-
return { diffPath:
|
|
1410
|
+
return { diffPath: Qe(r.to), label: r.to };
|
|
1364
1411
|
}
|
|
1365
1412
|
}
|
|
1366
|
-
const i =
|
|
1367
|
-
return i === "sil" ? { diffPath: null, label: "sil" } : { diffPath:
|
|
1413
|
+
const i = vt(e, t);
|
|
1414
|
+
return i === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Qe(i), label: i };
|
|
1368
1415
|
}
|
|
1369
|
-
function
|
|
1370
|
-
const n = t ??
|
|
1371
|
-
return `${
|
|
1416
|
+
function Ft(e, t) {
|
|
1417
|
+
const n = t ?? wt(e.expressionPath);
|
|
1418
|
+
return `${wt(e.mouthPath)}|${n}`;
|
|
1372
1419
|
}
|
|
1373
|
-
function
|
|
1374
|
-
const l =
|
|
1420
|
+
function Or(e, t, n, r, i, s, c, a) {
|
|
1421
|
+
const l = Lr(t, n), d = {
|
|
1375
1422
|
mouthPath: l.diffPath,
|
|
1376
1423
|
expressionPath: r
|
|
1377
|
-
},
|
|
1378
|
-
|
|
1379
|
-
|
|
1424
|
+
}, _ = Ft(d, i);
|
|
1425
|
+
_ !== s.lastDrawnKey && (a(l.label), c(e, d, _, (m) => {
|
|
1426
|
+
m === _ && (s.lastDrawnKey = _);
|
|
1380
1427
|
}));
|
|
1381
1428
|
}
|
|
1382
|
-
function
|
|
1383
|
-
const
|
|
1384
|
-
!(
|
|
1385
|
-
|
|
1386
|
-
), i(e,
|
|
1387
|
-
|
|
1429
|
+
function gt(e, t, n, r, i, s, c = null) {
|
|
1430
|
+
const a = { mouthPath: null, expressionPath: t }, l = c != null ? `|idle@${Math.round(c * 1e3)}` : "", d = Ft(a, n) + l;
|
|
1431
|
+
!(c != null) && d === r.lastDrawnKey || (s(
|
|
1432
|
+
c != null ? "idle" : "sil"
|
|
1433
|
+
), i(e, a, d, (m) => {
|
|
1434
|
+
m === d && (r.lastDrawnKey = d);
|
|
1388
1435
|
}));
|
|
1389
1436
|
}
|
|
1390
|
-
function
|
|
1437
|
+
function Lt(e) {
|
|
1391
1438
|
let t = 0, n = null, r = !1, i = !1;
|
|
1392
1439
|
const s = async () => {
|
|
1393
1440
|
if (!r) {
|
|
1394
1441
|
r = !0;
|
|
1395
1442
|
try {
|
|
1396
1443
|
for (; n; ) {
|
|
1397
|
-
const
|
|
1444
|
+
const a = n;
|
|
1398
1445
|
n = null;
|
|
1399
|
-
const l = ++t, d = await e(
|
|
1400
|
-
n || d && l === t &&
|
|
1446
|
+
const l = ++t, d = await e(a.diffs, l, a);
|
|
1447
|
+
n || d && l === t && a.onDisplayed?.(a.drawKey);
|
|
1401
1448
|
}
|
|
1402
1449
|
} finally {
|
|
1403
1450
|
r = !1, n && s();
|
|
1404
1451
|
}
|
|
1405
1452
|
}
|
|
1406
|
-
},
|
|
1453
|
+
}, c = () => {
|
|
1407
1454
|
i || (i = !0, queueMicrotask(() => {
|
|
1408
1455
|
i = !1, s();
|
|
1409
1456
|
}));
|
|
1410
1457
|
};
|
|
1411
1458
|
return {
|
|
1412
|
-
enqueue(
|
|
1413
|
-
n = { diffs:
|
|
1459
|
+
enqueue(a, l, d) {
|
|
1460
|
+
n = { diffs: a, drawKey: l, onDisplayed: d }, c();
|
|
1414
1461
|
},
|
|
1415
1462
|
reset() {
|
|
1416
1463
|
t += 1, n = null;
|
|
1417
1464
|
},
|
|
1418
|
-
isLatestSeq(
|
|
1419
|
-
return
|
|
1465
|
+
isLatestSeq(a) {
|
|
1466
|
+
return a === t;
|
|
1420
1467
|
},
|
|
1421
1468
|
getLatestSeq() {
|
|
1422
1469
|
return t;
|
|
1423
1470
|
}
|
|
1424
1471
|
};
|
|
1425
1472
|
}
|
|
1426
|
-
const
|
|
1427
|
-
async function
|
|
1428
|
-
let t =
|
|
1473
|
+
const yt = -1, pt = /* @__PURE__ */ new Map();
|
|
1474
|
+
async function Pr(e) {
|
|
1475
|
+
let t = pt.get(e);
|
|
1429
1476
|
if (!t) {
|
|
1430
1477
|
const n = await fetch(e);
|
|
1431
1478
|
if (!n.ok)
|
|
@@ -1433,37 +1480,37 @@ async function wr(e) {
|
|
|
1433
1480
|
`Failed to fetch worker script (${n.status}): ${e}`
|
|
1434
1481
|
);
|
|
1435
1482
|
const r = await n.blob();
|
|
1436
|
-
t = URL.createObjectURL(r),
|
|
1483
|
+
t = URL.createObjectURL(r), pt.set(e, t);
|
|
1437
1484
|
}
|
|
1438
1485
|
return new Worker(t, { name: "visemeDiffPreview" });
|
|
1439
1486
|
}
|
|
1440
|
-
function
|
|
1487
|
+
function Ur() {
|
|
1441
1488
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
1442
1489
|
}
|
|
1443
|
-
function
|
|
1490
|
+
function Br(e, t) {
|
|
1444
1491
|
(e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
|
|
1445
1492
|
const n = e.getContext("2d");
|
|
1446
1493
|
n && n.drawImage(t, 0, 0);
|
|
1447
1494
|
}
|
|
1448
|
-
function
|
|
1495
|
+
function Et(e, t) {
|
|
1449
1496
|
let n = 0;
|
|
1450
|
-
const r =
|
|
1497
|
+
const r = Lt(async (i, s) => (await Ye(), await Xe(e, i), r.isLatestSeq(s)));
|
|
1451
1498
|
return {
|
|
1452
1499
|
usesWorker: !1,
|
|
1453
1500
|
async loadAssets(i) {
|
|
1454
|
-
return await
|
|
1501
|
+
return await Ye(i);
|
|
1455
1502
|
},
|
|
1456
1503
|
async renderSilOnly() {
|
|
1457
|
-
n += 1, r.reset(), await
|
|
1504
|
+
n += 1, r.reset(), await kr(e);
|
|
1458
1505
|
},
|
|
1459
|
-
drawLiveFrame(i, s,
|
|
1460
|
-
r.enqueue(s,
|
|
1506
|
+
drawLiveFrame(i, s, c, a) {
|
|
1507
|
+
r.enqueue(s, c, a);
|
|
1461
1508
|
},
|
|
1462
1509
|
async renderViseme(i, s) {
|
|
1463
1510
|
n += 1;
|
|
1464
|
-
const
|
|
1465
|
-
t.onStatus?.(s), await
|
|
1466
|
-
mouthPath:
|
|
1511
|
+
const c = n;
|
|
1512
|
+
t.onStatus?.(s), await Xe(i, {
|
|
1513
|
+
mouthPath: Qe(s),
|
|
1467
1514
|
expressionPath: null
|
|
1468
1515
|
});
|
|
1469
1516
|
},
|
|
@@ -1472,9 +1519,9 @@ function ct(e, t) {
|
|
|
1472
1519
|
}
|
|
1473
1520
|
};
|
|
1474
1521
|
}
|
|
1475
|
-
function
|
|
1476
|
-
let r = null, i = 1, s = 0,
|
|
1477
|
-
const l = /* @__PURE__ */ new Map(), d =
|
|
1522
|
+
function Nr(e, t, n) {
|
|
1523
|
+
let r = null, i = 1, s = 0, c = !1, a = !1;
|
|
1524
|
+
const l = /* @__PURE__ */ new Map(), d = Lt(async (w, u, g) => (l.set(u, {
|
|
1478
1525
|
drawKey: g.drawKey,
|
|
1479
1526
|
onDisplayed: g.onDisplayed
|
|
1480
1527
|
}), await o(
|
|
@@ -1486,123 +1533,123 @@ function pr(e, t, n) {
|
|
|
1486
1533
|
},
|
|
1487
1534
|
void 0,
|
|
1488
1535
|
!0
|
|
1489
|
-
), !1)),
|
|
1490
|
-
if (w ===
|
|
1491
|
-
let
|
|
1492
|
-
for (const [
|
|
1493
|
-
|
|
1494
|
-
|
|
1536
|
+
), !1)), _ = (w) => {
|
|
1537
|
+
if (w === yt) {
|
|
1538
|
+
let y = -1, v;
|
|
1539
|
+
for (const [H, h] of l)
|
|
1540
|
+
H >= y && (y = H, v = h);
|
|
1541
|
+
y >= 0 && l.delete(y), v?.onDisplayed?.(v.drawKey);
|
|
1495
1542
|
return;
|
|
1496
1543
|
}
|
|
1497
1544
|
const u = -w, g = l.get(u);
|
|
1498
1545
|
l.delete(u), g?.onDisplayed?.(g.drawKey);
|
|
1499
|
-
},
|
|
1500
|
-
|
|
1546
|
+
}, m = /* @__PURE__ */ new Map(), S = (w, u) => {
|
|
1547
|
+
a || !r || r.postMessage(w, []);
|
|
1501
1548
|
}, o = (w, u, g = !1) => {
|
|
1502
|
-
if (
|
|
1503
|
-
const
|
|
1504
|
-
return new Promise((
|
|
1505
|
-
|
|
1506
|
-
resolve: (
|
|
1507
|
-
reject:
|
|
1549
|
+
if (a) return Promise.resolve();
|
|
1550
|
+
const y = i++;
|
|
1551
|
+
return new Promise((v, H) => {
|
|
1552
|
+
m.set(y, {
|
|
1553
|
+
resolve: (h) => v(h),
|
|
1554
|
+
reject: H,
|
|
1508
1555
|
generation: typeof w.generation == "number" ? w.generation : void 0,
|
|
1509
1556
|
expectRenderDone: g
|
|
1510
|
-
}), S({ ...w, requestId:
|
|
1557
|
+
}), S({ ...w, requestId: y });
|
|
1511
1558
|
});
|
|
1512
|
-
},
|
|
1513
|
-
r = await
|
|
1514
|
-
if (
|
|
1559
|
+
}, F = (async () => {
|
|
1560
|
+
r = await Pr(n), r.onmessage = (w) => {
|
|
1561
|
+
if (a) return;
|
|
1515
1562
|
const u = w.data;
|
|
1516
1563
|
if (u.type === "status") {
|
|
1517
1564
|
t.onStatus?.(u.label);
|
|
1518
1565
|
return;
|
|
1519
1566
|
}
|
|
1520
1567
|
if (u.type === "frame") {
|
|
1521
|
-
const
|
|
1522
|
-
if (!
|
|
1568
|
+
const y = u.generation < 0;
|
|
1569
|
+
if (!y && u.generation !== s) {
|
|
1523
1570
|
u.bitmap.close();
|
|
1524
1571
|
return;
|
|
1525
1572
|
}
|
|
1526
|
-
if (
|
|
1527
|
-
const
|
|
1528
|
-
if (!d.isLatestSeq(
|
|
1573
|
+
if (y && !(u.generation === yt)) {
|
|
1574
|
+
const H = -u.generation;
|
|
1575
|
+
if (!d.isLatestSeq(H)) {
|
|
1529
1576
|
u.bitmap.close();
|
|
1530
1577
|
return;
|
|
1531
1578
|
}
|
|
1532
1579
|
}
|
|
1533
|
-
if (
|
|
1580
|
+
if (y && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
1534
1581
|
u.bitmap.close();
|
|
1535
1582
|
return;
|
|
1536
1583
|
}
|
|
1537
|
-
|
|
1584
|
+
Br(e, u.bitmap), u.bitmap.close(), y && _(u.generation);
|
|
1538
1585
|
return;
|
|
1539
1586
|
}
|
|
1540
|
-
const g =
|
|
1587
|
+
const g = m.get(u.requestId);
|
|
1541
1588
|
if (g)
|
|
1542
1589
|
switch (u.type) {
|
|
1543
1590
|
case "ready":
|
|
1544
|
-
|
|
1591
|
+
m.delete(u.requestId), g.resolve();
|
|
1545
1592
|
break;
|
|
1546
1593
|
case "loadAssetsDone":
|
|
1547
|
-
|
|
1594
|
+
m.delete(u.requestId), g.resolve({ width: u.width, height: u.height });
|
|
1548
1595
|
break;
|
|
1549
1596
|
case "renderDone":
|
|
1550
1597
|
if (g.expectRenderDone && g.generation != null && u.generation !== g.generation)
|
|
1551
1598
|
return;
|
|
1552
|
-
|
|
1599
|
+
m.delete(u.requestId), g.resolve();
|
|
1553
1600
|
break;
|
|
1554
1601
|
case "renderAborted":
|
|
1555
|
-
|
|
1602
|
+
m.delete(u.requestId), g.resolve();
|
|
1556
1603
|
break;
|
|
1557
1604
|
case "error":
|
|
1558
|
-
|
|
1605
|
+
m.delete(u.requestId), t.onError?.(u.message), g.reject(new Error(u.message));
|
|
1559
1606
|
break;
|
|
1560
1607
|
}
|
|
1561
1608
|
}, r.onerror = (w) => {
|
|
1562
|
-
if (
|
|
1609
|
+
if (a) return;
|
|
1563
1610
|
const u = w.message || "Worker error";
|
|
1564
1611
|
t.onError?.(u);
|
|
1565
|
-
for (const [, g] of
|
|
1612
|
+
for (const [, g] of m)
|
|
1566
1613
|
g.reject(new Error(u));
|
|
1567
|
-
|
|
1568
|
-
}, await o({ type: "init" }),
|
|
1614
|
+
m.clear();
|
|
1615
|
+
}, await o({ type: "init" }), c = !0;
|
|
1569
1616
|
})();
|
|
1570
1617
|
return {
|
|
1571
1618
|
usesWorker: !0,
|
|
1572
1619
|
async loadAssets(w) {
|
|
1573
|
-
if (
|
|
1574
|
-
if (await
|
|
1575
|
-
if (!
|
|
1620
|
+
if (a) return { width: 842, height: 1264 };
|
|
1621
|
+
if (await F, a) return { width: 842, height: 1264 };
|
|
1622
|
+
if (!c) throw new Error("Worker init failed");
|
|
1576
1623
|
return await o({
|
|
1577
1624
|
type: "loadAssets",
|
|
1578
1625
|
keyHex: w,
|
|
1579
|
-
urls:
|
|
1626
|
+
urls: hn(he())
|
|
1580
1627
|
}) ?? { width: 842, height: 1264 };
|
|
1581
1628
|
},
|
|
1582
1629
|
async renderSilOnly() {
|
|
1583
|
-
if (
|
|
1630
|
+
if (a || (await F, a)) return;
|
|
1584
1631
|
s += 1, d.reset(), l.clear();
|
|
1585
1632
|
const w = s;
|
|
1586
|
-
await o(
|
|
1633
|
+
await o({ type: "cancelLiveDraws" }), await o(
|
|
1587
1634
|
{ type: "renderSil", generation: w },
|
|
1588
1635
|
void 0,
|
|
1589
1636
|
!0
|
|
1590
1637
|
);
|
|
1591
1638
|
},
|
|
1592
|
-
drawLiveFrame(w, u, g,
|
|
1593
|
-
|
|
1594
|
-
|
|
1639
|
+
drawLiveFrame(w, u, g, y) {
|
|
1640
|
+
a || F.then(() => {
|
|
1641
|
+
a || d.enqueue(u, g, y);
|
|
1595
1642
|
});
|
|
1596
1643
|
},
|
|
1597
1644
|
async renderViseme(w, u, g = {}) {
|
|
1598
|
-
if (
|
|
1599
|
-
s += 1;
|
|
1600
|
-
const
|
|
1645
|
+
if (a || (await F, a)) return;
|
|
1646
|
+
s += 1, d.reset(), l.clear();
|
|
1647
|
+
const y = s;
|
|
1601
1648
|
try {
|
|
1602
|
-
await o(
|
|
1649
|
+
await o({ type: "cancelLiveDraws" }), await o(
|
|
1603
1650
|
{
|
|
1604
1651
|
type: "renderViseme",
|
|
1605
|
-
generation:
|
|
1652
|
+
generation: y,
|
|
1606
1653
|
to: u,
|
|
1607
1654
|
from: g.from,
|
|
1608
1655
|
transitionDurationMs: g.transitionDurationMs,
|
|
@@ -1612,60 +1659,60 @@ function pr(e, t, n) {
|
|
|
1612
1659
|
void 0,
|
|
1613
1660
|
!0
|
|
1614
1661
|
);
|
|
1615
|
-
} catch (
|
|
1616
|
-
if (
|
|
1617
|
-
throw
|
|
1662
|
+
} catch (v) {
|
|
1663
|
+
if (v?.name === "AbortError") return;
|
|
1664
|
+
throw v;
|
|
1618
1665
|
}
|
|
1619
1666
|
},
|
|
1620
1667
|
dispose() {
|
|
1621
|
-
if (!
|
|
1622
|
-
|
|
1623
|
-
for (const [, w] of
|
|
1668
|
+
if (!a) {
|
|
1669
|
+
a = !0, s += 1, d.reset(), l.clear();
|
|
1670
|
+
for (const [, w] of m)
|
|
1624
1671
|
w.resolve();
|
|
1625
|
-
|
|
1672
|
+
m.clear(), r?.terminate(), r = null;
|
|
1626
1673
|
}
|
|
1627
1674
|
}
|
|
1628
1675
|
};
|
|
1629
1676
|
}
|
|
1630
|
-
function
|
|
1631
|
-
if (!
|
|
1632
|
-
return
|
|
1633
|
-
const n =
|
|
1677
|
+
function Vr(e, t = {}) {
|
|
1678
|
+
if (!Ur())
|
|
1679
|
+
return Et(e, t);
|
|
1680
|
+
const n = zt(t.workerScriptUrl);
|
|
1634
1681
|
try {
|
|
1635
|
-
return
|
|
1682
|
+
return Nr(e, t, n);
|
|
1636
1683
|
} catch {
|
|
1637
|
-
return
|
|
1684
|
+
return Et(e, t);
|
|
1638
1685
|
}
|
|
1639
1686
|
}
|
|
1640
|
-
class
|
|
1687
|
+
class $r extends Error {
|
|
1641
1688
|
constructor(t, n) {
|
|
1642
1689
|
super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
1643
1690
|
}
|
|
1644
1691
|
}
|
|
1645
|
-
function
|
|
1692
|
+
function qe(e, t, n) {
|
|
1646
1693
|
return new Promise((r, i) => {
|
|
1647
1694
|
const s = globalThis.setTimeout(() => {
|
|
1648
|
-
i(new
|
|
1695
|
+
i(new $r(n, t));
|
|
1649
1696
|
}, t);
|
|
1650
1697
|
e.then(
|
|
1651
|
-
(
|
|
1652
|
-
globalThis.clearTimeout(s), r(
|
|
1698
|
+
(c) => {
|
|
1699
|
+
globalThis.clearTimeout(s), r(c);
|
|
1653
1700
|
},
|
|
1654
|
-
(
|
|
1655
|
-
globalThis.clearTimeout(s), i(
|
|
1701
|
+
(c) => {
|
|
1702
|
+
globalThis.clearTimeout(s), i(c);
|
|
1656
1703
|
}
|
|
1657
1704
|
);
|
|
1658
1705
|
});
|
|
1659
1706
|
}
|
|
1660
|
-
const
|
|
1707
|
+
const Hr = {
|
|
1661
1708
|
position: "relative",
|
|
1662
1709
|
display: "inline-block",
|
|
1663
1710
|
lineHeight: 0
|
|
1664
|
-
},
|
|
1711
|
+
}, Wr = {
|
|
1665
1712
|
display: "block",
|
|
1666
1713
|
maxWidth: "100%",
|
|
1667
1714
|
height: "auto"
|
|
1668
|
-
},
|
|
1715
|
+
}, qr = {
|
|
1669
1716
|
position: "absolute",
|
|
1670
1717
|
inset: 0,
|
|
1671
1718
|
display: "flex",
|
|
@@ -1677,304 +1724,394 @@ const Sr = {
|
|
|
1677
1724
|
fontSize: "0.875rem",
|
|
1678
1725
|
textAlign: "center"
|
|
1679
1726
|
};
|
|
1680
|
-
function
|
|
1681
|
-
return
|
|
1727
|
+
function Oe(e) {
|
|
1728
|
+
return Xt(e) ? Nn : It;
|
|
1682
1729
|
}
|
|
1683
|
-
const
|
|
1730
|
+
const zr = Nt(function({
|
|
1684
1731
|
id: t,
|
|
1685
1732
|
assets: n,
|
|
1686
1733
|
authToken: r,
|
|
1687
|
-
ttsEngineId: i =
|
|
1734
|
+
ttsEngineId: i = pe,
|
|
1688
1735
|
voiceId: s,
|
|
1689
|
-
speakingRate:
|
|
1690
|
-
className:
|
|
1736
|
+
speakingRate: c = At,
|
|
1737
|
+
className: a,
|
|
1691
1738
|
style: l,
|
|
1692
1739
|
canvasStyle: d,
|
|
1693
|
-
onStatusChange:
|
|
1694
|
-
onDisplayStatus:
|
|
1740
|
+
onStatusChange: _,
|
|
1741
|
+
onDisplayStatus: m,
|
|
1695
1742
|
onError: S,
|
|
1696
1743
|
onReady: o,
|
|
1697
|
-
showErrorOverlay:
|
|
1744
|
+
showErrorOverlay: F = !0
|
|
1698
1745
|
}, w) {
|
|
1699
|
-
const u =
|
|
1746
|
+
const u = R(null), g = R(null), y = R(xr()), v = R(dr()), H = R(0), h = R(0), E = R(null), D = R(null), L = R(!1), z = R(!1), U = R(!1), ae = R("sil"), me = R(!1), N = R(
|
|
1700
1747
|
null
|
|
1701
|
-
),
|
|
1702
|
-
P.current = o,
|
|
1703
|
-
const
|
|
1748
|
+
), X = R(!1), [Re, He] = ke("idle"), [De, ue] = ke(null), [se, xe] = ke(!1), [nt, p] = ke(!1), [V, W] = ke({ width: 842, height: 1264 }), x = R(r ?? null), M = R(null), I = R(null), Q = R(!1), J = R({ width: 842, height: 1264 }), P = R(o), O = R(m), q = R(S);
|
|
1749
|
+
P.current = o, O.current = m, q.current = S;
|
|
1750
|
+
const ce = ie(
|
|
1704
1751
|
(f) => {
|
|
1705
|
-
const k = f?.ttsEngineId ?? i ??
|
|
1706
|
-
return { ttsEngineId: k, voiceId:
|
|
1752
|
+
const k = f?.ttsEngineId ?? i ?? I.current?.ttsEngineId ?? pe, T = f?.voiceId ?? s ?? I.current?.voiceId ?? Oe(k);
|
|
1753
|
+
return { ttsEngineId: k, voiceId: T };
|
|
1707
1754
|
},
|
|
1708
1755
|
[i, s]
|
|
1709
|
-
), $ =
|
|
1710
|
-
|
|
1711
|
-
}, []),
|
|
1756
|
+
), $ = ie((f) => {
|
|
1757
|
+
ue(f), q.current?.(f);
|
|
1758
|
+
}, []), Me = ie(
|
|
1712
1759
|
(f) => {
|
|
1713
|
-
|
|
1760
|
+
He(f), _?.(f);
|
|
1714
1761
|
},
|
|
1715
|
-
[
|
|
1716
|
-
),
|
|
1717
|
-
|
|
1718
|
-
),
|
|
1762
|
+
[_]
|
|
1763
|
+
), B = R(
|
|
1764
|
+
Vn(Me, Pe)
|
|
1765
|
+
), b = ie(() => {
|
|
1719
1766
|
E.current != null && (clearTimeout(E.current), E.current = null);
|
|
1720
|
-
}, []),
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1767
|
+
}, []), K = ie(() => {
|
|
1768
|
+
D.current != null && (clearTimeout(D.current), D.current = null), U.current = !1;
|
|
1769
|
+
}, []), te = ie(() => {
|
|
1770
|
+
!X.current || !N.current || (K(), U.current = !0, D.current = setTimeout(() => {
|
|
1771
|
+
if (D.current = null, B.current.isSpeaking()) {
|
|
1772
|
+
U.current = !1;
|
|
1773
|
+
return;
|
|
1774
|
+
}
|
|
1775
|
+
if (L.current) {
|
|
1776
|
+
U.current = !1;
|
|
1777
|
+
return;
|
|
1778
|
+
}
|
|
1779
|
+
const f = N.current;
|
|
1780
|
+
if (!f) {
|
|
1781
|
+
U.current = !1;
|
|
1782
|
+
return;
|
|
1783
|
+
}
|
|
1784
|
+
f.restart(), f.setActive(!0);
|
|
1785
|
+
const k = f.getVideo();
|
|
1786
|
+
let T = !1;
|
|
1787
|
+
const A = () => {
|
|
1788
|
+
T || (T = !0, k.removeEventListener("playing", C), U.current = !1);
|
|
1789
|
+
}, C = () => {
|
|
1790
|
+
A();
|
|
1791
|
+
};
|
|
1792
|
+
if (k.addEventListener("playing", C, { once: !0 }), k.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !k.paused) {
|
|
1793
|
+
A();
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1796
|
+
setTimeout(A, 300);
|
|
1797
|
+
}, br));
|
|
1798
|
+
}, [K]), Z = ie(() => {
|
|
1799
|
+
if (b(), O.current?.("sil"), L.current = !1, !X.current || !N.current) {
|
|
1800
|
+
U.current = !1;
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
te();
|
|
1804
|
+
}, [b, te]), j = ie(
|
|
1805
|
+
async (f) => {
|
|
1806
|
+
const k = h.current, T = g.current, A = u.current, C = () => {
|
|
1807
|
+
f?.fallbackOnly || (L.current = !1);
|
|
1808
|
+
};
|
|
1809
|
+
if (!T || !A || !se) {
|
|
1810
|
+
C();
|
|
1811
|
+
return;
|
|
1812
|
+
}
|
|
1813
|
+
if (B.current.isSpeaking()) {
|
|
1814
|
+
C();
|
|
1815
|
+
return;
|
|
1816
|
+
}
|
|
1817
|
+
if (f?.fallbackOnly) {
|
|
1818
|
+
if (!L.current || (ge(y.current), await T.renderSilOnly(), k !== h.current) || B.current.isSpeaking()) return;
|
|
1819
|
+
Z();
|
|
1820
|
+
return;
|
|
1821
|
+
}
|
|
1822
|
+
const Y = ae.current !== "sil" ? ae.current : Mr(B.current.getVisemeQueue()), ne = Cr(Y);
|
|
1823
|
+
if (ge(y.current), !ne) {
|
|
1824
|
+
if (await T.renderSilOnly(), k !== h.current || B.current.isSpeaking()) return;
|
|
1825
|
+
Z();
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1828
|
+
try {
|
|
1829
|
+
await T.renderViseme(A, "sil", {
|
|
1830
|
+
from: Y,
|
|
1831
|
+
transitionDurationMs: Ct
|
|
1832
|
+
});
|
|
1833
|
+
} catch (oe) {
|
|
1834
|
+
if (oe?.name !== "AbortError")
|
|
1835
|
+
throw oe;
|
|
1836
|
+
}
|
|
1837
|
+
if (k !== h.current) {
|
|
1838
|
+
C();
|
|
1839
|
+
return;
|
|
1840
|
+
}
|
|
1841
|
+
if (B.current.isSpeaking()) {
|
|
1842
|
+
C();
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
Z();
|
|
1846
|
+
},
|
|
1847
|
+
[se, Z]
|
|
1848
|
+
), _e = ie(() => {
|
|
1849
|
+
if (z.current || L.current) return;
|
|
1850
|
+
z.current = !0, L.current = !0, b();
|
|
1851
|
+
const f = h.current;
|
|
1852
|
+
j().finally(() => {
|
|
1853
|
+
z.current = !1;
|
|
1854
|
+
}), E.current = setTimeout(() => {
|
|
1855
|
+
E.current = null, f === h.current && j({ fallbackOnly: !0 });
|
|
1856
|
+
}, Fr());
|
|
1857
|
+
}, [b, j]), rt = ie(async () => {
|
|
1730
1858
|
const f = Math.floor(Date.now() / 1e3);
|
|
1731
|
-
if (
|
|
1732
|
-
return
|
|
1733
|
-
const k =
|
|
1734
|
-
|
|
1735
|
-
const
|
|
1736
|
-
return
|
|
1737
|
-
key:
|
|
1738
|
-
expiresAt:
|
|
1739
|
-
},
|
|
1859
|
+
if (M.current && f < M.current.expiresAt - 60)
|
|
1860
|
+
return M.current.key;
|
|
1861
|
+
const k = x.current ?? await ot();
|
|
1862
|
+
x.current = k, B.current.setDeveloperToken(k);
|
|
1863
|
+
const T = await an(k, Pe);
|
|
1864
|
+
return M.current = {
|
|
1865
|
+
key: T.value,
|
|
1866
|
+
expiresAt: T.expiresAt
|
|
1867
|
+
}, T.value;
|
|
1740
1868
|
}, []);
|
|
1741
|
-
|
|
1742
|
-
r && (
|
|
1743
|
-
}, [r]),
|
|
1744
|
-
|
|
1745
|
-
}, [i]),
|
|
1746
|
-
const f = s ??
|
|
1747
|
-
|
|
1869
|
+
Te(() => {
|
|
1870
|
+
r && (x.current = r, B.current.setDeveloperToken(r));
|
|
1871
|
+
}, [r]), Te(() => {
|
|
1872
|
+
B.current.setTtsEngineId(i), I.current && (I.current.ttsEngineId = i);
|
|
1873
|
+
}, [i]), Te(() => {
|
|
1874
|
+
const f = s ?? Oe(i);
|
|
1875
|
+
I.current && (I.current.voiceId = f);
|
|
1748
1876
|
}, [s, i]);
|
|
1749
|
-
const
|
|
1877
|
+
const Ot = Vt(
|
|
1750
1878
|
() => n ? JSON.stringify(n) : `id:${t ?? ""}`,
|
|
1751
1879
|
[n, t]
|
|
1752
1880
|
);
|
|
1753
|
-
return
|
|
1881
|
+
return Te(() => {
|
|
1754
1882
|
if (!t && !n) {
|
|
1755
1883
|
$("AiTwin requires either `id` or `assets`");
|
|
1756
1884
|
return;
|
|
1757
1885
|
}
|
|
1758
1886
|
let f = !1;
|
|
1759
|
-
|
|
1887
|
+
Q.current = !1, xe(!1), p(!1), ue(null), I.current = null, N.current = null, X.current = !1;
|
|
1760
1888
|
const k = u.current;
|
|
1761
1889
|
if (!k) return;
|
|
1762
|
-
let
|
|
1890
|
+
let T = null;
|
|
1763
1891
|
return (async () => {
|
|
1764
1892
|
try {
|
|
1765
|
-
let
|
|
1893
|
+
let A, C, Y;
|
|
1766
1894
|
if (n)
|
|
1767
|
-
|
|
1895
|
+
A = n, C = i, Y = s ?? Oe(C);
|
|
1768
1896
|
else {
|
|
1769
|
-
|
|
1770
|
-
const
|
|
1771
|
-
|
|
1897
|
+
O.current?.("getAiTwin");
|
|
1898
|
+
const G = await qe(
|
|
1899
|
+
en(t),
|
|
1772
1900
|
3e4,
|
|
1773
1901
|
"getAiTwin"
|
|
1774
1902
|
);
|
|
1775
1903
|
if (f) return;
|
|
1776
|
-
if (!
|
|
1904
|
+
if (!G.faceId?.trim())
|
|
1777
1905
|
throw new Error("getAiTwin returned no faceId");
|
|
1778
|
-
|
|
1906
|
+
C = G.ttsEngineId, Y = s ?? G.voiceId ?? Oe(C), A = fn(G.faceId);
|
|
1779
1907
|
}
|
|
1780
|
-
|
|
1781
|
-
onStatus: (
|
|
1782
|
-
f ||
|
|
1908
|
+
I.current = { ttsEngineId: C, voiceId: Y }, dn(A), N.current = hr(), T = Vr(k, {
|
|
1909
|
+
onStatus: (G) => {
|
|
1910
|
+
f || O.current?.(G);
|
|
1783
1911
|
},
|
|
1784
|
-
onError: (
|
|
1785
|
-
f || $(
|
|
1912
|
+
onError: (G) => {
|
|
1913
|
+
f || $(G);
|
|
1786
1914
|
},
|
|
1787
|
-
shouldAcceptLiveFrame: () =>
|
|
1788
|
-
}), g.current =
|
|
1789
|
-
const
|
|
1915
|
+
shouldAcceptLiveFrame: () => B.current.isSpeaking() && !L.current
|
|
1916
|
+
}), g.current = T, O.current?.("auth");
|
|
1917
|
+
const ne = x.current ?? r ?? await qe(ot(), 3e4, "getAuthToken");
|
|
1790
1918
|
if (f) return;
|
|
1791
|
-
|
|
1792
|
-
const
|
|
1919
|
+
x.current = ne, B.current.setDeveloperToken(ne), B.current.setTtsEngineId(C);
|
|
1920
|
+
const oe = Be() ? await rt() : void 0;
|
|
1793
1921
|
if (f) return;
|
|
1794
|
-
|
|
1795
|
-
const
|
|
1796
|
-
|
|
1922
|
+
O.current?.("loadAssets");
|
|
1923
|
+
const we = await qe(
|
|
1924
|
+
T.loadAssets(oe),
|
|
1797
1925
|
18e4,
|
|
1798
1926
|
"load face assets"
|
|
1799
1927
|
);
|
|
1800
|
-
if (!f &&
|
|
1801
|
-
|
|
1802
|
-
f ||
|
|
1928
|
+
if (!f && we.width > 0 && we.height > 0 && (J.current = we, W(we)), f) return;
|
|
1929
|
+
Q.current = !0, xe(!0), P.current?.(), T.renderSilOnly().then(() => {
|
|
1930
|
+
f || O.current?.("sil");
|
|
1803
1931
|
}), (async () => {
|
|
1804
1932
|
try {
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1933
|
+
const G = await zn(oe);
|
|
1934
|
+
if (await N.current.load(G), f) return;
|
|
1935
|
+
X.current = !0, p(!0), ge(y.current), N.current.setActive(!0);
|
|
1936
|
+
const re = N.current.getVideo();
|
|
1937
|
+
await _t(
|
|
1809
1938
|
k,
|
|
1810
|
-
|
|
1939
|
+
re,
|
|
1811
1940
|
null,
|
|
1812
1941
|
void 0,
|
|
1813
|
-
|
|
1814
|
-
), f ||
|
|
1815
|
-
} catch (
|
|
1942
|
+
J.current
|
|
1943
|
+
), f || O.current?.("idle");
|
|
1944
|
+
} catch (G) {
|
|
1816
1945
|
if (f) return;
|
|
1817
|
-
|
|
1946
|
+
X.current = !1, p(!1), console.warn("[AiTwin] Idle video unavailable:", G);
|
|
1818
1947
|
}
|
|
1819
1948
|
})();
|
|
1820
|
-
} catch (
|
|
1949
|
+
} catch (A) {
|
|
1821
1950
|
if (f) return;
|
|
1822
|
-
if (
|
|
1823
|
-
$(
|
|
1951
|
+
if (A instanceof Ke) {
|
|
1952
|
+
$(A.message);
|
|
1824
1953
|
return;
|
|
1825
1954
|
}
|
|
1826
|
-
$(
|
|
1955
|
+
$(A instanceof Error ? A.message : "Failed to load AI twin");
|
|
1827
1956
|
}
|
|
1828
1957
|
})(), () => {
|
|
1829
|
-
f = !0,
|
|
1958
|
+
f = !0, N.current?.dispose(), T?.dispose(), g.current = null;
|
|
1830
1959
|
};
|
|
1831
|
-
}, [
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
if (!I || !R || !K) {
|
|
1837
|
-
V.current = requestAnimationFrame(v);
|
|
1960
|
+
}, [Ot, n, i, s, r, rt, $]), Te(() => {
|
|
1961
|
+
const f = B.current, k = { current: !1 }, T = () => {
|
|
1962
|
+
const A = u.current, C = g.current;
|
|
1963
|
+
if (!A || !C || !se) {
|
|
1964
|
+
H.current = requestAnimationFrame(T);
|
|
1838
1965
|
return;
|
|
1839
1966
|
}
|
|
1840
|
-
const
|
|
1841
|
-
|
|
1967
|
+
const Y = f.isSpeaking(), ne = me.current && !Y;
|
|
1968
|
+
ne && (v.current.reset(), N.current?.setActive(!1), _e());
|
|
1969
|
+
const oe = f.getPlaybackElapsedMs(), we = Y ? gr(
|
|
1970
|
+
oe,
|
|
1842
1971
|
f.getSentenceEmotions(),
|
|
1843
1972
|
f.getWordQueue(),
|
|
1844
1973
|
f.getStreamMood()
|
|
1845
|
-
) : f.getStreamMood();
|
|
1846
|
-
if (
|
|
1847
|
-
|
|
1848
|
-
|
|
1974
|
+
) : f.getStreamMood(), G = ne || L.current || U.current;
|
|
1975
|
+
if (Y) {
|
|
1976
|
+
X.current && N.current?.setActive(!1);
|
|
1977
|
+
const re = f.getVisemeQueue();
|
|
1978
|
+
if (re.length === 0) {
|
|
1979
|
+
H.current = requestAnimationFrame(T);
|
|
1849
1980
|
return;
|
|
1850
1981
|
}
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1982
|
+
const le = vt(re, oe);
|
|
1983
|
+
le !== "sil" && (ae.current = le), v.current.setTargetEmotion(we), v.current.advance(performance.now());
|
|
1984
|
+
const fe = v.current.getExpressionPath(), Ee = v.current.getDrawKey();
|
|
1985
|
+
Or(
|
|
1986
|
+
A,
|
|
1855
1987
|
f.getVisemeQueue(),
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
(
|
|
1861
|
-
(
|
|
1988
|
+
oe,
|
|
1989
|
+
fe,
|
|
1990
|
+
Ee,
|
|
1991
|
+
y.current,
|
|
1992
|
+
(Se, We, Pt, Ut) => C.drawLiveFrame(Se, We, Pt, Ut),
|
|
1993
|
+
(Se) => O.current?.(Se)
|
|
1862
1994
|
);
|
|
1863
|
-
} else if (
|
|
1864
|
-
const
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1995
|
+
} else if (!G && X.current && N.current) {
|
|
1996
|
+
const re = N.current, le = re.getVideo();
|
|
1997
|
+
le.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), k.current || (k.current = !0, _t(
|
|
1998
|
+
A,
|
|
1999
|
+
le,
|
|
1868
2000
|
null,
|
|
1869
2001
|
void 0,
|
|
1870
|
-
|
|
1871
|
-
() => !f.isSpeaking()
|
|
1872
|
-
).then(() =>
|
|
2002
|
+
J.current,
|
|
2003
|
+
() => !f.isSpeaking() && !L.current && !U.current
|
|
2004
|
+
).then(() => O.current?.("idle")).finally(() => {
|
|
1873
2005
|
k.current = !1;
|
|
1874
|
-
}))) :
|
|
1875
|
-
|
|
2006
|
+
}))) : gt(
|
|
2007
|
+
A,
|
|
1876
2008
|
null,
|
|
1877
2009
|
"__sil__",
|
|
1878
|
-
|
|
1879
|
-
(
|
|
1880
|
-
(
|
|
2010
|
+
y.current,
|
|
2011
|
+
(fe, Ee, Se, We) => C.drawLiveFrame(fe, Ee, Se, We),
|
|
2012
|
+
(fe) => O.current?.(fe)
|
|
1881
2013
|
);
|
|
1882
|
-
} else
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
x.current && !G && (A.current.reset(), b.current?.setActive(!1), H()), x.current = G, V.current = requestAnimationFrame(v);
|
|
2014
|
+
} else G || gt(
|
|
2015
|
+
A,
|
|
2016
|
+
null,
|
|
2017
|
+
"__sil__",
|
|
2018
|
+
y.current,
|
|
2019
|
+
(re, le, fe, Ee) => C.drawLiveFrame(re, le, fe, Ee),
|
|
2020
|
+
(re) => O.current?.(re)
|
|
2021
|
+
);
|
|
2022
|
+
me.current = Y, H.current = requestAnimationFrame(T);
|
|
1892
2023
|
};
|
|
1893
|
-
return
|
|
1894
|
-
cancelAnimationFrame(
|
|
2024
|
+
return H.current = requestAnimationFrame(T), () => {
|
|
2025
|
+
cancelAnimationFrame(H.current), b(), K(), f.stop();
|
|
1895
2026
|
};
|
|
1896
|
-
}, [
|
|
2027
|
+
}, [
|
|
2028
|
+
se,
|
|
2029
|
+
nt,
|
|
2030
|
+
_e,
|
|
2031
|
+
b,
|
|
2032
|
+
K
|
|
2033
|
+
]), $t(
|
|
1897
2034
|
w,
|
|
1898
2035
|
() => ({
|
|
1899
2036
|
speakText: async (f, k) => {
|
|
1900
|
-
const
|
|
1901
|
-
if (!
|
|
1902
|
-
const
|
|
1903
|
-
if (!
|
|
2037
|
+
const T = f.trim();
|
|
2038
|
+
if (!T) return;
|
|
2039
|
+
const A = g.current;
|
|
2040
|
+
if (!A || !Q.current && !se)
|
|
1904
2041
|
throw new Error("AI twin is not ready");
|
|
1905
|
-
const { ttsEngineId:
|
|
1906
|
-
|
|
2042
|
+
const { ttsEngineId: C, voiceId: Y } = ce(k);
|
|
2043
|
+
ue(null), h.current += 1, b(), K(), L.current = !1, z.current = !1, ae.current = "sil", ge(y.current), v.current.reset(), me.current = !1;
|
|
1907
2044
|
try {
|
|
1908
|
-
|
|
1909
|
-
voiceId:
|
|
1910
|
-
speakingRate: k?.speakingRate ??
|
|
1911
|
-
ttsEngineId:
|
|
2045
|
+
X.current ? (N.current?.setActive(!1), N.current?.restart(), ge(y.current)) : await A.renderSilOnly(), await B.current.speak(T, {
|
|
2046
|
+
voiceId: Y,
|
|
2047
|
+
speakingRate: k?.speakingRate ?? c,
|
|
2048
|
+
ttsEngineId: C
|
|
1912
2049
|
});
|
|
1913
|
-
} catch (
|
|
1914
|
-
throw $(
|
|
2050
|
+
} catch (ne) {
|
|
2051
|
+
throw $(ne instanceof Error ? ne.message : "TTS failed"), ne;
|
|
1915
2052
|
}
|
|
1916
2053
|
},
|
|
1917
2054
|
stop: () => {
|
|
1918
|
-
|
|
2055
|
+
h.current += 1, b(), K(), L.current = !1, z.current = !1, B.current.stop(), ge(y.current), me.current = !1, _e();
|
|
1919
2056
|
},
|
|
1920
2057
|
setTtsEngineId: (f) => {
|
|
1921
|
-
|
|
2058
|
+
B.current.setTtsEngineId(f), I.current && (I.current.ttsEngineId = f);
|
|
1922
2059
|
},
|
|
1923
2060
|
renderViseme: async (f, k) => {
|
|
1924
|
-
const
|
|
1925
|
-
if (!
|
|
2061
|
+
const T = g.current, A = u.current;
|
|
2062
|
+
if (!T || !A || !Q.current)
|
|
1926
2063
|
throw new Error("AI twin is not ready");
|
|
1927
|
-
await
|
|
2064
|
+
await T.renderViseme(A, f, {
|
|
1928
2065
|
from: k?.from,
|
|
1929
2066
|
transitionDurationMs: k?.transitionDurationMs,
|
|
1930
2067
|
gapMs: k?.gapMs,
|
|
1931
|
-
onStatus: (
|
|
2068
|
+
onStatus: (C) => O.current?.(C)
|
|
1932
2069
|
});
|
|
1933
2070
|
},
|
|
1934
|
-
isReady: () =>
|
|
1935
|
-
getStatus: () =>
|
|
2071
|
+
isReady: () => Q.current,
|
|
2072
|
+
getStatus: () => Re
|
|
1936
2073
|
}),
|
|
1937
2074
|
[
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2075
|
+
se,
|
|
2076
|
+
c,
|
|
2077
|
+
b,
|
|
2078
|
+
_e,
|
|
1942
2079
|
$,
|
|
1943
|
-
|
|
1944
|
-
|
|
2080
|
+
ce,
|
|
2081
|
+
Re
|
|
1945
2082
|
]
|
|
1946
|
-
), /* @__PURE__ */
|
|
1947
|
-
/* @__PURE__ */
|
|
2083
|
+
), /* @__PURE__ */ Bt("div", { className: a, style: { ...Hr, ...l }, children: [
|
|
2084
|
+
/* @__PURE__ */ it(
|
|
1948
2085
|
"canvas",
|
|
1949
2086
|
{
|
|
1950
2087
|
ref: u,
|
|
1951
|
-
width:
|
|
1952
|
-
height:
|
|
1953
|
-
style: { ...
|
|
2088
|
+
width: V.width,
|
|
2089
|
+
height: V.height,
|
|
2090
|
+
style: { ...Wr, ...d },
|
|
1954
2091
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
1955
2092
|
}
|
|
1956
2093
|
),
|
|
1957
|
-
|
|
2094
|
+
F && De ? /* @__PURE__ */ it("div", { style: qr, children: De }) : null
|
|
1958
2095
|
] });
|
|
1959
2096
|
});
|
|
1960
2097
|
export {
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2098
|
+
zr as AiTwin,
|
|
2099
|
+
Ke as AiTwinNotFoundError,
|
|
2100
|
+
pe as DEFAULT_TTS_ENGINE_ID,
|
|
2101
|
+
En as OCULUS_VISEME_IDS,
|
|
2102
|
+
Bn as SPEAKING_RATE_MAX,
|
|
2103
|
+
Un as SPEAKING_RATE_MIN,
|
|
2104
|
+
be as TTS_ENGINE_CARTESIA,
|
|
2105
|
+
kt as TTS_ENGINE_GOOGLE,
|
|
2106
|
+
Ze as TTS_ENGINE_INWORLD,
|
|
2107
|
+
Gr as VISEME_IDS,
|
|
2108
|
+
Nn as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
2109
|
+
At as VISEME_TEST_SPEAKING_RATE,
|
|
2110
|
+
It as VISEME_TEST_VOICE_ID,
|
|
2111
|
+
Vn as createAvatarTtsLipsyncController,
|
|
2112
|
+
en as fetchAiTwin,
|
|
2113
|
+
ot as fetchDevAuthToken,
|
|
2114
|
+
kn as normalizeOculusViseme,
|
|
2115
|
+
vt as resolveVisemeAtTime,
|
|
2116
|
+
Pn as resolveWordAtTime
|
|
1980
2117
|
};
|