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