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