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