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