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