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