@streamoji/aitwin 0.2.4 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aitwin.cjs +2 -2
- package/dist/aitwin.js +580 -560
- package/dist/index.d.ts +6 -0
- package/package.json +1 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { jsxs as kn, jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { PipecatClient as
|
|
4
|
-
import { WebSocketTransport as
|
|
5
|
-
const
|
|
6
|
-
publicBase:
|
|
7
|
-
},
|
|
8
|
-
version:
|
|
9
|
-
},
|
|
10
|
-
function
|
|
1
|
+
import { jsxs as kn, jsx as It } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as vn, useRef as F, useState as Le, useCallback as oe, useEffect as ke, useMemo as Rt, useImperativeHandle as bn } from "react";
|
|
3
|
+
import { PipecatClient as Tn } from "@pipecat-ai/client-js";
|
|
4
|
+
import { WebSocketTransport as An, DailyMediaManager as In } from "@pipecat-ai/websocket-transport";
|
|
5
|
+
const Rn = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", Jt = {
|
|
6
|
+
publicBase: Rn
|
|
7
|
+
}, Dn = "0.2.6", Mn = {
|
|
8
|
+
version: Dn
|
|
9
|
+
}, Cn = {}, be = "https://ai.streamoji.com", ut = `${Jt.publicBase}/custom-faces`, xn = `${Jt.publicBase}/aitwin-workers/v${Mn.version}/visemeDiffPreview.worker.js`;
|
|
10
|
+
function Pn(e) {
|
|
11
11
|
if (e) return e;
|
|
12
|
-
const t = typeof import.meta < "u" ?
|
|
12
|
+
const t = typeof import.meta < "u" ? Cn?.VITE_AITWIN_WORKER_URL : void 0;
|
|
13
13
|
return t?.trim() ? t.trim() : xn;
|
|
14
14
|
}
|
|
15
|
-
const
|
|
16
|
-
|
|
15
|
+
const Bn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Qt = "eng_a7f2b9c1", lt = "eng_d4e8f3a2", Ae = "eng_c9b1e6d4", Te = Ae, Ln = /* @__PURE__ */ new Set([
|
|
16
|
+
lt,
|
|
17
17
|
Ae
|
|
18
18
|
]), Xt = {
|
|
19
19
|
[Qt]: "oculus_direct",
|
|
20
20
|
[Ae]: "oculus_direct",
|
|
21
|
-
[
|
|
22
|
-
},
|
|
21
|
+
[lt]: "inworld_word"
|
|
22
|
+
}, Dt = {
|
|
23
23
|
google: Qt,
|
|
24
|
-
inworld:
|
|
24
|
+
inworld: lt,
|
|
25
25
|
cartesia: Ae
|
|
26
26
|
};
|
|
27
|
-
function
|
|
27
|
+
function On(e) {
|
|
28
28
|
return Xt[e];
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function Fn(e) {
|
|
31
31
|
return e === Ae;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function Un(e) {
|
|
34
34
|
if (e.ttsEngineId && e.ttsEngineId in Xt)
|
|
35
35
|
return e.ttsEngineId;
|
|
36
36
|
const t = e.tts?.toLowerCase();
|
|
37
|
-
return t && t in
|
|
37
|
+
return t && t in Dt ? Dt[t] : Te;
|
|
38
38
|
}
|
|
39
39
|
class nt extends Error {
|
|
40
40
|
constructor(t = "AI twin not found") {
|
|
41
41
|
super(t), this.name = "AiTwinNotFoundError";
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
async function
|
|
44
|
+
async function Nn(e, t = Bn) {
|
|
45
45
|
const n = new URL(t);
|
|
46
46
|
n.searchParams.set("id", e);
|
|
47
47
|
const r = await fetch(n.toString());
|
|
@@ -55,21 +55,21 @@ async function Un(e, t = Pn) {
|
|
|
55
55
|
const { tts: i, ...o } = s.data;
|
|
56
56
|
return {
|
|
57
57
|
...o,
|
|
58
|
-
ttsEngineId:
|
|
58
|
+
ttsEngineId: Un(s.data)
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
-
const
|
|
61
|
+
const Vn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", $n = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Wn = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hn = "6TNvp3SCs4Og0a1ijm9TommXLql1", qn = "Swaraj Mali";
|
|
62
62
|
async function et() {
|
|
63
|
-
const e = await fetch(
|
|
63
|
+
const e = await fetch(Vn, {
|
|
64
64
|
method: "POST",
|
|
65
65
|
headers: {
|
|
66
66
|
"Content-Type": "application/json",
|
|
67
|
-
"Client-Id":
|
|
68
|
-
"Client-Secret":
|
|
67
|
+
"Client-Id": $n,
|
|
68
|
+
"Client-Secret": Wn
|
|
69
69
|
},
|
|
70
70
|
body: JSON.stringify({
|
|
71
71
|
userId: Hn,
|
|
72
|
-
userName:
|
|
72
|
+
userName: qn
|
|
73
73
|
})
|
|
74
74
|
});
|
|
75
75
|
if (!e.ok)
|
|
@@ -79,7 +79,7 @@ async function et() {
|
|
|
79
79
|
throw new Error("getAuthToken returned no token");
|
|
80
80
|
return n;
|
|
81
81
|
}
|
|
82
|
-
async function
|
|
82
|
+
async function Kn(e, t = be) {
|
|
83
83
|
const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
84
84
|
headers: { Authorization: `Bearer ${e}` }
|
|
85
85
|
});
|
|
@@ -89,7 +89,7 @@ async function qn(e, t = be) {
|
|
|
89
89
|
if (!r.value) throw new Error("Session value response missing value");
|
|
90
90
|
return r;
|
|
91
91
|
}
|
|
92
|
-
function
|
|
92
|
+
function jn(e) {
|
|
93
93
|
const t = e.trim();
|
|
94
94
|
if (t.length % 2 !== 0) throw new Error("Invalid hex key");
|
|
95
95
|
const n = new Uint8Array(t.length / 2);
|
|
@@ -100,17 +100,17 @@ function Kn(e) {
|
|
|
100
100
|
function Ve(e) {
|
|
101
101
|
return Uint8Array.from(e);
|
|
102
102
|
}
|
|
103
|
-
function
|
|
103
|
+
function Gn(e, t) {
|
|
104
104
|
const n = new Uint8Array(e.length + t.length);
|
|
105
105
|
return n.set(e, 0), n.set(t, e.length), n;
|
|
106
106
|
}
|
|
107
|
-
async function
|
|
107
|
+
async function zn(e, t) {
|
|
108
108
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
109
109
|
if (e.byteLength < 28)
|
|
110
110
|
throw new Error("Encrypted payload too small");
|
|
111
|
-
const n = new Uint8Array(e), r = Ve(n.subarray(0, 12)), s = Ve(n.subarray(12, 28)), i = Ve(n.subarray(28)), o = Ve(
|
|
111
|
+
const n = new Uint8Array(e), r = Ve(n.subarray(0, 12)), s = Ve(n.subarray(12, 28)), i = Ve(n.subarray(28)), o = Ve(Gn(i, s)), a = await crypto.subtle.importKey(
|
|
112
112
|
"raw",
|
|
113
|
-
|
|
113
|
+
jn(t),
|
|
114
114
|
{ name: "AES-GCM" },
|
|
115
115
|
!1,
|
|
116
116
|
["decrypt"]
|
|
@@ -136,18 +136,18 @@ function qe(e) {
|
|
|
136
136
|
function Ie(e) {
|
|
137
137
|
return qe(e).encrypted;
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function Mt(e, t = ut) {
|
|
140
140
|
const n = `${t.replace(/\/$/, "")}/${e}`;
|
|
141
141
|
return { twinBase: n, binBase: n, encrypted: !0 };
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function Yn(e, t) {
|
|
144
144
|
return (e ?? t)?.trim() || void 0;
|
|
145
145
|
}
|
|
146
|
-
function
|
|
146
|
+
function Jn(e) {
|
|
147
147
|
rt = qe(e);
|
|
148
148
|
for (const t of st) t();
|
|
149
149
|
}
|
|
150
|
-
function
|
|
150
|
+
function Qn(e, t) {
|
|
151
151
|
const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
152
152
|
if (!n) return qe(e);
|
|
153
153
|
const r = (s) => {
|
|
@@ -168,33 +168,33 @@ function Ee() {
|
|
|
168
168
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
169
169
|
return rt;
|
|
170
170
|
}
|
|
171
|
-
function
|
|
171
|
+
function Xn(e) {
|
|
172
172
|
return st.add(e), () => st.delete(e);
|
|
173
173
|
}
|
|
174
|
-
function
|
|
174
|
+
function Ct() {
|
|
175
175
|
const e = Ee();
|
|
176
176
|
return Ie(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function Zn() {
|
|
179
179
|
const e = Ee();
|
|
180
180
|
return Ie(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
181
181
|
}
|
|
182
|
-
function
|
|
182
|
+
function er() {
|
|
183
183
|
const e = Ee();
|
|
184
184
|
return Ie(e) ? e.binBase : e.twinBase;
|
|
185
185
|
}
|
|
186
186
|
function Ge() {
|
|
187
187
|
return Ie(Ee());
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function tr() {
|
|
190
190
|
const e = Ee();
|
|
191
191
|
return Ie(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
192
192
|
}
|
|
193
|
-
function
|
|
193
|
+
function nr() {
|
|
194
194
|
const e = Ee();
|
|
195
195
|
return Ie(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
196
196
|
}
|
|
197
|
-
function
|
|
197
|
+
function rr(e) {
|
|
198
198
|
const t = e.split(/\r?\n/);
|
|
199
199
|
let n = "", r = "";
|
|
200
200
|
for (const i of t)
|
|
@@ -209,7 +209,7 @@ function nr(e) {
|
|
|
209
209
|
}
|
|
210
210
|
return { event: n, data: s };
|
|
211
211
|
}
|
|
212
|
-
const
|
|
212
|
+
const sr = [
|
|
213
213
|
"aa",
|
|
214
214
|
"CH",
|
|
215
215
|
"DD",
|
|
@@ -225,14 +225,14 @@ const rr = [
|
|
|
225
225
|
"kk",
|
|
226
226
|
"nn",
|
|
227
227
|
"sil"
|
|
228
|
-
],
|
|
229
|
-
|
|
228
|
+
], ir = new Map(
|
|
229
|
+
sr.map((e) => [e.toLowerCase(), e])
|
|
230
230
|
);
|
|
231
|
-
function
|
|
231
|
+
function or(e) {
|
|
232
232
|
const t = (e ?? "").trim();
|
|
233
|
-
return t ?
|
|
233
|
+
return t ? ir.get(t.toLowerCase()) ?? "sil" : "sil";
|
|
234
234
|
}
|
|
235
|
-
const
|
|
235
|
+
const ar = {
|
|
236
236
|
aei: ["aa", "E", "I"],
|
|
237
237
|
o: ["O", "U"],
|
|
238
238
|
ee: ["I"],
|
|
@@ -244,12 +244,12 @@ const or = {
|
|
|
244
244
|
qw: ["U", "O"],
|
|
245
245
|
cdgknstxyz: ["DD", "SS", "kk", "CH"]
|
|
246
246
|
};
|
|
247
|
-
function
|
|
247
|
+
function cr(e) {
|
|
248
248
|
if (!e) return ["sil"];
|
|
249
249
|
const t = e.toLowerCase();
|
|
250
|
-
return
|
|
250
|
+
return ar[t] ?? ["sil"];
|
|
251
251
|
}
|
|
252
|
-
function
|
|
252
|
+
function ur(e, t) {
|
|
253
253
|
const n = e.word.length;
|
|
254
254
|
if (n <= 0) return 0;
|
|
255
255
|
const r = e.wduration;
|
|
@@ -261,11 +261,11 @@ function ze(e, t) {
|
|
|
261
261
|
const n = Math.max(0, Math.min(e.length - 1, t));
|
|
262
262
|
return e[n] ?? "";
|
|
263
263
|
}
|
|
264
|
-
function
|
|
264
|
+
function lr(e, t) {
|
|
265
265
|
const n = e.toLowerCase(), r = ze(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
|
|
266
266
|
return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
|
|
267
267
|
}
|
|
268
|
-
function
|
|
268
|
+
function fr(e, t) {
|
|
269
269
|
const n = e.toLowerCase(), r = n.slice(
|
|
270
270
|
Math.max(0, t - 1),
|
|
271
271
|
Math.min(n.length, t + 3)
|
|
@@ -274,7 +274,7 @@ function lr(e, t) {
|
|
|
274
274
|
const s = ze(n, t);
|
|
275
275
|
return s === "u" || s === "w" ? "U" : "O";
|
|
276
276
|
}
|
|
277
|
-
function
|
|
277
|
+
function dr(e, t) {
|
|
278
278
|
const n = e.toLowerCase(), r = n.slice(Math.max(0, t - 2), t + 1);
|
|
279
279
|
if (/qu/.test(r)) return "U";
|
|
280
280
|
const s = n.slice(
|
|
@@ -283,7 +283,7 @@ function fr(e, t) {
|
|
|
283
283
|
);
|
|
284
284
|
return /wo|wh/.test(s) || ze(n, t) === "o" ? "O" : "U";
|
|
285
285
|
}
|
|
286
|
-
const
|
|
286
|
+
const We = {
|
|
287
287
|
d: "DD",
|
|
288
288
|
t: "DD",
|
|
289
289
|
n: "DD",
|
|
@@ -295,46 +295,46 @@ const He = {
|
|
|
295
295
|
x: "CH",
|
|
296
296
|
j: "CH"
|
|
297
297
|
};
|
|
298
|
-
function
|
|
298
|
+
function hr(e, t) {
|
|
299
299
|
const n = e.toLowerCase(), r = ze(n, t);
|
|
300
|
-
if (
|
|
300
|
+
if (We[r]) return We[r];
|
|
301
301
|
for (let s = 0; s < n.length; s++) {
|
|
302
302
|
const i = n[s];
|
|
303
|
-
if (
|
|
303
|
+
if (We[i]) return We[i];
|
|
304
304
|
}
|
|
305
305
|
return "DD";
|
|
306
306
|
}
|
|
307
|
-
function
|
|
308
|
-
const r =
|
|
307
|
+
function mr(e, t, n) {
|
|
308
|
+
const r = cr(e);
|
|
309
309
|
if (r.length === 1) return r[0];
|
|
310
310
|
const s = t.trim();
|
|
311
311
|
if (!s) return r[0];
|
|
312
312
|
const i = (e ?? "").toLowerCase(), o = Math.max(0, n);
|
|
313
313
|
switch (i) {
|
|
314
314
|
case "aei":
|
|
315
|
-
return ur(s, o);
|
|
316
|
-
case "o":
|
|
317
315
|
return lr(s, o);
|
|
318
|
-
case "
|
|
316
|
+
case "o":
|
|
319
317
|
return fr(s, o);
|
|
320
|
-
case "
|
|
318
|
+
case "qw":
|
|
321
319
|
return dr(s, o);
|
|
320
|
+
case "cdgknstxyz":
|
|
321
|
+
return hr(s, o);
|
|
322
322
|
default:
|
|
323
323
|
return r[0];
|
|
324
324
|
}
|
|
325
325
|
}
|
|
326
|
-
const
|
|
327
|
-
function
|
|
326
|
+
const wr = 24e3;
|
|
327
|
+
function gr(e) {
|
|
328
328
|
let t = e.trim();
|
|
329
329
|
const n = t.indexOf(",");
|
|
330
330
|
t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
|
|
331
331
|
const r = t.length % 4;
|
|
332
332
|
return r !== 0 && (t += "=".repeat(4 - r)), t;
|
|
333
333
|
}
|
|
334
|
-
function
|
|
334
|
+
function _r(e) {
|
|
335
335
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
336
336
|
}
|
|
337
|
-
function xt(e, t, n =
|
|
337
|
+
function xt(e, t, n = wr) {
|
|
338
338
|
const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
|
|
339
339
|
r.buffer,
|
|
340
340
|
r.byteOffset,
|
|
@@ -345,15 +345,15 @@ function xt(e, t, n = mr) {
|
|
|
345
345
|
const o = e.createBuffer(1, i.length, n);
|
|
346
346
|
return o.copyToChannel(i, 0), o;
|
|
347
347
|
}
|
|
348
|
-
function
|
|
349
|
-
const t =
|
|
348
|
+
function pr(e) {
|
|
349
|
+
const t = gr(e), n = window.atob(t), r = new Uint8Array(n.length);
|
|
350
350
|
for (let s = 0; s < n.length; s++)
|
|
351
351
|
r[s] = n.charCodeAt(s);
|
|
352
352
|
return r;
|
|
353
353
|
}
|
|
354
|
-
async function
|
|
355
|
-
const n =
|
|
356
|
-
if (
|
|
354
|
+
async function yr(e, t) {
|
|
355
|
+
const n = pr(t);
|
|
356
|
+
if (_r(n)) {
|
|
357
357
|
const r = n.buffer.slice(
|
|
358
358
|
n.byteOffset,
|
|
359
359
|
n.byteOffset + n.byteLength
|
|
@@ -372,13 +372,13 @@ async function pr(e, t) {
|
|
|
372
372
|
return xt(e, n);
|
|
373
373
|
}
|
|
374
374
|
}
|
|
375
|
-
function
|
|
375
|
+
function Pt(e) {
|
|
376
376
|
let t = 0;
|
|
377
377
|
for (const n of e)
|
|
378
378
|
t = Math.max(t, n.vtime + n.vduration);
|
|
379
379
|
return t;
|
|
380
380
|
}
|
|
381
|
-
function
|
|
381
|
+
function Er(e, t) {
|
|
382
382
|
for (const n of e)
|
|
383
383
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
384
384
|
return n;
|
|
@@ -386,9 +386,9 @@ function yr(e, t) {
|
|
|
386
386
|
}
|
|
387
387
|
function Zt(e, t) {
|
|
388
388
|
const n = [], r = [];
|
|
389
|
-
let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, _ = 0, m = 0,
|
|
389
|
+
let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, _ = 0, m = 0, k = null, S = 1, u = t, p = !1;
|
|
390
390
|
const d = () => {
|
|
391
|
-
|
|
391
|
+
k != null && (clearTimeout(k), k = null);
|
|
392
392
|
}, I = () => {
|
|
393
393
|
for (const g of r)
|
|
394
394
|
try {
|
|
@@ -398,46 +398,46 @@ function Zt(e, t) {
|
|
|
398
398
|
r.length = 0;
|
|
399
399
|
}, E = () => {
|
|
400
400
|
for (const g of r)
|
|
401
|
-
g.playbackRate.value =
|
|
401
|
+
g.playbackRate.value = S;
|
|
402
402
|
}, R = () => {
|
|
403
403
|
!f || i || r.length > 0 || n.length > 0 || (o = !1, d(), e.onSpeakingDone(), e.onNotify());
|
|
404
|
-
},
|
|
405
|
-
const
|
|
406
|
-
if (
|
|
404
|
+
}, H = (g) => {
|
|
405
|
+
const C = Pt(g);
|
|
406
|
+
if (C <= 0) {
|
|
407
407
|
e.onSpeakingDone(), e.onNotify();
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
410
410
|
o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), d();
|
|
411
|
-
const b =
|
|
412
|
-
|
|
413
|
-
p || (o = !1,
|
|
411
|
+
const b = S > 0 ? C / S : C;
|
|
412
|
+
k = setTimeout(() => {
|
|
413
|
+
p || (o = !1, k = null, e.onSpeakingDone(), e.onNotify());
|
|
414
414
|
}, b);
|
|
415
|
-
}, V = (g,
|
|
416
|
-
|
|
415
|
+
}, V = (g, C, b, D) => {
|
|
416
|
+
C.length !== 0 && (D && (_ = b), C.forEach((A) => {
|
|
417
417
|
const B = String(A.word ?? "").trim();
|
|
418
418
|
if (!B) return;
|
|
419
|
-
const
|
|
419
|
+
const W = Math.round((A.start ?? 0) * 1e3), U = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
|
|
420
420
|
g.push({
|
|
421
421
|
word: B,
|
|
422
|
-
wtime: _ +
|
|
422
|
+
wtime: _ + W,
|
|
423
423
|
wduration: U,
|
|
424
424
|
queueIndex: g.length,
|
|
425
425
|
gesture: A.gesture ?? null,
|
|
426
426
|
emphasis: A.emphasis === !0
|
|
427
427
|
});
|
|
428
428
|
}));
|
|
429
|
-
},
|
|
429
|
+
}, $ = (g, C, b, D, A, P) => {
|
|
430
430
|
b.length !== 0 && (A && (_ = D), b.forEach((B) => {
|
|
431
|
-
const
|
|
432
|
-
if (
|
|
431
|
+
const W = String(B.symbol ?? B.viseme ?? "").trim();
|
|
432
|
+
if (!W) return;
|
|
433
433
|
const U = Math.round((B.start ?? 0) * 1e3), X = Math.max(1, Math.round((B.duration ?? 0) * 1e3)), se = _ + U;
|
|
434
434
|
let Z;
|
|
435
|
-
if (
|
|
436
|
-
Z =
|
|
435
|
+
if (On(P) === "oculus_direct")
|
|
436
|
+
Z = or(W);
|
|
437
437
|
else {
|
|
438
|
-
const ce =
|
|
439
|
-
Z =
|
|
440
|
-
|
|
438
|
+
const ce = Er(C, se), J = ce ? ur(ce, se) : 0;
|
|
439
|
+
Z = mr(
|
|
440
|
+
W,
|
|
441
441
|
ce?.word ?? "",
|
|
442
442
|
J
|
|
443
443
|
);
|
|
@@ -449,20 +449,20 @@ function Zt(e, t) {
|
|
|
449
449
|
vduration: X
|
|
450
450
|
});
|
|
451
451
|
}), e.onNotify());
|
|
452
|
-
}, j = (g,
|
|
453
|
-
V(
|
|
452
|
+
}, j = (g, C, b, D, A, P, B) => {
|
|
453
|
+
V(C, D, A, P), $(
|
|
454
454
|
g,
|
|
455
|
-
|
|
455
|
+
C,
|
|
456
456
|
b,
|
|
457
457
|
A,
|
|
458
458
|
P,
|
|
459
459
|
B
|
|
460
460
|
);
|
|
461
|
-
}, y = async (g,
|
|
461
|
+
}, y = async (g, C, b, D, A, P, B) => {
|
|
462
462
|
if (p || !b?.trim()) {
|
|
463
463
|
(D.length > 0 || A.length > 0) && !a && j(
|
|
464
464
|
g,
|
|
465
|
-
|
|
465
|
+
C,
|
|
466
466
|
D,
|
|
467
467
|
A,
|
|
468
468
|
_,
|
|
@@ -482,23 +482,23 @@ function Zt(e, t) {
|
|
|
482
482
|
}
|
|
483
483
|
i = !0;
|
|
484
484
|
try {
|
|
485
|
-
const
|
|
486
|
-
s || (s = new
|
|
485
|
+
const W = window.AudioContext || window.webkitAudioContext;
|
|
486
|
+
s || (s = new W());
|
|
487
487
|
const U = s;
|
|
488
488
|
U.state === "suspended" && await U.resume();
|
|
489
|
-
const X = await
|
|
489
|
+
const X = await yr(U, b);
|
|
490
490
|
a = !0;
|
|
491
491
|
const se = U.currentTime;
|
|
492
492
|
let Z = m;
|
|
493
493
|
const ce = !o;
|
|
494
494
|
Z < se && (Z = se + 0.1), m = Z + X.duration;
|
|
495
495
|
const J = U.createBufferSource();
|
|
496
|
-
if (J.buffer = X, J.playbackRate.value =
|
|
496
|
+
if (J.buffer = X, J.playbackRate.value = S, J.connect(U.destination), r.push(J), p) {
|
|
497
497
|
r.pop();
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
if (ce) {
|
|
501
|
-
o = !0, e.onSpeakingStart(), w = Z, _ = 0, g.length = 0,
|
|
501
|
+
o = !0, e.onSpeakingStart(), w = Z, _ = 0, g.length = 0, C.length = 0, B?.();
|
|
502
502
|
const v = (Z - se) * 1e3;
|
|
503
503
|
l = performance.now() + v;
|
|
504
504
|
}
|
|
@@ -509,25 +509,25 @@ function Zt(e, t) {
|
|
|
509
509
|
const c = (Z - w) * 1e3;
|
|
510
510
|
j(
|
|
511
511
|
g,
|
|
512
|
-
|
|
512
|
+
C,
|
|
513
513
|
D,
|
|
514
514
|
A,
|
|
515
515
|
c,
|
|
516
516
|
P,
|
|
517
517
|
u
|
|
518
518
|
);
|
|
519
|
-
} catch (
|
|
520
|
-
console.error("[avatarChunkPlayback] audio chunk failed:",
|
|
519
|
+
} catch (W) {
|
|
520
|
+
console.error("[avatarChunkPlayback] audio chunk failed:", W);
|
|
521
521
|
} finally {
|
|
522
522
|
i = !1;
|
|
523
|
-
const
|
|
524
|
-
|
|
523
|
+
const W = n.shift();
|
|
524
|
+
W ? await y(
|
|
525
525
|
g,
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
526
|
+
C,
|
|
527
|
+
W.audio,
|
|
528
|
+
W.visemes,
|
|
529
|
+
W.words,
|
|
530
|
+
W.isNewSegment,
|
|
531
531
|
B
|
|
532
532
|
) : R();
|
|
533
533
|
}
|
|
@@ -537,9 +537,9 @@ function Zt(e, t) {
|
|
|
537
537
|
u = g;
|
|
538
538
|
},
|
|
539
539
|
setPlaybackSpeed: (g) => {
|
|
540
|
-
|
|
540
|
+
S = Math.max(0.1, Math.min(1, g)), E();
|
|
541
541
|
},
|
|
542
|
-
getPlaybackSpeed: () =>
|
|
542
|
+
getPlaybackSpeed: () => S,
|
|
543
543
|
resetForNewStream: (g) => {
|
|
544
544
|
p = !1, f = !1, u = g;
|
|
545
545
|
},
|
|
@@ -553,17 +553,17 @@ function Zt(e, t) {
|
|
|
553
553
|
},
|
|
554
554
|
markStreamComplete: (g) => {
|
|
555
555
|
if (f = !0, !a && g.length > 0) {
|
|
556
|
-
|
|
556
|
+
H(g);
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
559
|
R();
|
|
560
560
|
},
|
|
561
561
|
playAudioChunk: y,
|
|
562
|
-
queueTimingsOnly: (g,
|
|
562
|
+
queueTimingsOnly: (g, C, b, D, A) => {
|
|
563
563
|
let P = _;
|
|
564
|
-
A && g.length > 0 && (P =
|
|
564
|
+
A && g.length > 0 && (P = Pt(g)), j(
|
|
565
565
|
g,
|
|
566
|
-
|
|
566
|
+
C,
|
|
567
567
|
b,
|
|
568
568
|
D,
|
|
569
569
|
P,
|
|
@@ -574,7 +574,7 @@ function Zt(e, t) {
|
|
|
574
574
|
getPlaybackElapsedMs: () => o ? a && s && w > 0 ? Math.max(
|
|
575
575
|
0,
|
|
576
576
|
(s.currentTime - w) * 1e3
|
|
577
|
-
) : Math.max(0, (performance.now() - l) *
|
|
577
|
+
) : Math.max(0, (performance.now() - l) * S) : 0,
|
|
578
578
|
isSpeaking: () => o,
|
|
579
579
|
getPlaybackStartPerf: () => l,
|
|
580
580
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
@@ -586,23 +586,23 @@ function Zt(e, t) {
|
|
|
586
586
|
}
|
|
587
587
|
};
|
|
588
588
|
}
|
|
589
|
-
function
|
|
589
|
+
function ft(e, t) {
|
|
590
590
|
let n = null;
|
|
591
591
|
for (const r of e)
|
|
592
592
|
t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
|
|
593
593
|
return n ? n.viseme : "sil";
|
|
594
594
|
}
|
|
595
|
-
function
|
|
595
|
+
function js(e, t) {
|
|
596
596
|
for (const n of e)
|
|
597
597
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
598
598
|
return n;
|
|
599
599
|
return null;
|
|
600
600
|
}
|
|
601
|
-
const en = 0.5, tn = 1.5, nn = "Olivia",
|
|
602
|
-
function
|
|
601
|
+
const en = 0.5, tn = 1.5, nn = "Olivia", Sr = "f786b574-daa5-4673-aa0c-cbe3e8534c02", dt = 0.85;
|
|
602
|
+
function Bt(e, t = be) {
|
|
603
603
|
const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
|
|
604
604
|
let o = "neutral", a = "", f = Te;
|
|
605
|
-
const l = /* @__PURE__ */ new Set(), w = () => l.forEach((
|
|
605
|
+
const l = /* @__PURE__ */ new Set(), w = () => l.forEach((S) => S()), _ = Zt(
|
|
606
606
|
{
|
|
607
607
|
onSpeakingStart: () => e("speaking"),
|
|
608
608
|
onSpeakingDone: () => e("done"),
|
|
@@ -613,30 +613,30 @@ function Pt(e, t = be) {
|
|
|
613
613
|
_.stop(), r.length = 0, s.length = 0, i.length = 0, o = "neutral", e("idle"), w();
|
|
614
614
|
};
|
|
615
615
|
return {
|
|
616
|
-
setDeveloperToken: (
|
|
617
|
-
a =
|
|
616
|
+
setDeveloperToken: (S) => {
|
|
617
|
+
a = S;
|
|
618
618
|
},
|
|
619
|
-
setTtsEngineId: (
|
|
620
|
-
f =
|
|
619
|
+
setTtsEngineId: (S) => {
|
|
620
|
+
f = S;
|
|
621
621
|
},
|
|
622
622
|
getTtsEngineId: () => f,
|
|
623
|
-
speak: async (
|
|
623
|
+
speak: async (S, u) => {
|
|
624
624
|
m(), e("loading");
|
|
625
625
|
const p = a.trim();
|
|
626
626
|
if (!p)
|
|
627
627
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
628
628
|
const d = u?.ttsEngineId ?? f ?? Te;
|
|
629
629
|
_.resetForNewStream(d), _.setStreamTtsEngineId(d);
|
|
630
|
-
const I = u?.voiceId ?? nn, E = u?.speakingRate ??
|
|
630
|
+
const I = u?.voiceId ?? nn, E = u?.speakingRate ?? dt, R = Math.max(
|
|
631
631
|
en,
|
|
632
632
|
Math.min(tn, E)
|
|
633
|
-
),
|
|
634
|
-
user_query:
|
|
633
|
+
), H = {
|
|
634
|
+
user_query: S,
|
|
635
635
|
ttsEngineId: d,
|
|
636
636
|
speakingRate: R,
|
|
637
637
|
tenant: "aiTwin"
|
|
638
638
|
};
|
|
639
|
-
|
|
639
|
+
Ln.has(d) && (H.voice_id = I);
|
|
640
640
|
try {
|
|
641
641
|
const V = await fetch(n, {
|
|
642
642
|
method: "POST",
|
|
@@ -644,16 +644,16 @@ function Pt(e, t = be) {
|
|
|
644
644
|
"Content-Type": "application/json",
|
|
645
645
|
Authorization: `Bearer ${p}`
|
|
646
646
|
},
|
|
647
|
-
body: JSON.stringify(
|
|
647
|
+
body: JSON.stringify(H)
|
|
648
648
|
});
|
|
649
649
|
if (!V.ok)
|
|
650
650
|
throw new Error(`avatar_ttsWithPoses failed (${V.status})`);
|
|
651
|
-
const
|
|
652
|
-
if (
|
|
653
|
-
const j =
|
|
651
|
+
const $ = V.body;
|
|
652
|
+
if (!$) throw new Error("No response body");
|
|
653
|
+
const j = $.getReader(), y = new TextDecoder();
|
|
654
654
|
let T = "";
|
|
655
|
-
const g = async (
|
|
656
|
-
const b =
|
|
655
|
+
const g = async (C) => {
|
|
656
|
+
const b = rr(C);
|
|
657
657
|
if (b) {
|
|
658
658
|
if (b.event === "audio") {
|
|
659
659
|
const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], B = b.data.is_new_segment ?? !1;
|
|
@@ -698,14 +698,14 @@ function Pt(e, t = be) {
|
|
|
698
698
|
}
|
|
699
699
|
};
|
|
700
700
|
for (; ; ) {
|
|
701
|
-
const { done:
|
|
701
|
+
const { done: C, value: b } = await j.read();
|
|
702
702
|
b && (T += y.decode(b, { stream: !0 }));
|
|
703
703
|
const D = T.split(`
|
|
704
704
|
|
|
705
705
|
`);
|
|
706
706
|
T = D.pop() ?? "";
|
|
707
707
|
for (const A of D) await g(A);
|
|
708
|
-
if (
|
|
708
|
+
if (C) {
|
|
709
709
|
T.trim() && await g(T.trim()), _.markStreamComplete(r);
|
|
710
710
|
break;
|
|
711
711
|
}
|
|
@@ -721,15 +721,15 @@ function Pt(e, t = be) {
|
|
|
721
721
|
getStreamMood: () => o,
|
|
722
722
|
getPlaybackElapsedMs: () => _.getPlaybackElapsedMs(),
|
|
723
723
|
isSpeaking: () => _.isSpeaking(),
|
|
724
|
-
setPlaybackSpeed: (
|
|
725
|
-
_.setPlaybackSpeed(
|
|
724
|
+
setPlaybackSpeed: (S) => {
|
|
725
|
+
_.setPlaybackSpeed(S);
|
|
726
726
|
},
|
|
727
727
|
getPlaybackSpeed: () => _.getPlaybackSpeed(),
|
|
728
|
-
subscribe: (
|
|
728
|
+
subscribe: (S) => (l.add(S), () => l.delete(S))
|
|
729
729
|
};
|
|
730
730
|
}
|
|
731
731
|
const rn = 16e3, sn = 24e3;
|
|
732
|
-
class kr extends
|
|
732
|
+
class kr extends In {
|
|
733
733
|
constructor() {
|
|
734
734
|
super(
|
|
735
735
|
!0,
|
|
@@ -745,32 +745,32 @@ class kr extends An {
|
|
|
745
745
|
bufferBotAudio(t, n) {
|
|
746
746
|
}
|
|
747
747
|
}
|
|
748
|
-
const
|
|
749
|
-
function vr(e) {
|
|
750
|
-
return Sr.test(e.trim());
|
|
751
|
-
}
|
|
748
|
+
const vr = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
752
749
|
function br(e) {
|
|
750
|
+
return vr.test(e.trim());
|
|
751
|
+
}
|
|
752
|
+
function Tr(e) {
|
|
753
753
|
const t = e.replace(/\/$/, "");
|
|
754
754
|
return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
|
|
755
755
|
}
|
|
756
|
-
function
|
|
756
|
+
function Ar(e) {
|
|
757
757
|
if (e.wsUrl?.trim()) return e.wsUrl.trim();
|
|
758
758
|
const t = e.authToken?.trim();
|
|
759
759
|
if (!t)
|
|
760
760
|
throw new Error(
|
|
761
761
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
762
762
|
);
|
|
763
|
-
const n = e.apiBase ?? be, r = new URL(`${
|
|
763
|
+
const n = e.apiBase ?? be, r = new URL(`${Tr(n)}/ws/voice`);
|
|
764
764
|
r.searchParams.set("authToken", t);
|
|
765
765
|
const s = e.voiceId?.trim();
|
|
766
|
-
s &&
|
|
767
|
-
const i = e.speakingRate ??
|
|
766
|
+
s && br(s) && r.searchParams.set("voiceId", s);
|
|
767
|
+
const i = e.speakingRate ?? dt;
|
|
768
768
|
return r.searchParams.set(
|
|
769
769
|
"speaking_rate",
|
|
770
770
|
String(Math.max(en, Math.min(tn, i)))
|
|
771
771
|
), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
|
|
772
772
|
}
|
|
773
|
-
function
|
|
773
|
+
function Lt(e, t) {
|
|
774
774
|
if (!Array.isArray(e)) return [];
|
|
775
775
|
const n = [];
|
|
776
776
|
for (const r of e)
|
|
@@ -784,14 +784,14 @@ function Bt(e, t) {
|
|
|
784
784
|
});
|
|
785
785
|
return n;
|
|
786
786
|
}
|
|
787
|
-
function
|
|
787
|
+
function Ir(e) {
|
|
788
788
|
if (!e || typeof e != "object") return null;
|
|
789
789
|
const t = e, n = t.data;
|
|
790
790
|
return n && typeof n == "object" ? n : t;
|
|
791
791
|
}
|
|
792
|
-
function
|
|
792
|
+
function Rr(e, t = {}) {
|
|
793
793
|
const n = [], r = [], s = [], i = [];
|
|
794
|
-
let o = "", a = "neutral", f = Ae, l = !1, w = null, _ = null, m = { ...t },
|
|
794
|
+
let o = "", a = "neutral", f = Ae, l = !1, w = null, _ = null, m = { ...t }, k = 0, S = null;
|
|
795
795
|
const u = /* @__PURE__ */ new Set(), p = [];
|
|
796
796
|
let d = !1, I = null;
|
|
797
797
|
const E = () => u.forEach((c) => c()), R = Zt(
|
|
@@ -801,18 +801,18 @@ function Ir(e, t = {}) {
|
|
|
801
801
|
onNotify: E
|
|
802
802
|
},
|
|
803
803
|
f
|
|
804
|
-
),
|
|
804
|
+
), H = () => {
|
|
805
805
|
if (I) return I;
|
|
806
806
|
const c = new MessageChannel();
|
|
807
807
|
return c.port1.onmessage = () => {
|
|
808
808
|
const v = p.shift();
|
|
809
|
-
v !== void 0 &&
|
|
809
|
+
v !== void 0 && W(v), p.length > 0 ? c.port2.postMessage(null) : d = !1;
|
|
810
810
|
}, I = c, c;
|
|
811
811
|
}, V = (c) => {
|
|
812
|
-
p.push(c), !d && (d = !0,
|
|
813
|
-
},
|
|
812
|
+
p.push(c), !d && (d = !0, H().port2.postMessage(null));
|
|
813
|
+
}, $ = () => R.getPlaybackElapsedMs(), j = (c, v = o) => {
|
|
814
814
|
if (!m.onLipsyncDebug) return;
|
|
815
|
-
const L =
|
|
815
|
+
const L = $(), z = n;
|
|
816
816
|
m.onLipsyncDebug({
|
|
817
817
|
event: c,
|
|
818
818
|
spokenText: v,
|
|
@@ -820,32 +820,32 @@ function Ir(e, t = {}) {
|
|
|
820
820
|
playbackAnchorPerf: R.getPlaybackStartPerf(),
|
|
821
821
|
playbackElapsedMs: L,
|
|
822
822
|
queueLength: z.length,
|
|
823
|
-
activeViseme:
|
|
823
|
+
activeViseme: ft(z, L),
|
|
824
824
|
segments: i.map((ne) => ({
|
|
825
825
|
...ne,
|
|
826
826
|
visemes: [...ne.visemes]
|
|
827
827
|
}))
|
|
828
828
|
});
|
|
829
829
|
}, y = (c, v) => {
|
|
830
|
-
m.onLipsyncDebug && (
|
|
831
|
-
|
|
832
|
-
const L =
|
|
833
|
-
|
|
830
|
+
m.onLipsyncDebug && (S = { event: c, spokenText: v }, k === 0 && (k = requestAnimationFrame(() => {
|
|
831
|
+
k = 0;
|
|
832
|
+
const L = S;
|
|
833
|
+
S = null, L && j(L.event, L.spokenText);
|
|
834
834
|
})));
|
|
835
835
|
}, T = () => {
|
|
836
836
|
n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
|
|
837
837
|
}, g = () => {
|
|
838
838
|
R.stop(), T(), y("reset"), E();
|
|
839
|
-
},
|
|
839
|
+
}, C = () => {
|
|
840
840
|
g(), e("idle"), E();
|
|
841
841
|
}, b = (c, v) => {
|
|
842
842
|
typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (v && (s.length = 0), s.push(
|
|
843
|
-
...
|
|
843
|
+
...Lt(c.sentence_emotions, a)
|
|
844
844
|
));
|
|
845
845
|
}, D = (c) => {
|
|
846
846
|
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
847
847
|
v && (o = v), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
|
|
848
|
-
...
|
|
848
|
+
...Lt(c.sentence_emotions, a)
|
|
849
849
|
), Array.isArray(c.gestures) && c.gestures, y("metadata", v), E();
|
|
850
850
|
}, A = (c, v, L, z) => {
|
|
851
851
|
if (!m.onLipsyncDebug) return;
|
|
@@ -858,8 +858,8 @@ function Ir(e, t = {}) {
|
|
|
858
858
|
isNewSegment: !!c.is_new_segment,
|
|
859
859
|
chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
|
|
860
860
|
receivedAtMs: performance.now(),
|
|
861
|
-
visemes: ne.map((G,
|
|
862
|
-
const Y = Re[
|
|
861
|
+
visemes: ne.map((G, Se) => {
|
|
862
|
+
const Y = Re[Se];
|
|
863
863
|
return {
|
|
864
864
|
rawSymbol: String(Y?.symbol ?? Y?.viseme ?? G.viseme).trim(),
|
|
865
865
|
viseme: G.viseme,
|
|
@@ -906,8 +906,8 @@ function Ir(e, t = {}) {
|
|
|
906
906
|
L,
|
|
907
907
|
c.visemes ?? []
|
|
908
908
|
), y("lipsync", v), E();
|
|
909
|
-
},
|
|
910
|
-
const v =
|
|
909
|
+
}, W = (c) => {
|
|
910
|
+
const v = Ir(c);
|
|
911
911
|
if (!v) {
|
|
912
912
|
console.warn("[realtimeVoice] server message with no payload", c);
|
|
913
913
|
return;
|
|
@@ -935,8 +935,8 @@ function Ir(e, t = {}) {
|
|
|
935
935
|
);
|
|
936
936
|
break;
|
|
937
937
|
}
|
|
938
|
-
}, U = () => w || (_ = new kr(), w = new
|
|
939
|
-
transport: new
|
|
938
|
+
}, U = () => w || (_ = new kr(), w = new Tn({
|
|
939
|
+
transport: new An({
|
|
940
940
|
mediaManager: _,
|
|
941
941
|
recorderSampleRate: rn,
|
|
942
942
|
playerSampleRate: sn
|
|
@@ -948,7 +948,7 @@ function Ir(e, t = {}) {
|
|
|
948
948
|
l = !0, e("idle"), E();
|
|
949
949
|
},
|
|
950
950
|
onDisconnected: () => {
|
|
951
|
-
l = !1,
|
|
951
|
+
l = !1, C();
|
|
952
952
|
},
|
|
953
953
|
onError: (c) => {
|
|
954
954
|
const v = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
|
|
@@ -1005,7 +1005,7 @@ function Ir(e, t = {}) {
|
|
|
1005
1005
|
e("loading");
|
|
1006
1006
|
const v = U();
|
|
1007
1007
|
await v.initDevices();
|
|
1008
|
-
const L =
|
|
1008
|
+
const L = Ar(m);
|
|
1009
1009
|
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", L);
|
|
1010
1010
|
try {
|
|
1011
1011
|
await v.connect({ wsUrl: L });
|
|
@@ -1023,7 +1023,7 @@ function Ir(e, t = {}) {
|
|
|
1023
1023
|
} catch (c) {
|
|
1024
1024
|
console.error("[realtimeVoice] disconnect failed:", c);
|
|
1025
1025
|
}
|
|
1026
|
-
l = !1,
|
|
1026
|
+
l = !1, C();
|
|
1027
1027
|
},
|
|
1028
1028
|
isConnected: () => l,
|
|
1029
1029
|
unlockAudio: async () => {
|
|
@@ -1033,7 +1033,7 @@ function Ir(e, t = {}) {
|
|
|
1033
1033
|
getWordQueue: () => r,
|
|
1034
1034
|
getSentenceEmotions: () => s,
|
|
1035
1035
|
getStreamMood: () => a,
|
|
1036
|
-
getPlaybackElapsedMs:
|
|
1036
|
+
getPlaybackElapsedMs: $,
|
|
1037
1037
|
isSpeaking: () => R.isSpeaking(),
|
|
1038
1038
|
setPlaybackSpeed: (c) => {
|
|
1039
1039
|
R.setPlaybackSpeed(c);
|
|
@@ -1042,13 +1042,13 @@ function Ir(e, t = {}) {
|
|
|
1042
1042
|
subscribe: (c) => (u.add(c), () => u.delete(c))
|
|
1043
1043
|
};
|
|
1044
1044
|
}
|
|
1045
|
-
function
|
|
1045
|
+
function Dr(e, t, n) {
|
|
1046
1046
|
return {
|
|
1047
1047
|
width: e.crop?.source_width ?? t,
|
|
1048
1048
|
height: e.crop?.source_height ?? n
|
|
1049
1049
|
};
|
|
1050
1050
|
}
|
|
1051
|
-
function
|
|
1051
|
+
function Mr(e, t) {
|
|
1052
1052
|
const n = e.crop;
|
|
1053
1053
|
return {
|
|
1054
1054
|
x: t?.source_x ?? n?.x ?? 0,
|
|
@@ -1057,21 +1057,21 @@ function Dr(e, t) {
|
|
|
1057
1057
|
height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
|
|
1058
1058
|
};
|
|
1059
1059
|
}
|
|
1060
|
-
function
|
|
1060
|
+
function Cr(e) {
|
|
1061
1061
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
1062
1062
|
}
|
|
1063
1063
|
async function Ye(e, t) {
|
|
1064
1064
|
const n = await fetch(e);
|
|
1065
1065
|
if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
|
|
1066
1066
|
const r = await n.arrayBuffer();
|
|
1067
|
-
return
|
|
1067
|
+
return zn(r, t);
|
|
1068
1068
|
}
|
|
1069
1069
|
async function xr(e, t) {
|
|
1070
1070
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
1071
1071
|
const n = await Ye(e, t), r = new TextDecoder().decode(n);
|
|
1072
1072
|
return JSON.parse(r);
|
|
1073
1073
|
}
|
|
1074
|
-
async function
|
|
1074
|
+
async function Pr(e) {
|
|
1075
1075
|
const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
|
|
1076
1076
|
return new Promise((r, s) => {
|
|
1077
1077
|
const i = new Image();
|
|
@@ -1082,7 +1082,7 @@ async function Cr(e) {
|
|
|
1082
1082
|
}, i.src = n;
|
|
1083
1083
|
});
|
|
1084
1084
|
}
|
|
1085
|
-
async function
|
|
1085
|
+
async function Br(e) {
|
|
1086
1086
|
const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
|
|
1087
1087
|
return new Promise((r, s) => {
|
|
1088
1088
|
const i = new Image();
|
|
@@ -1093,18 +1093,18 @@ async function Pr(e) {
|
|
|
1093
1093
|
}, i.src = n;
|
|
1094
1094
|
});
|
|
1095
1095
|
}
|
|
1096
|
-
function
|
|
1096
|
+
function Lr(e) {
|
|
1097
1097
|
const t = new Blob([e], { type: "video/mp4" });
|
|
1098
1098
|
return URL.createObjectURL(t);
|
|
1099
1099
|
}
|
|
1100
|
-
async function
|
|
1101
|
-
const t =
|
|
1100
|
+
async function Or(e) {
|
|
1101
|
+
const t = Zn();
|
|
1102
1102
|
if (!Ge()) return t;
|
|
1103
1103
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
1104
1104
|
const n = await Ye(t, e);
|
|
1105
|
-
return
|
|
1105
|
+
return Lr(n);
|
|
1106
1106
|
}
|
|
1107
|
-
function
|
|
1107
|
+
function ht(e, t) {
|
|
1108
1108
|
return `${e}/${t}_minus_sil.png`;
|
|
1109
1109
|
}
|
|
1110
1110
|
const on = 5;
|
|
@@ -1114,7 +1114,7 @@ function an(e) {
|
|
|
1114
1114
|
const n = e?.crop?.content_threshold;
|
|
1115
1115
|
return typeof n == "number" && n > 0 ? n : on;
|
|
1116
1116
|
}
|
|
1117
|
-
const
|
|
1117
|
+
const Gs = [
|
|
1118
1118
|
"aa",
|
|
1119
1119
|
"E",
|
|
1120
1120
|
"I",
|
|
@@ -1133,7 +1133,7 @@ const qs = [
|
|
|
1133
1133
|
"t01_0.25",
|
|
1134
1134
|
"t02_0.50",
|
|
1135
1135
|
"t03_0.75"
|
|
1136
|
-
],
|
|
1136
|
+
], Fr = it.length, Ot = /* @__PURE__ */ new Set([
|
|
1137
1137
|
"aa__kk",
|
|
1138
1138
|
"aa__nn",
|
|
1139
1139
|
"aa__sil",
|
|
@@ -1240,16 +1240,16 @@ const qs = [
|
|
|
1240
1240
|
"U__nn",
|
|
1241
1241
|
"U__sil"
|
|
1242
1242
|
]);
|
|
1243
|
-
function
|
|
1243
|
+
function Ft(e, t) {
|
|
1244
1244
|
return `${e}__${t}`;
|
|
1245
1245
|
}
|
|
1246
|
-
function
|
|
1246
|
+
function Ut(e, t) {
|
|
1247
1247
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1248
1248
|
}
|
|
1249
1249
|
function Ke(e) {
|
|
1250
1250
|
return `${e}_minus_sil.png`;
|
|
1251
1251
|
}
|
|
1252
|
-
function
|
|
1252
|
+
function Ur(e, t) {
|
|
1253
1253
|
if (t.has(e)) return e;
|
|
1254
1254
|
const n = /^pairs\/([^/]+)\//.exec(e);
|
|
1255
1255
|
if (!n) return null;
|
|
@@ -1261,33 +1261,33 @@ function Fr(e, t) {
|
|
|
1261
1261
|
function cn(e, t) {
|
|
1262
1262
|
return e.filter((n) => t.has(n));
|
|
1263
1263
|
}
|
|
1264
|
-
function
|
|
1265
|
-
const r =
|
|
1264
|
+
function Nr(e, t, n) {
|
|
1265
|
+
const r = mt(e, t);
|
|
1266
1266
|
return cn(r, n).length > 0;
|
|
1267
1267
|
}
|
|
1268
|
-
function
|
|
1268
|
+
function mt(e, t) {
|
|
1269
1269
|
if (e === t) return [];
|
|
1270
|
-
const n = [], r =
|
|
1271
|
-
if (
|
|
1270
|
+
const n = [], r = Ft(e, t);
|
|
1271
|
+
if (Ot.has(r)) {
|
|
1272
1272
|
for (const i of it)
|
|
1273
|
-
n.push(
|
|
1273
|
+
n.push(Ut(r, i));
|
|
1274
1274
|
return n;
|
|
1275
1275
|
}
|
|
1276
|
-
const s =
|
|
1277
|
-
if (
|
|
1278
|
-
for (let i =
|
|
1279
|
-
n.push(
|
|
1276
|
+
const s = Ft(t, e);
|
|
1277
|
+
if (Ot.has(s)) {
|
|
1278
|
+
for (let i = Fr - 1; i >= 0; i--)
|
|
1279
|
+
n.push(Ut(s, it[i]));
|
|
1280
1280
|
return n;
|
|
1281
1281
|
}
|
|
1282
1282
|
return [];
|
|
1283
1283
|
}
|
|
1284
|
-
function
|
|
1284
|
+
function Vr(e) {
|
|
1285
1285
|
return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
|
|
1286
1286
|
}
|
|
1287
|
-
function
|
|
1288
|
-
return
|
|
1287
|
+
function $r(e, t) {
|
|
1288
|
+
return Vr(t).map((r) => e[r]).filter((r) => r != null);
|
|
1289
1289
|
}
|
|
1290
|
-
function
|
|
1290
|
+
function Wr(e, t, n, r) {
|
|
1291
1291
|
if (r <= 0) return 0;
|
|
1292
1292
|
const i = Math.max(1, n - t) / r, o = e - t, a = Math.floor(o / i);
|
|
1293
1293
|
return Math.min(r - 1, Math.max(0, a));
|
|
@@ -1297,18 +1297,18 @@ function Hr(e, t, n) {
|
|
|
1297
1297
|
const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
|
|
1298
1298
|
return `${e}/${s}.bin`;
|
|
1299
1299
|
}
|
|
1300
|
-
const
|
|
1300
|
+
const qr = [0.32, 0.24, 0.16, 0.08, 0], Kr = qr.map(
|
|
1301
1301
|
(e) => `eyes_${e.toFixed(2)}`
|
|
1302
|
-
),
|
|
1302
|
+
), jr = [
|
|
1303
1303
|
"eyes_0.32",
|
|
1304
1304
|
"eyes_0.16",
|
|
1305
1305
|
"eyes_0.00"
|
|
1306
|
-
],
|
|
1306
|
+
], Gr = [
|
|
1307
1307
|
"eyes_0.32",
|
|
1308
1308
|
"eyes_0.16",
|
|
1309
1309
|
"eyes_0.08",
|
|
1310
1310
|
"eyes_0.00"
|
|
1311
|
-
],
|
|
1311
|
+
], Nt = 2, zr = -30, ot = 20, Yr = {
|
|
1312
1312
|
fear: -30,
|
|
1313
1313
|
anger: -20,
|
|
1314
1314
|
sad: -10,
|
|
@@ -1317,24 +1317,24 @@ const Wr = [0.32, 0.24, 0.16, 0.08, 0], qr = Wr.map(
|
|
|
1317
1317
|
happy: 0,
|
|
1318
1318
|
disgust: 20
|
|
1319
1319
|
};
|
|
1320
|
-
function
|
|
1320
|
+
function wt(e) {
|
|
1321
1321
|
return `brow_${e}`;
|
|
1322
1322
|
}
|
|
1323
|
-
function
|
|
1324
|
-
return
|
|
1323
|
+
function gt(e) {
|
|
1324
|
+
return Yr[e];
|
|
1325
1325
|
}
|
|
1326
1326
|
function ye(e) {
|
|
1327
|
-
return Math.max(
|
|
1327
|
+
return Math.max(zr, Math.min(ot, e));
|
|
1328
1328
|
}
|
|
1329
|
-
function
|
|
1329
|
+
function Jr(e, t) {
|
|
1330
1330
|
if (e === t) return [];
|
|
1331
|
-
const n = e < t ?
|
|
1331
|
+
const n = e < t ? Nt : -Nt, r = [];
|
|
1332
1332
|
let s = e;
|
|
1333
1333
|
for (; s !== t; )
|
|
1334
1334
|
s += n, r.push(s);
|
|
1335
1335
|
return r;
|
|
1336
1336
|
}
|
|
1337
|
-
const
|
|
1337
|
+
const Qr = {
|
|
1338
1338
|
fear: "fear",
|
|
1339
1339
|
afraid: "fear",
|
|
1340
1340
|
anxiety: "fear",
|
|
@@ -1359,61 +1359,61 @@ const Jr = {
|
|
|
1359
1359
|
};
|
|
1360
1360
|
function ve(e, t = "neutral") {
|
|
1361
1361
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1362
|
-
return n ?
|
|
1362
|
+
return n ? Qr[n] ?? t : t;
|
|
1363
1363
|
}
|
|
1364
1364
|
function un(e) {
|
|
1365
|
-
return e === 0 ? null :
|
|
1365
|
+
return e === 0 ? null : ht(wt(e), "eyes_standard");
|
|
1366
1366
|
}
|
|
1367
1367
|
function ln(e) {
|
|
1368
|
-
return un(
|
|
1368
|
+
return un(gt(e));
|
|
1369
1369
|
}
|
|
1370
|
-
function
|
|
1371
|
-
const n =
|
|
1372
|
-
return !t || t === "eyes_standard" ? ln(e) : e === "neutral" && t === "eyes_standard" ? null :
|
|
1370
|
+
function Vt(e, t) {
|
|
1371
|
+
const n = wt(gt(e));
|
|
1372
|
+
return !t || t === "eyes_standard" ? ln(e) : e === "neutral" && t === "eyes_standard" ? null : ht(n, t);
|
|
1373
1373
|
}
|
|
1374
|
-
function
|
|
1374
|
+
function Xr(e, t) {
|
|
1375
1375
|
const n = [];
|
|
1376
1376
|
for (const r of t)
|
|
1377
|
-
n.push(
|
|
1377
|
+
n.push(Vt(e, r));
|
|
1378
1378
|
for (let r = t.length - 2; r >= 0; r--)
|
|
1379
|
-
n.push(
|
|
1379
|
+
n.push(Vt(e, t[r]));
|
|
1380
1380
|
return n.push(ln(e)), n;
|
|
1381
1381
|
}
|
|
1382
|
-
function
|
|
1383
|
-
return e === 0 ? null :
|
|
1382
|
+
function Zr(e) {
|
|
1383
|
+
return e === 0 ? null : ht(wt(e), "eyes_standard");
|
|
1384
1384
|
}
|
|
1385
|
-
function
|
|
1386
|
-
return
|
|
1385
|
+
function es(e, t) {
|
|
1386
|
+
return Jr(e, t).map(Zr).filter((n) => n != null);
|
|
1387
1387
|
}
|
|
1388
|
-
const
|
|
1389
|
-
function
|
|
1388
|
+
const ts = 6;
|
|
1389
|
+
function ns(e, t) {
|
|
1390
1390
|
for (const n of e)
|
|
1391
1391
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
1392
1392
|
return n;
|
|
1393
1393
|
return null;
|
|
1394
1394
|
}
|
|
1395
|
-
function
|
|
1395
|
+
function rs(e) {
|
|
1396
1396
|
const t = ye(e);
|
|
1397
|
-
return t >= ot ? ot : ye(t +
|
|
1397
|
+
return t >= ot ? ot : ye(t + ts);
|
|
1398
1398
|
}
|
|
1399
|
-
function
|
|
1399
|
+
function ss(e, t, n) {
|
|
1400
1400
|
const r = ye(n);
|
|
1401
|
-
return
|
|
1401
|
+
return ns(t, e)?.emphasis ? rs(r) : r;
|
|
1402
1402
|
}
|
|
1403
|
-
function
|
|
1403
|
+
function $t(e) {
|
|
1404
1404
|
if (!e) return 0;
|
|
1405
1405
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1406
1406
|
if (!t?.[1]) return null;
|
|
1407
1407
|
const n = Number.parseInt(t[1], 10);
|
|
1408
1408
|
return Number.isFinite(n) ? ye(n) : null;
|
|
1409
1409
|
}
|
|
1410
|
-
function
|
|
1410
|
+
function Fe(e, t) {
|
|
1411
1411
|
return e + Math.random() * (t - e);
|
|
1412
1412
|
}
|
|
1413
|
-
function
|
|
1414
|
-
return
|
|
1413
|
+
function He() {
|
|
1414
|
+
return Fe(14, 32);
|
|
1415
1415
|
}
|
|
1416
|
-
function
|
|
1416
|
+
function is(e = {}) {
|
|
1417
1417
|
const {
|
|
1418
1418
|
initialDelayMs: t = 800 + Math.random() * 1200,
|
|
1419
1419
|
intervalMinMs: n = 2200,
|
|
@@ -1425,52 +1425,52 @@ function ss(e = {}) {
|
|
|
1425
1425
|
postEmotionChangeDelayMs: f = 380,
|
|
1426
1426
|
minDwellMs: l = 550
|
|
1427
1427
|
} = e;
|
|
1428
|
-
let w = "neutral", _ = "neutral", m = 0,
|
|
1428
|
+
let w = "neutral", _ = "neutral", m = 0, k = 0, S = 0, u = {
|
|
1429
1429
|
kind: "idle",
|
|
1430
1430
|
nextBlinkAt: performance.now() + t
|
|
1431
1431
|
}, p = null, d = "__eyes_open__|neutral|brow:0";
|
|
1432
1432
|
function I(y = w) {
|
|
1433
|
-
d = `${p ?? "__eyes_open__"}|${y}|brow:${
|
|
1433
|
+
d = `${p ?? "__eyes_open__"}|${y}|brow:${k}`;
|
|
1434
1434
|
}
|
|
1435
1435
|
function E(y, T = w) {
|
|
1436
1436
|
p = y;
|
|
1437
|
-
const g =
|
|
1438
|
-
g != null ?
|
|
1437
|
+
const g = $t(y);
|
|
1438
|
+
g != null ? k = g : y == null && (k = 0), I(T);
|
|
1439
1439
|
}
|
|
1440
1440
|
function R(y) {
|
|
1441
1441
|
return un(y);
|
|
1442
1442
|
}
|
|
1443
|
-
function
|
|
1444
|
-
const
|
|
1445
|
-
if (m = b,
|
|
1443
|
+
function H(y, T, g) {
|
|
1444
|
+
const C = ye(T), b = ye(g);
|
|
1445
|
+
if (m = b, C === b) {
|
|
1446
1446
|
E(R(b));
|
|
1447
1447
|
return;
|
|
1448
1448
|
}
|
|
1449
1449
|
const D = [
|
|
1450
|
-
...
|
|
1450
|
+
...es(C, b),
|
|
1451
1451
|
R(b)
|
|
1452
1452
|
];
|
|
1453
1453
|
u = {
|
|
1454
1454
|
kind: "browBlend",
|
|
1455
1455
|
paths: D,
|
|
1456
1456
|
index: 0,
|
|
1457
|
-
holdUntil: y +
|
|
1457
|
+
holdUntil: y + He(),
|
|
1458
1458
|
targetBrow: b
|
|
1459
1459
|
}, E(D[0] ?? null);
|
|
1460
1460
|
}
|
|
1461
1461
|
function V(y, T) {
|
|
1462
1462
|
u = {
|
|
1463
1463
|
kind: "idle",
|
|
1464
|
-
nextBlinkAt: y +
|
|
1464
|
+
nextBlinkAt: y + Fe(n, r)
|
|
1465
1465
|
}, _ = T, E(R(m), T);
|
|
1466
1466
|
}
|
|
1467
|
-
function
|
|
1468
|
-
const
|
|
1467
|
+
function $(y, T, g) {
|
|
1468
|
+
const C = g ? jr : Math.random() < a ? Kr : Gr;
|
|
1469
1469
|
u = {
|
|
1470
1470
|
kind: "playing",
|
|
1471
|
-
paths:
|
|
1471
|
+
paths: Xr(T, C),
|
|
1472
1472
|
index: 0,
|
|
1473
|
-
holdUntil: y +
|
|
1473
|
+
holdUntil: y + He(),
|
|
1474
1474
|
after: "idle",
|
|
1475
1475
|
blinkEmotion: T
|
|
1476
1476
|
}, _ = T, E(u.paths[0] ?? null, T);
|
|
@@ -1478,25 +1478,25 @@ function ss(e = {}) {
|
|
|
1478
1478
|
function j(y) {
|
|
1479
1479
|
if (u.kind === "browBlend") {
|
|
1480
1480
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1481
|
-
u.index += 1, u.holdUntil = y +
|
|
1481
|
+
u.index += 1, u.holdUntil = y + He();
|
|
1482
1482
|
const T = u.paths[u.index] ?? null;
|
|
1483
|
-
E(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (
|
|
1483
|
+
E(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (k = u.targetBrow, m = u.targetBrow, E(R(u.targetBrow)), u = {
|
|
1484
1484
|
kind: "idle",
|
|
1485
1485
|
nextBlinkAt: y + f
|
|
1486
1486
|
});
|
|
1487
1487
|
return;
|
|
1488
1488
|
}
|
|
1489
1489
|
if (u.kind === "idle") {
|
|
1490
|
-
E(R(m), _), y >= u.nextBlinkAt &&
|
|
1490
|
+
E(R(m), _), y >= u.nextBlinkAt && $(y, _, !1);
|
|
1491
1491
|
return;
|
|
1492
1492
|
}
|
|
1493
1493
|
if (u.kind === "doublePause") {
|
|
1494
|
-
E(R(m), u.blinkEmotion), y >= u.resumeAt &&
|
|
1494
|
+
E(R(m), u.blinkEmotion), y >= u.resumeAt && $(y, u.blinkEmotion, !0);
|
|
1495
1495
|
return;
|
|
1496
1496
|
}
|
|
1497
1497
|
if (u.kind === "playing") {
|
|
1498
1498
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1499
|
-
u.index += 1, u.holdUntil = y +
|
|
1499
|
+
u.index += 1, u.holdUntil = y + He();
|
|
1500
1500
|
if (E(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
|
|
1501
1501
|
if (u.after === "resumeIdle") {
|
|
1502
1502
|
V(y + f, w);
|
|
@@ -1505,7 +1505,7 @@ function ss(e = {}) {
|
|
|
1505
1505
|
if (u.after === "doublePause") {
|
|
1506
1506
|
u = {
|
|
1507
1507
|
kind: "doublePause",
|
|
1508
|
-
resumeAt: y +
|
|
1508
|
+
resumeAt: y + Fe(i, o),
|
|
1509
1509
|
blinkEmotion: u.blinkEmotion
|
|
1510
1510
|
}, E(R(m), u.blinkEmotion);
|
|
1511
1511
|
return;
|
|
@@ -1513,7 +1513,7 @@ function ss(e = {}) {
|
|
|
1513
1513
|
if (u.after === "idle" && Math.random() < s) {
|
|
1514
1514
|
u = {
|
|
1515
1515
|
kind: "doublePause",
|
|
1516
|
-
resumeAt: y +
|
|
1516
|
+
resumeAt: y + Fe(i, o),
|
|
1517
1517
|
blinkEmotion: u.blinkEmotion
|
|
1518
1518
|
}, E(R(m), u.blinkEmotion);
|
|
1519
1519
|
return;
|
|
@@ -1528,27 +1528,27 @@ function ss(e = {}) {
|
|
|
1528
1528
|
const T = ve(y, w);
|
|
1529
1529
|
if (T === w) return;
|
|
1530
1530
|
const g = performance.now();
|
|
1531
|
-
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g -
|
|
1531
|
+
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g - S < l || (w = T, _ = T, S = g);
|
|
1532
1532
|
},
|
|
1533
1533
|
setTargetEyebrow(y) {
|
|
1534
1534
|
const T = ye(y);
|
|
1535
1535
|
if (T === m && u.kind !== "browBlend") return;
|
|
1536
|
-
const g = performance.now(),
|
|
1537
|
-
m = T, !(T ===
|
|
1536
|
+
const g = performance.now(), C = u.kind === "browBlend" ? $t(p) ?? k : k;
|
|
1537
|
+
m = T, !(T === C && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || H(g, C, T));
|
|
1538
1538
|
},
|
|
1539
1539
|
getTargetEmotion: () => w,
|
|
1540
1540
|
getTargetEyebrow: () => m,
|
|
1541
1541
|
getExpressionPath: () => p,
|
|
1542
1542
|
getDrawKey: () => d,
|
|
1543
1543
|
reset() {
|
|
1544
|
-
w = "neutral", _ = "neutral", m = 0,
|
|
1545
|
-
performance.now() +
|
|
1544
|
+
w = "neutral", _ = "neutral", m = 0, k = 0, S = 0, V(
|
|
1545
|
+
performance.now() + Fe(n, r),
|
|
1546
1546
|
"neutral"
|
|
1547
1547
|
);
|
|
1548
1548
|
}
|
|
1549
1549
|
};
|
|
1550
1550
|
}
|
|
1551
|
-
function
|
|
1551
|
+
function os() {
|
|
1552
1552
|
const e = document.createElement("video");
|
|
1553
1553
|
e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
|
|
1554
1554
|
let t = !1, n = null, r = "";
|
|
@@ -1591,17 +1591,17 @@ function is() {
|
|
|
1591
1591
|
}
|
|
1592
1592
|
};
|
|
1593
1593
|
}
|
|
1594
|
-
const
|
|
1595
|
-
function
|
|
1594
|
+
const as = 50, fn = 400;
|
|
1595
|
+
function cs(e, t, n) {
|
|
1596
1596
|
return e.filter((r) => {
|
|
1597
1597
|
const s = r.queueIndex ?? -1;
|
|
1598
1598
|
return s >= t && s <= n;
|
|
1599
1599
|
});
|
|
1600
1600
|
}
|
|
1601
|
-
function
|
|
1601
|
+
function us(e, t) {
|
|
1602
1602
|
const n = [];
|
|
1603
1603
|
for (const r of e) {
|
|
1604
|
-
const s =
|
|
1604
|
+
const s = cs(
|
|
1605
1605
|
t,
|
|
1606
1606
|
r.start_word,
|
|
1607
1607
|
r.end_word
|
|
@@ -1610,18 +1610,18 @@ function cs(e, t) {
|
|
|
1610
1610
|
const i = s[0], o = s[s.length - 1];
|
|
1611
1611
|
n.push({
|
|
1612
1612
|
sentence: r,
|
|
1613
|
-
startMs: Math.max(0, i.wtime -
|
|
1613
|
+
startMs: Math.max(0, i.wtime - as),
|
|
1614
1614
|
endMs: o.wtime + o.wduration + fn
|
|
1615
1615
|
});
|
|
1616
1616
|
}
|
|
1617
1617
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
1618
1618
|
}
|
|
1619
|
-
function
|
|
1619
|
+
function ls(e, t, n, r = "neutral") {
|
|
1620
1620
|
const s = ve(r);
|
|
1621
1621
|
if (t.length === 0) return s;
|
|
1622
1622
|
if (n.length === 0 || e < n[0].wtime)
|
|
1623
1623
|
return ve(t[0]?.emotion, s);
|
|
1624
|
-
const i =
|
|
1624
|
+
const i = us(t, n);
|
|
1625
1625
|
let o = null;
|
|
1626
1626
|
for (const l of i)
|
|
1627
1627
|
e >= l.startMs && e <= l.endMs && (o = l);
|
|
@@ -1642,45 +1642,45 @@ function dn(e, t, n, r, s = on) {
|
|
|
1642
1642
|
for (const _ of t) {
|
|
1643
1643
|
w.clearRect(0, 0, n, r), w.drawImage(_, 0, 0, n, r);
|
|
1644
1644
|
const m = w.getImageData(0, 0, n, r);
|
|
1645
|
-
for (let
|
|
1646
|
-
const
|
|
1647
|
-
Math.max(
|
|
1645
|
+
for (let k = 0; k < f.data.length; k += 4) {
|
|
1646
|
+
const S = m.data[k], u = m.data[k + 1], p = m.data[k + 2];
|
|
1647
|
+
Math.max(S, u, p) > s && (f.data[k] = S, f.data[k + 1] = u, f.data[k + 2] = p, f.data[k + 3] = 255);
|
|
1648
1648
|
}
|
|
1649
1649
|
}
|
|
1650
1650
|
return o.putImageData(f, 0, 0), i;
|
|
1651
1651
|
}
|
|
1652
|
-
let pe = null,
|
|
1652
|
+
let pe = null, Ue = null;
|
|
1653
1653
|
const je = /* @__PURE__ */ new Map();
|
|
1654
|
-
function
|
|
1655
|
-
pe = null,
|
|
1654
|
+
function fs() {
|
|
1655
|
+
pe = null, Ue = null, je.clear();
|
|
1656
1656
|
}
|
|
1657
|
-
|
|
1658
|
-
function
|
|
1659
|
-
return e ??
|
|
1657
|
+
Xn(fs);
|
|
1658
|
+
function ds(e) {
|
|
1659
|
+
return e ?? Ue ?? void 0;
|
|
1660
1660
|
}
|
|
1661
|
-
function
|
|
1661
|
+
function _t(e) {
|
|
1662
1662
|
return new Promise((t, n) => {
|
|
1663
1663
|
const r = new Image();
|
|
1664
1664
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
1665
1665
|
});
|
|
1666
1666
|
}
|
|
1667
|
-
async function
|
|
1668
|
-
return Ge() ?
|
|
1669
|
-
await Ye(
|
|
1670
|
-
) :
|
|
1667
|
+
async function hs(e) {
|
|
1668
|
+
return Ge() ? Br(
|
|
1669
|
+
await Ye(Ct(), e ?? "")
|
|
1670
|
+
) : _t(Ct());
|
|
1671
1671
|
}
|
|
1672
|
-
async function
|
|
1672
|
+
async function Wt(e, t, n, r) {
|
|
1673
1673
|
const s = n ? await xr(e, r) : await fetch(e).then((l) => {
|
|
1674
1674
|
if (!l.ok) throw new Error(`Failed to load ${e}`);
|
|
1675
1675
|
return l.json();
|
|
1676
1676
|
}), i = s.sheets?.[0];
|
|
1677
1677
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
1678
|
-
const o = n ? await
|
|
1678
|
+
const o = n ? await Pr(
|
|
1679
1679
|
await Ye(
|
|
1680
1680
|
Hr(t, i.path, n),
|
|
1681
1681
|
r ?? ""
|
|
1682
1682
|
)
|
|
1683
|
-
) : await
|
|
1683
|
+
) : await _t(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
|
|
1684
1684
|
for (const l of s.cells ?? [])
|
|
1685
1685
|
l.path && a.set(l.path, l);
|
|
1686
1686
|
const f = /* @__PURE__ */ new Map();
|
|
@@ -1689,29 +1689,29 @@ async function $t(e, t, n, r) {
|
|
|
1689
1689
|
return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: f, diffBase: t };
|
|
1690
1690
|
}
|
|
1691
1691
|
async function at(e) {
|
|
1692
|
-
const t =
|
|
1692
|
+
const t = ds(e), n = Ge();
|
|
1693
1693
|
if (n && !t)
|
|
1694
1694
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
1695
|
-
if (pe && (!n ||
|
|
1695
|
+
if (pe && (!n || Ue === (t ?? null))) {
|
|
1696
1696
|
const i = await pe;
|
|
1697
1697
|
return {
|
|
1698
|
-
...
|
|
1698
|
+
...Ne(i),
|
|
1699
1699
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
1700
1700
|
};
|
|
1701
1701
|
}
|
|
1702
|
-
|
|
1703
|
-
const r =
|
|
1702
|
+
Ue = t ?? null, je.clear();
|
|
1703
|
+
const r = er();
|
|
1704
1704
|
pe = (async () => {
|
|
1705
|
-
const i = await
|
|
1706
|
-
|
|
1705
|
+
const i = await hs(t), o = await Wt(
|
|
1706
|
+
tr(),
|
|
1707
1707
|
r,
|
|
1708
1708
|
n,
|
|
1709
1709
|
t
|
|
1710
1710
|
);
|
|
1711
1711
|
let a = null;
|
|
1712
1712
|
try {
|
|
1713
|
-
a = await
|
|
1714
|
-
|
|
1713
|
+
a = await Wt(
|
|
1714
|
+
nr(),
|
|
1715
1715
|
r,
|
|
1716
1716
|
n,
|
|
1717
1717
|
t
|
|
@@ -1722,20 +1722,20 @@ async function at(e) {
|
|
|
1722
1722
|
return { sil: i, viseme: o, expression: a };
|
|
1723
1723
|
})();
|
|
1724
1724
|
const s = await pe;
|
|
1725
|
-
return { ...
|
|
1725
|
+
return { ...Ne(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
1726
1726
|
}
|
|
1727
1727
|
async function hn(e) {
|
|
1728
1728
|
if (await at(e), !pe) throw new Error("Assets not loaded");
|
|
1729
1729
|
return pe;
|
|
1730
1730
|
}
|
|
1731
|
-
function
|
|
1732
|
-
return
|
|
1731
|
+
function Ne(e) {
|
|
1732
|
+
return Dr(
|
|
1733
1733
|
e.viseme.atlasMeta,
|
|
1734
1734
|
e.sil.naturalWidth,
|
|
1735
1735
|
e.sil.naturalHeight
|
|
1736
1736
|
);
|
|
1737
1737
|
}
|
|
1738
|
-
function
|
|
1738
|
+
function ms(e, t) {
|
|
1739
1739
|
const n = document.createElement("canvas");
|
|
1740
1740
|
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;
|
|
1741
1741
|
}
|
|
@@ -1745,40 +1745,40 @@ async function Ht(e, t, n) {
|
|
|
1745
1745
|
const i = (async () => {
|
|
1746
1746
|
const o = t.cellByPath.get(n);
|
|
1747
1747
|
if (!o) throw new Error(`No atlas cell for path: ${n}`);
|
|
1748
|
-
const a =
|
|
1749
|
-
if (
|
|
1750
|
-
const _ =
|
|
1748
|
+
const a = Mr(t.atlasMeta, o), f = Ne(e);
|
|
1749
|
+
if (Cr(o)) {
|
|
1750
|
+
const _ = ms(t, o), m = document.createElement("canvas");
|
|
1751
1751
|
m.width = f.width, m.height = f.height;
|
|
1752
|
-
const
|
|
1753
|
-
return
|
|
1752
|
+
const k = m.getContext("2d");
|
|
1753
|
+
return k.fillStyle = "#000", k.fillRect(0, 0, f.width, f.height), k.drawImage(_, a.x, a.y), m;
|
|
1754
1754
|
}
|
|
1755
|
-
const l = `${t.diffBase}/${n}`, w = await
|
|
1755
|
+
const l = `${t.diffBase}/${n}`, w = await _t(l);
|
|
1756
1756
|
if (w.naturalWidth === f.width && w.naturalHeight === f.height)
|
|
1757
1757
|
return w;
|
|
1758
1758
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
1759
1759
|
})();
|
|
1760
1760
|
return je.set(r, i), i;
|
|
1761
1761
|
}
|
|
1762
|
-
async function
|
|
1762
|
+
async function qt(e, t, n, r, s, i) {
|
|
1763
1763
|
if (s) {
|
|
1764
|
-
const { width:
|
|
1764
|
+
const { width: k, height: S } = s;
|
|
1765
1765
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
1766
1766
|
return;
|
|
1767
1767
|
const u = document.createElement("canvas");
|
|
1768
|
-
u.width =
|
|
1768
|
+
u.width = k, u.height = S;
|
|
1769
1769
|
const p = u.getContext("2d");
|
|
1770
|
-
if (p.clearRect(0, 0,
|
|
1771
|
-
(e.width !==
|
|
1770
|
+
if (p.clearRect(0, 0, k, S), p.drawImage(t, 0, 0, k, S), i && !i()) return;
|
|
1771
|
+
(e.width !== k || e.height !== S) && (e.width = k, e.height = S);
|
|
1772
1772
|
const d = e.getContext("2d");
|
|
1773
|
-
d.clearRect(0, 0,
|
|
1773
|
+
d.clearRect(0, 0, k, S), d.drawImage(u, 0, 0);
|
|
1774
1774
|
return;
|
|
1775
1775
|
}
|
|
1776
|
-
const o = await hn(), a = an(o.viseme.atlasMeta), { width: f, height: l } =
|
|
1776
|
+
const o = await hn(), a = an(o.viseme.atlasMeta), { width: f, height: l } = Ne(o);
|
|
1777
1777
|
(e.width !== f || e.height !== l) && (e.width = f, e.height = l);
|
|
1778
1778
|
const w = [], _ = e.getContext("2d");
|
|
1779
1779
|
if (_.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
1780
|
-
const
|
|
1781
|
-
_.drawImage(
|
|
1780
|
+
const k = o.sil;
|
|
1781
|
+
_.drawImage(k, 0, 0, f, l);
|
|
1782
1782
|
return;
|
|
1783
1783
|
}
|
|
1784
1784
|
if (w.length === 0) {
|
|
@@ -1789,11 +1789,11 @@ async function Wt(e, t, n, r, s, i) {
|
|
|
1789
1789
|
_.drawImage(m, 0, 0);
|
|
1790
1790
|
}
|
|
1791
1791
|
async function ct(e, t, n) {
|
|
1792
|
-
const r = await hn(
|
|
1792
|
+
const r = await hn(Ue ?? void 0), s = an(r.viseme.atlasMeta), { width: i, height: o } = Ne(r);
|
|
1793
1793
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
1794
1794
|
const a = [];
|
|
1795
1795
|
if (t.mouthPath) {
|
|
1796
|
-
const w = new Set(r.viseme.cellByPath.keys()), _ =
|
|
1796
|
+
const w = new Set(r.viseme.cellByPath.keys()), _ = Ur(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
|
|
1797
1797
|
_ && a.push(await Ht(r, r.viseme, _));
|
|
1798
1798
|
}
|
|
1799
1799
|
t.expressionPath && r.expression && a.push(
|
|
@@ -1813,72 +1813,75 @@ async function ct(e, t, n) {
|
|
|
1813
1813
|
);
|
|
1814
1814
|
f.drawImage(l, 0, 0);
|
|
1815
1815
|
}
|
|
1816
|
-
async function
|
|
1816
|
+
async function ws(e) {
|
|
1817
1817
|
await ct(e, { mouthPath: null, expressionPath: null });
|
|
1818
1818
|
}
|
|
1819
|
-
function
|
|
1819
|
+
function gs(e) {
|
|
1820
1820
|
const t = /* @__PURE__ */ new Map();
|
|
1821
1821
|
for (const n of e)
|
|
1822
1822
|
t.has(n.vtime) || t.set(n.vtime, n);
|
|
1823
1823
|
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
1824
1824
|
}
|
|
1825
|
-
function
|
|
1826
|
-
const t =
|
|
1825
|
+
function _s(e) {
|
|
1826
|
+
const t = gs(e), n = [];
|
|
1827
1827
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1828
1828
|
const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
|
|
1829
1829
|
s === i || a <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: a });
|
|
1830
1830
|
}
|
|
1831
1831
|
return n;
|
|
1832
1832
|
}
|
|
1833
|
-
function
|
|
1833
|
+
function ps(e, t) {
|
|
1834
1834
|
let n = null;
|
|
1835
1835
|
for (const r of e)
|
|
1836
1836
|
t >= r.fromVtime && t < r.toVtime && (n = r);
|
|
1837
1837
|
return n;
|
|
1838
1838
|
}
|
|
1839
|
-
function
|
|
1839
|
+
function ys(e, t) {
|
|
1840
1840
|
return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
|
|
1841
1841
|
}
|
|
1842
|
-
const mn = 400,
|
|
1843
|
-
function
|
|
1842
|
+
const mn = 400, Es = 200, Ss = 600, wn = "__sil__";
|
|
1843
|
+
function ks(e) {
|
|
1844
|
+
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === wn : !1;
|
|
1845
|
+
}
|
|
1846
|
+
function vs() {
|
|
1844
1847
|
return { lastDrawnKey: "" };
|
|
1845
1848
|
}
|
|
1846
|
-
function
|
|
1849
|
+
function fe(e) {
|
|
1847
1850
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
1848
1851
|
}
|
|
1849
|
-
function
|
|
1852
|
+
function bs(e, t) {
|
|
1850
1853
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
1851
1854
|
return t.transitionCache.transitions;
|
|
1852
|
-
const n =
|
|
1855
|
+
const n = _s(e);
|
|
1853
1856
|
return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
|
|
1854
1857
|
}
|
|
1855
|
-
function
|
|
1858
|
+
function Ts(e) {
|
|
1856
1859
|
let t = "sil";
|
|
1857
1860
|
for (const n of e)
|
|
1858
1861
|
n.viseme !== "sil" && (t = n.viseme);
|
|
1859
1862
|
return t;
|
|
1860
1863
|
}
|
|
1861
|
-
function
|
|
1862
|
-
return e === "sil" ? !1 : t ?
|
|
1864
|
+
function As(e, t) {
|
|
1865
|
+
return e === "sil" ? !1 : t ? Nr(e, "sil", t) : mt(e, "sil").length > 0;
|
|
1863
1866
|
}
|
|
1864
|
-
function
|
|
1865
|
-
return mn +
|
|
1867
|
+
function Is() {
|
|
1868
|
+
return mn + Ss;
|
|
1866
1869
|
}
|
|
1867
|
-
function
|
|
1868
|
-
return e ??
|
|
1870
|
+
function Kt(e) {
|
|
1871
|
+
return e ?? wn;
|
|
1869
1872
|
}
|
|
1870
|
-
function
|
|
1873
|
+
function Rs(e, t, n, r) {
|
|
1871
1874
|
if (e.length === 0)
|
|
1872
1875
|
return { diffPath: null, label: "sil" };
|
|
1873
|
-
const s =
|
|
1876
|
+
const s = bs(e, r), i = ps(s, t);
|
|
1874
1877
|
if (i) {
|
|
1875
|
-
const a = i.toVtime - i.fromVtime, f =
|
|
1878
|
+
const a = i.toVtime - i.fromVtime, f = ys(i.fromVtime, i.toVtime);
|
|
1876
1879
|
if (t >= f.transStart && t < i.toVtime) {
|
|
1877
|
-
let l =
|
|
1880
|
+
let l = mt(i.from, i.to);
|
|
1878
1881
|
n && (l = cn(l, n));
|
|
1879
|
-
const w =
|
|
1882
|
+
const w = $r(l, a);
|
|
1880
1883
|
if (w.length > 0) {
|
|
1881
|
-
const _ =
|
|
1884
|
+
const _ = Wr(
|
|
1882
1885
|
t,
|
|
1883
1886
|
f.transStart,
|
|
1884
1887
|
i.toVtime,
|
|
@@ -1889,31 +1892,31 @@ function Is(e, t, n, r) {
|
|
|
1889
1892
|
return { diffPath: Ke(i.to), label: i.to };
|
|
1890
1893
|
}
|
|
1891
1894
|
}
|
|
1892
|
-
const o =
|
|
1895
|
+
const o = ft(e, t);
|
|
1893
1896
|
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Ke(o), label: o };
|
|
1894
1897
|
}
|
|
1895
|
-
function
|
|
1896
|
-
const n = t ??
|
|
1897
|
-
return `${
|
|
1898
|
+
function gn(e, t) {
|
|
1899
|
+
const n = t ?? Kt(e.expressionPath);
|
|
1900
|
+
return `${Kt(e.mouthPath)}|${n}`;
|
|
1898
1901
|
}
|
|
1899
|
-
function
|
|
1900
|
-
const w =
|
|
1902
|
+
function Ds(e, t, n, r, s, i, o, a, f, l) {
|
|
1903
|
+
const w = Rs(t, n, f, i), _ = {
|
|
1901
1904
|
mouthPath: w.diffPath,
|
|
1902
1905
|
expressionPath: r
|
|
1903
|
-
}, m =
|
|
1904
|
-
m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (
|
|
1905
|
-
|
|
1906
|
+
}, m = gn(_, s);
|
|
1907
|
+
m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (k) => {
|
|
1908
|
+
k === m && (i.lastDrawnKey = m);
|
|
1906
1909
|
}));
|
|
1907
1910
|
}
|
|
1908
|
-
function
|
|
1909
|
-
const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l =
|
|
1911
|
+
function jt(e, t, n, r, s, i, o = null) {
|
|
1912
|
+
const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = gn(a, n) + f;
|
|
1910
1913
|
!(o != null) && l === r.lastDrawnKey || (i(
|
|
1911
1914
|
o != null ? "idle" : "sil"
|
|
1912
1915
|
), s(e, a, l, (_) => {
|
|
1913
1916
|
_ === l && (r.lastDrawnKey = l);
|
|
1914
1917
|
}));
|
|
1915
1918
|
}
|
|
1916
|
-
function
|
|
1919
|
+
function _n(e) {
|
|
1917
1920
|
let t = 0, n = null, r = !1, s = !1;
|
|
1918
1921
|
const i = async () => {
|
|
1919
1922
|
if (!r) {
|
|
@@ -1949,9 +1952,9 @@ function gn(e) {
|
|
|
1949
1952
|
}
|
|
1950
1953
|
};
|
|
1951
1954
|
}
|
|
1952
|
-
const
|
|
1953
|
-
async function
|
|
1954
|
-
let t =
|
|
1955
|
+
const Gt = -1, zt = /* @__PURE__ */ new Map();
|
|
1956
|
+
async function Ms(e) {
|
|
1957
|
+
let t = zt.get(e);
|
|
1955
1958
|
if (!t) {
|
|
1956
1959
|
const n = await fetch(e);
|
|
1957
1960
|
if (!n.ok)
|
|
@@ -1959,11 +1962,11 @@ async function Ds(e) {
|
|
|
1959
1962
|
`Failed to fetch worker script (${n.status}): ${e}`
|
|
1960
1963
|
);
|
|
1961
1964
|
const r = await n.blob();
|
|
1962
|
-
t = URL.createObjectURL(r),
|
|
1965
|
+
t = URL.createObjectURL(r), zt.set(e, t);
|
|
1963
1966
|
}
|
|
1964
1967
|
return new Worker(t, { name: "visemeDiffPreview" });
|
|
1965
1968
|
}
|
|
1966
|
-
function
|
|
1969
|
+
function Cs() {
|
|
1967
1970
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
1968
1971
|
}
|
|
1969
1972
|
function xs(e, t) {
|
|
@@ -1971,9 +1974,9 @@ function xs(e, t) {
|
|
|
1971
1974
|
const n = e.getContext("2d");
|
|
1972
1975
|
n && n.drawImage(t, 0, 0);
|
|
1973
1976
|
}
|
|
1974
|
-
function
|
|
1977
|
+
function Yt(e, t) {
|
|
1975
1978
|
let n = 0, r = null;
|
|
1976
|
-
const s =
|
|
1979
|
+
const s = _n(async (i, o) => (await at(), await ct(e, i), s.isLatestSeq(o)));
|
|
1977
1980
|
return {
|
|
1978
1981
|
usesWorker: !1,
|
|
1979
1982
|
async loadAssets(i) {
|
|
@@ -1984,7 +1987,7 @@ function zt(e, t) {
|
|
|
1984
1987
|
return r;
|
|
1985
1988
|
},
|
|
1986
1989
|
async renderSilOnly() {
|
|
1987
|
-
n += 1, s.reset(), await
|
|
1990
|
+
n += 1, s.reset(), await ws(e);
|
|
1988
1991
|
},
|
|
1989
1992
|
drawLiveFrame(i, o, a, f) {
|
|
1990
1993
|
s.enqueue(o, a, f);
|
|
@@ -2002,12 +2005,12 @@ function zt(e, t) {
|
|
|
2002
2005
|
}
|
|
2003
2006
|
};
|
|
2004
2007
|
}
|
|
2005
|
-
function
|
|
2008
|
+
function Ps(e, t, n) {
|
|
2006
2009
|
let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
|
|
2007
|
-
const l = /* @__PURE__ */ new Map(), w =
|
|
2010
|
+
const l = /* @__PURE__ */ new Map(), w = _n(async (p, d, I) => (l.set(d, {
|
|
2008
2011
|
drawKey: I.drawKey,
|
|
2009
2012
|
onDisplayed: I.onDisplayed
|
|
2010
|
-
}), await
|
|
2013
|
+
}), await S(
|
|
2011
2014
|
{
|
|
2012
2015
|
type: "drawFrame",
|
|
2013
2016
|
diffPath: p.mouthPath,
|
|
@@ -2017,30 +2020,30 @@ function Cs(e, t, n) {
|
|
|
2017
2020
|
void 0,
|
|
2018
2021
|
!0
|
|
2019
2022
|
), !1)), _ = (p) => {
|
|
2020
|
-
if (p ===
|
|
2023
|
+
if (p === Gt) {
|
|
2021
2024
|
let E = -1, R;
|
|
2022
|
-
for (const [
|
|
2023
|
-
|
|
2025
|
+
for (const [H, V] of l)
|
|
2026
|
+
H >= E && (E = H, R = V);
|
|
2024
2027
|
E >= 0 && l.delete(E), R?.onDisplayed?.(R.drawKey);
|
|
2025
2028
|
return;
|
|
2026
2029
|
}
|
|
2027
2030
|
const d = -p, I = l.get(d);
|
|
2028
2031
|
l.delete(d), I?.onDisplayed?.(I.drawKey);
|
|
2029
|
-
}, m = /* @__PURE__ */ new Map(),
|
|
2032
|
+
}, m = /* @__PURE__ */ new Map(), k = (p, d) => {
|
|
2030
2033
|
a || !r || r.postMessage(p, []);
|
|
2031
|
-
},
|
|
2034
|
+
}, S = (p, d, I = !1) => {
|
|
2032
2035
|
if (a) return Promise.resolve();
|
|
2033
2036
|
const E = s++;
|
|
2034
|
-
return new Promise((R,
|
|
2037
|
+
return new Promise((R, H) => {
|
|
2035
2038
|
m.set(E, {
|
|
2036
2039
|
resolve: (V) => R(V),
|
|
2037
|
-
reject:
|
|
2040
|
+
reject: H,
|
|
2038
2041
|
generation: typeof p.generation == "number" ? p.generation : void 0,
|
|
2039
2042
|
expectRenderDone: I
|
|
2040
|
-
}),
|
|
2043
|
+
}), k({ ...p, requestId: E });
|
|
2041
2044
|
});
|
|
2042
2045
|
}, u = (async () => {
|
|
2043
|
-
r = await
|
|
2046
|
+
r = await Ms(n), r.onmessage = (p) => {
|
|
2044
2047
|
if (a) return;
|
|
2045
2048
|
const d = p.data;
|
|
2046
2049
|
if (d.type === "status") {
|
|
@@ -2053,9 +2056,9 @@ function Cs(e, t, n) {
|
|
|
2053
2056
|
d.bitmap.close();
|
|
2054
2057
|
return;
|
|
2055
2058
|
}
|
|
2056
|
-
if (E && !(d.generation ===
|
|
2057
|
-
const
|
|
2058
|
-
if (!w.isLatestSeq(
|
|
2059
|
+
if (E && !(d.generation === Gt)) {
|
|
2060
|
+
const H = -d.generation;
|
|
2061
|
+
if (!w.isLatestSeq(H)) {
|
|
2059
2062
|
d.bitmap.close();
|
|
2060
2063
|
return;
|
|
2061
2064
|
}
|
|
@@ -2095,7 +2098,7 @@ function Cs(e, t, n) {
|
|
|
2095
2098
|
for (const [, I] of m)
|
|
2096
2099
|
I.reject(new Error(d));
|
|
2097
2100
|
m.clear();
|
|
2098
|
-
}, await
|
|
2101
|
+
}, await S({ type: "init" }), o = !0;
|
|
2099
2102
|
})();
|
|
2100
2103
|
return {
|
|
2101
2104
|
usesWorker: !0,
|
|
@@ -2103,10 +2106,10 @@ function Cs(e, t, n) {
|
|
|
2103
2106
|
if (a) return { width: 842, height: 1264 };
|
|
2104
2107
|
if (await u, a) return { width: 842, height: 1264 };
|
|
2105
2108
|
if (!o) throw new Error("Worker init failed");
|
|
2106
|
-
return await
|
|
2109
|
+
return await S({
|
|
2107
2110
|
type: "loadAssets",
|
|
2108
2111
|
keyHex: p,
|
|
2109
|
-
urls:
|
|
2112
|
+
urls: Qn(Ee())
|
|
2110
2113
|
}) ?? { width: 842, height: 1264 };
|
|
2111
2114
|
},
|
|
2112
2115
|
getVisemeAtlasPaths() {
|
|
@@ -2116,7 +2119,7 @@ function Cs(e, t, n) {
|
|
|
2116
2119
|
if (a || (await u, a)) return;
|
|
2117
2120
|
i += 1, w.reset(), l.clear();
|
|
2118
2121
|
const p = i;
|
|
2119
|
-
await
|
|
2122
|
+
await S({ type: "cancelLiveDraws" }), await S(
|
|
2120
2123
|
{ type: "renderSil", generation: p },
|
|
2121
2124
|
void 0,
|
|
2122
2125
|
!0
|
|
@@ -2132,7 +2135,7 @@ function Cs(e, t, n) {
|
|
|
2132
2135
|
i += 1, w.reset(), l.clear();
|
|
2133
2136
|
const E = i;
|
|
2134
2137
|
try {
|
|
2135
|
-
await
|
|
2138
|
+
await S({ type: "cancelLiveDraws" }), await S(
|
|
2136
2139
|
{
|
|
2137
2140
|
type: "renderViseme",
|
|
2138
2141
|
generation: E,
|
|
@@ -2160,17 +2163,17 @@ function Cs(e, t, n) {
|
|
|
2160
2163
|
}
|
|
2161
2164
|
};
|
|
2162
2165
|
}
|
|
2163
|
-
function
|
|
2164
|
-
if (!
|
|
2165
|
-
return
|
|
2166
|
-
const n =
|
|
2166
|
+
function Bs(e, t = {}) {
|
|
2167
|
+
if (!Cs())
|
|
2168
|
+
return Yt(e, t);
|
|
2169
|
+
const n = Pn(t.workerScriptUrl);
|
|
2167
2170
|
try {
|
|
2168
|
-
return
|
|
2171
|
+
return Ps(e, t, n);
|
|
2169
2172
|
} catch {
|
|
2170
|
-
return
|
|
2173
|
+
return Yt(e, t);
|
|
2171
2174
|
}
|
|
2172
2175
|
}
|
|
2173
|
-
class
|
|
2176
|
+
class Ls extends Error {
|
|
2174
2177
|
constructor(t, n) {
|
|
2175
2178
|
super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
2176
2179
|
}
|
|
@@ -2178,7 +2181,7 @@ class Bs extends Error {
|
|
|
2178
2181
|
function tt(e, t, n) {
|
|
2179
2182
|
return new Promise((r, s) => {
|
|
2180
2183
|
const i = globalThis.setTimeout(() => {
|
|
2181
|
-
s(new
|
|
2184
|
+
s(new Ls(n, t));
|
|
2182
2185
|
}, t);
|
|
2183
2186
|
e.then(
|
|
2184
2187
|
(o) => {
|
|
@@ -2190,15 +2193,15 @@ function tt(e, t, n) {
|
|
|
2190
2193
|
);
|
|
2191
2194
|
});
|
|
2192
2195
|
}
|
|
2193
|
-
const
|
|
2196
|
+
const Os = {
|
|
2194
2197
|
position: "relative",
|
|
2195
2198
|
display: "inline-block",
|
|
2196
2199
|
lineHeight: 0
|
|
2197
|
-
},
|
|
2200
|
+
}, Fs = {
|
|
2198
2201
|
display: "block",
|
|
2199
2202
|
maxWidth: "100%",
|
|
2200
2203
|
height: "auto"
|
|
2201
|
-
},
|
|
2204
|
+
}, Us = {
|
|
2202
2205
|
position: "absolute",
|
|
2203
2206
|
inset: 0,
|
|
2204
2207
|
display: "flex",
|
|
@@ -2210,13 +2213,13 @@ const Ls = {
|
|
|
2210
2213
|
fontSize: "0.875rem",
|
|
2211
2214
|
textAlign: "center"
|
|
2212
2215
|
};
|
|
2213
|
-
function
|
|
2214
|
-
return
|
|
2216
|
+
function Oe(e) {
|
|
2217
|
+
return Fn(e) ? Sr : nn;
|
|
2215
2218
|
}
|
|
2216
2219
|
function we(e, t) {
|
|
2217
2220
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
2218
2221
|
}
|
|
2219
|
-
const
|
|
2222
|
+
const zs = vn(function({
|
|
2220
2223
|
id: t,
|
|
2221
2224
|
avatarId: n,
|
|
2222
2225
|
faceId: r,
|
|
@@ -2224,40 +2227,40 @@ const Ks = Sn(function({
|
|
|
2224
2227
|
authToken: i,
|
|
2225
2228
|
ttsEngineId: o = Te,
|
|
2226
2229
|
voiceId: a,
|
|
2227
|
-
speakingRate: f =
|
|
2230
|
+
speakingRate: f = dt,
|
|
2228
2231
|
className: l,
|
|
2229
2232
|
style: w,
|
|
2230
2233
|
canvasStyle: _,
|
|
2231
2234
|
onStatusChange: m,
|
|
2232
|
-
onDisplayStatus:
|
|
2233
|
-
onError:
|
|
2235
|
+
onDisplayStatus: k,
|
|
2236
|
+
onError: S,
|
|
2234
2237
|
onReady: u,
|
|
2235
2238
|
showErrorOverlay: p = !0,
|
|
2236
2239
|
onUserTranscript: d,
|
|
2237
2240
|
onBotOutput: I,
|
|
2238
2241
|
onRealtimeLipsyncDebug: E
|
|
2239
2242
|
}, R) {
|
|
2240
|
-
const
|
|
2243
|
+
const H = F(null), V = F(null), $ = F(vs()), j = F(is()), y = F(0), T = F(0), g = F(0), C = F(null), b = F(null), D = F(!1), A = F(!1), P = F(!1), B = F("sil"), W = F(!1), U = F(
|
|
2241
2244
|
null
|
|
2242
|
-
), X = F(!1), [se, Z] =
|
|
2243
|
-
|
|
2244
|
-
const
|
|
2245
|
+
), X = F(!1), [se, Z] = Le("idle"), [ce, J] = Le(null), [c, v] = Le(!1), [L, z] = Le(!1), [ne, Re] = Le({ width: 842, height: 1264 }), G = F(i ?? null), Se = F(null), Y = F(null), De = F(!1), Je = F({ width: 842, height: 1264 }), Qe = F(null), pt = F(u), ee = F(k), yt = F(S), Et = F(d), St = F(I), kt = F(E);
|
|
2246
|
+
pt.current = u, ee.current = k, yt.current = S, Et.current = d, St.current = I, kt.current = E;
|
|
2247
|
+
const vt = oe(
|
|
2245
2248
|
(h) => {
|
|
2246
|
-
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te,
|
|
2247
|
-
return { ttsEngineId: M, voiceId:
|
|
2249
|
+
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, x = h?.voiceId ?? a ?? Y.current?.voiceId ?? Oe(M);
|
|
2250
|
+
return { ttsEngineId: M, voiceId: x };
|
|
2248
2251
|
},
|
|
2249
2252
|
[o, a]
|
|
2250
|
-
),
|
|
2251
|
-
J(h),
|
|
2253
|
+
), de = oe((h) => {
|
|
2254
|
+
J(h), yt.current?.(h);
|
|
2252
2255
|
}, []), Me = oe(
|
|
2253
2256
|
(h) => {
|
|
2254
2257
|
Z(h), m?.(h);
|
|
2255
2258
|
},
|
|
2256
2259
|
[m]
|
|
2257
2260
|
), q = F(
|
|
2258
|
-
|
|
2261
|
+
Bt(Me, be)
|
|
2259
2262
|
), K = F(null);
|
|
2260
|
-
|
|
2263
|
+
ke(() => (q.current = Bt(
|
|
2261
2264
|
Me,
|
|
2262
2265
|
be
|
|
2263
2266
|
), i && q.current.setDeveloperToken(i), q.current.setTtsEngineId(o), () => {
|
|
@@ -2265,19 +2268,19 @@ const Ks = Sn(function({
|
|
|
2265
2268
|
const h = K.current;
|
|
2266
2269
|
h && (h.disconnect(), K.current = null);
|
|
2267
2270
|
}), [Me, i, o]);
|
|
2268
|
-
const
|
|
2271
|
+
const bt = oe(() => (K.current || (K.current = Rr(
|
|
2269
2272
|
Me,
|
|
2270
2273
|
{
|
|
2271
2274
|
speakingRate: f,
|
|
2272
|
-
onUserTranscript: (h, M) =>
|
|
2273
|
-
onBotOutput: (h) =>
|
|
2275
|
+
onUserTranscript: (h, M) => Et.current?.(h, M),
|
|
2276
|
+
onBotOutput: (h) => St.current?.(h),
|
|
2274
2277
|
onLipsyncDebug: (h) => kt.current?.(h)
|
|
2275
2278
|
}
|
|
2276
2279
|
), K.current.setTtsEngineId(o)), K.current), [Me, f, o]), ie = oe(() => {
|
|
2277
|
-
|
|
2280
|
+
C.current != null && (clearTimeout(C.current), C.current = null);
|
|
2278
2281
|
}, []), ue = oe(() => {
|
|
2279
2282
|
b.current != null && (clearTimeout(b.current), b.current = null), P.current = !1;
|
|
2280
|
-
}, []),
|
|
2283
|
+
}, []), Tt = oe(() => {
|
|
2281
2284
|
!X.current || !U.current || (ue(), P.current = !0, b.current = setTimeout(() => {
|
|
2282
2285
|
if (b.current = null, we(
|
|
2283
2286
|
q.current,
|
|
@@ -2297,9 +2300,9 @@ const Ks = Sn(function({
|
|
|
2297
2300
|
}
|
|
2298
2301
|
h.restart(), h.setActive(!0);
|
|
2299
2302
|
const M = h.getVideo();
|
|
2300
|
-
let
|
|
2303
|
+
let x = !1;
|
|
2301
2304
|
const O = () => {
|
|
2302
|
-
|
|
2305
|
+
x || (x = !0, M.removeEventListener("playing", N), P.current = !1);
|
|
2303
2306
|
}, N = () => {
|
|
2304
2307
|
O();
|
|
2305
2308
|
};
|
|
@@ -2308,19 +2311,19 @@ const Ks = Sn(function({
|
|
|
2308
2311
|
return;
|
|
2309
2312
|
}
|
|
2310
2313
|
setTimeout(O, 300);
|
|
2311
|
-
},
|
|
2312
|
-
}, [ue]),
|
|
2314
|
+
}, Es));
|
|
2315
|
+
}, [ue]), Ce = oe(() => {
|
|
2313
2316
|
if (ie(), ee.current?.("sil"), D.current = !1, !X.current || !U.current) {
|
|
2314
2317
|
P.current = !1;
|
|
2315
2318
|
return;
|
|
2316
2319
|
}
|
|
2317
|
-
|
|
2318
|
-
}, [ie,
|
|
2320
|
+
Tt();
|
|
2321
|
+
}, [ie, Tt]), Xe = oe(
|
|
2319
2322
|
async (h) => {
|
|
2320
|
-
const M = T.current,
|
|
2323
|
+
const M = T.current, x = V.current, O = H.current, N = () => {
|
|
2321
2324
|
h?.fallbackOnly || (D.current = !1);
|
|
2322
2325
|
};
|
|
2323
|
-
if (!
|
|
2326
|
+
if (!x || !O || !c) {
|
|
2324
2327
|
N();
|
|
2325
2328
|
return;
|
|
2326
2329
|
}
|
|
@@ -2332,40 +2335,44 @@ const Ks = Sn(function({
|
|
|
2332
2335
|
return;
|
|
2333
2336
|
}
|
|
2334
2337
|
if (h?.fallbackOnly) {
|
|
2335
|
-
if (!D.current || (
|
|
2338
|
+
if (!D.current || (fe($.current), await x.renderSilOnly(), M !== T.current) || we(
|
|
2336
2339
|
q.current,
|
|
2337
2340
|
K.current
|
|
2338
2341
|
).isSpeaking())
|
|
2339
2342
|
return;
|
|
2340
|
-
|
|
2343
|
+
Ce();
|
|
2341
2344
|
return;
|
|
2342
2345
|
}
|
|
2343
|
-
|
|
2346
|
+
if (ks($.current)) {
|
|
2347
|
+
fe($.current), Ce();
|
|
2348
|
+
return;
|
|
2349
|
+
}
|
|
2350
|
+
const te = B.current !== "sil" ? B.current : Ts(
|
|
2344
2351
|
we(
|
|
2345
2352
|
q.current,
|
|
2346
2353
|
K.current
|
|
2347
2354
|
).getVisemeQueue()
|
|
2348
|
-
), ae =
|
|
2355
|
+
), ae = As(
|
|
2349
2356
|
te,
|
|
2350
2357
|
Qe.current
|
|
2351
2358
|
);
|
|
2352
|
-
if (
|
|
2353
|
-
if (await
|
|
2359
|
+
if (fe($.current), !ae) {
|
|
2360
|
+
if (await x.renderSilOnly(), M !== T.current || we(
|
|
2354
2361
|
q.current,
|
|
2355
2362
|
K.current
|
|
2356
2363
|
).isSpeaking())
|
|
2357
2364
|
return;
|
|
2358
|
-
|
|
2365
|
+
Ce();
|
|
2359
2366
|
return;
|
|
2360
2367
|
}
|
|
2361
2368
|
try {
|
|
2362
|
-
await
|
|
2369
|
+
await x.renderViseme(O, "sil", {
|
|
2363
2370
|
from: te,
|
|
2364
2371
|
transitionDurationMs: mn
|
|
2365
2372
|
});
|
|
2366
|
-
} catch (
|
|
2367
|
-
if (
|
|
2368
|
-
throw
|
|
2373
|
+
} catch (he) {
|
|
2374
|
+
if (he?.name !== "AbortError")
|
|
2375
|
+
throw he;
|
|
2369
2376
|
}
|
|
2370
2377
|
if (M !== T.current) {
|
|
2371
2378
|
N();
|
|
@@ -2378,104 +2385,104 @@ const Ks = Sn(function({
|
|
|
2378
2385
|
N();
|
|
2379
2386
|
return;
|
|
2380
2387
|
}
|
|
2381
|
-
|
|
2388
|
+
Ce();
|
|
2382
2389
|
},
|
|
2383
|
-
[c,
|
|
2390
|
+
[c, Ce]
|
|
2384
2391
|
), xe = oe(() => {
|
|
2385
2392
|
if (A.current || D.current) return;
|
|
2386
2393
|
A.current = !0, D.current = !0, ie();
|
|
2387
2394
|
const h = T.current;
|
|
2388
2395
|
Xe().finally(() => {
|
|
2389
2396
|
A.current = !1;
|
|
2390
|
-
}),
|
|
2391
|
-
|
|
2392
|
-
},
|
|
2393
|
-
}, [ie, Xe]),
|
|
2397
|
+
}), C.current = setTimeout(() => {
|
|
2398
|
+
C.current = null, h === T.current && Xe({ fallbackOnly: !0 });
|
|
2399
|
+
}, Is());
|
|
2400
|
+
}, [ie, Xe]), At = oe(async () => {
|
|
2394
2401
|
const h = Math.floor(Date.now() / 1e3);
|
|
2395
|
-
if (
|
|
2396
|
-
return
|
|
2402
|
+
if (Se.current && h < Se.current.expiresAt - 60)
|
|
2403
|
+
return Se.current.key;
|
|
2397
2404
|
const M = G.current ?? await et();
|
|
2398
2405
|
G.current = M, q.current.setDeveloperToken(M);
|
|
2399
|
-
const
|
|
2400
|
-
return
|
|
2401
|
-
key:
|
|
2402
|
-
expiresAt:
|
|
2403
|
-
},
|
|
2406
|
+
const x = await Kn(M, be);
|
|
2407
|
+
return Se.current = {
|
|
2408
|
+
key: x.value,
|
|
2409
|
+
expiresAt: x.expiresAt
|
|
2410
|
+
}, x.value;
|
|
2404
2411
|
}, []);
|
|
2405
|
-
|
|
2412
|
+
ke(() => {
|
|
2406
2413
|
i && (G.current = i, q.current.setDeveloperToken(i));
|
|
2407
|
-
}, [i]),
|
|
2414
|
+
}, [i]), ke(() => {
|
|
2408
2415
|
q.current.setTtsEngineId(o), K.current?.setTtsEngineId(o), Y.current && (Y.current.ttsEngineId = o);
|
|
2409
|
-
}, [o]),
|
|
2410
|
-
const h = a ??
|
|
2416
|
+
}, [o]), ke(() => {
|
|
2417
|
+
const h = a ?? Oe(o);
|
|
2411
2418
|
Y.current && (Y.current.voiceId = h);
|
|
2412
2419
|
}, [a, o]);
|
|
2413
|
-
const ge =
|
|
2414
|
-
() =>
|
|
2420
|
+
const ge = Rt(
|
|
2421
|
+
() => Yn(n, r),
|
|
2415
2422
|
[n, r]
|
|
2416
|
-
),
|
|
2417
|
-
return
|
|
2423
|
+
), pn = Rt(() => s ? JSON.stringify(s) : ge ? `face:${ge}` : `id:${t ?? ""}`, [s, ge, t]);
|
|
2424
|
+
return ke(() => {
|
|
2418
2425
|
if (!t && !s && !ge) {
|
|
2419
|
-
|
|
2426
|
+
de("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
2420
2427
|
return;
|
|
2421
2428
|
}
|
|
2422
2429
|
let h = !1;
|
|
2423
2430
|
De.current = !1, v(!1), z(!1), J(null), Y.current = null, U.current = null, X.current = !1;
|
|
2424
|
-
const M =
|
|
2431
|
+
const M = H.current;
|
|
2425
2432
|
if (!M) return;
|
|
2426
|
-
let
|
|
2433
|
+
let x = null;
|
|
2427
2434
|
return (async () => {
|
|
2428
2435
|
try {
|
|
2429
2436
|
let O, N, te;
|
|
2430
2437
|
if (s)
|
|
2431
|
-
O = s, N = o, te = a ??
|
|
2438
|
+
O = s, N = o, te = a ?? Oe(N);
|
|
2432
2439
|
else if (ge)
|
|
2433
|
-
ee.current?.("loadFace"), O =
|
|
2440
|
+
ee.current?.("loadFace"), O = Mt(ge), N = o, te = a ?? Oe(N);
|
|
2434
2441
|
else {
|
|
2435
2442
|
ee.current?.("getAiTwin");
|
|
2436
2443
|
const Q = await tt(
|
|
2437
|
-
|
|
2444
|
+
Nn(t),
|
|
2438
2445
|
3e4,
|
|
2439
2446
|
"getAiTwin"
|
|
2440
2447
|
);
|
|
2441
2448
|
if (h) return;
|
|
2442
2449
|
if (!Q.faceId?.trim())
|
|
2443
2450
|
throw new Error("getAiTwin returned no faceId");
|
|
2444
|
-
N = Q.ttsEngineId, te = a ?? Q.voiceId ??
|
|
2451
|
+
N = Q.ttsEngineId, te = a ?? Q.voiceId ?? Oe(N), O = Mt(Q.faceId);
|
|
2445
2452
|
}
|
|
2446
|
-
Y.current = { ttsEngineId: N, voiceId: te },
|
|
2453
|
+
Y.current = { ttsEngineId: N, voiceId: te }, Jn(O), U.current = os(), x = Bs(M, {
|
|
2447
2454
|
onStatus: (Q) => {
|
|
2448
2455
|
h || ee.current?.(Q);
|
|
2449
2456
|
},
|
|
2450
2457
|
onError: (Q) => {
|
|
2451
|
-
h ||
|
|
2458
|
+
h || de(Q);
|
|
2452
2459
|
},
|
|
2453
2460
|
shouldAcceptLiveFrame: () => we(
|
|
2454
2461
|
q.current,
|
|
2455
2462
|
K.current
|
|
2456
2463
|
).isSpeaking() && !D.current
|
|
2457
|
-
}), V.current =
|
|
2464
|
+
}), V.current = x, ee.current?.("auth");
|
|
2458
2465
|
const ae = G.current ?? i ?? await tt(et(), 3e4, "getAuthToken");
|
|
2459
2466
|
if (h) return;
|
|
2460
2467
|
G.current = ae, q.current.setDeveloperToken(ae), q.current.setTtsEngineId(N);
|
|
2461
|
-
const
|
|
2468
|
+
const he = Ge() ? await At() : void 0;
|
|
2462
2469
|
if (h) return;
|
|
2463
2470
|
ee.current?.("loadAssets");
|
|
2464
2471
|
const le = await tt(
|
|
2465
|
-
|
|
2472
|
+
x.loadAssets(he),
|
|
2466
2473
|
18e4,
|
|
2467
2474
|
"load face assets"
|
|
2468
2475
|
);
|
|
2469
2476
|
if (!h && le.width > 0 && le.height > 0 && (Je.current = le, Re(le)), h) return;
|
|
2470
|
-
Qe.current =
|
|
2477
|
+
Qe.current = x.getVisemeAtlasPaths(), De.current = !0, v(!0), pt.current?.(), x.renderSilOnly().then(() => {
|
|
2471
2478
|
h || ee.current?.("sil");
|
|
2472
2479
|
}), (async () => {
|
|
2473
2480
|
try {
|
|
2474
|
-
const Q = await
|
|
2481
|
+
const Q = await Or(he);
|
|
2475
2482
|
if (await U.current.load(Q), h) return;
|
|
2476
|
-
X.current = !0, z(!0),
|
|
2483
|
+
X.current = !0, z(!0), fe($.current), U.current.setActive(!0);
|
|
2477
2484
|
const re = U.current.getVideo();
|
|
2478
|
-
await
|
|
2485
|
+
await qt(
|
|
2479
2486
|
M,
|
|
2480
2487
|
re,
|
|
2481
2488
|
null,
|
|
@@ -2490,60 +2497,60 @@ const Ks = Sn(function({
|
|
|
2490
2497
|
} catch (O) {
|
|
2491
2498
|
if (h) return;
|
|
2492
2499
|
if (O instanceof nt) {
|
|
2493
|
-
|
|
2500
|
+
de(O.message);
|
|
2494
2501
|
return;
|
|
2495
2502
|
}
|
|
2496
|
-
|
|
2503
|
+
de(O instanceof Error ? O.message : "Failed to load AI twin");
|
|
2497
2504
|
}
|
|
2498
2505
|
})(), () => {
|
|
2499
|
-
h = !0, U.current?.dispose(),
|
|
2506
|
+
h = !0, U.current?.dispose(), x?.dispose(), V.current = null;
|
|
2500
2507
|
};
|
|
2501
|
-
}, [
|
|
2508
|
+
}, [pn, s, ge, t, o, a, i, At, de]), ke(() => {
|
|
2502
2509
|
const h = { current: !1 }, M = () => {
|
|
2503
|
-
const
|
|
2510
|
+
const x = H.current, O = V.current, N = we(
|
|
2504
2511
|
q.current,
|
|
2505
2512
|
K.current
|
|
2506
2513
|
);
|
|
2507
|
-
if (!
|
|
2514
|
+
if (!x || !O || !c) {
|
|
2508
2515
|
y.current = requestAnimationFrame(M);
|
|
2509
2516
|
return;
|
|
2510
2517
|
}
|
|
2511
|
-
const te = N.isSpeaking(), ae = te &&
|
|
2512
|
-
ae && (ie(), ue(), D.current = !1, A.current = !1,
|
|
2513
|
-
const le = N.getPlaybackElapsedMs(), Q =
|
|
2518
|
+
const te = N.isSpeaking(), ae = te && !W.current, he = W.current && !te;
|
|
2519
|
+
ae && (ie(), ue(), D.current = !1, A.current = !1, fe($.current), g.current = 0, B.current = "sil", U.current?.setActive(!1)), he && (j.current.reset(), U.current?.setActive(!1), xe());
|
|
2520
|
+
const le = N.getPlaybackElapsedMs(), Q = he || D.current || P.current;
|
|
2514
2521
|
if (te) {
|
|
2515
2522
|
X.current && U.current?.setActive(!1);
|
|
2516
|
-
const re = N.getVisemeQueue(), _e = re.length > 0 ?
|
|
2523
|
+
const re = N.getVisemeQueue(), _e = re.length > 0 ? ft(re, le) : "sil";
|
|
2517
2524
|
_e !== "sil" && (B.current = _e);
|
|
2518
|
-
const
|
|
2525
|
+
const me = ls(
|
|
2519
2526
|
le,
|
|
2520
2527
|
N.getSentenceEmotions(),
|
|
2521
2528
|
N.getWordQueue(),
|
|
2522
2529
|
N.getStreamMood()
|
|
2523
2530
|
);
|
|
2524
|
-
j.current.setTargetEmotion(
|
|
2525
|
-
|
|
2531
|
+
j.current.setTargetEmotion(me), j.current.setTargetEyebrow(
|
|
2532
|
+
ss(
|
|
2526
2533
|
le,
|
|
2527
2534
|
N.getWordQueue(),
|
|
2528
|
-
|
|
2535
|
+
gt(me)
|
|
2529
2536
|
)
|
|
2530
2537
|
), j.current.advance(performance.now());
|
|
2531
|
-
const
|
|
2532
|
-
|
|
2533
|
-
|
|
2538
|
+
const Pe = j.current.getExpressionPath(), Ze = j.current.getDrawKey();
|
|
2539
|
+
Ds(
|
|
2540
|
+
x,
|
|
2534
2541
|
re,
|
|
2535
2542
|
le,
|
|
2536
|
-
|
|
2543
|
+
Pe,
|
|
2537
2544
|
Ze,
|
|
2538
|
-
|
|
2539
|
-
(
|
|
2540
|
-
(
|
|
2545
|
+
$.current,
|
|
2546
|
+
(Be, yn, En, Sn) => O.drawLiveFrame(Be, yn, En, Sn),
|
|
2547
|
+
(Be) => ee.current?.(Be),
|
|
2541
2548
|
Qe.current
|
|
2542
2549
|
);
|
|
2543
2550
|
} else if (!Q && X.current && U.current) {
|
|
2544
2551
|
const re = U.current, _e = re.getVideo();
|
|
2545
|
-
_e.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), h.current || (h.current = !0,
|
|
2546
|
-
|
|
2552
|
+
_e.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), h.current || (h.current = !0, qt(
|
|
2553
|
+
x,
|
|
2547
2554
|
_e,
|
|
2548
2555
|
null,
|
|
2549
2556
|
void 0,
|
|
@@ -2551,23 +2558,23 @@ const Ks = Sn(function({
|
|
|
2551
2558
|
() => !N.isSpeaking() && !D.current && !P.current
|
|
2552
2559
|
).then(() => ee.current?.("idle")).finally(() => {
|
|
2553
2560
|
h.current = !1;
|
|
2554
|
-
}))) :
|
|
2555
|
-
|
|
2561
|
+
}))) : jt(
|
|
2562
|
+
x,
|
|
2556
2563
|
null,
|
|
2557
2564
|
"__sil__",
|
|
2558
|
-
|
|
2559
|
-
(
|
|
2560
|
-
(
|
|
2565
|
+
$.current,
|
|
2566
|
+
(me, Pe, Ze, Be) => O.drawLiveFrame(me, Pe, Ze, Be),
|
|
2567
|
+
(me) => ee.current?.(me)
|
|
2561
2568
|
);
|
|
2562
|
-
} else Q ||
|
|
2563
|
-
|
|
2569
|
+
} else Q || jt(
|
|
2570
|
+
x,
|
|
2564
2571
|
null,
|
|
2565
2572
|
"__sil__",
|
|
2566
|
-
|
|
2567
|
-
(re, _e,
|
|
2573
|
+
$.current,
|
|
2574
|
+
(re, _e, me, Pe) => O.drawLiveFrame(re, _e, me, Pe),
|
|
2568
2575
|
(re) => ee.current?.(re)
|
|
2569
2576
|
);
|
|
2570
|
-
|
|
2577
|
+
W.current = te, y.current = requestAnimationFrame(M);
|
|
2571
2578
|
};
|
|
2572
2579
|
return y.current = requestAnimationFrame(M), () => {
|
|
2573
2580
|
cancelAnimationFrame(y.current), ie(), ue(), q.current.stop(), K.current?.stop();
|
|
@@ -2578,38 +2585,38 @@ const Ks = Sn(function({
|
|
|
2578
2585
|
xe,
|
|
2579
2586
|
ie,
|
|
2580
2587
|
ue
|
|
2581
|
-
]),
|
|
2588
|
+
]), bn(
|
|
2582
2589
|
R,
|
|
2583
2590
|
() => ({
|
|
2584
2591
|
speakText: async (h, M) => {
|
|
2585
|
-
const
|
|
2586
|
-
if (!
|
|
2592
|
+
const x = h.trim();
|
|
2593
|
+
if (!x) return;
|
|
2587
2594
|
const O = V.current;
|
|
2588
2595
|
if (!O || !De.current && !c)
|
|
2589
2596
|
throw new Error("AI twin is not ready");
|
|
2590
|
-
const { ttsEngineId: N, voiceId: te } =
|
|
2591
|
-
J(null), T.current += 1, ie(), ue(), D.current = !1, A.current = !1, B.current = "sil",
|
|
2597
|
+
const { ttsEngineId: N, voiceId: te } = vt(M);
|
|
2598
|
+
J(null), T.current += 1, ie(), ue(), D.current = !1, A.current = !1, B.current = "sil", fe($.current), j.current.reset(), W.current = !1;
|
|
2592
2599
|
try {
|
|
2593
|
-
X.current ? (U.current?.setActive(!1), U.current?.restart(),
|
|
2600
|
+
X.current ? (U.current?.setActive(!1), U.current?.restart(), fe($.current)) : await O.renderSilOnly(), await q.current.speak(x, {
|
|
2594
2601
|
voiceId: te,
|
|
2595
2602
|
speakingRate: M?.speakingRate ?? f,
|
|
2596
2603
|
ttsEngineId: N
|
|
2597
2604
|
});
|
|
2598
2605
|
} catch (ae) {
|
|
2599
|
-
throw
|
|
2606
|
+
throw de(ae instanceof Error ? ae.message : "TTS failed"), ae;
|
|
2600
2607
|
}
|
|
2601
2608
|
},
|
|
2602
2609
|
stop: () => {
|
|
2603
|
-
T.current += 1, ie(), ue(), D.current = !1, A.current = !1, q.current.stop(), K.current?.stop(),
|
|
2610
|
+
T.current += 1, ie(), ue(), D.current = !1, A.current = !1, q.current.stop(), K.current?.stop(), fe($.current), W.current = !1, xe();
|
|
2604
2611
|
},
|
|
2605
2612
|
setTtsEngineId: (h) => {
|
|
2606
2613
|
q.current.setTtsEngineId(h), K.current?.setTtsEngineId(h), Y.current && (Y.current.ttsEngineId = h);
|
|
2607
2614
|
},
|
|
2608
2615
|
renderViseme: async (h, M) => {
|
|
2609
|
-
const
|
|
2610
|
-
if (!
|
|
2616
|
+
const x = V.current, O = H.current;
|
|
2617
|
+
if (!x || !O || !De.current)
|
|
2611
2618
|
throw new Error("AI twin is not ready");
|
|
2612
|
-
await
|
|
2619
|
+
await x.renderViseme(O, h, {
|
|
2613
2620
|
from: M?.from,
|
|
2614
2621
|
transitionDurationMs: M?.transitionDurationMs,
|
|
2615
2622
|
gapMs: M?.gapMs,
|
|
@@ -2623,22 +2630,22 @@ const Ks = Sn(function({
|
|
|
2623
2630
|
try {
|
|
2624
2631
|
let M = h.authToken?.trim();
|
|
2625
2632
|
M || (M = G.current ?? i ?? await et(), G.current = M);
|
|
2626
|
-
const
|
|
2633
|
+
const x = h.voiceId?.trim() ?? a ?? Y.current?.voiceId, O = bt();
|
|
2627
2634
|
await O.unlockAudio(), await O.connect({
|
|
2628
2635
|
...h,
|
|
2629
2636
|
authToken: M,
|
|
2630
|
-
voiceId:
|
|
2637
|
+
voiceId: x,
|
|
2631
2638
|
speakingRate: h.speakingRate ?? f
|
|
2632
2639
|
});
|
|
2633
2640
|
} catch (M) {
|
|
2634
|
-
throw
|
|
2641
|
+
throw de(
|
|
2635
2642
|
M instanceof Error ? M.message : "Voice connect failed"
|
|
2636
2643
|
), M;
|
|
2637
2644
|
}
|
|
2638
2645
|
},
|
|
2639
2646
|
disconnect: async () => {
|
|
2640
2647
|
const h = K.current;
|
|
2641
|
-
h && (T.current += 1, ie(), ue(), D.current = !1, A.current = !1,
|
|
2648
|
+
h && (T.current += 1, ie(), ue(), D.current = !1, A.current = !1, fe($.current), W.current = !1, await h.disconnect(), xe());
|
|
2642
2649
|
},
|
|
2643
2650
|
isConnected: () => K.current?.isConnected() ?? !1
|
|
2644
2651
|
}),
|
|
@@ -2650,58 +2657,71 @@ const Ks = Sn(function({
|
|
|
2650
2657
|
ie,
|
|
2651
2658
|
ue,
|
|
2652
2659
|
xe,
|
|
2653
|
-
|
|
2654
|
-
St,
|
|
2660
|
+
de,
|
|
2655
2661
|
vt,
|
|
2662
|
+
bt,
|
|
2656
2663
|
se
|
|
2657
2664
|
]
|
|
2658
|
-
), /* @__PURE__ */ kn("div", { className: l, style: { ...
|
|
2659
|
-
/* @__PURE__ */
|
|
2665
|
+
), /* @__PURE__ */ kn("div", { className: l, style: { ...Os, ...w }, children: [
|
|
2666
|
+
/* @__PURE__ */ It(
|
|
2660
2667
|
"canvas",
|
|
2661
2668
|
{
|
|
2662
|
-
ref:
|
|
2669
|
+
ref: H,
|
|
2663
2670
|
width: ne.width,
|
|
2664
2671
|
height: ne.height,
|
|
2665
|
-
style: { ...
|
|
2672
|
+
style: { ...Fs, ..._ },
|
|
2666
2673
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
2667
2674
|
}
|
|
2668
2675
|
),
|
|
2669
|
-
p && ce ? /* @__PURE__ */
|
|
2676
|
+
p && ce ? /* @__PURE__ */ It("div", { style: Us, children: ce }) : null
|
|
2670
2677
|
] });
|
|
2671
|
-
}),
|
|
2672
|
-
function
|
|
2678
|
+
}), Ns = "thumbnail.webp";
|
|
2679
|
+
function Ys(e, t = ut) {
|
|
2673
2680
|
const n = e.trim();
|
|
2674
2681
|
if (!n)
|
|
2675
2682
|
throw new Error("faceId is required");
|
|
2676
|
-
return `${t.replace(/\/$/, "")}/${n}/${
|
|
2683
|
+
return `${t.replace(/\/$/, "")}/${n}/${Ns}`;
|
|
2684
|
+
}
|
|
2685
|
+
const Vs = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
2686
|
+
function $s(e = ".png") {
|
|
2687
|
+
const t = e.toLowerCase();
|
|
2688
|
+
return Vs.has(t) ? `source${t}` : "source.png";
|
|
2689
|
+
}
|
|
2690
|
+
function Js(e, t = ut, n = ".png") {
|
|
2691
|
+
const r = e.trim();
|
|
2692
|
+
if (!r)
|
|
2693
|
+
throw new Error("faceId is required");
|
|
2694
|
+
return `${t.replace(/\/$/, "")}/${r}/${$s(n)}`;
|
|
2677
2695
|
}
|
|
2678
2696
|
export {
|
|
2679
|
-
|
|
2680
|
-
|
|
2697
|
+
Ns as AI_TWIN_THUMBNAIL_FILENAME,
|
|
2698
|
+
zs as AiTwin,
|
|
2681
2699
|
nt as AiTwinNotFoundError,
|
|
2682
2700
|
Te as DEFAULT_TTS_ENGINE_ID,
|
|
2683
2701
|
rn as MIC_SAMPLE_RATE,
|
|
2684
|
-
|
|
2702
|
+
sr as OCULUS_VISEME_IDS,
|
|
2685
2703
|
sn as PLAYBACK_SAMPLE_RATE,
|
|
2686
2704
|
tn as SPEAKING_RATE_MAX,
|
|
2687
2705
|
en as SPEAKING_RATE_MIN,
|
|
2688
2706
|
Ae as TTS_ENGINE_CARTESIA,
|
|
2689
2707
|
Qt as TTS_ENGINE_GOOGLE,
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2708
|
+
lt as TTS_ENGINE_INWORLD,
|
|
2709
|
+
Gs as VISEME_IDS,
|
|
2710
|
+
Sr as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
2711
|
+
dt as VISEME_TEST_SPEAKING_RATE,
|
|
2694
2712
|
nn as VISEME_TEST_VOICE_ID,
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2713
|
+
$s as aiTwinSourceFilename,
|
|
2714
|
+
Ar as buildVoiceWebSocketUrl,
|
|
2715
|
+
Bt as createAvatarTtsLipsyncController,
|
|
2716
|
+
Rr as createRealtimeVoiceLipsyncController,
|
|
2717
|
+
Mt as faceAssetUrls,
|
|
2718
|
+
Nn as fetchAiTwin,
|
|
2700
2719
|
et as fetchDevAuthToken,
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2720
|
+
Js as getAiTwinSourceUrl,
|
|
2721
|
+
Ys as getAiTwinThumbnailUrl,
|
|
2722
|
+
or as normalizeOculusViseme,
|
|
2723
|
+
Yn as resolveDirectFaceId,
|
|
2724
|
+
ft as resolveVisemeAtTime,
|
|
2725
|
+
js as resolveWordAtTime,
|
|
2726
|
+
Jn as setActiveTwinAssets
|
|
2707
2727
|
};
|