@streamoji/aitwin 0.4.3 → 0.4.5
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 +5 -5
- package/dist/aitwin.js +1325 -1310
- package/package.json +4 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { PipecatClient as
|
|
4
|
-
import { WebSocketTransport as
|
|
5
|
-
import { Filter as
|
|
6
|
-
const
|
|
7
|
-
publicBase:
|
|
8
|
-
},
|
|
9
|
-
version:
|
|
10
|
-
},
|
|
11
|
-
function
|
|
1
|
+
import { jsxs as Hn, jsx as Ir } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as $n, useRef as $, useState as Ze, useEffect as $e, useCallback as Ae, useMemo as Mr, useImperativeHandle as qn } from "react";
|
|
3
|
+
import { PipecatClient as Kn } from "@pipecat-ai/client-js";
|
|
4
|
+
import { WebSocketTransport as Gn, DailyMediaManager as zn, ProtobufFrameSerializer as jn } from "@pipecat-ai/websocket-transport";
|
|
5
|
+
import { Filter as Yn, GlProgram as Xn, Application as Jn, RendererType as Qn, Sprite as Pt, Texture as we, VideoSource as Zn, Rectangle as es } from "pixi.js";
|
|
6
|
+
const ts = "https://aitwin.bubu.social", sn = {
|
|
7
|
+
publicBase: ts
|
|
8
|
+
}, rs = "0.4.5", ns = {
|
|
9
|
+
version: rs
|
|
10
|
+
}, ss = {}, vt = "https://ai.aitwin.me", ir = `${sn.publicBase}/custom-faces`, is = `${sn.publicBase}/aitwin-workers/v${ns.version}/visemeDiffPreview.worker.js`;
|
|
11
|
+
function as(e) {
|
|
12
12
|
if (e) return e;
|
|
13
|
-
const t = typeof import.meta < "u" ?
|
|
14
|
-
return t?.trim() ? t.trim() :
|
|
15
|
-
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
]),
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
13
|
+
const t = typeof import.meta < "u" ? ss?.VITE_AITWIN_WORKER_URL : void 0;
|
|
14
|
+
return t?.trim() ? t.trim() : is;
|
|
15
|
+
}
|
|
16
|
+
const os = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Gt = 3e3, yt = 16, Rr = 3e3, cs = 4e3, us = 0.85, ls = 8, ar = 400, an = "eng_a7f2b9c1", or = "eng_d4e8f3a2", it = "eng_c9b1e6d4", tt = it, on = /* @__PURE__ */ new Set([
|
|
17
|
+
or,
|
|
18
|
+
it
|
|
19
|
+
]), cn = {
|
|
20
|
+
[an]: "oculus_direct",
|
|
21
|
+
[it]: "oculus_direct",
|
|
22
|
+
[or]: "inworld_word"
|
|
23
23
|
}, Dr = {
|
|
24
|
-
google:
|
|
25
|
-
inworld:
|
|
26
|
-
cartesia:
|
|
24
|
+
google: an,
|
|
25
|
+
inworld: or,
|
|
26
|
+
cartesia: it
|
|
27
27
|
};
|
|
28
|
-
function ls(e) {
|
|
29
|
-
return on[e];
|
|
30
|
-
}
|
|
31
28
|
function fs(e) {
|
|
32
|
-
return e
|
|
29
|
+
return cn[e];
|
|
33
30
|
}
|
|
34
31
|
function ds(e) {
|
|
35
|
-
|
|
32
|
+
return e === it;
|
|
33
|
+
}
|
|
34
|
+
function ms(e) {
|
|
35
|
+
if (e.ttsEngineId && e.ttsEngineId in cn)
|
|
36
36
|
return e.ttsEngineId;
|
|
37
37
|
const t = e.tts?.toLowerCase();
|
|
38
|
-
return t && t in Dr ? Dr[t] :
|
|
38
|
+
return t && t in Dr ? Dr[t] : tt;
|
|
39
39
|
}
|
|
40
|
-
class
|
|
40
|
+
class Jt extends Error {
|
|
41
41
|
constructor(t = "AI twin not found") {
|
|
42
42
|
super(t), this.name = "AiTwinNotFoundError";
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
async function
|
|
45
|
+
async function hs(e, t = os) {
|
|
46
46
|
const r = new URL(t);
|
|
47
47
|
r.searchParams.set("id", e);
|
|
48
48
|
const n = await fetch(r.toString());
|
|
49
49
|
if (n.status === 404)
|
|
50
|
-
throw new
|
|
50
|
+
throw new Jt();
|
|
51
51
|
if (!n.ok)
|
|
52
52
|
throw new Error(`getAiTwin failed (${n.status})`);
|
|
53
53
|
const s = await n.json();
|
|
54
54
|
if (!s.success)
|
|
55
|
-
throw new
|
|
55
|
+
throw new Jt(s.error ?? "AI twin not found");
|
|
56
56
|
const { tts: i, token: o, ...a } = s.data, u = String(a.authToken ?? o ?? "").trim() || void 0;
|
|
57
57
|
return {
|
|
58
58
|
...a,
|
|
59
|
-
ttsEngineId:
|
|
59
|
+
ttsEngineId: ms(s.data),
|
|
60
60
|
authToken: u
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
const
|
|
64
|
-
async function
|
|
65
|
-
const e = await fetch(
|
|
63
|
+
const ps = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", ws = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", gs = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", ys = "6TNvp3SCs4Og0a1ijm9TommXLql1", _s = "Swaraj Mali";
|
|
64
|
+
async function zt() {
|
|
65
|
+
const e = await fetch(ps, {
|
|
66
66
|
method: "POST",
|
|
67
67
|
headers: {
|
|
68
68
|
"Content-Type": "application/json",
|
|
69
|
-
"Client-Id":
|
|
70
|
-
"Client-Secret":
|
|
69
|
+
"Client-Id": ws,
|
|
70
|
+
"Client-Secret": gs
|
|
71
71
|
},
|
|
72
72
|
body: JSON.stringify({
|
|
73
|
-
userId:
|
|
74
|
-
userName:
|
|
73
|
+
userId: ys,
|
|
74
|
+
userName: _s
|
|
75
75
|
})
|
|
76
76
|
});
|
|
77
77
|
if (!e.ok)
|
|
@@ -81,7 +81,7 @@ async function jt() {
|
|
|
81
81
|
throw new Error("getAuthToken returned no token");
|
|
82
82
|
return r;
|
|
83
83
|
}
|
|
84
|
-
async function
|
|
84
|
+
async function vs(e, t = vt) {
|
|
85
85
|
const r = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
86
86
|
headers: { Authorization: `Bearer ${e}` }
|
|
87
87
|
});
|
|
@@ -91,7 +91,7 @@ async function _s(e, t = kt) {
|
|
|
91
91
|
if (!n.value) throw new Error("Session value response missing value");
|
|
92
92
|
return n;
|
|
93
93
|
}
|
|
94
|
-
function
|
|
94
|
+
function Ss(e) {
|
|
95
95
|
const t = e.trim();
|
|
96
96
|
if (t.length % 2 !== 0) throw new Error("Invalid hex key");
|
|
97
97
|
const r = new Uint8Array(t.length / 2);
|
|
@@ -99,20 +99,20 @@ function vs(e) {
|
|
|
99
99
|
r[n / 2] = Number.parseInt(t.slice(n, n + 2), 16);
|
|
100
100
|
return r;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function xt(e) {
|
|
103
103
|
return Uint8Array.from(e);
|
|
104
104
|
}
|
|
105
|
-
function
|
|
105
|
+
function bs(e, t) {
|
|
106
106
|
const r = new Uint8Array(e.length + t.length);
|
|
107
107
|
return r.set(e, 0), r.set(t, e.length), r;
|
|
108
108
|
}
|
|
109
|
-
async function
|
|
109
|
+
async function ks(e, t) {
|
|
110
110
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
111
111
|
if (e.byteLength < 28)
|
|
112
112
|
throw new Error("Encrypted payload too small");
|
|
113
|
-
const r = new Uint8Array(e), n =
|
|
113
|
+
const r = new Uint8Array(e), n = xt(r.subarray(0, 12)), s = xt(r.subarray(12, 28)), i = xt(r.subarray(28)), o = xt(bs(i, s)), a = await crypto.subtle.importKey(
|
|
114
114
|
"raw",
|
|
115
|
-
|
|
115
|
+
Ss(t),
|
|
116
116
|
{ name: "AES-GCM" },
|
|
117
117
|
!1,
|
|
118
118
|
["decrypt"]
|
|
@@ -123,35 +123,35 @@ async function bs(e, t) {
|
|
|
123
123
|
o
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
|
-
let
|
|
127
|
-
const
|
|
128
|
-
function
|
|
126
|
+
let Qt = null;
|
|
127
|
+
const Zt = /* @__PURE__ */ new Set();
|
|
128
|
+
function It(e) {
|
|
129
129
|
return e.includes("/custom-faces/");
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function Bt(e) {
|
|
132
132
|
const t = e.binBase.trim().replace(/\/$/, ""), r = e.twinBase.trim().replace(/\/$/, "");
|
|
133
|
-
if (!(e.encrypted ||
|
|
133
|
+
if (!(e.encrypted || It(t) || It(r)))
|
|
134
134
|
return { twinBase: r, binBase: t, encrypted: !1 };
|
|
135
|
-
const s =
|
|
135
|
+
const s = It(t) ? t : It(r) ? r : t;
|
|
136
136
|
return { twinBase: s, binBase: s, encrypted: !0 };
|
|
137
137
|
}
|
|
138
138
|
function ze(e) {
|
|
139
|
-
return
|
|
139
|
+
return Bt(e).encrypted;
|
|
140
140
|
}
|
|
141
|
-
function Br(e, t =
|
|
141
|
+
function Br(e, t = ir) {
|
|
142
142
|
const r = `${t.replace(/\/$/, "")}/${e}`;
|
|
143
143
|
return { twinBase: r, binBase: r, encrypted: !0 };
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function Ts(e, t) {
|
|
146
146
|
return (e ?? t)?.trim() || void 0;
|
|
147
147
|
}
|
|
148
|
-
function
|
|
149
|
-
|
|
150
|
-
for (const t of
|
|
148
|
+
function Es(e) {
|
|
149
|
+
Qt = Bt(e);
|
|
150
|
+
for (const t of Zt) t();
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function As(e, t) {
|
|
153
153
|
const r = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
154
|
-
if (!r) return
|
|
154
|
+
if (!r) return Bt(e);
|
|
155
155
|
const n = (s) => {
|
|
156
156
|
try {
|
|
157
157
|
return new URL(s, r).href.replace(/\/$/, "");
|
|
@@ -159,44 +159,44 @@ function Es(e, t) {
|
|
|
159
159
|
return s;
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
|
-
return
|
|
162
|
+
return Bt({
|
|
163
163
|
twinBase: n(e.twinBase),
|
|
164
164
|
binBase: n(e.binBase),
|
|
165
165
|
encrypted: e.encrypted
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
168
|
function je() {
|
|
169
|
-
if (!
|
|
169
|
+
if (!Qt)
|
|
170
170
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
171
|
-
return
|
|
171
|
+
return Qt;
|
|
172
172
|
}
|
|
173
|
-
function
|
|
174
|
-
return
|
|
173
|
+
function un(e) {
|
|
174
|
+
return Zt.add(e), () => Zt.delete(e);
|
|
175
175
|
}
|
|
176
|
-
function
|
|
176
|
+
function Ct() {
|
|
177
177
|
const e = je();
|
|
178
178
|
return ze(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function Ps() {
|
|
181
181
|
const e = je();
|
|
182
182
|
return ze(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
183
183
|
}
|
|
184
|
-
function
|
|
184
|
+
function ln() {
|
|
185
185
|
const e = je();
|
|
186
186
|
return ze(e) ? e.binBase : e.twinBase;
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function St() {
|
|
189
189
|
return ze(je());
|
|
190
190
|
}
|
|
191
|
-
function
|
|
191
|
+
function fn() {
|
|
192
192
|
const e = je();
|
|
193
193
|
return ze(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
194
194
|
}
|
|
195
|
-
function
|
|
195
|
+
function dn() {
|
|
196
196
|
const e = je();
|
|
197
197
|
return ze(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
198
198
|
}
|
|
199
|
-
function
|
|
199
|
+
function mn(e) {
|
|
200
200
|
const t = e.split(/\r?\n/);
|
|
201
201
|
let r = "", n = "";
|
|
202
202
|
for (const i of t)
|
|
@@ -211,7 +211,7 @@ function dn(e) {
|
|
|
211
211
|
}
|
|
212
212
|
return { event: r, data: s };
|
|
213
213
|
}
|
|
214
|
-
const
|
|
214
|
+
const xs = [
|
|
215
215
|
"aa",
|
|
216
216
|
"CH",
|
|
217
217
|
"DD",
|
|
@@ -227,14 +227,14 @@ const Ps = [
|
|
|
227
227
|
"kk",
|
|
228
228
|
"nn",
|
|
229
229
|
"sil"
|
|
230
|
-
],
|
|
231
|
-
|
|
230
|
+
], Is = new Map(
|
|
231
|
+
xs.map((e) => [e.toLowerCase(), e])
|
|
232
232
|
);
|
|
233
|
-
function
|
|
233
|
+
function Ms(e) {
|
|
234
234
|
const t = (e ?? "").trim();
|
|
235
|
-
return t ?
|
|
235
|
+
return t ? Is.get(t.toLowerCase()) ?? "sil" : "sil";
|
|
236
236
|
}
|
|
237
|
-
const
|
|
237
|
+
const Rs = {
|
|
238
238
|
aei: ["aa", "E", "I"],
|
|
239
239
|
o: ["O", "U"],
|
|
240
240
|
ee: ["I"],
|
|
@@ -246,12 +246,12 @@ const Ms = {
|
|
|
246
246
|
qw: ["U", "O"],
|
|
247
247
|
cdgknstxyz: ["DD", "SS", "kk", "CH"]
|
|
248
248
|
};
|
|
249
|
-
function
|
|
249
|
+
function Ds(e) {
|
|
250
250
|
if (!e) return ["sil"];
|
|
251
251
|
const t = e.toLowerCase();
|
|
252
|
-
return
|
|
252
|
+
return Rs[t] ?? ["sil"];
|
|
253
253
|
}
|
|
254
|
-
function
|
|
254
|
+
function Bs(e, t) {
|
|
255
255
|
const r = e.word.length;
|
|
256
256
|
if (r <= 0) return 0;
|
|
257
257
|
const n = e.wduration;
|
|
@@ -259,40 +259,40 @@ function Ds(e, t) {
|
|
|
259
259
|
const s = Math.max(0, Math.min(1, (t - e.wtime) / n));
|
|
260
260
|
return Math.min(r - 1, Math.floor(s * r));
|
|
261
261
|
}
|
|
262
|
-
function
|
|
262
|
+
function rt(e, t) {
|
|
263
263
|
const r = Math.max(0, Math.min(e.length - 1, t));
|
|
264
264
|
return e[r] ?? "";
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function cr(e, t) {
|
|
267
267
|
const r = e.toLowerCase().replace(/[^a-z']/g, "");
|
|
268
|
-
return !r ||
|
|
268
|
+
return !r || rt(r, t) !== "w" || t > 0 && rt(r, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(r);
|
|
269
269
|
}
|
|
270
|
-
function
|
|
271
|
-
const r = e.toLowerCase(), n =
|
|
270
|
+
function Cs(e, t) {
|
|
271
|
+
const r = e.toLowerCase(), n = rt(r, t), s = r.slice(Math.max(0, t - 1), t + 2);
|
|
272
272
|
return n === "i" || n === "y" ? "I" : s.includes("ee") || n === "e" || r.includes("ea") ? "E" : "aa";
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function Fs(e, t) {
|
|
275
275
|
const r = e.toLowerCase(), n = r.slice(
|
|
276
276
|
Math.max(0, t - 1),
|
|
277
277
|
Math.min(r.length, t + 3)
|
|
278
278
|
);
|
|
279
279
|
if (/oo|ou|uw/.test(n)) return "U";
|
|
280
|
-
if (
|
|
281
|
-
const s =
|
|
280
|
+
if (cr(r, t)) return "FF";
|
|
281
|
+
const s = rt(r, t);
|
|
282
282
|
return s === "u" || s === "w" ? "U" : "O";
|
|
283
283
|
}
|
|
284
|
-
function
|
|
284
|
+
function Ls(e, t) {
|
|
285
285
|
const r = e.toLowerCase();
|
|
286
|
-
if (
|
|
286
|
+
if (cr(r, t)) return "FF";
|
|
287
287
|
const n = r.slice(Math.max(0, t - 2), t + 1);
|
|
288
288
|
if (/qu/.test(n)) return "U";
|
|
289
289
|
const s = r.slice(
|
|
290
290
|
Math.max(0, t - 1),
|
|
291
291
|
Math.min(r.length, t + 3)
|
|
292
292
|
);
|
|
293
|
-
return /wo|wh/.test(s) ||
|
|
293
|
+
return /wo|wh/.test(s) || rt(r, t) === "o" ? "O" : "U";
|
|
294
294
|
}
|
|
295
|
-
const
|
|
295
|
+
const Mt = {
|
|
296
296
|
d: "DD",
|
|
297
297
|
t: "DD",
|
|
298
298
|
n: "DD",
|
|
@@ -304,42 +304,42 @@ const Dt = {
|
|
|
304
304
|
x: "CH",
|
|
305
305
|
j: "CH"
|
|
306
306
|
};
|
|
307
|
-
function
|
|
308
|
-
const r = e.toLowerCase(), n =
|
|
309
|
-
if (
|
|
307
|
+
function Os(e, t) {
|
|
308
|
+
const r = e.toLowerCase(), n = rt(r, t);
|
|
309
|
+
if (Mt[n]) return Mt[n];
|
|
310
310
|
for (let s = 0; s < r.length; s++) {
|
|
311
311
|
const i = r[s];
|
|
312
|
-
if (
|
|
312
|
+
if (Mt[i]) return Mt[i];
|
|
313
313
|
}
|
|
314
314
|
return "DD";
|
|
315
315
|
}
|
|
316
|
-
function
|
|
317
|
-
const n =
|
|
316
|
+
function Ns(e, t, r) {
|
|
317
|
+
const n = Ds(e);
|
|
318
318
|
if (n.length === 1) return n[0];
|
|
319
319
|
const s = t.trim();
|
|
320
320
|
if (!s) return n[0];
|
|
321
321
|
const i = (e ?? "").toLowerCase(), o = Math.max(0, r);
|
|
322
322
|
switch (i) {
|
|
323
323
|
case "aei":
|
|
324
|
-
return Bs(s, o);
|
|
325
|
-
case "o":
|
|
326
324
|
return Cs(s, o);
|
|
327
|
-
case "
|
|
325
|
+
case "o":
|
|
328
326
|
return Fs(s, o);
|
|
329
|
-
case "
|
|
327
|
+
case "qw":
|
|
330
328
|
return Ls(s, o);
|
|
329
|
+
case "cdgknstxyz":
|
|
330
|
+
return Os(s, o);
|
|
331
331
|
default:
|
|
332
332
|
return n[0];
|
|
333
333
|
}
|
|
334
334
|
}
|
|
335
|
-
const
|
|
336
|
-
function
|
|
335
|
+
const Us = 32, Cr = 48;
|
|
336
|
+
function hn(e) {
|
|
337
337
|
let t = 0;
|
|
338
338
|
for (const r of e)
|
|
339
339
|
t = Math.max(t, r.vtime + r.vduration);
|
|
340
340
|
return t;
|
|
341
341
|
}
|
|
342
|
-
function
|
|
342
|
+
function pn(e) {
|
|
343
343
|
let t = null, r = -1;
|
|
344
344
|
for (const n of e) {
|
|
345
345
|
if (n.viseme === "sil") continue;
|
|
@@ -348,53 +348,53 @@ function hn(e) {
|
|
|
348
348
|
}
|
|
349
349
|
return t;
|
|
350
350
|
}
|
|
351
|
-
function
|
|
352
|
-
return
|
|
351
|
+
function Vs(e) {
|
|
352
|
+
return wn(e).find((r) => r.viseme !== "sil") ?? null;
|
|
353
353
|
}
|
|
354
354
|
function qe(e) {
|
|
355
|
-
const t =
|
|
356
|
-
return
|
|
355
|
+
const t = hn(e);
|
|
356
|
+
return pn(e) ? t + ar : t;
|
|
357
357
|
}
|
|
358
|
-
function
|
|
359
|
-
const t = [], r =
|
|
358
|
+
function Ws(e) {
|
|
359
|
+
const t = [], r = Vs(e);
|
|
360
360
|
r && r.vtime > 0 && t.push({
|
|
361
361
|
from: "sil",
|
|
362
362
|
to: r.viseme,
|
|
363
363
|
fromVtime: 0,
|
|
364
364
|
toVtime: r.vtime
|
|
365
365
|
});
|
|
366
|
-
const n =
|
|
366
|
+
const n = pn(e), s = hn(e);
|
|
367
367
|
return n && t.push({
|
|
368
368
|
from: n.viseme,
|
|
369
369
|
to: "sil",
|
|
370
370
|
fromVtime: s,
|
|
371
|
-
toVtime: s +
|
|
371
|
+
toVtime: s + ar
|
|
372
372
|
}), t;
|
|
373
373
|
}
|
|
374
|
-
function
|
|
374
|
+
function wn(e) {
|
|
375
375
|
const t = /* @__PURE__ */ new Map();
|
|
376
376
|
for (const r of e)
|
|
377
377
|
t.has(r.vtime) || t.set(r.vtime, r);
|
|
378
378
|
return [...t.values()].sort((r, n) => r.vtime - n.vtime);
|
|
379
379
|
}
|
|
380
|
-
function
|
|
381
|
-
const t =
|
|
380
|
+
function Hs(e) {
|
|
381
|
+
const t = wn(e), r = [];
|
|
382
382
|
for (let n = 0; n < t.length - 1; n++) {
|
|
383
383
|
const s = t[n].viseme, i = t[n + 1].viseme, o = t[n].vtime, a = t[n + 1].vtime;
|
|
384
384
|
s === i || a <= o || r.push({ from: s, to: i, fromVtime: o, toVtime: a });
|
|
385
385
|
}
|
|
386
386
|
return r;
|
|
387
387
|
}
|
|
388
|
-
function
|
|
388
|
+
function $s(e) {
|
|
389
389
|
return e.length === 0 ? [] : [
|
|
390
|
-
...
|
|
391
|
-
...
|
|
390
|
+
...Ws(e),
|
|
391
|
+
...Hs(e)
|
|
392
392
|
];
|
|
393
393
|
}
|
|
394
|
-
function
|
|
394
|
+
function qs(e, t) {
|
|
395
395
|
let r = null;
|
|
396
396
|
for (const n of e) {
|
|
397
|
-
const { transStart: s, transEnd: i } =
|
|
397
|
+
const { transStart: s, transEnd: i } = gn(
|
|
398
398
|
n.fromVtime,
|
|
399
399
|
n.toVtime,
|
|
400
400
|
n.from,
|
|
@@ -404,7 +404,7 @@ function $s(e, t) {
|
|
|
404
404
|
}
|
|
405
405
|
return r;
|
|
406
406
|
}
|
|
407
|
-
function
|
|
407
|
+
function gn(e, t, r, n) {
|
|
408
408
|
const s = Math.max(0, t - e);
|
|
409
409
|
if ((r === "PP" || n === "PP") && s > Cr) {
|
|
410
410
|
const l = Cr, f = t, c = f - l;
|
|
@@ -416,25 +416,25 @@ function wn(e, t, r, n) {
|
|
|
416
416
|
transEnd: f
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
|
-
const o = s > 0 ? Math.max(s,
|
|
419
|
+
const o = s > 0 ? Math.max(s, Us) : 0, a = e, u = e + o;
|
|
420
420
|
return { gapMs: s, effectiveGapMs: o, holdEnd: e, transStart: a, transEnd: u };
|
|
421
421
|
}
|
|
422
|
-
const
|
|
423
|
-
function
|
|
422
|
+
const ur = 16e3;
|
|
423
|
+
function yn(e) {
|
|
424
424
|
const t = Number(e);
|
|
425
|
-
return Number.isFinite(t) && t > 0 ? t :
|
|
425
|
+
return Number.isFinite(t) && t > 0 ? t : ur;
|
|
426
426
|
}
|
|
427
|
-
function
|
|
427
|
+
function Ks(e) {
|
|
428
428
|
let t = e.trim();
|
|
429
429
|
const r = t.indexOf(",");
|
|
430
430
|
t.startsWith("data:") && r >= 0 && (t = t.slice(r + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
|
|
431
431
|
const n = t.length % 4;
|
|
432
432
|
return n !== 0 && (t += "=".repeat(4 - n)), t;
|
|
433
433
|
}
|
|
434
|
-
function
|
|
434
|
+
function Gs(e) {
|
|
435
435
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
436
436
|
}
|
|
437
|
-
function Fr(e, t, r =
|
|
437
|
+
function Fr(e, t, r = ur) {
|
|
438
438
|
const n = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
|
|
439
439
|
n.buffer,
|
|
440
440
|
n.byteOffset,
|
|
@@ -445,15 +445,15 @@ function Fr(e, t, r = lr) {
|
|
|
445
445
|
const o = e.createBuffer(1, i.length, r);
|
|
446
446
|
return o.copyToChannel(i, 0), o;
|
|
447
447
|
}
|
|
448
|
-
function
|
|
449
|
-
const t =
|
|
448
|
+
function zs(e) {
|
|
449
|
+
const t = Ks(e), r = window.atob(t), n = new Uint8Array(r.length);
|
|
450
450
|
for (let s = 0; s < r.length; s++)
|
|
451
451
|
n[s] = r.charCodeAt(s);
|
|
452
452
|
return n;
|
|
453
453
|
}
|
|
454
|
-
async function Lr(e, t, r =
|
|
455
|
-
const n =
|
|
456
|
-
if (
|
|
454
|
+
async function Lr(e, t, r = ur) {
|
|
455
|
+
const n = zs(t), s = yn(r);
|
|
456
|
+
if (Gs(n)) {
|
|
457
457
|
const i = n.buffer.slice(
|
|
458
458
|
n.byteOffset,
|
|
459
459
|
n.byteOffset + n.byteLength
|
|
@@ -472,15 +472,15 @@ async function Lr(e, t, r = lr) {
|
|
|
472
472
|
return Fr(e, n, s);
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
|
-
function
|
|
475
|
+
function js(e, t) {
|
|
476
476
|
for (const r of e)
|
|
477
477
|
if (t >= r.wtime && t < r.wtime + r.wduration)
|
|
478
478
|
return r;
|
|
479
479
|
return null;
|
|
480
480
|
}
|
|
481
|
-
function
|
|
481
|
+
function _n(e, t) {
|
|
482
482
|
const r = [], n = [];
|
|
483
|
-
let s = null, i = !1, o = !1, a = !1, u = !1, l = 0, f = 0, c = 0, d = null, g = 1, S = t, m = !1, I = null, _ = 0, R = !1, w = !1, b = 0, L = null, B = null,
|
|
483
|
+
let s = null, i = !1, o = !1, a = !1, u = !1, l = 0, f = 0, c = 0, d = null, g = 1, S = t, m = !1, I = null, _ = 0, R = !1, w = !1, b = 0, L = null, B = null, j = null;
|
|
484
484
|
const C = () => ({
|
|
485
485
|
visemes: [],
|
|
486
486
|
words: [],
|
|
@@ -489,7 +489,7 @@ function yn(e, t) {
|
|
|
489
489
|
w = !1, b = 0;
|
|
490
490
|
}, P = () => {
|
|
491
491
|
d != null && (clearTimeout(d), d = null);
|
|
492
|
-
},
|
|
492
|
+
}, U = () => {
|
|
493
493
|
for (const h of n) {
|
|
494
494
|
try {
|
|
495
495
|
h.onended = null, h.stop(0);
|
|
@@ -501,125 +501,125 @@ function yn(e, t) {
|
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
n.length = 0;
|
|
504
|
-
},
|
|
504
|
+
}, O = () => {
|
|
505
505
|
for (const h of n)
|
|
506
506
|
h.playbackRate.value = g;
|
|
507
|
-
},
|
|
507
|
+
}, q = () => {
|
|
508
508
|
if (!(m || !u || i || w || n.length > 0 || r.length > 0)) {
|
|
509
509
|
if (a && s && f > 0) {
|
|
510
510
|
const h = (s.currentTime - f) * 1e3;
|
|
511
511
|
if (h < _) {
|
|
512
512
|
P();
|
|
513
|
-
const
|
|
513
|
+
const T = g > 0 ? (_ - h) / g : _ - h;
|
|
514
514
|
d = setTimeout(() => {
|
|
515
515
|
m || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
|
|
516
|
-
}, Math.max(0,
|
|
516
|
+
}, Math.max(0, T));
|
|
517
517
|
return;
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
o = !1, P(), e.onSpeakingDone(), e.onNotify();
|
|
521
521
|
}
|
|
522
|
-
},
|
|
523
|
-
const
|
|
524
|
-
if (
|
|
522
|
+
}, fe = (h) => {
|
|
523
|
+
const T = qe(h);
|
|
524
|
+
if (T <= 0) {
|
|
525
525
|
e.onSpeakingDone(), e.onNotify();
|
|
526
526
|
return;
|
|
527
527
|
}
|
|
528
528
|
o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), P();
|
|
529
|
-
const M = g > 0 ?
|
|
529
|
+
const M = g > 0 ? T / g : T;
|
|
530
530
|
d = setTimeout(() => {
|
|
531
531
|
m || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
|
|
532
532
|
}, M);
|
|
533
|
-
},
|
|
534
|
-
|
|
535
|
-
const
|
|
536
|
-
if (!
|
|
537
|
-
const
|
|
533
|
+
}, D = (h, T, M, F) => {
|
|
534
|
+
T.length !== 0 && (c = M, T.forEach((A) => {
|
|
535
|
+
const J = String(A.word ?? "").trim();
|
|
536
|
+
if (!J) return;
|
|
537
|
+
const Z = Math.round((A.start ?? 0) * 1e3), ee = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
|
|
538
538
|
h.push({
|
|
539
|
-
word:
|
|
540
|
-
wtime: c +
|
|
541
|
-
wduration:
|
|
539
|
+
word: J,
|
|
540
|
+
wtime: c + Z,
|
|
541
|
+
wduration: ee,
|
|
542
542
|
queueIndex: h.length,
|
|
543
543
|
gesture: A.gesture ?? null,
|
|
544
544
|
emphasis: A.emphasis === !0
|
|
545
545
|
});
|
|
546
546
|
}));
|
|
547
|
-
},
|
|
548
|
-
M.length !== 0 && (c = F, M.forEach((
|
|
549
|
-
const
|
|
550
|
-
if (!
|
|
551
|
-
const
|
|
552
|
-
let
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
547
|
+
}, Y = (h, T, M, F, A, W) => {
|
|
548
|
+
M.length !== 0 && (c = F, M.forEach((J) => {
|
|
549
|
+
const Z = String(J.symbol ?? J.viseme ?? "").trim();
|
|
550
|
+
if (!Z) return;
|
|
551
|
+
const ee = Math.round((J.start ?? 0) * 1e3), Se = Math.max(1, Math.round((J.duration ?? 0) * 1e3)), ye = c + ee, Be = js(T, ye), ot = Be ? Bs(Be, ye) : 0;
|
|
552
|
+
let xe;
|
|
553
|
+
fs(W) === "oculus_direct" ? (xe = Ms(Z), xe === "U" && Be && cr(Be.word, ot) && (xe = "FF")) : xe = Ns(
|
|
554
|
+
Z,
|
|
555
|
+
Be?.word ?? "",
|
|
556
|
+
ot
|
|
557
557
|
), h.push({
|
|
558
|
-
viseme:
|
|
558
|
+
viseme: xe,
|
|
559
559
|
weight: 1,
|
|
560
|
-
vtime:
|
|
561
|
-
vduration:
|
|
560
|
+
vtime: ye,
|
|
561
|
+
vduration: Se
|
|
562
562
|
});
|
|
563
563
|
}), e.onNotify());
|
|
564
|
-
},
|
|
565
|
-
|
|
564
|
+
}, Q = (h, T, M, F, A, W, J) => {
|
|
565
|
+
D(T, F, A), Y(
|
|
566
566
|
h,
|
|
567
|
-
|
|
567
|
+
T,
|
|
568
568
|
M,
|
|
569
569
|
A,
|
|
570
|
-
|
|
571
|
-
|
|
570
|
+
W,
|
|
571
|
+
J
|
|
572
572
|
);
|
|
573
|
-
},
|
|
574
|
-
|
|
575
|
-
},
|
|
573
|
+
}, de = (h, T, M) => {
|
|
574
|
+
j === h && h.visemes === T || (T.length = 0, M.length = 0, h.visemes = T, h.words = M, h.segmentOffsetMs = 0, j = h, c = 0, _ = 0);
|
|
575
|
+
}, ce = async () => {
|
|
576
576
|
const h = window.AudioContext || window.webkitAudioContext;
|
|
577
577
|
return s || (s = new h()), s.state === "suspended" && await s.resume(), I || (I = s.createMediaStreamDestination()), s;
|
|
578
|
-
},
|
|
578
|
+
}, ue = (h, T) => {
|
|
579
579
|
if (!s) return 0;
|
|
580
580
|
const M = s, F = M.currentTime, A = F + 0.02;
|
|
581
|
-
if (
|
|
581
|
+
if (T.isFirstAudio) {
|
|
582
582
|
f <= 0 && (f = A);
|
|
583
|
-
const
|
|
584
|
-
l = performance.now() +
|
|
583
|
+
const J = (A - F) * 1e3;
|
|
584
|
+
l = performance.now() + J;
|
|
585
585
|
}
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
return
|
|
589
|
-
const
|
|
590
|
-
|
|
591
|
-
},
|
|
592
|
-
},
|
|
586
|
+
T.onBeforeStart?.(A);
|
|
587
|
+
const W = M.createBufferSource();
|
|
588
|
+
return W.buffer = h, W.playbackRate.value = g, W.connect(M.destination), I && W.connect(I), n.push(W), m ? (n.pop(), A) : (T.isFirstAudio && (o = !0, e.onSpeakingStart()), W.onended = () => {
|
|
589
|
+
const J = n.indexOf(W);
|
|
590
|
+
J >= 0 && n.splice(J, 1), e.onNotify(), !m && (L && B ? se(L, B) : q());
|
|
591
|
+
}, W.start(A), A);
|
|
592
|
+
}, se = async (h, T) => {
|
|
593
593
|
if (m || i || n.length > 0) return;
|
|
594
594
|
if (r.length === 0) {
|
|
595
|
-
|
|
595
|
+
q();
|
|
596
596
|
return;
|
|
597
597
|
}
|
|
598
598
|
i = !0;
|
|
599
599
|
let M = !1;
|
|
600
600
|
try {
|
|
601
|
-
const F = await
|
|
601
|
+
const F = await ce();
|
|
602
602
|
if (m) return;
|
|
603
603
|
const A = r[0];
|
|
604
604
|
if (!A) return;
|
|
605
|
-
const
|
|
606
|
-
if (R && (e.shouldHoldForWarmup?.() ?? !1) && (w ||
|
|
607
|
-
|
|
608
|
-
for (const
|
|
605
|
+
const W = !o;
|
|
606
|
+
if (R && (e.shouldHoldForWarmup?.() ?? !1) && (w || W && A.newStream) || w) {
|
|
607
|
+
de(A.utterance, h, T);
|
|
608
|
+
for (const ee of r) {
|
|
609
609
|
if (m) return;
|
|
610
|
-
|
|
610
|
+
ee.audioBuffer || (ee.audioBuffer = await Lr(
|
|
611
611
|
F,
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
)), a = !0, w || (w = !0, b = 0,
|
|
612
|
+
ee.audio,
|
|
613
|
+
ee.sampleRate
|
|
614
|
+
)), a = !0, w || (w = !0, b = 0, ee.newStream && ee.onNewStream?.()), ee.visemesQueued || (Q(
|
|
615
615
|
h,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
616
|
+
T,
|
|
617
|
+
ee.visemes,
|
|
618
|
+
ee.words,
|
|
619
619
|
b,
|
|
620
620
|
!0,
|
|
621
621
|
S
|
|
622
|
-
),
|
|
622
|
+
), ee.visemesQueued = !0, b += Math.round(ee.audioBuffer.duration * 1e3), _ = Math.max(
|
|
623
623
|
_,
|
|
624
624
|
qe(h)
|
|
625
625
|
));
|
|
@@ -627,25 +627,25 @@ function yn(e, t) {
|
|
|
627
627
|
e.onNotify();
|
|
628
628
|
return;
|
|
629
629
|
}
|
|
630
|
-
const
|
|
631
|
-
if (!
|
|
630
|
+
const Z = r.shift();
|
|
631
|
+
if (!Z || (Z.audioBuffer || (Z.audioBuffer = await Lr(
|
|
632
632
|
F,
|
|
633
|
-
|
|
634
|
-
|
|
633
|
+
Z.audio,
|
|
634
|
+
Z.sampleRate
|
|
635
635
|
)), m)) return;
|
|
636
|
-
a = !0, P(),
|
|
636
|
+
a = !0, P(), de(Z.utterance, h, T), Z.visemesQueued = !1, Z.newStream && Z.onNewStream?.(), ue(Z.audioBuffer, {
|
|
637
637
|
isFirstAudio: !o,
|
|
638
638
|
isFirstOfStream: !1,
|
|
639
|
-
onBeforeStart: (
|
|
640
|
-
f =
|
|
639
|
+
onBeforeStart: (ee) => {
|
|
640
|
+
f = ee, c = 0, l = performance.now() + (ee - F.currentTime) * 1e3, Q(
|
|
641
641
|
h,
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
642
|
+
T,
|
|
643
|
+
Z.visemes,
|
|
644
|
+
Z.words,
|
|
645
645
|
0,
|
|
646
646
|
!0,
|
|
647
647
|
S
|
|
648
|
-
),
|
|
648
|
+
), Z.visemesQueued = !0, Z.utterance.segmentOffsetMs = 0;
|
|
649
649
|
}
|
|
650
650
|
}), M = n.length > 0, _ = qe(h), e.onNotify();
|
|
651
651
|
} catch (F) {
|
|
@@ -655,10 +655,10 @@ function yn(e, t) {
|
|
|
655
655
|
if (w) {
|
|
656
656
|
r.some(
|
|
657
657
|
(A) => !A.audioBuffer || !A.visemesQueued
|
|
658
|
-
) &&
|
|
658
|
+
) && se(h, T);
|
|
659
659
|
return;
|
|
660
660
|
}
|
|
661
|
-
!M && n.length === 0 && r.length > 0 ?
|
|
661
|
+
!M && n.length === 0 && r.length > 0 ? se(h, T) : n.length === 0 && r.length === 0 && q();
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
664
|
return {
|
|
@@ -666,7 +666,7 @@ function yn(e, t) {
|
|
|
666
666
|
S = h;
|
|
667
667
|
},
|
|
668
668
|
setPlaybackSpeed: (h) => {
|
|
669
|
-
g = Math.max(0.1, Math.min(1, h)),
|
|
669
|
+
g = Math.max(0.1, Math.min(1, h)), O();
|
|
670
670
|
},
|
|
671
671
|
getPlaybackSpeed: () => g,
|
|
672
672
|
setLipsyncWarmupHoldEnabled: (h) => {
|
|
@@ -678,7 +678,7 @@ function yn(e, t) {
|
|
|
678
678
|
w = !1, b = 0;
|
|
679
679
|
for (const h of r)
|
|
680
680
|
h.newStream = !1;
|
|
681
|
-
L && B &&
|
|
681
|
+
L && B && se(L, B), e.onNotify();
|
|
682
682
|
}
|
|
683
683
|
},
|
|
684
684
|
resetForNewStream: (h) => {
|
|
@@ -698,57 +698,57 @@ function yn(e, t) {
|
|
|
698
698
|
s || (s = new h()), s.state === "suspended" && await s.resume(), s && !I && (I = s.createMediaStreamDestination());
|
|
699
699
|
},
|
|
700
700
|
stop: () => {
|
|
701
|
-
m = !0, P(),
|
|
701
|
+
m = !0, P(), U(), r.length = 0, i = !1, o = !1, a = !1, u = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, j = null, k();
|
|
702
702
|
},
|
|
703
703
|
markStreamComplete: (h) => {
|
|
704
704
|
if (_ = Math.max(_, qe(h)), u = !0, !a && h.length > 0) {
|
|
705
|
-
|
|
705
|
+
fe(h);
|
|
706
706
|
return;
|
|
707
707
|
}
|
|
708
|
-
|
|
708
|
+
q();
|
|
709
709
|
},
|
|
710
|
-
playAudioChunk: async (h,
|
|
710
|
+
playAudioChunk: async (h, T, M, F, A, W, J) => {
|
|
711
711
|
if (m) return;
|
|
712
|
-
L = h, B =
|
|
713
|
-
const
|
|
712
|
+
L = h, B = T;
|
|
713
|
+
const Z = yn(J?.sampleRate), ee = J?.newStream === !0, Se = C();
|
|
714
714
|
if (!M?.trim()) {
|
|
715
715
|
if (F.length === 0 && A.length === 0) return;
|
|
716
|
-
|
|
716
|
+
de(Se, h, T), ee && J?.onNewStream?.(), Q(
|
|
717
717
|
h,
|
|
718
|
-
|
|
718
|
+
T,
|
|
719
719
|
F,
|
|
720
720
|
A,
|
|
721
721
|
0,
|
|
722
722
|
!0,
|
|
723
723
|
S
|
|
724
|
-
), _ = qe(h), !o && _ > 0 &&
|
|
724
|
+
), _ = qe(h), !o && _ > 0 && fe(h), e.onNotify();
|
|
725
725
|
return;
|
|
726
726
|
}
|
|
727
727
|
r.push({
|
|
728
728
|
audio: M,
|
|
729
729
|
audioBuffer: null,
|
|
730
|
-
utterance:
|
|
730
|
+
utterance: Se,
|
|
731
731
|
visemes: F,
|
|
732
732
|
words: A,
|
|
733
|
-
isNewSegment:
|
|
734
|
-
sampleRate:
|
|
735
|
-
newStream:
|
|
736
|
-
onNewStream:
|
|
733
|
+
isNewSegment: W,
|
|
734
|
+
sampleRate: Z,
|
|
735
|
+
newStream: ee,
|
|
736
|
+
onNewStream: J?.onNewStream,
|
|
737
737
|
visemesQueued: !1
|
|
738
|
-
}), await
|
|
738
|
+
}), await se(h, T);
|
|
739
739
|
},
|
|
740
|
-
queueTimingsOnly: (h,
|
|
740
|
+
queueTimingsOnly: (h, T, M, F, A) => {
|
|
741
741
|
if (m) return;
|
|
742
|
-
const
|
|
743
|
-
|
|
742
|
+
const W = C();
|
|
743
|
+
de(W, h, T), Q(
|
|
744
744
|
h,
|
|
745
|
-
|
|
745
|
+
T,
|
|
746
746
|
M,
|
|
747
747
|
F,
|
|
748
748
|
0,
|
|
749
749
|
!0,
|
|
750
750
|
S
|
|
751
|
-
),
|
|
751
|
+
), W.segmentOffsetMs = 0, _ = qe(h);
|
|
752
752
|
},
|
|
753
753
|
getPlaybackElapsedMs: () => a && s && f > 0 ? Math.max(
|
|
754
754
|
0,
|
|
@@ -759,21 +759,21 @@ function yn(e, t) {
|
|
|
759
759
|
getPlaybackStartPerf: () => l,
|
|
760
760
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
761
761
|
bargeIn: () => {
|
|
762
|
-
m = !0, u = !1, P(),
|
|
762
|
+
m = !0, u = !1, P(), U(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, j = null, k();
|
|
763
763
|
},
|
|
764
764
|
interrupt: () => {
|
|
765
|
-
m = !0, u = !1, P(),
|
|
765
|
+
m = !0, u = !1, P(), U(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, j = null, k();
|
|
766
766
|
}
|
|
767
767
|
};
|
|
768
768
|
}
|
|
769
|
-
function
|
|
769
|
+
function Nt(e, t) {
|
|
770
770
|
let r = null;
|
|
771
771
|
for (const n of e)
|
|
772
772
|
t < n.vtime || t >= n.vtime + n.vduration || (!r || n.vtime >= r.vtime) && (r = n);
|
|
773
773
|
return r ? r.viseme : "sil";
|
|
774
774
|
}
|
|
775
|
-
function
|
|
776
|
-
const n =
|
|
775
|
+
function vn(e, t, r = 120) {
|
|
776
|
+
const n = Nt(e, t);
|
|
777
777
|
if (n !== "sil") return n;
|
|
778
778
|
let s = null;
|
|
779
779
|
for (const i of e) {
|
|
@@ -783,7 +783,7 @@ function _n(e, t, r = 120) {
|
|
|
783
783
|
}
|
|
784
784
|
return s?.viseme ?? "sil";
|
|
785
785
|
}
|
|
786
|
-
function
|
|
786
|
+
function Ys(e, t, r = 400) {
|
|
787
787
|
const n = t - r;
|
|
788
788
|
let s = 0;
|
|
789
789
|
for (const i of e)
|
|
@@ -791,13 +791,13 @@ function js(e, t, r = 400) {
|
|
|
791
791
|
else break;
|
|
792
792
|
s > 0 && e.splice(0, s);
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function Ma(e, t) {
|
|
795
795
|
for (const r of e)
|
|
796
796
|
if (t >= r.wtime && t < r.wtime + r.wduration)
|
|
797
797
|
return r;
|
|
798
798
|
return null;
|
|
799
799
|
}
|
|
800
|
-
function
|
|
800
|
+
function Xs(e, t) {
|
|
801
801
|
const r = e.trim();
|
|
802
802
|
if (!r) return null;
|
|
803
803
|
try {
|
|
@@ -807,36 +807,36 @@ function Ys(e, t) {
|
|
|
807
807
|
return null;
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
|
-
const
|
|
811
|
-
function Or(e, t =
|
|
810
|
+
const lr = 0.5, fr = 1.5, Sn = "Olivia", bn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Ut = 0.85;
|
|
811
|
+
function Or(e, t = vt, r = {}) {
|
|
812
812
|
const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], o = [], a = [];
|
|
813
|
-
let u = "", l = "neutral", f = "", c =
|
|
813
|
+
let u = "", l = "neutral", f = "", c = tt;
|
|
814
814
|
const d = /* @__PURE__ */ new Set();
|
|
815
815
|
let g = 0, S = null;
|
|
816
816
|
const m = () => d.forEach((C) => C());
|
|
817
817
|
let I = () => !1;
|
|
818
|
-
const _ =
|
|
818
|
+
const _ = _n(
|
|
819
819
|
{
|
|
820
820
|
onSpeakingStart: () => e("speaking"),
|
|
821
821
|
onSpeakingDone: () => e("done"),
|
|
822
822
|
onNotify: m,
|
|
823
823
|
shouldHoldForWarmup: () => I()
|
|
824
824
|
},
|
|
825
|
-
|
|
825
|
+
tt
|
|
826
826
|
), R = () => _.getPlaybackElapsedMs(), w = (C, k = u) => {
|
|
827
827
|
if (!r.onLipsyncDebug) return;
|
|
828
|
-
const P = R(),
|
|
828
|
+
const P = R(), U = s;
|
|
829
829
|
r.onLipsyncDebug({
|
|
830
830
|
event: C,
|
|
831
831
|
spokenText: k,
|
|
832
832
|
mood: l,
|
|
833
833
|
playbackAnchorPerf: _.getPlaybackStartPerf(),
|
|
834
834
|
playbackElapsedMs: P,
|
|
835
|
-
queueLength:
|
|
836
|
-
activeViseme:
|
|
837
|
-
segments: a.map((
|
|
838
|
-
...
|
|
839
|
-
visemes: [...
|
|
835
|
+
queueLength: U.length,
|
|
836
|
+
activeViseme: Nt(U, P),
|
|
837
|
+
segments: a.map((O) => ({
|
|
838
|
+
...O,
|
|
839
|
+
visemes: [...O.visemes]
|
|
840
840
|
}))
|
|
841
841
|
});
|
|
842
842
|
}, b = (C, k) => {
|
|
@@ -845,26 +845,26 @@ function Or(e, t = kt, r = {}) {
|
|
|
845
845
|
const P = S;
|
|
846
846
|
S = null, P && w(P.event, P.spokenText);
|
|
847
847
|
})));
|
|
848
|
-
}, L = (C, k, P,
|
|
848
|
+
}, L = (C, k, P, U, O) => {
|
|
849
849
|
if (!r.onLipsyncDebug) return;
|
|
850
|
-
const
|
|
851
|
-
(
|
|
850
|
+
const q = s.slice(k), fe = P.filter(
|
|
851
|
+
(D) => String(D.symbol ?? D.viseme ?? "").trim()
|
|
852
852
|
);
|
|
853
853
|
a.push({
|
|
854
854
|
spokenText: C,
|
|
855
|
-
audioOffsetMs:
|
|
856
|
-
isNewSegment:
|
|
857
|
-
chunkDurationMs:
|
|
855
|
+
audioOffsetMs: q[0]?.vtime ?? 0,
|
|
856
|
+
isNewSegment: U,
|
|
857
|
+
chunkDurationMs: O,
|
|
858
858
|
receivedAtMs: performance.now(),
|
|
859
|
-
visemes:
|
|
860
|
-
const
|
|
859
|
+
visemes: q.map((D, Y) => {
|
|
860
|
+
const Q = fe[Y];
|
|
861
861
|
return {
|
|
862
|
-
rawSymbol: String(
|
|
863
|
-
viseme:
|
|
864
|
-
startSec: Number(
|
|
865
|
-
durationSec: Number(
|
|
866
|
-
vtimeMs:
|
|
867
|
-
vdurationMs:
|
|
862
|
+
rawSymbol: String(Q?.symbol ?? Q?.viseme ?? D.viseme).trim(),
|
|
863
|
+
viseme: D.viseme,
|
|
864
|
+
startSec: Number(Q?.start ?? 0),
|
|
865
|
+
durationSec: Number(Q?.duration ?? 0),
|
|
866
|
+
vtimeMs: D.vtime,
|
|
867
|
+
vdurationMs: D.vduration
|
|
868
868
|
};
|
|
869
869
|
})
|
|
870
870
|
});
|
|
@@ -884,75 +884,75 @@ function Or(e, t = kt, r = {}) {
|
|
|
884
884
|
const P = f.trim();
|
|
885
885
|
if (!P)
|
|
886
886
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
887
|
-
const
|
|
888
|
-
_.resetForNewStream(
|
|
889
|
-
const
|
|
890
|
-
|
|
891
|
-
Math.min(
|
|
892
|
-
),
|
|
887
|
+
const U = k?.ttsEngineId ?? c ?? tt;
|
|
888
|
+
_.resetForNewStream(U), _.setStreamTtsEngineId(U);
|
|
889
|
+
const O = k?.voiceId ?? Sn, q = k?.speakingRate ?? Ut, fe = Math.max(
|
|
890
|
+
lr,
|
|
891
|
+
Math.min(fr, q)
|
|
892
|
+
), D = {
|
|
893
893
|
user_query: C,
|
|
894
|
-
ttsEngineId:
|
|
895
|
-
speakingRate:
|
|
894
|
+
ttsEngineId: U,
|
|
895
|
+
speakingRate: fe,
|
|
896
896
|
tenant: "aiTwin"
|
|
897
897
|
};
|
|
898
|
-
|
|
898
|
+
on.has(U) && (D.voice_id = O);
|
|
899
899
|
try {
|
|
900
|
-
const
|
|
900
|
+
const Y = await fetch(n, {
|
|
901
901
|
method: "POST",
|
|
902
902
|
headers: {
|
|
903
903
|
"Content-Type": "application/json",
|
|
904
904
|
Authorization: `Bearer ${P}`
|
|
905
905
|
},
|
|
906
|
-
body: JSON.stringify(
|
|
906
|
+
body: JSON.stringify(D)
|
|
907
907
|
});
|
|
908
|
-
if (!
|
|
909
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
910
|
-
const
|
|
911
|
-
if (!
|
|
912
|
-
const
|
|
913
|
-
let
|
|
914
|
-
const
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
-
if (
|
|
918
|
-
const h =
|
|
908
|
+
if (!Y.ok)
|
|
909
|
+
throw new Error(`avatar_ttsWithPoses failed (${Y.status})`);
|
|
910
|
+
const Q = Y.body;
|
|
911
|
+
if (!Q) throw new Error("No response body");
|
|
912
|
+
const de = Q.getReader(), ce = new TextDecoder();
|
|
913
|
+
let ue = "", se = !0;
|
|
914
|
+
const me = async (v) => {
|
|
915
|
+
const E = mn(v);
|
|
916
|
+
if (E) {
|
|
917
|
+
if (E.event === "audio") {
|
|
918
|
+
const h = E.data.chunk, T = E.data.visemes ?? [], M = E.data.words ?? [], F = E.data.is_new_segment ?? !1, A = E.data.sample_rate, W = s.length;
|
|
919
919
|
if (h) {
|
|
920
|
-
const
|
|
921
|
-
|
|
920
|
+
const J = se;
|
|
921
|
+
se = !1, await _.playAudioChunk(
|
|
922
922
|
s,
|
|
923
923
|
i,
|
|
924
924
|
h,
|
|
925
|
-
|
|
925
|
+
T,
|
|
926
926
|
M,
|
|
927
927
|
F,
|
|
928
|
-
{ sampleRate: A, newStream:
|
|
928
|
+
{ sampleRate: A, newStream: J }
|
|
929
929
|
), L(
|
|
930
930
|
C,
|
|
931
|
-
|
|
932
|
-
|
|
931
|
+
W,
|
|
932
|
+
T,
|
|
933
933
|
F,
|
|
934
|
-
|
|
934
|
+
Xs(h, A)
|
|
935
935
|
), b("audio_chunk", C);
|
|
936
|
-
} else (
|
|
936
|
+
} else (T.length > 0 || M.length > 0) && (_.queueTimingsOnly(
|
|
937
937
|
s,
|
|
938
938
|
i,
|
|
939
|
-
|
|
939
|
+
T,
|
|
940
940
|
M,
|
|
941
941
|
F
|
|
942
942
|
), L(
|
|
943
943
|
C,
|
|
944
|
-
|
|
945
|
-
|
|
944
|
+
W,
|
|
945
|
+
T,
|
|
946
946
|
F,
|
|
947
947
|
null
|
|
948
948
|
), b("audio_chunk", C));
|
|
949
|
-
} else if (
|
|
950
|
-
const h =
|
|
949
|
+
} else if (E.event === "metadata") {
|
|
950
|
+
const h = E.data.mood;
|
|
951
951
|
typeof h == "string" && h.trim() && (l = h.trim());
|
|
952
|
-
const
|
|
953
|
-
if (Array.isArray(
|
|
952
|
+
const T = E.data.sentence_emotions;
|
|
953
|
+
if (Array.isArray(T)) {
|
|
954
954
|
o.length = 0;
|
|
955
|
-
for (const M of
|
|
955
|
+
for (const M of T) {
|
|
956
956
|
if (!M || typeof M != "object") continue;
|
|
957
957
|
const F = M;
|
|
958
958
|
o.push({
|
|
@@ -966,27 +966,27 @@ function Or(e, t = kt, r = {}) {
|
|
|
966
966
|
}
|
|
967
967
|
}
|
|
968
968
|
m(), b("metadata", C);
|
|
969
|
-
} else if (
|
|
969
|
+
} else if (E.event === "error")
|
|
970
970
|
throw new Error(
|
|
971
|
-
String(
|
|
971
|
+
String(E.data.message ?? "avatar_ttsWithPoses stream error")
|
|
972
972
|
);
|
|
973
973
|
}
|
|
974
974
|
};
|
|
975
975
|
for (; ; ) {
|
|
976
|
-
const { done: v, value:
|
|
977
|
-
|
|
978
|
-
const h =
|
|
976
|
+
const { done: v, value: E } = await de.read();
|
|
977
|
+
E && (ue += ce.decode(E, { stream: !0 }));
|
|
978
|
+
const h = ue.split(`
|
|
979
979
|
|
|
980
980
|
`);
|
|
981
|
-
|
|
982
|
-
for (const
|
|
981
|
+
ue = h.pop() ?? "";
|
|
982
|
+
for (const T of h) await me(T);
|
|
983
983
|
if (v) {
|
|
984
|
-
|
|
984
|
+
ue.trim() && await me(ue.trim()), _.markStreamComplete(s), b("bot_stopped", C);
|
|
985
985
|
break;
|
|
986
986
|
}
|
|
987
987
|
}
|
|
988
|
-
} catch (
|
|
989
|
-
throw console.error("[avatarTtsLipsync]",
|
|
988
|
+
} catch (Y) {
|
|
989
|
+
throw console.error("[avatarTtsLipsync]", Y), B(), e("error"), Y;
|
|
990
990
|
}
|
|
991
991
|
},
|
|
992
992
|
stop: B,
|
|
@@ -1009,8 +1009,12 @@ function Or(e, t = kt, r = {}) {
|
|
|
1009
1009
|
subscribe: (C) => (d.add(C), () => d.delete(C))
|
|
1010
1010
|
};
|
|
1011
1011
|
}
|
|
1012
|
-
const
|
|
1013
|
-
|
|
1012
|
+
const kn = 16e3, Tn = 16e3, Nr = 4;
|
|
1013
|
+
function Js(e) {
|
|
1014
|
+
const t = e.trim();
|
|
1015
|
+
return t ? t.split(/\s+/).filter(Boolean).length : 0;
|
|
1016
|
+
}
|
|
1017
|
+
class Qs extends jn {
|
|
1014
1018
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1015
1019
|
async deserialize(t) {
|
|
1016
1020
|
try {
|
|
@@ -1022,7 +1026,7 @@ class Xs extends zn {
|
|
|
1022
1026
|
}
|
|
1023
1027
|
}
|
|
1024
1028
|
}
|
|
1025
|
-
class
|
|
1029
|
+
class Zs extends zn {
|
|
1026
1030
|
constructor() {
|
|
1027
1031
|
super(
|
|
1028
1032
|
!0,
|
|
@@ -1030,42 +1034,42 @@ class Js extends Gn {
|
|
|
1030
1034
|
void 0,
|
|
1031
1035
|
void 0,
|
|
1032
1036
|
512,
|
|
1033
|
-
|
|
1034
|
-
|
|
1037
|
+
kn,
|
|
1038
|
+
Tn
|
|
1035
1039
|
);
|
|
1036
1040
|
}
|
|
1037
1041
|
/** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
|
|
1038
1042
|
bufferBotAudio(t, r) {
|
|
1039
1043
|
}
|
|
1040
1044
|
}
|
|
1041
|
-
const
|
|
1042
|
-
function
|
|
1043
|
-
return
|
|
1045
|
+
const ei = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1046
|
+
function ti(e) {
|
|
1047
|
+
return ei.test(e.trim());
|
|
1044
1048
|
}
|
|
1045
|
-
function
|
|
1049
|
+
function ri(e) {
|
|
1046
1050
|
const t = e.replace(/\/$/, "");
|
|
1047
1051
|
return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
|
|
1048
1052
|
}
|
|
1049
|
-
function
|
|
1053
|
+
function ni(e) {
|
|
1050
1054
|
if (e.wsUrl?.trim()) return e.wsUrl.trim();
|
|
1051
1055
|
const t = e.authToken?.trim();
|
|
1052
1056
|
if (!t)
|
|
1053
1057
|
throw new Error(
|
|
1054
1058
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1055
1059
|
);
|
|
1056
|
-
const r = e.apiBase ??
|
|
1060
|
+
const r = e.apiBase ?? vt, n = new URL(`${ri(r)}/ws/voice`);
|
|
1057
1061
|
n.searchParams.set("authToken", t), n.searchParams.set("tenant", "aiTwin");
|
|
1058
1062
|
const s = e.voiceId?.trim();
|
|
1059
|
-
s &&
|
|
1063
|
+
s && ti(s) && n.searchParams.set("voiceId", s);
|
|
1060
1064
|
const i = e.personaId?.trim();
|
|
1061
1065
|
i && n.searchParams.set("personaId", i);
|
|
1062
|
-
const o = e.speakingRate ??
|
|
1066
|
+
const o = e.speakingRate ?? Ut;
|
|
1063
1067
|
return n.searchParams.set(
|
|
1064
1068
|
"speaking_rate",
|
|
1065
|
-
String(Math.max(
|
|
1069
|
+
String(Math.max(lr, Math.min(fr, o)))
|
|
1066
1070
|
), e.ttsStream === !1 ? n.searchParams.set("tts_stream", "false") : n.searchParams.set("tts_stream", "true"), n.toString();
|
|
1067
1071
|
}
|
|
1068
|
-
function
|
|
1072
|
+
function jt(e, t) {
|
|
1069
1073
|
if (!Array.isArray(e)) return [];
|
|
1070
1074
|
const r = [];
|
|
1071
1075
|
for (const n of e)
|
|
@@ -1079,7 +1083,7 @@ function Yt(e, t) {
|
|
|
1079
1083
|
});
|
|
1080
1084
|
return r;
|
|
1081
1085
|
}
|
|
1082
|
-
function
|
|
1086
|
+
function si(e) {
|
|
1083
1087
|
if (!e || typeof e != "object") return null;
|
|
1084
1088
|
const t = e, n = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
|
|
1085
1089
|
return {
|
|
@@ -1087,66 +1091,68 @@ function ri(e) {
|
|
|
1087
1091
|
type: String(n.type ?? t.type ?? "server-message")
|
|
1088
1092
|
};
|
|
1089
1093
|
}
|
|
1090
|
-
function
|
|
1094
|
+
function Yt(e) {
|
|
1091
1095
|
return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
|
|
1092
1096
|
}
|
|
1093
|
-
function
|
|
1097
|
+
function ii(e) {
|
|
1094
1098
|
return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
|
|
1095
1099
|
}
|
|
1096
|
-
function
|
|
1100
|
+
function ai(e, t = {}) {
|
|
1097
1101
|
const r = [], n = [], s = [], i = [];
|
|
1098
|
-
let o = "", a = "neutral", u =
|
|
1102
|
+
let o = "", a = "neutral", u = it, l = !1, f = null, c = null, d = { ...t }, g = 0, S = null;
|
|
1099
1103
|
const m = /* @__PURE__ */ new Set(), I = [];
|
|
1100
1104
|
let _ = !1, R = null, w = !0, b = "default";
|
|
1101
1105
|
const L = /* @__PURE__ */ new Set();
|
|
1102
|
-
let B = null,
|
|
1103
|
-
const
|
|
1106
|
+
let B = null, j = 0, C = !1, k = null, P = "", U = !1;
|
|
1107
|
+
const O = () => {
|
|
1104
1108
|
k != null && (clearTimeout(k), k = null);
|
|
1105
|
-
},
|
|
1106
|
-
let
|
|
1107
|
-
const
|
|
1109
|
+
}, q = () => m.forEach((p) => p());
|
|
1110
|
+
let fe = () => !1;
|
|
1111
|
+
const D = _n(
|
|
1108
1112
|
{
|
|
1109
1113
|
onSpeakingStart: () => e("speaking"),
|
|
1110
|
-
onSpeakingDone: () =>
|
|
1111
|
-
|
|
1112
|
-
|
|
1114
|
+
onSpeakingDone: () => {
|
|
1115
|
+
U = !1, e("done");
|
|
1116
|
+
},
|
|
1117
|
+
onNotify: q,
|
|
1118
|
+
shouldHoldForWarmup: () => fe()
|
|
1113
1119
|
},
|
|
1114
1120
|
u
|
|
1115
|
-
),
|
|
1121
|
+
), Y = () => {
|
|
1116
1122
|
if (R) return R;
|
|
1117
1123
|
const p = new MessageChannel();
|
|
1118
1124
|
return p.port1.onmessage = () => {
|
|
1119
1125
|
const x = I.shift();
|
|
1120
|
-
x !== void 0 &&
|
|
1126
|
+
x !== void 0 && Se(x), I.length > 0 ? p.port2.postMessage(null) : _ = !1;
|
|
1121
1127
|
}, R = p, p;
|
|
1122
|
-
},
|
|
1123
|
-
I.push(p), !_ && (_ = !0,
|
|
1124
|
-
},
|
|
1128
|
+
}, Q = (p) => {
|
|
1129
|
+
I.push(p), !_ && (_ = !0, Y().port2.postMessage(null));
|
|
1130
|
+
}, de = () => D.getPlaybackElapsedMs(), ce = (p, x = o) => {
|
|
1125
1131
|
if (!d.onLipsyncDebug) return;
|
|
1126
|
-
const
|
|
1132
|
+
const G = de(), X = r;
|
|
1127
1133
|
d.onLipsyncDebug({
|
|
1128
1134
|
event: p,
|
|
1129
1135
|
spokenText: x,
|
|
1130
1136
|
mood: a,
|
|
1131
|
-
playbackAnchorPerf:
|
|
1132
|
-
playbackElapsedMs:
|
|
1133
|
-
queueLength:
|
|
1134
|
-
activeViseme:
|
|
1135
|
-
segments: i.map((
|
|
1136
|
-
...
|
|
1137
|
-
visemes: [...
|
|
1137
|
+
playbackAnchorPerf: D.getPlaybackStartPerf(),
|
|
1138
|
+
playbackElapsedMs: G,
|
|
1139
|
+
queueLength: X.length,
|
|
1140
|
+
activeViseme: Nt(X, G),
|
|
1141
|
+
segments: i.map((oe) => ({
|
|
1142
|
+
...oe,
|
|
1143
|
+
visemes: [...oe.visemes]
|
|
1138
1144
|
}))
|
|
1139
1145
|
});
|
|
1140
|
-
},
|
|
1146
|
+
}, ue = (p, x) => {
|
|
1141
1147
|
d.onLipsyncDebug && (S = { event: p, spokenText: x }, g === 0 && (g = requestAnimationFrame(() => {
|
|
1142
1148
|
g = 0;
|
|
1143
|
-
const
|
|
1144
|
-
S = null,
|
|
1149
|
+
const G = S;
|
|
1150
|
+
S = null, G && ce(G.event, G.spokenText);
|
|
1145
1151
|
})));
|
|
1146
|
-
},
|
|
1147
|
-
w = !0, L.clear(),
|
|
1148
|
-
},
|
|
1149
|
-
const p =
|
|
1152
|
+
}, se = () => {
|
|
1153
|
+
w = !0, L.clear(), D.clearAborted();
|
|
1154
|
+
}, me = () => {
|
|
1155
|
+
const p = ii(f);
|
|
1150
1156
|
if (p) {
|
|
1151
1157
|
b = `bot-${Date.now()}`, p.interruptedTrackIds = { [b]: !0 };
|
|
1152
1158
|
try {
|
|
@@ -1159,261 +1165,270 @@ function si(e, t = {}) {
|
|
|
1159
1165
|
x?.interrupt?.();
|
|
1160
1166
|
} catch {
|
|
1161
1167
|
}
|
|
1162
|
-
},
|
|
1168
|
+
}, v = (p) => {
|
|
1169
|
+
if (U && D.isSpeaking())
|
|
1170
|
+
return !0;
|
|
1163
1171
|
const x = p.context_id?.trim();
|
|
1164
|
-
return x && L.has(x) ? !0 : w ? !1 : !(p.type === "avatar_metadata" ||
|
|
1165
|
-
},
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1172
|
+
return x && L.has(x) ? !0 : w ? !1 : !(p.type === "avatar_metadata" || Yt(p));
|
|
1173
|
+
}, E = (p) => {
|
|
1174
|
+
const x = Js(P);
|
|
1175
|
+
if (D.isSpeaking() && x < Nr) {
|
|
1176
|
+
console.debug(
|
|
1177
|
+
"[realtimeVoice] ignoring interrupt — backchannel below barge-in threshold",
|
|
1178
|
+
{ wordCount: x, minWords: Nr, source: p.source }
|
|
1179
|
+
), U = !0;
|
|
1180
|
+
return;
|
|
1181
|
+
}
|
|
1182
|
+
w = !1, U = !1;
|
|
1183
|
+
const X = p.context_id?.trim();
|
|
1184
|
+
X && L.add(X), O(), C = !1, I.length = 0, _ = !1, B?.abort(), B = null, j += 1, me(), D.bargeIn(), h(), e("idle"), ue("interrupt"), q();
|
|
1185
|
+
}, h = () => {
|
|
1170
1186
|
r.length = 0, n.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
|
|
1171
1187
|
}, T = () => {
|
|
1172
|
-
|
|
1173
|
-
},
|
|
1174
|
-
T(), e("idle"),
|
|
1175
|
-
},
|
|
1188
|
+
D.stop(), h(), ue("reset"), q();
|
|
1189
|
+
}, M = () => {
|
|
1190
|
+
T(), e("idle"), q();
|
|
1191
|
+
}, F = (p, x) => {
|
|
1176
1192
|
typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), Array.isArray(p.sentence_emotions) && p.sentence_emotions.length > 0 && (x && (s.length = 0), s.push(
|
|
1177
|
-
...
|
|
1193
|
+
...jt(p.sentence_emotions, a)
|
|
1178
1194
|
));
|
|
1179
|
-
},
|
|
1180
|
-
if (
|
|
1195
|
+
}, A = (p) => {
|
|
1196
|
+
if (v({ ...p, type: "avatar_metadata" }))
|
|
1181
1197
|
return;
|
|
1182
|
-
|
|
1198
|
+
se(), C = !0;
|
|
1183
1199
|
const x = String(p.spoken_text ?? p.text ?? "").trim();
|
|
1184
|
-
x && (o = x),
|
|
1185
|
-
...
|
|
1186
|
-
), Array.isArray(p.gestures) && p.gestures,
|
|
1187
|
-
},
|
|
1200
|
+
x && (o = x), D.resetForNewStream(u), typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), s.length = 0, s.push(
|
|
1201
|
+
...jt(p.sentence_emotions, a)
|
|
1202
|
+
), Array.isArray(p.gestures) && p.gestures, ue("metadata", x), q();
|
|
1203
|
+
}, W = (p, x, G, X) => {
|
|
1188
1204
|
if (!d.onLipsyncDebug) return;
|
|
1189
|
-
const
|
|
1190
|
-
(
|
|
1205
|
+
const oe = r.slice(G), Ce = X.filter(
|
|
1206
|
+
(te) => String(te.symbol ?? te.viseme ?? "").trim()
|
|
1191
1207
|
);
|
|
1192
1208
|
i.push({
|
|
1193
1209
|
spokenText: x,
|
|
1194
|
-
audioOffsetMs:
|
|
1210
|
+
audioOffsetMs: oe[0]?.vtime ?? 0,
|
|
1195
1211
|
isNewSegment: !!p.is_new_segment,
|
|
1196
1212
|
chunkDurationMs: p.chunk_duration_ms != null ? Number(p.chunk_duration_ms) : null,
|
|
1197
1213
|
receivedAtMs: performance.now(),
|
|
1198
|
-
visemes:
|
|
1199
|
-
const
|
|
1214
|
+
visemes: oe.map((te, be) => {
|
|
1215
|
+
const Ie = Ce[be];
|
|
1200
1216
|
return {
|
|
1201
|
-
rawSymbol: String(
|
|
1202
|
-
viseme:
|
|
1203
|
-
startSec: Number(
|
|
1204
|
-
durationSec: Number(
|
|
1205
|
-
vtimeMs:
|
|
1206
|
-
vdurationMs:
|
|
1217
|
+
rawSymbol: String(Ie?.symbol ?? Ie?.viseme ?? te.viseme).trim(),
|
|
1218
|
+
viseme: te.viseme,
|
|
1219
|
+
startSec: Number(Ie?.start ?? 0),
|
|
1220
|
+
durationSec: Number(Ie?.duration ?? 0),
|
|
1221
|
+
vtimeMs: te.vtime,
|
|
1222
|
+
vdurationMs: te.vduration
|
|
1207
1223
|
};
|
|
1208
1224
|
})
|
|
1209
1225
|
});
|
|
1210
|
-
},
|
|
1211
|
-
if (
|
|
1212
|
-
|
|
1213
|
-
const x = String(p.spoken_text ?? p.text ?? "").trim(),
|
|
1214
|
-
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1226
|
+
}, J = (p) => {
|
|
1227
|
+
if (v(p)) return;
|
|
1228
|
+
O(), Yt(p) && se();
|
|
1229
|
+
const x = String(p.spoken_text ?? p.text ?? "").trim(), G = Yt(p), X = p.visemes ?? [], oe = p.words ?? [], Ce = String(p.chunk ?? "").trim(), te = C;
|
|
1230
|
+
te && (C = !1), x && (o = x), F(p, G), te ? D.resetForNewStream(u) : G && D.resumeBotStream();
|
|
1231
|
+
const be = r.length;
|
|
1232
|
+
D.playAudioChunk(
|
|
1217
1233
|
r,
|
|
1218
1234
|
n,
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1235
|
+
Ce,
|
|
1236
|
+
X,
|
|
1237
|
+
oe,
|
|
1238
|
+
G,
|
|
1223
1239
|
{
|
|
1224
1240
|
sampleRate: p.sample_rate,
|
|
1225
|
-
newStream:
|
|
1241
|
+
newStream: te,
|
|
1226
1242
|
onNewStream: () => {
|
|
1227
1243
|
i.length = 0;
|
|
1228
1244
|
}
|
|
1229
1245
|
}
|
|
1230
1246
|
).then(() => {
|
|
1231
|
-
|
|
1247
|
+
W(p, x, be, X), ue("audio_chunk", x);
|
|
1232
1248
|
});
|
|
1233
|
-
},
|
|
1234
|
-
if (
|
|
1235
|
-
(p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) &&
|
|
1249
|
+
}, Z = (p) => {
|
|
1250
|
+
if (v(p)) return;
|
|
1251
|
+
(p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) && se(), console.warn(
|
|
1236
1252
|
"[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
|
|
1237
1253
|
);
|
|
1238
1254
|
const x = String(p.spoken_text ?? p.text ?? "").trim();
|
|
1239
|
-
x && (o = x),
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1255
|
+
x && (o = x), F(p, !!p.is_new_segment);
|
|
1256
|
+
const G = r.length;
|
|
1257
|
+
D.queueTimingsOnly(
|
|
1242
1258
|
r,
|
|
1243
1259
|
n,
|
|
1244
1260
|
p.visemes ?? [],
|
|
1245
1261
|
p.words ?? [],
|
|
1246
1262
|
!!p.is_new_segment
|
|
1247
|
-
),
|
|
1263
|
+
), W(
|
|
1248
1264
|
p,
|
|
1249
1265
|
x,
|
|
1250
|
-
|
|
1266
|
+
G,
|
|
1251
1267
|
p.visemes ?? []
|
|
1252
|
-
),
|
|
1253
|
-
},
|
|
1268
|
+
), ue("lipsync", x), q();
|
|
1269
|
+
}, ee = async (p) => {
|
|
1254
1270
|
const x = String(p.text ?? "").trim();
|
|
1255
1271
|
if (!x) return;
|
|
1256
|
-
const
|
|
1257
|
-
if (!
|
|
1272
|
+
const G = d.authToken?.trim();
|
|
1273
|
+
if (!G) {
|
|
1258
1274
|
console.error("[realtimeVoice] avatar_speak requires authToken");
|
|
1259
1275
|
return;
|
|
1260
1276
|
}
|
|
1261
1277
|
B?.abort();
|
|
1262
|
-
const
|
|
1263
|
-
B =
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1267
|
-
|
|
1268
|
-
Math.min(
|
|
1269
|
-
),
|
|
1278
|
+
const X = new AbortController();
|
|
1279
|
+
B = X;
|
|
1280
|
+
const oe = ++j;
|
|
1281
|
+
se(), D.resetForNewStream(u), o = x;
|
|
1282
|
+
const te = `${(d.apiBase ?? vt).replace(/\/$/, "")}/avatar_ttsWithPoses`, be = d.voiceId?.trim() || bn, Ie = d.speakingRate ?? Ut, Oe = Math.max(
|
|
1283
|
+
lr,
|
|
1284
|
+
Math.min(fr, Ie)
|
|
1285
|
+
), ct = {
|
|
1270
1286
|
user_query: x,
|
|
1271
1287
|
ttsEngineId: u,
|
|
1272
|
-
speakingRate:
|
|
1288
|
+
speakingRate: Oe,
|
|
1273
1289
|
tenant: "aiTwin"
|
|
1274
1290
|
};
|
|
1275
|
-
|
|
1291
|
+
on.has(u) && (ct.voice_id = be);
|
|
1276
1292
|
try {
|
|
1277
|
-
const
|
|
1293
|
+
const Me = await fetch(te, {
|
|
1278
1294
|
method: "POST",
|
|
1279
1295
|
headers: {
|
|
1280
1296
|
"Content-Type": "application/json",
|
|
1281
|
-
Authorization: `Bearer ${
|
|
1297
|
+
Authorization: `Bearer ${G}`
|
|
1282
1298
|
},
|
|
1283
|
-
body: JSON.stringify(
|
|
1284
|
-
signal:
|
|
1299
|
+
body: JSON.stringify(ct),
|
|
1300
|
+
signal: X.signal
|
|
1285
1301
|
});
|
|
1286
|
-
if (!
|
|
1287
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
1288
|
-
const
|
|
1289
|
-
if (!
|
|
1290
|
-
const
|
|
1291
|
-
let Ne = "",
|
|
1292
|
-
const
|
|
1293
|
-
if (
|
|
1302
|
+
if (!Me.ok)
|
|
1303
|
+
throw new Error(`avatar_ttsWithPoses failed (${Me.status})`);
|
|
1304
|
+
const Ye = Me.body;
|
|
1305
|
+
if (!Ye) throw new Error("No response body");
|
|
1306
|
+
const bt = Ye.getReader(), le = new TextDecoder();
|
|
1307
|
+
let Ne = "", ut = !0;
|
|
1308
|
+
const lt = async (Ue) => {
|
|
1309
|
+
if (oe !== j || X.signal.aborted || !w)
|
|
1294
1310
|
return;
|
|
1295
|
-
const
|
|
1296
|
-
if (
|
|
1297
|
-
if (
|
|
1298
|
-
const pe =
|
|
1311
|
+
const he = mn(Ue);
|
|
1312
|
+
if (he) {
|
|
1313
|
+
if (he.event === "audio") {
|
|
1314
|
+
const pe = he.data.chunk, ke = he.data.visemes ?? [], _e = he.data.words ?? [], Ve = he.data.is_new_segment ?? !1, re = he.data.sample_rate;
|
|
1299
1315
|
if (pe) {
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1316
|
+
const ne = ut;
|
|
1317
|
+
ut = !1, await D.playAudioChunk(
|
|
1302
1318
|
r,
|
|
1303
1319
|
n,
|
|
1304
1320
|
pe,
|
|
1305
1321
|
ke,
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
{ sampleRate:
|
|
1322
|
+
_e,
|
|
1323
|
+
Ve,
|
|
1324
|
+
{ sampleRate: re, newStream: ne }
|
|
1309
1325
|
);
|
|
1310
|
-
} else (ke.length > 0 ||
|
|
1326
|
+
} else (ke.length > 0 || _e.length > 0) && D.queueTimingsOnly(
|
|
1311
1327
|
r,
|
|
1312
1328
|
n,
|
|
1313
1329
|
ke,
|
|
1314
|
-
|
|
1315
|
-
|
|
1330
|
+
_e,
|
|
1331
|
+
Ve
|
|
1316
1332
|
);
|
|
1317
|
-
} else if (
|
|
1318
|
-
const pe =
|
|
1333
|
+
} else if (he.event === "metadata") {
|
|
1334
|
+
const pe = he.data.mood;
|
|
1319
1335
|
typeof pe == "string" && pe.trim() && (a = pe.trim());
|
|
1320
|
-
const ke =
|
|
1336
|
+
const ke = he.data.sentence_emotions;
|
|
1321
1337
|
Array.isArray(ke) && (s.length = 0, s.push(
|
|
1322
|
-
...
|
|
1323
|
-
)),
|
|
1324
|
-
} else if (
|
|
1338
|
+
...jt(ke, a)
|
|
1339
|
+
)), q();
|
|
1340
|
+
} else if (he.event === "error")
|
|
1325
1341
|
throw new Error(
|
|
1326
|
-
String(
|
|
1342
|
+
String(he.data.message ?? "avatar_ttsWithPoses stream error")
|
|
1327
1343
|
);
|
|
1328
1344
|
}
|
|
1329
1345
|
};
|
|
1330
|
-
for (; !(
|
|
1331
|
-
const { done:
|
|
1332
|
-
|
|
1346
|
+
for (; !(oe !== j || X.signal.aborted || !w); ) {
|
|
1347
|
+
const { done: Ue, value: he } = await bt.read();
|
|
1348
|
+
he && (Ne += le.decode(he, { stream: !0 }));
|
|
1333
1349
|
const pe = Ne.split(`
|
|
1334
1350
|
|
|
1335
1351
|
`);
|
|
1336
1352
|
Ne = pe.pop() ?? "";
|
|
1337
|
-
for (const ke of pe) await
|
|
1338
|
-
if (
|
|
1339
|
-
Ne.trim() && await
|
|
1353
|
+
for (const ke of pe) await lt(ke);
|
|
1354
|
+
if (Ue) {
|
|
1355
|
+
Ne.trim() && await lt(Ne.trim()), oe === j && !X.signal.aborted && w && D.markStreamComplete(r);
|
|
1340
1356
|
break;
|
|
1341
1357
|
}
|
|
1342
1358
|
}
|
|
1343
|
-
} catch (
|
|
1344
|
-
if (
|
|
1345
|
-
console.error("[realtimeVoice] avatar_speak failed:",
|
|
1359
|
+
} catch (Me) {
|
|
1360
|
+
if (X.signal.aborted || !w) return;
|
|
1361
|
+
console.error("[realtimeVoice] avatar_speak failed:", Me), e("error"), q();
|
|
1346
1362
|
} finally {
|
|
1347
|
-
B ===
|
|
1363
|
+
B === X && (B = null);
|
|
1348
1364
|
}
|
|
1349
|
-
},
|
|
1350
|
-
const x =
|
|
1365
|
+
}, Se = (p) => {
|
|
1366
|
+
const x = si(p);
|
|
1351
1367
|
if (!x) {
|
|
1352
1368
|
console.warn("[realtimeVoice] server message with no payload", p);
|
|
1353
1369
|
return;
|
|
1354
1370
|
}
|
|
1355
|
-
const
|
|
1356
|
-
switch (
|
|
1371
|
+
const G = String(x.type ?? "unknown");
|
|
1372
|
+
switch (G !== "avatar_metadata" && G !== "avatar_audio_chunk" && G !== "avatar_lipsync" && G !== "avatar_interrupt" && G !== "error" && console.debug("[realtimeVoice] server message", G, x), G) {
|
|
1357
1373
|
case "avatar_metadata":
|
|
1358
|
-
|
|
1374
|
+
A(x);
|
|
1359
1375
|
break;
|
|
1360
1376
|
case "avatar_audio_chunk":
|
|
1361
|
-
|
|
1377
|
+
J(x);
|
|
1362
1378
|
break;
|
|
1363
1379
|
case "avatar_lipsync":
|
|
1364
|
-
|
|
1380
|
+
Z(x);
|
|
1365
1381
|
break;
|
|
1366
1382
|
case "avatar_interrupt":
|
|
1367
|
-
|
|
1383
|
+
E(x);
|
|
1368
1384
|
break;
|
|
1369
1385
|
case "error": {
|
|
1370
|
-
const
|
|
1371
|
-
console.error("[realtimeVoice] server error:",
|
|
1386
|
+
const X = String(x.message ?? "Voice session error");
|
|
1387
|
+
console.error("[realtimeVoice] server error:", X), e("error"), q();
|
|
1372
1388
|
break;
|
|
1373
1389
|
}
|
|
1374
1390
|
case "avatar_speak":
|
|
1375
|
-
|
|
1391
|
+
ee(x);
|
|
1376
1392
|
break;
|
|
1377
1393
|
}
|
|
1378
|
-
},
|
|
1379
|
-
transport: new
|
|
1394
|
+
}, ye = () => f || (c = new Zs(), f = new Kn({
|
|
1395
|
+
transport: new Gn({
|
|
1380
1396
|
mediaManager: c,
|
|
1381
|
-
serializer: new
|
|
1382
|
-
recorderSampleRate:
|
|
1383
|
-
playerSampleRate:
|
|
1397
|
+
serializer: new Qs(),
|
|
1398
|
+
recorderSampleRate: kn,
|
|
1399
|
+
playerSampleRate: Tn
|
|
1384
1400
|
}),
|
|
1385
1401
|
enableCam: !1,
|
|
1386
1402
|
enableMic: !0,
|
|
1387
1403
|
callbacks: {
|
|
1388
1404
|
onBotReady: () => {
|
|
1389
|
-
l = !0, e("idle"),
|
|
1405
|
+
l = !0, e("idle"), q();
|
|
1390
1406
|
},
|
|
1391
1407
|
onDisconnected: () => {
|
|
1392
|
-
l = !1,
|
|
1408
|
+
l = !1, M();
|
|
1393
1409
|
},
|
|
1394
1410
|
onError: (p) => {
|
|
1395
1411
|
const x = typeof p == "object" && p !== null && "data" in p ? String(p.data ?? p) : String(p);
|
|
1396
|
-
console.error("[realtimeVoice]", x, p), e("error"),
|
|
1412
|
+
console.error("[realtimeVoice]", x, p), e("error"), q();
|
|
1397
1413
|
},
|
|
1398
1414
|
onTransportStateChanged: (p) => {
|
|
1399
|
-
p === "error" && (e("error"),
|
|
1415
|
+
p === "error" && (e("error"), q());
|
|
1400
1416
|
},
|
|
1401
1417
|
onServerMessage: (p) => {
|
|
1402
|
-
|
|
1418
|
+
Q(p);
|
|
1403
1419
|
},
|
|
1404
1420
|
onUserStartedSpeaking: () => {
|
|
1405
|
-
le({});
|
|
1406
1421
|
},
|
|
1407
1422
|
onBotStartedSpeaking: () => {
|
|
1408
|
-
|
|
1423
|
+
se(), ue("bot_started");
|
|
1409
1424
|
},
|
|
1410
1425
|
onBotStoppedSpeaking: () => {
|
|
1411
|
-
w && (
|
|
1412
|
-
k = null, w && (
|
|
1426
|
+
w && (O(), k = setTimeout(() => {
|
|
1427
|
+
k = null, w && (D.markStreamComplete(r), ue("bot_stopped"));
|
|
1413
1428
|
}, 450));
|
|
1414
1429
|
},
|
|
1415
1430
|
onUserTranscript: (p) => {
|
|
1416
|
-
d.onUserTranscript?.(p.text, !!p.final);
|
|
1431
|
+
P = String(p.text ?? ""), d.onUserTranscript?.(p.text, !!p.final);
|
|
1417
1432
|
},
|
|
1418
1433
|
onBotOutput: (p) => {
|
|
1419
1434
|
d.onBotOutput?.(p.text);
|
|
@@ -1424,21 +1439,21 @@ function si(e, t = {}) {
|
|
|
1424
1439
|
setDeveloperToken: (p) => {
|
|
1425
1440
|
},
|
|
1426
1441
|
setTtsEngineId: (p) => {
|
|
1427
|
-
u = p,
|
|
1442
|
+
u = p, D.setStreamTtsEngineId(p);
|
|
1428
1443
|
},
|
|
1429
1444
|
getTtsEngineId: () => u,
|
|
1430
1445
|
speak: async (p, x) => {
|
|
1431
|
-
const
|
|
1432
|
-
if (
|
|
1446
|
+
const G = p.trim();
|
|
1447
|
+
if (G) {
|
|
1433
1448
|
if (!f || !l)
|
|
1434
1449
|
throw new Error(
|
|
1435
1450
|
"Realtime voice is not connected. Call connect() first."
|
|
1436
1451
|
);
|
|
1437
|
-
T(), await f.sendText(
|
|
1452
|
+
T(), await f.sendText(G);
|
|
1438
1453
|
}
|
|
1439
1454
|
},
|
|
1440
1455
|
stop: () => {
|
|
1441
|
-
B?.abort(), B = null,
|
|
1456
|
+
B?.abort(), B = null, j += 1, se(), T(), e("idle"), q();
|
|
1442
1457
|
},
|
|
1443
1458
|
connect: async (p) => {
|
|
1444
1459
|
if (p && (d = { ...d, ...p }), !d.authToken?.trim())
|
|
@@ -1446,58 +1461,58 @@ function si(e, t = {}) {
|
|
|
1446
1461
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1447
1462
|
);
|
|
1448
1463
|
e("loading");
|
|
1449
|
-
const x =
|
|
1464
|
+
const x = ye();
|
|
1450
1465
|
await x.initDevices();
|
|
1451
|
-
const
|
|
1452
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1466
|
+
const G = ni(d);
|
|
1467
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", G);
|
|
1453
1468
|
try {
|
|
1454
|
-
await x.connect({ wsUrl:
|
|
1455
|
-
} catch (
|
|
1456
|
-
l = !1, e("error"),
|
|
1457
|
-
const
|
|
1458
|
-
throw new Error(`${
|
|
1469
|
+
await x.connect({ wsUrl: G });
|
|
1470
|
+
} catch (X) {
|
|
1471
|
+
l = !1, e("error"), q();
|
|
1472
|
+
const oe = X instanceof Error ? X.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
|
|
1473
|
+
throw new Error(`${oe} — ${G}`);
|
|
1459
1474
|
}
|
|
1460
|
-
l = !0, e("idle"),
|
|
1475
|
+
l = !0, e("idle"), q();
|
|
1461
1476
|
},
|
|
1462
1477
|
disconnect: async () => {
|
|
1463
|
-
if (
|
|
1478
|
+
if (O(), C = !1, I.length = 0, _ = !1, B?.abort(), B = null, j += 1, se(), f)
|
|
1464
1479
|
try {
|
|
1465
1480
|
await f.disconnect();
|
|
1466
1481
|
} catch (p) {
|
|
1467
1482
|
console.error("[realtimeVoice] disconnect failed:", p);
|
|
1468
1483
|
}
|
|
1469
|
-
l = !1,
|
|
1484
|
+
l = !1, M();
|
|
1470
1485
|
},
|
|
1471
1486
|
isConnected: () => l,
|
|
1472
1487
|
unlockAudio: async () => {
|
|
1473
|
-
await
|
|
1488
|
+
await D.primeAudioContext();
|
|
1474
1489
|
},
|
|
1475
1490
|
getVisemeQueue: () => r,
|
|
1476
1491
|
getWordQueue: () => n,
|
|
1477
1492
|
getSentenceEmotions: () => s,
|
|
1478
1493
|
getStreamMood: () => a,
|
|
1479
|
-
getPlaybackElapsedMs:
|
|
1480
|
-
isSpeaking: () =>
|
|
1481
|
-
isWarmingUp: () =>
|
|
1482
|
-
releaseWarmupHold: () =>
|
|
1494
|
+
getPlaybackElapsedMs: de,
|
|
1495
|
+
isSpeaking: () => D.isSpeaking(),
|
|
1496
|
+
isWarmingUp: () => D.isWarmingUp(),
|
|
1497
|
+
releaseWarmupHold: () => D.releaseWarmupHold(),
|
|
1483
1498
|
setLipsyncWarmupHold: (p, x) => {
|
|
1484
|
-
x && (
|
|
1499
|
+
x && (fe = x), D.setLipsyncWarmupHoldEnabled(p);
|
|
1485
1500
|
},
|
|
1486
|
-
getVoiceStream: () =>
|
|
1501
|
+
getVoiceStream: () => D.getVoiceStream(),
|
|
1487
1502
|
setPlaybackSpeed: (p) => {
|
|
1488
|
-
|
|
1503
|
+
D.setPlaybackSpeed(p);
|
|
1489
1504
|
},
|
|
1490
|
-
getPlaybackSpeed: () =>
|
|
1505
|
+
getPlaybackSpeed: () => D.getPlaybackSpeed(),
|
|
1491
1506
|
subscribe: (p) => (m.add(p), () => m.delete(p))
|
|
1492
1507
|
};
|
|
1493
1508
|
}
|
|
1494
|
-
function
|
|
1509
|
+
function En(e, t, r) {
|
|
1495
1510
|
return {
|
|
1496
1511
|
width: e.crop?.source_width ?? t,
|
|
1497
1512
|
height: e.crop?.source_height ?? r
|
|
1498
1513
|
};
|
|
1499
1514
|
}
|
|
1500
|
-
function
|
|
1515
|
+
function An(e, t) {
|
|
1501
1516
|
const r = e.crop;
|
|
1502
1517
|
return {
|
|
1503
1518
|
x: t?.source_x ?? r?.x ?? 0,
|
|
@@ -1506,25 +1521,25 @@ function En(e, t) {
|
|
|
1506
1521
|
height: t?.source_h ?? r?.height ?? e.frame_height ?? 0
|
|
1507
1522
|
};
|
|
1508
1523
|
}
|
|
1509
|
-
function
|
|
1524
|
+
function Pn(e) {
|
|
1510
1525
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
1511
1526
|
}
|
|
1512
|
-
async function
|
|
1527
|
+
async function at(e, t) {
|
|
1513
1528
|
const r = await fetch(e);
|
|
1514
1529
|
if (!r.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
|
|
1515
1530
|
const n = await r.arrayBuffer();
|
|
1516
|
-
return
|
|
1531
|
+
return ks(n, t);
|
|
1517
1532
|
}
|
|
1518
|
-
async function
|
|
1533
|
+
async function xn(e, t) {
|
|
1519
1534
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
1520
|
-
const r = await
|
|
1535
|
+
const r = await at(e, t), n = new TextDecoder().decode(r);
|
|
1521
1536
|
return JSON.parse(n);
|
|
1522
1537
|
}
|
|
1523
|
-
async function
|
|
1538
|
+
async function oi(e) {
|
|
1524
1539
|
const t = new Blob([e], { type: "image/webp" });
|
|
1525
1540
|
return createImageBitmap(t);
|
|
1526
1541
|
}
|
|
1527
|
-
async function
|
|
1542
|
+
async function ci(e) {
|
|
1528
1543
|
const t = new Blob([e], { type: "image/webp" }), r = URL.createObjectURL(t);
|
|
1529
1544
|
return new Promise((n, s) => {
|
|
1530
1545
|
const i = new Image();
|
|
@@ -1535,11 +1550,11 @@ async function ai(e) {
|
|
|
1535
1550
|
}, i.src = r;
|
|
1536
1551
|
});
|
|
1537
1552
|
}
|
|
1538
|
-
async function
|
|
1553
|
+
async function ui(e) {
|
|
1539
1554
|
const t = new Blob([e], { type: "image/png" });
|
|
1540
1555
|
return createImageBitmap(t);
|
|
1541
1556
|
}
|
|
1542
|
-
async function
|
|
1557
|
+
async function li(e) {
|
|
1543
1558
|
const t = new Blob([e], { type: "image/png" }), r = URL.createObjectURL(t);
|
|
1544
1559
|
return new Promise((n, s) => {
|
|
1545
1560
|
const i = new Image();
|
|
@@ -1550,28 +1565,28 @@ async function ci(e) {
|
|
|
1550
1565
|
}, i.src = r;
|
|
1551
1566
|
});
|
|
1552
1567
|
}
|
|
1553
|
-
function
|
|
1568
|
+
function fi(e) {
|
|
1554
1569
|
const t = new Blob([e], { type: "video/mp4" });
|
|
1555
1570
|
return URL.createObjectURL(t);
|
|
1556
1571
|
}
|
|
1557
|
-
async function
|
|
1558
|
-
const t =
|
|
1559
|
-
if (!
|
|
1572
|
+
async function di(e) {
|
|
1573
|
+
const t = Ps();
|
|
1574
|
+
if (!St()) return t;
|
|
1560
1575
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
1561
|
-
const r = await
|
|
1562
|
-
return
|
|
1576
|
+
const r = await at(t, e);
|
|
1577
|
+
return fi(r);
|
|
1563
1578
|
}
|
|
1564
|
-
function
|
|
1579
|
+
function dr(e, t) {
|
|
1565
1580
|
return `${e}/${t}_minus_sil.png`;
|
|
1566
1581
|
}
|
|
1567
|
-
const
|
|
1568
|
-
function
|
|
1582
|
+
const In = 5;
|
|
1583
|
+
function Vt(e) {
|
|
1569
1584
|
const t = e?.composite_threshold;
|
|
1570
1585
|
if (typeof t == "number" && t > 0) return t;
|
|
1571
1586
|
const r = e?.crop?.content_threshold;
|
|
1572
|
-
return typeof r == "number" && r > 0 ? r :
|
|
1587
|
+
return typeof r == "number" && r > 0 ? r : In;
|
|
1573
1588
|
}
|
|
1574
|
-
const
|
|
1589
|
+
const Ra = [
|
|
1575
1590
|
"aa",
|
|
1576
1591
|
"E",
|
|
1577
1592
|
"I",
|
|
@@ -1586,11 +1601,11 @@ const Ia = [
|
|
|
1586
1601
|
"RR",
|
|
1587
1602
|
"kk",
|
|
1588
1603
|
"nn"
|
|
1589
|
-
],
|
|
1604
|
+
], er = [
|
|
1590
1605
|
"t01_0.25",
|
|
1591
1606
|
"t02_0.50",
|
|
1592
1607
|
"t03_0.75"
|
|
1593
|
-
],
|
|
1608
|
+
], mi = er.length, Ur = /* @__PURE__ */ new Set([
|
|
1594
1609
|
"aa__kk",
|
|
1595
1610
|
"aa__nn",
|
|
1596
1611
|
"aa__sil",
|
|
@@ -1697,75 +1712,75 @@ const Ia = [
|
|
|
1697
1712
|
"U__nn",
|
|
1698
1713
|
"U__sil"
|
|
1699
1714
|
]);
|
|
1700
|
-
function
|
|
1715
|
+
function Vr(e, t) {
|
|
1701
1716
|
return `${e}__${t}`;
|
|
1702
1717
|
}
|
|
1703
|
-
function
|
|
1718
|
+
function Wr(e, t) {
|
|
1704
1719
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1705
1720
|
}
|
|
1706
|
-
function
|
|
1721
|
+
function _t(e) {
|
|
1707
1722
|
return `${e}_minus_sil.png`;
|
|
1708
1723
|
}
|
|
1709
|
-
function
|
|
1724
|
+
function mr(e, t) {
|
|
1710
1725
|
if (t.has(e)) return e;
|
|
1711
1726
|
const r = /^pairs\/([^/]+)\//.exec(e);
|
|
1712
1727
|
if (!r) return null;
|
|
1713
1728
|
const n = r[1].split("__")[1];
|
|
1714
1729
|
if (!n || n === "sil") return null;
|
|
1715
|
-
const s =
|
|
1730
|
+
const s = _t(n);
|
|
1716
1731
|
return t.has(s) ? s : null;
|
|
1717
1732
|
}
|
|
1718
|
-
function
|
|
1733
|
+
function Mn(e, t) {
|
|
1719
1734
|
return e.filter((r) => t.has(r));
|
|
1720
1735
|
}
|
|
1721
|
-
function
|
|
1722
|
-
const n =
|
|
1723
|
-
return
|
|
1736
|
+
function hi(e, t, r) {
|
|
1737
|
+
const n = hr(e, t);
|
|
1738
|
+
return Mn(n, r).length > 0;
|
|
1724
1739
|
}
|
|
1725
|
-
function
|
|
1740
|
+
function hr(e, t) {
|
|
1726
1741
|
if (e === t) return [];
|
|
1727
|
-
const r = [], n =
|
|
1728
|
-
if (
|
|
1729
|
-
for (const i of
|
|
1730
|
-
r.push(
|
|
1742
|
+
const r = [], n = Vr(e, t);
|
|
1743
|
+
if (Ur.has(n)) {
|
|
1744
|
+
for (const i of er)
|
|
1745
|
+
r.push(Wr(n, i));
|
|
1731
1746
|
return r;
|
|
1732
1747
|
}
|
|
1733
|
-
const s =
|
|
1734
|
-
if (
|
|
1735
|
-
for (let i =
|
|
1736
|
-
r.push(
|
|
1748
|
+
const s = Vr(t, e);
|
|
1749
|
+
if (Ur.has(s)) {
|
|
1750
|
+
for (let i = mi - 1; i >= 0; i--)
|
|
1751
|
+
r.push(Wr(s, er[i]));
|
|
1737
1752
|
return r;
|
|
1738
1753
|
}
|
|
1739
1754
|
return [];
|
|
1740
1755
|
}
|
|
1741
|
-
function
|
|
1756
|
+
function pi(e) {
|
|
1742
1757
|
return e < 16 ? [1] : e < 24 ? [1] : e < 35 ? [0, 1, 2] : [0, 1, 2];
|
|
1743
1758
|
}
|
|
1744
|
-
function
|
|
1745
|
-
return
|
|
1759
|
+
function wi(e, t) {
|
|
1760
|
+
return pi(t).map((n) => e[n]).filter((n) => n != null);
|
|
1746
1761
|
}
|
|
1747
|
-
function
|
|
1762
|
+
function gi(e, t, r, n) {
|
|
1748
1763
|
if (n <= 0) return 0;
|
|
1749
1764
|
const i = Math.max(1, r - t) / n, o = e - t, a = Math.floor(o / i);
|
|
1750
1765
|
return Math.min(n - 1, Math.max(0, a));
|
|
1751
1766
|
}
|
|
1752
|
-
function
|
|
1767
|
+
function Rn(e, t, r) {
|
|
1753
1768
|
if (!r) return `${e}/${t}`;
|
|
1754
1769
|
const n = t.split("/").pop() ?? t, s = n.includes(".") ? n.slice(0, n.lastIndexOf(".")) : n;
|
|
1755
1770
|
return `${e}/${s}.bin`;
|
|
1756
1771
|
}
|
|
1757
|
-
const
|
|
1772
|
+
const yi = [0.32, 0.24, 0.16, 0.08, 0], _i = yi.map(
|
|
1758
1773
|
(e) => `eyes_${e.toFixed(2)}`
|
|
1759
|
-
),
|
|
1774
|
+
), vi = [
|
|
1760
1775
|
"eyes_0.32",
|
|
1761
1776
|
"eyes_0.16",
|
|
1762
1777
|
"eyes_0.00"
|
|
1763
|
-
],
|
|
1778
|
+
], Si = [
|
|
1764
1779
|
"eyes_0.32",
|
|
1765
1780
|
"eyes_0.16",
|
|
1766
1781
|
"eyes_0.08",
|
|
1767
1782
|
"eyes_0.00"
|
|
1768
|
-
],
|
|
1783
|
+
], Hr = 2, bi = -30, tr = 20, ki = {
|
|
1769
1784
|
fear: -30,
|
|
1770
1785
|
anger: -20,
|
|
1771
1786
|
sad: -10,
|
|
@@ -1774,24 +1789,24 @@ const wi = [0.32, 0.24, 0.16, 0.08, 0], gi = wi.map(
|
|
|
1774
1789
|
happy: 0,
|
|
1775
1790
|
disgust: 20
|
|
1776
1791
|
};
|
|
1777
|
-
function
|
|
1792
|
+
function pr(e) {
|
|
1778
1793
|
return `brow_${e}`;
|
|
1779
1794
|
}
|
|
1780
|
-
function
|
|
1781
|
-
return
|
|
1795
|
+
function wr(e) {
|
|
1796
|
+
return ki[e];
|
|
1782
1797
|
}
|
|
1783
1798
|
function Ge(e) {
|
|
1784
|
-
return Math.max(
|
|
1799
|
+
return Math.max(bi, Math.min(tr, e));
|
|
1785
1800
|
}
|
|
1786
|
-
function
|
|
1801
|
+
function Ti(e, t) {
|
|
1787
1802
|
if (e === t) return [];
|
|
1788
|
-
const r = e < t ?
|
|
1803
|
+
const r = e < t ? Hr : -Hr, n = [];
|
|
1789
1804
|
let s = e;
|
|
1790
1805
|
for (; s !== t; )
|
|
1791
1806
|
s += r, n.push(s);
|
|
1792
1807
|
return n;
|
|
1793
1808
|
}
|
|
1794
|
-
const
|
|
1809
|
+
const Ei = {
|
|
1795
1810
|
fear: "fear",
|
|
1796
1811
|
afraid: "fear",
|
|
1797
1812
|
anxiety: "fear",
|
|
@@ -1814,63 +1829,63 @@ const ki = {
|
|
|
1814
1829
|
disgust: "disgust",
|
|
1815
1830
|
disgusted: "disgust"
|
|
1816
1831
|
};
|
|
1817
|
-
function
|
|
1832
|
+
function et(e, t = "neutral") {
|
|
1818
1833
|
const r = String(e ?? "").trim().toLowerCase();
|
|
1819
|
-
return r ?
|
|
1820
|
-
}
|
|
1821
|
-
function Rn(e) {
|
|
1822
|
-
return e === 0 ? null : mr(wr(e), "eyes_standard");
|
|
1834
|
+
return r ? Ei[r] ?? t : t;
|
|
1823
1835
|
}
|
|
1824
1836
|
function Dn(e) {
|
|
1825
|
-
return
|
|
1837
|
+
return e === 0 ? null : dr(pr(e), "eyes_standard");
|
|
1826
1838
|
}
|
|
1827
|
-
function
|
|
1828
|
-
|
|
1829
|
-
return !t || t === "eyes_standard" ? Dn(e) : e === "neutral" && t === "eyes_standard" ? null : mr(r, t);
|
|
1839
|
+
function Bn(e) {
|
|
1840
|
+
return Dn(wr(e));
|
|
1830
1841
|
}
|
|
1831
|
-
function
|
|
1842
|
+
function $r(e, t) {
|
|
1843
|
+
const r = pr(wr(e));
|
|
1844
|
+
return !t || t === "eyes_standard" ? Bn(e) : e === "neutral" && t === "eyes_standard" ? null : dr(r, t);
|
|
1845
|
+
}
|
|
1846
|
+
function Ai(e, t) {
|
|
1832
1847
|
const r = [];
|
|
1833
1848
|
for (const n of t)
|
|
1834
|
-
r.push(
|
|
1849
|
+
r.push($r(e, n));
|
|
1835
1850
|
for (let n = t.length - 2; n >= 0; n--)
|
|
1836
|
-
r.push(
|
|
1837
|
-
return r.push(
|
|
1838
|
-
}
|
|
1839
|
-
function Ei(e) {
|
|
1840
|
-
return mr(wr(e), "eyes_standard");
|
|
1851
|
+
r.push($r(e, t[n]));
|
|
1852
|
+
return r.push(Bn(e)), r;
|
|
1841
1853
|
}
|
|
1842
|
-
function
|
|
1843
|
-
return
|
|
1854
|
+
function Pi(e) {
|
|
1855
|
+
return dr(pr(e), "eyes_standard");
|
|
1844
1856
|
}
|
|
1845
|
-
const Pi = 6;
|
|
1846
1857
|
function xi(e, t) {
|
|
1858
|
+
return Ti(e, t).map(Pi);
|
|
1859
|
+
}
|
|
1860
|
+
const Ii = 6;
|
|
1861
|
+
function Mi(e, t) {
|
|
1847
1862
|
for (const r of e)
|
|
1848
1863
|
if (t >= r.wtime && t < r.wtime + r.wduration)
|
|
1849
1864
|
return r;
|
|
1850
1865
|
return null;
|
|
1851
1866
|
}
|
|
1852
|
-
function
|
|
1867
|
+
function Ri(e) {
|
|
1853
1868
|
const t = Ge(e);
|
|
1854
|
-
return t >=
|
|
1869
|
+
return t >= tr ? tr : Ge(t + Ii);
|
|
1855
1870
|
}
|
|
1856
|
-
function
|
|
1871
|
+
function Di(e, t, r) {
|
|
1857
1872
|
const n = Ge(r);
|
|
1858
|
-
return
|
|
1873
|
+
return Mi(t, e)?.emphasis ? Ri(n) : n;
|
|
1859
1874
|
}
|
|
1860
|
-
function
|
|
1875
|
+
function qr(e) {
|
|
1861
1876
|
if (!e) return 0;
|
|
1862
1877
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1863
1878
|
if (!t?.[1]) return null;
|
|
1864
1879
|
const r = Number.parseInt(t[1], 10);
|
|
1865
1880
|
return Number.isFinite(r) ? Ge(r) : null;
|
|
1866
1881
|
}
|
|
1867
|
-
function
|
|
1882
|
+
function gt(e, t) {
|
|
1868
1883
|
return e + Math.random() * (t - e);
|
|
1869
1884
|
}
|
|
1870
|
-
function
|
|
1871
|
-
return
|
|
1885
|
+
function Rt() {
|
|
1886
|
+
return gt(14, 32);
|
|
1872
1887
|
}
|
|
1873
|
-
function
|
|
1888
|
+
function Bi(e = {}) {
|
|
1874
1889
|
const {
|
|
1875
1890
|
initialDelayMs: t = 800 + Math.random() * 1200,
|
|
1876
1891
|
intervalMinMs: r = 2200,
|
|
@@ -1891,43 +1906,43 @@ function Ri(e = {}) {
|
|
|
1891
1906
|
}
|
|
1892
1907
|
function w(k, P = f) {
|
|
1893
1908
|
I = k;
|
|
1894
|
-
const
|
|
1895
|
-
|
|
1909
|
+
const U = qr(k);
|
|
1910
|
+
U != null ? g = U : k == null && (g = 0), R(P);
|
|
1896
1911
|
}
|
|
1897
1912
|
function b(k) {
|
|
1898
|
-
return
|
|
1913
|
+
return Dn(k);
|
|
1899
1914
|
}
|
|
1900
|
-
function L(k, P,
|
|
1901
|
-
const
|
|
1902
|
-
if (d =
|
|
1903
|
-
w(b(
|
|
1915
|
+
function L(k, P, U) {
|
|
1916
|
+
const O = Ge(P), q = Ge(U);
|
|
1917
|
+
if (d = q, O === q) {
|
|
1918
|
+
w(b(q));
|
|
1904
1919
|
return;
|
|
1905
1920
|
}
|
|
1906
|
-
const
|
|
1907
|
-
...
|
|
1908
|
-
b(
|
|
1921
|
+
const fe = [
|
|
1922
|
+
...xi(O, q),
|
|
1923
|
+
b(q)
|
|
1909
1924
|
];
|
|
1910
1925
|
m = {
|
|
1911
1926
|
kind: "browBlend",
|
|
1912
|
-
paths:
|
|
1927
|
+
paths: fe,
|
|
1913
1928
|
index: 0,
|
|
1914
|
-
holdUntil: k +
|
|
1915
|
-
targetBrow:
|
|
1916
|
-
}, w(
|
|
1929
|
+
holdUntil: k + Rt(),
|
|
1930
|
+
targetBrow: q
|
|
1931
|
+
}, w(fe[0] ?? null);
|
|
1917
1932
|
}
|
|
1918
1933
|
function B(k, P) {
|
|
1919
1934
|
m = {
|
|
1920
1935
|
kind: "idle",
|
|
1921
|
-
nextBlinkAt: k +
|
|
1936
|
+
nextBlinkAt: k + gt(r, n)
|
|
1922
1937
|
}, c = P, w(b(d), P);
|
|
1923
1938
|
}
|
|
1924
|
-
function
|
|
1925
|
-
const
|
|
1939
|
+
function j(k, P, U) {
|
|
1940
|
+
const O = U ? vi : Math.random() < a ? _i : Si;
|
|
1926
1941
|
m = {
|
|
1927
1942
|
kind: "playing",
|
|
1928
|
-
paths:
|
|
1943
|
+
paths: Ai(P, O),
|
|
1929
1944
|
index: 0,
|
|
1930
|
-
holdUntil: k +
|
|
1945
|
+
holdUntil: k + Rt(),
|
|
1931
1946
|
after: "idle",
|
|
1932
1947
|
blinkEmotion: P
|
|
1933
1948
|
}, c = P, w(m.paths[0] ?? null, P);
|
|
@@ -1935,7 +1950,7 @@ function Ri(e = {}) {
|
|
|
1935
1950
|
function C(k) {
|
|
1936
1951
|
if (m.kind === "browBlend") {
|
|
1937
1952
|
for (; k >= m.holdUntil && m.index < m.paths.length - 1; )
|
|
1938
|
-
m.index += 1, m.holdUntil = k +
|
|
1953
|
+
m.index += 1, m.holdUntil = k + Rt();
|
|
1939
1954
|
const P = m.paths[m.index] ?? null;
|
|
1940
1955
|
w(P), k >= m.holdUntil && m.index >= m.paths.length - 1 && (g = m.targetBrow, d = m.targetBrow, w(b(m.targetBrow)), m = {
|
|
1941
1956
|
kind: "idle",
|
|
@@ -1944,16 +1959,16 @@ function Ri(e = {}) {
|
|
|
1944
1959
|
return;
|
|
1945
1960
|
}
|
|
1946
1961
|
if (m.kind === "idle") {
|
|
1947
|
-
w(b(d), c), k >= m.nextBlinkAt &&
|
|
1962
|
+
w(b(d), c), k >= m.nextBlinkAt && j(k, c, !1);
|
|
1948
1963
|
return;
|
|
1949
1964
|
}
|
|
1950
1965
|
if (m.kind === "doublePause") {
|
|
1951
|
-
w(b(d), m.blinkEmotion), k >= m.resumeAt &&
|
|
1966
|
+
w(b(d), m.blinkEmotion), k >= m.resumeAt && j(k, m.blinkEmotion, !0);
|
|
1952
1967
|
return;
|
|
1953
1968
|
}
|
|
1954
1969
|
if (m.kind === "playing") {
|
|
1955
1970
|
for (; k >= m.holdUntil && m.index < m.paths.length - 1; )
|
|
1956
|
-
m.index += 1, m.holdUntil = k +
|
|
1971
|
+
m.index += 1, m.holdUntil = k + Rt();
|
|
1957
1972
|
if (w(m.paths[m.index] ?? null, m.blinkEmotion), k >= m.holdUntil && m.index >= m.paths.length - 1) {
|
|
1958
1973
|
if (m.after === "resumeIdle") {
|
|
1959
1974
|
B(k + u, f);
|
|
@@ -1962,7 +1977,7 @@ function Ri(e = {}) {
|
|
|
1962
1977
|
if (m.after === "doublePause") {
|
|
1963
1978
|
m = {
|
|
1964
1979
|
kind: "doublePause",
|
|
1965
|
-
resumeAt: k +
|
|
1980
|
+
resumeAt: k + gt(i, o),
|
|
1966
1981
|
blinkEmotion: m.blinkEmotion
|
|
1967
1982
|
}, w(b(d), m.blinkEmotion);
|
|
1968
1983
|
return;
|
|
@@ -1970,7 +1985,7 @@ function Ri(e = {}) {
|
|
|
1970
1985
|
if (m.after === "idle" && Math.random() < s) {
|
|
1971
1986
|
m = {
|
|
1972
1987
|
kind: "doublePause",
|
|
1973
|
-
resumeAt: k +
|
|
1988
|
+
resumeAt: k + gt(i, o),
|
|
1974
1989
|
blinkEmotion: m.blinkEmotion
|
|
1975
1990
|
}, w(b(d), m.blinkEmotion);
|
|
1976
1991
|
return;
|
|
@@ -1982,16 +1997,16 @@ function Ri(e = {}) {
|
|
|
1982
1997
|
return {
|
|
1983
1998
|
advance: C,
|
|
1984
1999
|
setTargetEmotion(k) {
|
|
1985
|
-
const P =
|
|
2000
|
+
const P = et(k, f);
|
|
1986
2001
|
if (P === f) return;
|
|
1987
|
-
const
|
|
1988
|
-
l > 0 && P !== f && !(f === "neutral" && P !== "neutral") &&
|
|
2002
|
+
const U = performance.now();
|
|
2003
|
+
l > 0 && P !== f && !(f === "neutral" && P !== "neutral") && U - S < l || (f = P, c = P, S = U);
|
|
1989
2004
|
},
|
|
1990
2005
|
setTargetEyebrow(k) {
|
|
1991
2006
|
const P = Ge(k);
|
|
1992
2007
|
if (P === d) return;
|
|
1993
|
-
const
|
|
1994
|
-
d = P, !(P ===
|
|
2008
|
+
const U = performance.now(), O = m.kind === "browBlend" ? qr(I) ?? g : g;
|
|
2009
|
+
d = P, !(P === O && m.kind !== "browBlend") && (m.kind === "playing" || m.kind === "doublePause" || L(U, O, P));
|
|
1995
2010
|
},
|
|
1996
2011
|
getTargetEmotion: () => f,
|
|
1997
2012
|
getTargetEyebrow: () => d,
|
|
@@ -1999,13 +2014,13 @@ function Ri(e = {}) {
|
|
|
1999
2014
|
getDrawKey: () => _,
|
|
2000
2015
|
reset() {
|
|
2001
2016
|
f = "neutral", c = "neutral", d = 0, g = 0, S = 0, B(
|
|
2002
|
-
performance.now() +
|
|
2017
|
+
performance.now() + gt(r, n),
|
|
2003
2018
|
"neutral"
|
|
2004
2019
|
);
|
|
2005
2020
|
}
|
|
2006
2021
|
};
|
|
2007
2022
|
}
|
|
2008
|
-
function
|
|
2023
|
+
function Ci() {
|
|
2009
2024
|
const e = document.createElement("video");
|
|
2010
2025
|
e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
|
|
2011
2026
|
let t = !1, r = null, n = "";
|
|
@@ -2048,17 +2063,17 @@ function Di() {
|
|
|
2048
2063
|
}
|
|
2049
2064
|
};
|
|
2050
2065
|
}
|
|
2051
|
-
const
|
|
2052
|
-
function
|
|
2066
|
+
const Fi = 50, Cn = 400;
|
|
2067
|
+
function Li(e, t, r) {
|
|
2053
2068
|
return e.filter((n) => {
|
|
2054
2069
|
const s = n.queueIndex ?? -1;
|
|
2055
2070
|
return s >= t && s <= r;
|
|
2056
2071
|
});
|
|
2057
2072
|
}
|
|
2058
|
-
function
|
|
2073
|
+
function Oi(e, t) {
|
|
2059
2074
|
const r = [];
|
|
2060
2075
|
for (const n of e) {
|
|
2061
|
-
const s =
|
|
2076
|
+
const s = Li(
|
|
2062
2077
|
t,
|
|
2063
2078
|
n.start_word,
|
|
2064
2079
|
n.end_word
|
|
@@ -2067,30 +2082,30 @@ function Fi(e, t) {
|
|
|
2067
2082
|
const i = s[0], o = s[s.length - 1];
|
|
2068
2083
|
r.push({
|
|
2069
2084
|
sentence: n,
|
|
2070
|
-
startMs: Math.max(0, i.wtime -
|
|
2071
|
-
endMs: o.wtime + o.wduration +
|
|
2085
|
+
startMs: Math.max(0, i.wtime - Fi),
|
|
2086
|
+
endMs: o.wtime + o.wduration + Cn
|
|
2072
2087
|
});
|
|
2073
2088
|
}
|
|
2074
2089
|
return r.sort((n, s) => n.startMs - s.startMs);
|
|
2075
2090
|
}
|
|
2076
|
-
function
|
|
2077
|
-
const s =
|
|
2091
|
+
function Ni(e, t, r, n = "neutral") {
|
|
2092
|
+
const s = et(n);
|
|
2078
2093
|
if (t.length === 0) return s;
|
|
2079
2094
|
if (r.length === 0 || e < r[0].wtime)
|
|
2080
|
-
return
|
|
2081
|
-
const i =
|
|
2095
|
+
return et(t[0]?.emotion, s);
|
|
2096
|
+
const i = Oi(t, r);
|
|
2082
2097
|
let o = null;
|
|
2083
2098
|
for (const l of i)
|
|
2084
2099
|
e >= l.startMs && e <= l.endMs && (o = l);
|
|
2085
2100
|
if (o)
|
|
2086
|
-
return
|
|
2101
|
+
return et(o.sentence.emotion, s);
|
|
2087
2102
|
const a = r[r.length - 1], u = a.wtime + a.wduration;
|
|
2088
|
-
return e > u +
|
|
2103
|
+
return e > u + Cn ? et(
|
|
2089
2104
|
t[t.length - 1]?.emotion,
|
|
2090
2105
|
s
|
|
2091
2106
|
) : s;
|
|
2092
2107
|
}
|
|
2093
|
-
function
|
|
2108
|
+
function gr(e, t, r, n, s = In) {
|
|
2094
2109
|
const i = new OffscreenCanvas(r, n), o = i.getContext("2d", { willReadFrequently: !0 });
|
|
2095
2110
|
o.drawImage(e, 0, 0, r, n);
|
|
2096
2111
|
const a = o.getImageData(0, 0, r, n), u = o.createImageData(r, n);
|
|
@@ -2106,38 +2121,38 @@ function yr(e, t, r, n, s = xn) {
|
|
|
2106
2121
|
}
|
|
2107
2122
|
return o.putImageData(u, 0, 0), i;
|
|
2108
2123
|
}
|
|
2109
|
-
let Ke = null,
|
|
2110
|
-
const
|
|
2111
|
-
function
|
|
2112
|
-
Ke = null,
|
|
2124
|
+
let Ke = null, nt = null;
|
|
2125
|
+
const Ft = /* @__PURE__ */ new Map();
|
|
2126
|
+
function Ui() {
|
|
2127
|
+
Ke = null, nt = null, Ft.clear();
|
|
2113
2128
|
}
|
|
2114
|
-
|
|
2115
|
-
function
|
|
2116
|
-
return e ??
|
|
2129
|
+
un(Ui);
|
|
2130
|
+
function Vi(e) {
|
|
2131
|
+
return e ?? nt ?? void 0;
|
|
2117
2132
|
}
|
|
2118
|
-
function
|
|
2133
|
+
function yr(e) {
|
|
2119
2134
|
return new Promise((t, r) => {
|
|
2120
2135
|
const n = new Image();
|
|
2121
2136
|
n.decoding = "async", n.onload = () => t(n), n.onerror = () => r(new Error(`Failed to load image: ${e}`)), n.src = e;
|
|
2122
2137
|
});
|
|
2123
2138
|
}
|
|
2124
|
-
async function
|
|
2125
|
-
return
|
|
2126
|
-
await
|
|
2127
|
-
) :
|
|
2139
|
+
async function Wi(e) {
|
|
2140
|
+
return St() ? li(
|
|
2141
|
+
await at(Ct(), e ?? "")
|
|
2142
|
+
) : yr(Ct());
|
|
2128
2143
|
}
|
|
2129
|
-
async function
|
|
2130
|
-
const s = r ? await
|
|
2144
|
+
async function Kr(e, t, r, n) {
|
|
2145
|
+
const s = r ? await xn(e, n) : await fetch(e).then((l) => {
|
|
2131
2146
|
if (!l.ok) throw new Error(`Failed to load ${e}`);
|
|
2132
2147
|
return l.json();
|
|
2133
2148
|
}), i = s.sheets?.[0];
|
|
2134
2149
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
2135
|
-
const o = r ? await
|
|
2136
|
-
await
|
|
2137
|
-
|
|
2150
|
+
const o = r ? await ci(
|
|
2151
|
+
await at(
|
|
2152
|
+
Rn(t, i.path, r),
|
|
2138
2153
|
n ?? ""
|
|
2139
2154
|
)
|
|
2140
|
-
) : await
|
|
2155
|
+
) : await yr(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
|
|
2141
2156
|
for (const l of s.cells ?? [])
|
|
2142
2157
|
l.path && a.set(l.path, l);
|
|
2143
2158
|
const u = /* @__PURE__ */ new Map();
|
|
@@ -2145,30 +2160,30 @@ async function qr(e, t, r, n) {
|
|
|
2145
2160
|
u.set(l.index, l);
|
|
2146
2161
|
return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: u, diffBase: t };
|
|
2147
2162
|
}
|
|
2148
|
-
async function
|
|
2149
|
-
const t =
|
|
2163
|
+
async function rr(e) {
|
|
2164
|
+
const t = Vi(e), r = St();
|
|
2150
2165
|
if (r && !t)
|
|
2151
2166
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
2152
|
-
if (Ke && (!r ||
|
|
2167
|
+
if (Ke && (!r || nt === (t ?? null))) {
|
|
2153
2168
|
const i = await Ke;
|
|
2154
2169
|
return {
|
|
2155
|
-
...
|
|
2170
|
+
...st(i),
|
|
2156
2171
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
2157
2172
|
};
|
|
2158
2173
|
}
|
|
2159
|
-
|
|
2160
|
-
const n =
|
|
2174
|
+
nt = t ?? null, Ft.clear();
|
|
2175
|
+
const n = ln();
|
|
2161
2176
|
Ke = (async () => {
|
|
2162
|
-
const i = await
|
|
2163
|
-
|
|
2177
|
+
const i = await Wi(t), o = await Kr(
|
|
2178
|
+
fn(),
|
|
2164
2179
|
n,
|
|
2165
2180
|
r,
|
|
2166
2181
|
t
|
|
2167
2182
|
);
|
|
2168
2183
|
let a = null;
|
|
2169
2184
|
try {
|
|
2170
|
-
a = await
|
|
2171
|
-
|
|
2185
|
+
a = await Kr(
|
|
2186
|
+
dn(),
|
|
2172
2187
|
n,
|
|
2173
2188
|
r,
|
|
2174
2189
|
t
|
|
@@ -2179,44 +2194,44 @@ async function nr(e) {
|
|
|
2179
2194
|
return { sil: i, viseme: o, expression: a };
|
|
2180
2195
|
})();
|
|
2181
2196
|
const s = await Ke;
|
|
2182
|
-
return { ...
|
|
2197
|
+
return { ...st(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
2183
2198
|
}
|
|
2184
|
-
async function
|
|
2185
|
-
if (await
|
|
2199
|
+
async function _r(e) {
|
|
2200
|
+
if (await rr(e), !Ke) throw new Error("Assets not loaded");
|
|
2186
2201
|
return Ke;
|
|
2187
2202
|
}
|
|
2188
|
-
function
|
|
2189
|
-
return
|
|
2203
|
+
function st(e) {
|
|
2204
|
+
return En(
|
|
2190
2205
|
e.viseme.atlasMeta,
|
|
2191
2206
|
e.sil.naturalWidth,
|
|
2192
2207
|
e.sil.naturalHeight
|
|
2193
2208
|
);
|
|
2194
2209
|
}
|
|
2195
|
-
function
|
|
2210
|
+
function Hi(e, t) {
|
|
2196
2211
|
const r = document.createElement("canvas");
|
|
2197
2212
|
return r.width = t.w, r.height = t.h, r.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
|
|
2198
2213
|
}
|
|
2199
|
-
async function
|
|
2200
|
-
const n = `${t.diffBase}::${r}`, s =
|
|
2214
|
+
async function Lt(e, t, r) {
|
|
2215
|
+
const n = `${t.diffBase}::${r}`, s = Ft.get(n);
|
|
2201
2216
|
if (s) return s;
|
|
2202
2217
|
const i = (async () => {
|
|
2203
2218
|
const o = t.cellByPath.get(r);
|
|
2204
2219
|
if (!o) throw new Error(`No atlas cell for path: ${r}`);
|
|
2205
|
-
const a =
|
|
2206
|
-
if (
|
|
2207
|
-
const c =
|
|
2220
|
+
const a = An(t.atlasMeta, o), u = st(e);
|
|
2221
|
+
if (Pn(o)) {
|
|
2222
|
+
const c = Hi(t, o), d = document.createElement("canvas");
|
|
2208
2223
|
d.width = u.width, d.height = u.height;
|
|
2209
2224
|
const g = d.getContext("2d");
|
|
2210
2225
|
return g.fillStyle = "#000", g.fillRect(0, 0, u.width, u.height), g.drawImage(c, a.x, a.y), d;
|
|
2211
2226
|
}
|
|
2212
|
-
const l = `${t.diffBase}/${r}`, f = await
|
|
2227
|
+
const l = `${t.diffBase}/${r}`, f = await yr(l);
|
|
2213
2228
|
if (f.naturalWidth === u.width && f.naturalHeight === u.height)
|
|
2214
2229
|
return f;
|
|
2215
2230
|
throw new Error(`Diff PNG wrong size for ${r}`);
|
|
2216
2231
|
})();
|
|
2217
|
-
return
|
|
2232
|
+
return Ft.set(n, i), i;
|
|
2218
2233
|
}
|
|
2219
|
-
async function
|
|
2234
|
+
async function Gr(e, t, r, n, s, i) {
|
|
2220
2235
|
if (s) {
|
|
2221
2236
|
const { width: g, height: S } = s;
|
|
2222
2237
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
@@ -2230,7 +2245,7 @@ async function Kr(e, t, r, n, s, i) {
|
|
|
2230
2245
|
_.clearRect(0, 0, g, S), _.drawImage(m, 0, 0);
|
|
2231
2246
|
return;
|
|
2232
2247
|
}
|
|
2233
|
-
const o = await
|
|
2248
|
+
const o = await _r(), a = Vt(o.viseme.atlasMeta), { width: u, height: l } = st(o);
|
|
2234
2249
|
(e.width !== u || e.height !== l) && (e.width = u, e.height = l);
|
|
2235
2250
|
const f = [], c = e.getContext("2d");
|
|
2236
2251
|
if (c.clearRect(0, 0, u, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
@@ -2242,26 +2257,26 @@ async function Kr(e, t, r, n, s, i) {
|
|
|
2242
2257
|
c.drawImage(t, 0, 0, u, l);
|
|
2243
2258
|
return;
|
|
2244
2259
|
}
|
|
2245
|
-
const d =
|
|
2260
|
+
const d = gr(t, f, u, l, a);
|
|
2246
2261
|
c.drawImage(d, 0, 0);
|
|
2247
2262
|
}
|
|
2248
|
-
async function
|
|
2249
|
-
const n = await
|
|
2263
|
+
async function nr(e, t, r) {
|
|
2264
|
+
const n = await _r(nt ?? void 0), s = Vt(n.viseme.atlasMeta), { width: i, height: o } = st(n);
|
|
2250
2265
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
2251
2266
|
const a = [];
|
|
2252
2267
|
if (t.mouthPath) {
|
|
2253
|
-
const f = new Set(n.viseme.cellByPath.keys()), c =
|
|
2254
|
-
c && a.push(await
|
|
2268
|
+
const f = new Set(n.viseme.cellByPath.keys()), c = mr(t.mouthPath, f) ?? (f.has(t.mouthPath) ? t.mouthPath : null);
|
|
2269
|
+
c && a.push(await Lt(n, n.viseme, c));
|
|
2255
2270
|
}
|
|
2256
2271
|
t.expressionPath && n.expression && a.push(
|
|
2257
|
-
await
|
|
2272
|
+
await Lt(n, n.expression, t.expressionPath)
|
|
2258
2273
|
);
|
|
2259
2274
|
const u = e.getContext("2d");
|
|
2260
2275
|
if (u.clearRect(0, 0, i, o), a.length === 0) {
|
|
2261
2276
|
u.drawImage(n.sil, 0, 0, i, o);
|
|
2262
2277
|
return;
|
|
2263
2278
|
}
|
|
2264
|
-
const l =
|
|
2279
|
+
const l = gr(
|
|
2265
2280
|
n.sil,
|
|
2266
2281
|
a,
|
|
2267
2282
|
i,
|
|
@@ -2270,19 +2285,19 @@ async function sr(e, t, r) {
|
|
|
2270
2285
|
);
|
|
2271
2286
|
u.drawImage(l, 0, 0);
|
|
2272
2287
|
}
|
|
2273
|
-
async function
|
|
2274
|
-
const r = await
|
|
2288
|
+
async function $i(e, t) {
|
|
2289
|
+
const r = await _r(nt ?? void 0), n = Vt(r.viseme.atlasMeta), { width: s, height: i } = st(r), o = [];
|
|
2275
2290
|
if (e.mouthPath) {
|
|
2276
|
-
const f = new Set(r.viseme.cellByPath.keys()), c =
|
|
2277
|
-
c && o.push(await
|
|
2291
|
+
const f = new Set(r.viseme.cellByPath.keys()), c = mr(e.mouthPath, f) ?? (f.has(e.mouthPath) ? e.mouthPath : null);
|
|
2292
|
+
c && o.push(await Lt(r, r.viseme, c));
|
|
2278
2293
|
}
|
|
2279
2294
|
e.expressionPath && r.expression && o.push(
|
|
2280
|
-
await
|
|
2295
|
+
await Lt(r, r.expression, e.expressionPath)
|
|
2281
2296
|
);
|
|
2282
2297
|
const a = new OffscreenCanvas(s, i), u = a.getContext("2d");
|
|
2283
2298
|
if (o.length === 0)
|
|
2284
2299
|
return u.drawImage(r.sil, 0, 0, s, i), a.transferToImageBitmap();
|
|
2285
|
-
const l =
|
|
2300
|
+
const l = gr(
|
|
2286
2301
|
r.sil,
|
|
2287
2302
|
o,
|
|
2288
2303
|
s,
|
|
@@ -2291,20 +2306,20 @@ async function Wi(e, t) {
|
|
|
2291
2306
|
);
|
|
2292
2307
|
return u.drawImage(l, 0, 0), a.transferToImageBitmap();
|
|
2293
2308
|
}
|
|
2294
|
-
async function
|
|
2295
|
-
await
|
|
2309
|
+
async function qi(e) {
|
|
2310
|
+
await nr(e, { mouthPath: null, expressionPath: null });
|
|
2296
2311
|
}
|
|
2297
|
-
let
|
|
2298
|
-
function
|
|
2299
|
-
|
|
2312
|
+
let Fn = null;
|
|
2313
|
+
function zr(e) {
|
|
2314
|
+
Fn = e;
|
|
2300
2315
|
}
|
|
2301
|
-
function
|
|
2302
|
-
return
|
|
2316
|
+
function We() {
|
|
2317
|
+
return Fn;
|
|
2303
2318
|
}
|
|
2304
|
-
function
|
|
2319
|
+
function Ki(e) {
|
|
2305
2320
|
return `${e.from}→${e.to}@${e.fromVtime}`;
|
|
2306
2321
|
}
|
|
2307
|
-
function
|
|
2322
|
+
function jr() {
|
|
2308
2323
|
return {
|
|
2309
2324
|
rafTicksSpeaking: 0,
|
|
2310
2325
|
rafTicksDeduped: 0,
|
|
@@ -2322,12 +2337,12 @@ function zr() {
|
|
|
2322
2337
|
bufferPrefetched: 0
|
|
2323
2338
|
};
|
|
2324
2339
|
}
|
|
2325
|
-
function
|
|
2326
|
-
let e =
|
|
2340
|
+
function Gi() {
|
|
2341
|
+
let e = jr();
|
|
2327
2342
|
const t = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set();
|
|
2328
2343
|
let s = "", i = -1, o = "";
|
|
2329
2344
|
const a = () => {
|
|
2330
|
-
e =
|
|
2345
|
+
e = jr(), t.clear(), r.clear(), n.clear(), s = "", i = -1, o = "";
|
|
2331
2346
|
}, u = (f) => {
|
|
2332
2347
|
t.add(f);
|
|
2333
2348
|
}, l = (f) => {
|
|
@@ -2351,7 +2366,7 @@ function qi() {
|
|
|
2351
2366
|
e.workerStale += 1;
|
|
2352
2367
|
},
|
|
2353
2368
|
onTransitionSample(f, c) {
|
|
2354
|
-
const d =
|
|
2369
|
+
const d = Ki(f);
|
|
2355
2370
|
e.transitionFramesSampled += 1, d !== s && (s = d, i = -1, o !== d && (o = d, e.rifeFramesOmittedByGap += f.omittedByGap)), c && r.add(c), i >= 0 && f.frameIdx > i + 1 && (e.transitionFramesMissed += f.frameIdx - i - 1), i = f.frameIdx;
|
|
2356
2371
|
},
|
|
2357
2372
|
onBufferTick() {
|
|
@@ -2414,62 +2429,62 @@ function qi() {
|
|
|
2414
2429
|
}
|
|
2415
2430
|
};
|
|
2416
2431
|
}
|
|
2417
|
-
const
|
|
2418
|
-
function
|
|
2419
|
-
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] ===
|
|
2432
|
+
const Ln = ar, zi = 200, ji = 100, Yi = 600, On = "__sil__";
|
|
2433
|
+
function Yr(e) {
|
|
2434
|
+
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === On : !1;
|
|
2420
2435
|
}
|
|
2421
|
-
function
|
|
2436
|
+
function vr() {
|
|
2422
2437
|
return { lastDrawnKey: "" };
|
|
2423
2438
|
}
|
|
2424
2439
|
function Pe(e) {
|
|
2425
2440
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
2426
2441
|
}
|
|
2427
|
-
function
|
|
2442
|
+
function Xi(e, t) {
|
|
2428
2443
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
2429
2444
|
return t.transitionCache.transitions;
|
|
2430
|
-
const r =
|
|
2445
|
+
const r = $s(e);
|
|
2431
2446
|
return t && (t.transitionCache = { queueLength: e.length, transitions: r }), r;
|
|
2432
2447
|
}
|
|
2433
|
-
function
|
|
2448
|
+
function Ji(e, t) {
|
|
2434
2449
|
let r = "sil";
|
|
2435
2450
|
for (const n of e)
|
|
2436
2451
|
n.viseme !== "sil" && (t != null && n.vtime > t || (r = n.viseme));
|
|
2437
2452
|
return r;
|
|
2438
2453
|
}
|
|
2439
|
-
function
|
|
2454
|
+
function Qi(e, t, r, n = 120) {
|
|
2440
2455
|
if (r !== "sil")
|
|
2441
2456
|
return r;
|
|
2442
|
-
const s =
|
|
2443
|
-
return s !== "sil" ? s :
|
|
2457
|
+
const s = vn(e, t, n);
|
|
2458
|
+
return s !== "sil" ? s : Ji(e, t);
|
|
2444
2459
|
}
|
|
2445
|
-
function
|
|
2446
|
-
return e === "sil" ? !1 : t ?
|
|
2460
|
+
function Zi(e, t) {
|
|
2461
|
+
return e === "sil" ? !1 : t ? hi(e, "sil", t) : hr(e, "sil").length > 0;
|
|
2447
2462
|
}
|
|
2448
|
-
function
|
|
2449
|
-
return
|
|
2463
|
+
function ea() {
|
|
2464
|
+
return Ln + Yi;
|
|
2450
2465
|
}
|
|
2451
|
-
function
|
|
2452
|
-
return e ??
|
|
2466
|
+
function Ot(e) {
|
|
2467
|
+
return e ?? On;
|
|
2453
2468
|
}
|
|
2454
|
-
function
|
|
2469
|
+
function Sr(e, t, r, n, s = ji) {
|
|
2455
2470
|
if (e.length === 0)
|
|
2456
2471
|
return { diffPath: null, label: "sil" };
|
|
2457
2472
|
if (t >= qe(e))
|
|
2458
2473
|
return { diffPath: null, label: "sil" };
|
|
2459
|
-
const i =
|
|
2474
|
+
const i = Xi(e, n), o = qs(i, t);
|
|
2460
2475
|
if (o) {
|
|
2461
|
-
const u =
|
|
2476
|
+
const u = gn(
|
|
2462
2477
|
o.fromVtime,
|
|
2463
2478
|
o.toVtime,
|
|
2464
2479
|
o.from,
|
|
2465
2480
|
o.to
|
|
2466
2481
|
);
|
|
2467
2482
|
if (t >= u.transStart && t < u.transEnd) {
|
|
2468
|
-
let l =
|
|
2469
|
-
r && (l =
|
|
2470
|
-
const f =
|
|
2483
|
+
let l = hr(o.from, o.to);
|
|
2484
|
+
r && (l = Mn(l, r));
|
|
2485
|
+
const f = wi(l, u.effectiveGapMs);
|
|
2471
2486
|
if (f.length > 0) {
|
|
2472
|
-
const c =
|
|
2487
|
+
const c = gi(
|
|
2473
2488
|
t,
|
|
2474
2489
|
u.transStart,
|
|
2475
2490
|
u.transEnd,
|
|
@@ -2490,21 +2505,21 @@ function br(e, t, r, n, s = Gi) {
|
|
|
2490
2505
|
}
|
|
2491
2506
|
};
|
|
2492
2507
|
}
|
|
2493
|
-
return { diffPath:
|
|
2508
|
+
return { diffPath: _t(o.to), label: o.to };
|
|
2494
2509
|
}
|
|
2495
2510
|
}
|
|
2496
|
-
const a =
|
|
2497
|
-
return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath:
|
|
2511
|
+
const a = vn(e, t, s);
|
|
2512
|
+
return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: _t(a), label: a };
|
|
2498
2513
|
}
|
|
2499
|
-
function
|
|
2500
|
-
const r = t ??
|
|
2501
|
-
return `${
|
|
2514
|
+
function br(e, t) {
|
|
2515
|
+
const r = t ?? Ot(e.expressionPath);
|
|
2516
|
+
return `${Ot(e.mouthPath)}|${r}`;
|
|
2502
2517
|
}
|
|
2503
|
-
function
|
|
2504
|
-
const f =
|
|
2518
|
+
function Xr(e, t, r, n, s, i, o, a, u, l) {
|
|
2519
|
+
const f = Sr(t, r, u, i), c = {
|
|
2505
2520
|
mouthPath: f.diffPath,
|
|
2506
2521
|
expressionPath: n
|
|
2507
|
-
}, d =
|
|
2522
|
+
}, d = br(c, s), g = We();
|
|
2508
2523
|
if (f.transitionMeta && g?.onTransitionSample(f.transitionMeta, f.diffPath), d === i.lastDrawnKey) {
|
|
2509
2524
|
g?.onDrawDeduped();
|
|
2510
2525
|
return;
|
|
@@ -2513,25 +2528,25 @@ function Yr(e, t, r, n, s, i, o, a, u, l) {
|
|
|
2513
2528
|
S === d && (i.lastDrawnKey = d);
|
|
2514
2529
|
});
|
|
2515
2530
|
}
|
|
2516
|
-
function
|
|
2517
|
-
const a = { mouthPath: null, expressionPath: t }, u = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l =
|
|
2531
|
+
function Jr(e, t, r, n, s, i, o = null) {
|
|
2532
|
+
const a = { mouthPath: null, expressionPath: t }, u = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = br(a, r) + u;
|
|
2518
2533
|
!(o != null) && l === n.lastDrawnKey || (i(
|
|
2519
2534
|
o != null ? "idle" : "sil"
|
|
2520
2535
|
), s(e, a, l, (c) => {
|
|
2521
2536
|
c === l && (n.lastDrawnKey = l);
|
|
2522
2537
|
}));
|
|
2523
2538
|
}
|
|
2524
|
-
function
|
|
2539
|
+
function Nn(e, t, r, n, s = yt, i) {
|
|
2525
2540
|
if (r <= t || e.length === 0) return [];
|
|
2526
|
-
const o = i ??
|
|
2541
|
+
const o = i ?? vr(), a = [];
|
|
2527
2542
|
let u = "";
|
|
2528
2543
|
for (let l = t; l < r; l += s) {
|
|
2529
|
-
const f =
|
|
2544
|
+
const f = Sr(
|
|
2530
2545
|
e,
|
|
2531
2546
|
l,
|
|
2532
2547
|
n,
|
|
2533
2548
|
o
|
|
2534
|
-
), c =
|
|
2549
|
+
), c = Ot(f.diffPath);
|
|
2535
2550
|
c !== u && (u = c, a.push({
|
|
2536
2551
|
displayAtMs: l,
|
|
2537
2552
|
mouthPath: f.diffPath,
|
|
@@ -2541,8 +2556,8 @@ function On(e, t, r, n, s = St, i) {
|
|
|
2541
2556
|
}
|
|
2542
2557
|
return a;
|
|
2543
2558
|
}
|
|
2544
|
-
const
|
|
2545
|
-
function
|
|
2559
|
+
const ta = 3;
|
|
2560
|
+
function kr(e) {
|
|
2546
2561
|
let t = 0;
|
|
2547
2562
|
const r = [];
|
|
2548
2563
|
let n = !1, s = !1;
|
|
@@ -2566,7 +2581,7 @@ function Tr(e) {
|
|
|
2566
2581
|
return {
|
|
2567
2582
|
enqueue(a, u, l) {
|
|
2568
2583
|
const f = r.findIndex((c) => c.drawKey === u);
|
|
2569
|
-
f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >=
|
|
2584
|
+
f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >= ta && (r.shift(), We()?.onQueueSuperseded()), r.push({ diffs: a, drawKey: u, onDisplayed: l })), o();
|
|
2570
2585
|
},
|
|
2571
2586
|
reset() {
|
|
2572
2587
|
t += 1, r.length = 0;
|
|
@@ -2579,7 +2594,7 @@ function Tr(e) {
|
|
|
2579
2594
|
}
|
|
2580
2595
|
};
|
|
2581
2596
|
}
|
|
2582
|
-
function
|
|
2597
|
+
function ra(e, t = 2) {
|
|
2583
2598
|
const r = [], n = /* @__PURE__ */ new Set();
|
|
2584
2599
|
let s = 0, i = !1, o = 0;
|
|
2585
2600
|
const a = (l, f) => `${l}|${f}`, u = async () => {
|
|
@@ -2621,7 +2636,7 @@ function ea(e, t = 2) {
|
|
|
2621
2636
|
}
|
|
2622
2637
|
};
|
|
2623
2638
|
}
|
|
2624
|
-
function
|
|
2639
|
+
function na() {
|
|
2625
2640
|
const e = /* @__PURE__ */ new Map(), t = (r) => {
|
|
2626
2641
|
r.bitmap.close();
|
|
2627
2642
|
};
|
|
@@ -2656,13 +2671,13 @@ function ta() {
|
|
|
2656
2671
|
}
|
|
2657
2672
|
};
|
|
2658
2673
|
}
|
|
2659
|
-
function
|
|
2660
|
-
const o =
|
|
2674
|
+
function sa(e, t, r, n, s, i) {
|
|
2675
|
+
const o = Nn(
|
|
2661
2676
|
t,
|
|
2662
2677
|
r,
|
|
2663
2678
|
n,
|
|
2664
2679
|
s,
|
|
2665
|
-
|
|
2680
|
+
yt,
|
|
2666
2681
|
i
|
|
2667
2682
|
);
|
|
2668
2683
|
if (o.length === 0) return { ready: 0, total: 0 };
|
|
@@ -2671,10 +2686,10 @@ function ra(e, t, r, n, s, i) {
|
|
|
2671
2686
|
e.has(u.displayAtMs, u.mouthKey) && (a += 1);
|
|
2672
2687
|
return { ready: a, total: o.length };
|
|
2673
2688
|
}
|
|
2674
|
-
function
|
|
2675
|
-
const t =
|
|
2689
|
+
function ia(e) {
|
|
2690
|
+
const t = na(), r = vr(), n = /* @__PURE__ */ new Set();
|
|
2676
2691
|
let s = "", i = null;
|
|
2677
|
-
const o =
|
|
2692
|
+
const o = ra(
|
|
2678
2693
|
async (c) => {
|
|
2679
2694
|
try {
|
|
2680
2695
|
if (!e.supportsBufferedPlayback) return;
|
|
@@ -2689,12 +2704,12 @@ function na(e) {
|
|
|
2689
2704
|
c.label,
|
|
2690
2705
|
c.mouthPath,
|
|
2691
2706
|
d
|
|
2692
|
-
),
|
|
2707
|
+
), We()?.onBufferPrefetched();
|
|
2693
2708
|
} finally {
|
|
2694
2709
|
n.delete(c.mouthKey);
|
|
2695
2710
|
}
|
|
2696
2711
|
},
|
|
2697
|
-
|
|
2712
|
+
ls
|
|
2698
2713
|
), a = (c) => {
|
|
2699
2714
|
for (const d of c)
|
|
2700
2715
|
t.has(d.displayAtMs, d.mouthKey) || n.has(d.mouthKey) || o.isQueuedOrInflight(0, d.mouthKey) || (n.add(d.mouthKey), o.enqueue({
|
|
@@ -2706,14 +2721,14 @@ function na(e) {
|
|
|
2706
2721
|
expressionPath: null
|
|
2707
2722
|
}
|
|
2708
2723
|
}));
|
|
2709
|
-
}, u = (c, d, g, S =
|
|
2724
|
+
}, u = (c, d, g, S = Gt) => {
|
|
2710
2725
|
if (!e.supportsBufferedPlayback) return;
|
|
2711
|
-
const m = Math.max(0, d -
|
|
2726
|
+
const m = Math.max(0, d - yt * 4), I = Nn(
|
|
2712
2727
|
c,
|
|
2713
2728
|
m,
|
|
2714
2729
|
d + S,
|
|
2715
2730
|
g,
|
|
2716
|
-
|
|
2731
|
+
yt,
|
|
2717
2732
|
r
|
|
2718
2733
|
);
|
|
2719
2734
|
a(I);
|
|
@@ -2722,7 +2737,7 @@ function na(e) {
|
|
|
2722
2737
|
}, f = (c, d) => !(s !== c || i !== d);
|
|
2723
2738
|
return {
|
|
2724
2739
|
reset() {
|
|
2725
|
-
t.reset(), o.reset(), n.clear(), Pe(r), s = "", i = null,
|
|
2740
|
+
t.reset(), o.reset(), n.clear(), Pe(r), s = "", i = null, We()?.onBufferReset();
|
|
2726
2741
|
},
|
|
2727
2742
|
markExternallyDisplayed(c, d) {
|
|
2728
2743
|
l(c.split("|")[0] ?? c, d);
|
|
@@ -2732,12 +2747,12 @@ function na(e) {
|
|
|
2732
2747
|
c.queue,
|
|
2733
2748
|
0,
|
|
2734
2749
|
c.availablePaths,
|
|
2735
|
-
Math.max(Rr,
|
|
2750
|
+
Math.max(Rr, Gt)
|
|
2736
2751
|
);
|
|
2737
2752
|
},
|
|
2738
2753
|
isWarmupReady(c, d = Rr) {
|
|
2739
2754
|
if (!e.supportsBufferedPlayback) return !0;
|
|
2740
|
-
const { ready: g, total: S } =
|
|
2755
|
+
const { ready: g, total: S } = sa(
|
|
2741
2756
|
t,
|
|
2742
2757
|
c.queue,
|
|
2743
2758
|
0,
|
|
@@ -2745,22 +2760,22 @@ function na(e) {
|
|
|
2745
2760
|
c.availablePaths,
|
|
2746
2761
|
r
|
|
2747
2762
|
);
|
|
2748
|
-
return S === 0 ? !1 : g / S >=
|
|
2763
|
+
return S === 0 ? !1 : g / S >= us;
|
|
2749
2764
|
},
|
|
2750
2765
|
getBufferedFrameCount: () => t.size(),
|
|
2751
2766
|
tick(c) {
|
|
2752
|
-
const d =
|
|
2767
|
+
const d = We();
|
|
2753
2768
|
d?.onBufferTick(), u(
|
|
2754
2769
|
c.queue,
|
|
2755
2770
|
c.elapsedMs,
|
|
2756
2771
|
c.availablePaths
|
|
2757
|
-
), t.pruneBefore(c.elapsedMs -
|
|
2758
|
-
const g =
|
|
2772
|
+
), t.pruneBefore(c.elapsedMs - Gt);
|
|
2773
|
+
const g = Sr(
|
|
2759
2774
|
c.queue,
|
|
2760
2775
|
c.elapsedMs,
|
|
2761
2776
|
c.availablePaths,
|
|
2762
2777
|
r
|
|
2763
|
-
), S =
|
|
2778
|
+
), S = Ot(g.diffPath), m = br(
|
|
2764
2779
|
{ mouthPath: g.diffPath, expressionPath: c.expressionPath },
|
|
2765
2780
|
c.expressionDrawKey
|
|
2766
2781
|
), I = () => (l(S, c.expressionPath), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
|
|
@@ -2769,7 +2784,7 @@ function na(e) {
|
|
|
2769
2784
|
const _ = t.findForMouthKey(
|
|
2770
2785
|
S,
|
|
2771
2786
|
c.elapsedMs,
|
|
2772
|
-
|
|
2787
|
+
yt
|
|
2773
2788
|
);
|
|
2774
2789
|
return _ && c.expressionPath != null ? (d?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : _ ? (e.blitBitmap(c.canvas, _.bitmap), l(_.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = m, c.onStatus({
|
|
2775
2790
|
diffPath: _.mouthPath,
|
|
@@ -2778,7 +2793,7 @@ function na(e) {
|
|
|
2778
2793
|
}
|
|
2779
2794
|
};
|
|
2780
2795
|
}
|
|
2781
|
-
const
|
|
2796
|
+
const aa = `
|
|
2782
2797
|
in vec2 aPosition;
|
|
2783
2798
|
out vec2 vTextureCoord;
|
|
2784
2799
|
|
|
@@ -2806,7 +2821,7 @@ void main(void)
|
|
|
2806
2821
|
gl_Position = filterVertexPosition();
|
|
2807
2822
|
vTextureCoord = filterTextureCoord();
|
|
2808
2823
|
}
|
|
2809
|
-
`,
|
|
2824
|
+
`, oa = `
|
|
2810
2825
|
in vec2 vTextureCoord;
|
|
2811
2826
|
out vec4 finalColor;
|
|
2812
2827
|
|
|
@@ -2821,11 +2836,11 @@ void main(void)
|
|
|
2821
2836
|
finalColor = vec4(color.rgb, keep);
|
|
2822
2837
|
}
|
|
2823
2838
|
`;
|
|
2824
|
-
function
|
|
2825
|
-
const t = new
|
|
2826
|
-
glProgram:
|
|
2827
|
-
vertex:
|
|
2828
|
-
fragment:
|
|
2839
|
+
function Qr(e = 5) {
|
|
2840
|
+
const t = new Yn({
|
|
2841
|
+
glProgram: Xn.from({
|
|
2842
|
+
vertex: aa,
|
|
2843
|
+
fragment: oa,
|
|
2829
2844
|
name: "threshold-key-filter"
|
|
2830
2845
|
}),
|
|
2831
2846
|
resources: {
|
|
@@ -2840,16 +2855,16 @@ function Jr(e = 5) {
|
|
|
2840
2855
|
t.resources.thresholdUniforms.uniforms.uThreshold * 255
|
|
2841
2856
|
), t;
|
|
2842
2857
|
}
|
|
2843
|
-
function
|
|
2858
|
+
function ca(e, t, r) {
|
|
2844
2859
|
return e > r || t > r;
|
|
2845
2860
|
}
|
|
2846
|
-
function
|
|
2861
|
+
function ua(e) {
|
|
2847
2862
|
return e ? e.getParameter(e.MAX_TEXTURE_SIZE) : 4096;
|
|
2848
2863
|
}
|
|
2849
|
-
function
|
|
2850
|
-
return t != null && t > 0 ? Math.floor(t) :
|
|
2864
|
+
function la(e, t) {
|
|
2865
|
+
return t != null && t > 0 ? Math.floor(t) : ua(e);
|
|
2851
2866
|
}
|
|
2852
|
-
function
|
|
2867
|
+
function fa(e, t) {
|
|
2853
2868
|
const r = document.createElement("canvas");
|
|
2854
2869
|
r.width = t.w, r.height = t.h;
|
|
2855
2870
|
const n = r.getContext("2d");
|
|
@@ -2857,28 +2872,28 @@ function ua(e, t) {
|
|
|
2857
2872
|
throw new Error("Failed to acquire 2d context for atlas cell crop");
|
|
2858
2873
|
return n.drawImage(e, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
|
|
2859
2874
|
}
|
|
2860
|
-
function
|
|
2875
|
+
function Un(e) {
|
|
2861
2876
|
return fetch(e).then((t) => {
|
|
2862
2877
|
if (!t.ok) throw new Error(`Failed to load image: ${e}`);
|
|
2863
2878
|
return t.blob();
|
|
2864
2879
|
}).then((t) => createImageBitmap(t));
|
|
2865
2880
|
}
|
|
2866
|
-
async function
|
|
2867
|
-
const i = r ? await
|
|
2881
|
+
async function Zr(e, t, r, n, s) {
|
|
2882
|
+
const i = r ? await xn(e, s) : await fetch(e).then((c) => {
|
|
2868
2883
|
if (!c.ok) throw new Error(`Failed to load ${e}`);
|
|
2869
2884
|
return c.json();
|
|
2870
2885
|
}), o = i.sheets?.[0];
|
|
2871
2886
|
if (!o?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
2872
2887
|
const a = /* @__PURE__ */ new Map(), u = async (c, d) => {
|
|
2873
|
-
const g =
|
|
2874
|
-
await
|
|
2875
|
-
) : await
|
|
2876
|
-
if (
|
|
2888
|
+
const g = Rn(t, d, r), S = r ? await oi(
|
|
2889
|
+
await at(g, s ?? "")
|
|
2890
|
+
) : await Un(g);
|
|
2891
|
+
if (ca(S.width, S.height, n))
|
|
2877
2892
|
return console.info(
|
|
2878
2893
|
`[PixiVisemeCompositor] Sheet ${d} (${S.width}x${S.height}) exceeds MAX_TEXTURE_SIZE=${n}; using per-cell crops.`
|
|
2879
2894
|
), { mode: "cells", bitmap: S };
|
|
2880
2895
|
const m = we.from(S);
|
|
2881
|
-
return m.source.scaleMode = "nearest",
|
|
2896
|
+
return m.source.scaleMode = "nearest", { mode: "full", texture: m };
|
|
2882
2897
|
};
|
|
2883
2898
|
a.set(o.index, await u(o.index, o.path));
|
|
2884
2899
|
for (const c of i.sheets ?? [])
|
|
@@ -2897,8 +2912,8 @@ async function Qr(e, t, r, n, s) {
|
|
|
2897
2912
|
sheets: a
|
|
2898
2913
|
};
|
|
2899
2914
|
}
|
|
2900
|
-
async function
|
|
2901
|
-
const r = new
|
|
2915
|
+
async function da(e, t = {}) {
|
|
2916
|
+
const r = new Jn();
|
|
2902
2917
|
try {
|
|
2903
2918
|
await r.init({
|
|
2904
2919
|
canvas: e,
|
|
@@ -2916,9 +2931,9 @@ async function la(e, t = {}) {
|
|
|
2916
2931
|
} catch (v) {
|
|
2917
2932
|
throw r.destroy({ removeView: !1 }), v;
|
|
2918
2933
|
}
|
|
2919
|
-
if (r.renderer.type !==
|
|
2934
|
+
if (r.renderer.type !== Qn.WEBGL)
|
|
2920
2935
|
throw r.destroy({ removeView: !1 }), new Error("Pixi did not initialize a WebGL renderer");
|
|
2921
|
-
const n =
|
|
2936
|
+
const n = la(
|
|
2922
2937
|
r.renderer.gl,
|
|
2923
2938
|
t.maxTextureSize
|
|
2924
2939
|
);
|
|
@@ -2927,22 +2942,22 @@ async function la(e, t = {}) {
|
|
|
2927
2942
|
s = !0, !i && !o && (i = !0, t.onWebGlContextLost?.());
|
|
2928
2943
|
};
|
|
2929
2944
|
a.addEventListener("webglcontextlost", u);
|
|
2930
|
-
const l = new
|
|
2945
|
+
const l = new Pt(we.EMPTY), f = new Pt(we.EMPTY), c = new Pt(we.EMPTY), d = new Pt(we.EMPTY);
|
|
2931
2946
|
d.visible = !1;
|
|
2932
|
-
const g =
|
|
2947
|
+
const g = Qr(5), S = Qr(5);
|
|
2933
2948
|
f.filters = [g], c.filters = [S], r.stage.addChild(l), r.stage.addChild(f), r.stage.addChild(c), r.stage.addChild(d);
|
|
2934
|
-
let m = null, I = null, _ = null, R = null, w = null, b = null, L = 842, B = 1264,
|
|
2949
|
+
let m = null, I = null, _ = null, R = null, w = null, b = null, L = 842, B = 1264, j = null, C = 5;
|
|
2935
2950
|
const k = /* @__PURE__ */ new Map();
|
|
2936
|
-
let P = null,
|
|
2937
|
-
const
|
|
2938
|
-
k.clear(), w = null, b = null, m = null,
|
|
2939
|
-
}),
|
|
2940
|
-
L = v, B =
|
|
2941
|
-
},
|
|
2942
|
-
f.visible = !1, c.visible = !1, f.texture = we.EMPTY, c.texture = we.EMPTY, P = null,
|
|
2943
|
-
},
|
|
2951
|
+
let P = null, U = null, O = null;
|
|
2952
|
+
const q = un(() => {
|
|
2953
|
+
k.clear(), w = null, b = null, m = null, j = null;
|
|
2954
|
+
}), fe = (v, E) => {
|
|
2955
|
+
L = v, B = E, r.renderer.resize(v, E), (e.width !== v || e.height !== E) && (e.width = v, e.height = E);
|
|
2956
|
+
}, D = () => {
|
|
2957
|
+
f.visible = !1, c.visible = !1, f.texture = we.EMPTY, c.texture = we.EMPTY, P = null, U = null;
|
|
2958
|
+
}, Y = () => {
|
|
2944
2959
|
d.visible = !1, m && (l.texture = m, l.visible = !0, l.width = L, l.height = B, l.x = 0, l.y = 0);
|
|
2945
|
-
},
|
|
2960
|
+
}, Q = () => {
|
|
2946
2961
|
if (_) {
|
|
2947
2962
|
try {
|
|
2948
2963
|
_.resource = null;
|
|
@@ -2951,49 +2966,49 @@ async function la(e, t = {}) {
|
|
|
2951
2966
|
_.destroy(), _ = null;
|
|
2952
2967
|
}
|
|
2953
2968
|
I && (I.destroy(!1), I = null), R = null;
|
|
2954
|
-
},
|
|
2955
|
-
const h = v.cellByPath.get(
|
|
2956
|
-
if (!h || !
|
|
2957
|
-
const
|
|
2958
|
-
let M = k.get(
|
|
2969
|
+
}, de = (v, E) => {
|
|
2970
|
+
const h = v.cellByPath.get(E);
|
|
2971
|
+
if (!h || !Pn(h)) return null;
|
|
2972
|
+
const T = `${v.diffBase}::${E}`;
|
|
2973
|
+
let M = k.get(T);
|
|
2959
2974
|
if (!M) {
|
|
2960
2975
|
const F = h.sheet ?? 0, A = v.sheets.get(F);
|
|
2961
2976
|
if (!A) return null;
|
|
2962
|
-
let
|
|
2977
|
+
let W, J = !1;
|
|
2963
2978
|
if (A.mode === "full")
|
|
2964
|
-
|
|
2979
|
+
W = new we({
|
|
2965
2980
|
source: A.texture.source,
|
|
2966
|
-
frame: new
|
|
2981
|
+
frame: new es(h.x, h.y, h.w, h.h)
|
|
2967
2982
|
});
|
|
2968
2983
|
else {
|
|
2969
|
-
const
|
|
2970
|
-
|
|
2984
|
+
const Z = fa(A.bitmap, h);
|
|
2985
|
+
W = we.from(Z), W.source.scaleMode = "nearest", J = !0;
|
|
2971
2986
|
}
|
|
2972
|
-
M = { texture:
|
|
2987
|
+
M = { texture: W, ownsSource: J }, k.set(T, M);
|
|
2973
2988
|
}
|
|
2974
2989
|
return { texture: M.texture, cell: h };
|
|
2975
|
-
},
|
|
2976
|
-
if (!
|
|
2990
|
+
}, ce = (v, E, h, T) => {
|
|
2991
|
+
if (!T || !h)
|
|
2977
2992
|
return v.visible = !1, v.texture = we.EMPTY, !1;
|
|
2978
|
-
const M =
|
|
2993
|
+
const M = de(h, T);
|
|
2979
2994
|
if (!M)
|
|
2980
2995
|
return v.visible = !1, v.texture = we.EMPTY, !1;
|
|
2981
|
-
const F =
|
|
2982
|
-
return
|
|
2983
|
-
},
|
|
2996
|
+
const F = An(h.atlasMeta, M.cell);
|
|
2997
|
+
return E.setThreshold(C), v.texture = M.texture, v.x = F.x, v.y = F.y, v.width = M.cell.w, v.height = M.cell.h, v.visible = !0, !0;
|
|
2998
|
+
}, ue = (v) => {
|
|
2984
2999
|
if (!v || !w) return null;
|
|
2985
|
-
const
|
|
2986
|
-
return
|
|
2987
|
-
},
|
|
2988
|
-
d.visible = !1,
|
|
2989
|
-
const
|
|
2990
|
-
|
|
3000
|
+
const E = j ?? new Set(w.cellByPath.keys());
|
|
3001
|
+
return mr(v, E) ?? (E.has(v) ? v : null);
|
|
3002
|
+
}, se = (v) => {
|
|
3003
|
+
d.visible = !1, Y();
|
|
3004
|
+
const E = ue(v.mouthPath), h = v.expressionPath && b && b.cellByPath.has(v.expressionPath) ? v.expressionPath : null;
|
|
3005
|
+
E !== P ? (ce(f, g, w, E), P = E) : E ? f.visible = !0 : f.visible = !1, h !== U ? (ce(
|
|
2991
3006
|
c,
|
|
2992
3007
|
S,
|
|
2993
3008
|
b,
|
|
2994
3009
|
h
|
|
2995
|
-
),
|
|
2996
|
-
},
|
|
3010
|
+
), U = h) : h ? c.visible = !0 : c.visible = !1;
|
|
3011
|
+
}, me = () => {
|
|
2997
3012
|
if (!(o || s || document.hidden))
|
|
2998
3013
|
try {
|
|
2999
3014
|
r.render();
|
|
@@ -3003,84 +3018,84 @@ async function la(e, t = {}) {
|
|
|
3003
3018
|
return {
|
|
3004
3019
|
async loadAssets(v) {
|
|
3005
3020
|
if (o) return { width: L, height: B, visemePaths: [] };
|
|
3006
|
-
const
|
|
3007
|
-
if (
|
|
3021
|
+
const E = St();
|
|
3022
|
+
if (E && !v)
|
|
3008
3023
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
3009
|
-
const h =
|
|
3010
|
-
await
|
|
3011
|
-
) : await
|
|
3024
|
+
const h = E ? await ui(
|
|
3025
|
+
await at(Ct(), v ?? "")
|
|
3026
|
+
) : await Un(Ct());
|
|
3012
3027
|
m && m.destroy(!0), m = we.from(h), m.source.scaleMode = "linear";
|
|
3013
|
-
const
|
|
3014
|
-
w = await
|
|
3015
|
-
|
|
3016
|
-
E,
|
|
3028
|
+
const T = ln();
|
|
3029
|
+
w = await Zr(
|
|
3030
|
+
fn(),
|
|
3017
3031
|
T,
|
|
3032
|
+
E,
|
|
3018
3033
|
n,
|
|
3019
3034
|
v
|
|
3020
3035
|
);
|
|
3021
3036
|
try {
|
|
3022
|
-
b = await
|
|
3023
|
-
|
|
3024
|
-
E,
|
|
3037
|
+
b = await Zr(
|
|
3038
|
+
dn(),
|
|
3025
3039
|
T,
|
|
3040
|
+
E,
|
|
3026
3041
|
n,
|
|
3027
3042
|
v
|
|
3028
3043
|
);
|
|
3029
3044
|
} catch {
|
|
3030
3045
|
b = null;
|
|
3031
3046
|
}
|
|
3032
|
-
const M =
|
|
3047
|
+
const M = En(
|
|
3033
3048
|
w.atlasMeta,
|
|
3034
3049
|
h.width,
|
|
3035
3050
|
h.height
|
|
3036
3051
|
);
|
|
3037
|
-
return
|
|
3052
|
+
return fe(M.width, M.height), C = Vt(w.atlasMeta), g.setThreshold(C), S.setThreshold(C), j = new Set(w.cellByPath.keys()), k.clear(), Y(), D(), me(), {
|
|
3038
3053
|
width: M.width,
|
|
3039
3054
|
height: M.height,
|
|
3040
3055
|
visemePaths: [...w.cellByPath.keys()]
|
|
3041
3056
|
};
|
|
3042
3057
|
},
|
|
3043
3058
|
getVisemeAtlasPaths() {
|
|
3044
|
-
return
|
|
3059
|
+
return j;
|
|
3045
3060
|
},
|
|
3046
3061
|
drawLiveFrame(v) {
|
|
3047
|
-
o || s || !m || (
|
|
3062
|
+
o || s || !m || (se(v), me());
|
|
3048
3063
|
},
|
|
3049
|
-
drawIdleVideo(v,
|
|
3050
|
-
o || s || document.hidden ||
|
|
3064
|
+
drawIdleVideo(v, E) {
|
|
3065
|
+
o || s || document.hidden || E && !E() || v.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (D(), d.visible = !1, !I || R !== v ? (Q(), _ = new Zn({
|
|
3051
3066
|
resource: v,
|
|
3052
3067
|
autoPlay: !1,
|
|
3053
3068
|
updateFPS: 0
|
|
3054
|
-
}), _.autoUpdate = !1, I = new we({ source: _ }), R = v) : I.source.update(), l.texture = I, l.visible = !0, l.x = 0, l.y = 0, l.width = L, l.height = B,
|
|
3069
|
+
}), _.autoUpdate = !1, I = new we({ source: _ }), R = v) : I.source.update(), l.texture = I, l.visible = !0, l.x = 0, l.y = 0, l.width = L, l.height = B, me());
|
|
3055
3070
|
},
|
|
3056
3071
|
renderSilOnly() {
|
|
3057
|
-
o || s || !m || (
|
|
3072
|
+
o || s || !m || (D(), Y(), me());
|
|
3058
3073
|
},
|
|
3059
3074
|
blitBitmap(v) {
|
|
3060
|
-
o || s || (
|
|
3075
|
+
o || s || (D(), O && (O.destroy(!0), O = null), O = we.from(v), d.texture = O, d.visible = !0, d.x = 0, d.y = 0, d.width = L, d.height = B, l.visible = !1, me());
|
|
3061
3076
|
},
|
|
3062
3077
|
async compositePrefetchFrame(v) {
|
|
3063
3078
|
return null;
|
|
3064
3079
|
},
|
|
3065
|
-
renderFrame:
|
|
3080
|
+
renderFrame: me,
|
|
3066
3081
|
isContextLost() {
|
|
3067
3082
|
return s;
|
|
3068
3083
|
},
|
|
3069
3084
|
dispose() {
|
|
3070
3085
|
if (o) return;
|
|
3071
|
-
o = !0, a.removeEventListener("webglcontextlost", u),
|
|
3072
|
-
for (const { texture:
|
|
3073
|
-
|
|
3086
|
+
o = !0, a.removeEventListener("webglcontextlost", u), q(), Q(), O && (O.destroy(!0), O = null);
|
|
3087
|
+
for (const { texture: E, ownsSource: h } of k.values())
|
|
3088
|
+
E.destroy(h);
|
|
3074
3089
|
k.clear(), m && (m.destroy(!0), m = null);
|
|
3075
|
-
const v = (
|
|
3076
|
-
|
|
3090
|
+
const v = (E) => {
|
|
3091
|
+
E.mode === "full" ? E.texture.destroy(!0) : E.bitmap.close();
|
|
3077
3092
|
};
|
|
3078
3093
|
if (w)
|
|
3079
|
-
for (const
|
|
3080
|
-
v(
|
|
3094
|
+
for (const E of w.sheets.values())
|
|
3095
|
+
v(E);
|
|
3081
3096
|
if (b)
|
|
3082
|
-
for (const
|
|
3083
|
-
v(
|
|
3097
|
+
for (const E of b.sheets.values())
|
|
3098
|
+
v(E);
|
|
3084
3099
|
g.destroy(!0), S.destroy(!0), r.destroy(
|
|
3085
3100
|
{ removeView: !1 },
|
|
3086
3101
|
{ children: !0, texture: !0 }
|
|
@@ -3088,9 +3103,9 @@ async function la(e, t = {}) {
|
|
|
3088
3103
|
}
|
|
3089
3104
|
};
|
|
3090
3105
|
}
|
|
3091
|
-
const
|
|
3092
|
-
async function
|
|
3093
|
-
let t =
|
|
3106
|
+
const en = -1, Dt = 1e5, tn = /* @__PURE__ */ new Map();
|
|
3107
|
+
async function ma(e) {
|
|
3108
|
+
let t = tn.get(e);
|
|
3094
3109
|
if (!t) {
|
|
3095
3110
|
const r = await fetch(e);
|
|
3096
3111
|
if (!r.ok)
|
|
@@ -3098,46 +3113,46 @@ async function fa(e) {
|
|
|
3098
3113
|
`Failed to fetch worker script (${r.status}): ${e}`
|
|
3099
3114
|
);
|
|
3100
3115
|
const n = await r.blob();
|
|
3101
|
-
t = URL.createObjectURL(n),
|
|
3116
|
+
t = URL.createObjectURL(n), tn.set(e, t);
|
|
3102
3117
|
}
|
|
3103
3118
|
return new Worker(t, { name: "visemeDiffPreview" });
|
|
3104
3119
|
}
|
|
3105
|
-
function
|
|
3120
|
+
function ha() {
|
|
3106
3121
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
3107
3122
|
}
|
|
3108
|
-
function
|
|
3123
|
+
function sr(e, t) {
|
|
3109
3124
|
(e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
|
|
3110
3125
|
const r = e.getContext("2d");
|
|
3111
3126
|
r && r.drawImage(t, 0, 0);
|
|
3112
3127
|
}
|
|
3113
|
-
function
|
|
3128
|
+
function rn(e, t) {
|
|
3114
3129
|
let r = 0, n = null;
|
|
3115
|
-
const s =
|
|
3130
|
+
const s = kr(async (i, o) => (await rr(), await nr(e, i), s.isLatestSeq(o)));
|
|
3116
3131
|
return {
|
|
3117
3132
|
usesWorker: !1,
|
|
3118
3133
|
usesPixi: !1,
|
|
3119
3134
|
async loadAssets(i) {
|
|
3120
|
-
const o = await
|
|
3135
|
+
const o = await rr(i);
|
|
3121
3136
|
return n = o.visemePaths ? new Set(o.visemePaths) : null, o;
|
|
3122
3137
|
},
|
|
3123
3138
|
getVisemeAtlasPaths() {
|
|
3124
3139
|
return n;
|
|
3125
3140
|
},
|
|
3126
3141
|
async renderSilOnly() {
|
|
3127
|
-
r += 1, s.reset(), await
|
|
3142
|
+
r += 1, s.reset(), await qi(e);
|
|
3128
3143
|
},
|
|
3129
3144
|
drawLiveFrame(i, o, a, u) {
|
|
3130
3145
|
s.enqueue(o, a, u);
|
|
3131
3146
|
},
|
|
3132
3147
|
async compositePrefetchFrame(i, o) {
|
|
3133
3148
|
try {
|
|
3134
|
-
return await
|
|
3149
|
+
return await $i(i);
|
|
3135
3150
|
} catch {
|
|
3136
3151
|
return null;
|
|
3137
3152
|
}
|
|
3138
3153
|
},
|
|
3139
3154
|
blitBitmap(i, o) {
|
|
3140
|
-
|
|
3155
|
+
sr(i, o);
|
|
3141
3156
|
},
|
|
3142
3157
|
drawIdleVideo() {
|
|
3143
3158
|
},
|
|
@@ -3145,8 +3160,8 @@ function tn(e, t) {
|
|
|
3145
3160
|
async renderViseme(i, o) {
|
|
3146
3161
|
r += 1;
|
|
3147
3162
|
const a = r;
|
|
3148
|
-
t.onStatus?.(o), await
|
|
3149
|
-
mouthPath:
|
|
3163
|
+
t.onStatus?.(o), await nr(i, {
|
|
3164
|
+
mouthPath: _t(o),
|
|
3150
3165
|
expressionPath: null
|
|
3151
3166
|
});
|
|
3152
3167
|
},
|
|
@@ -3155,11 +3170,11 @@ function tn(e, t) {
|
|
|
3155
3170
|
}
|
|
3156
3171
|
};
|
|
3157
3172
|
}
|
|
3158
|
-
function
|
|
3173
|
+
function pa(e, t, r) {
|
|
3159
3174
|
let n = null, s = 1, i = 0, o = !1, a = !1, u = null;
|
|
3160
3175
|
const l = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
3161
|
-
let c =
|
|
3162
|
-
const d =
|
|
3176
|
+
let c = Dt;
|
|
3177
|
+
const d = kr(async (R, w, b) => (l.set(w, {
|
|
3163
3178
|
drawKey: b.drawKey,
|
|
3164
3179
|
onDisplayed: b.onDisplayed
|
|
3165
3180
|
}), await I(
|
|
@@ -3172,10 +3187,10 @@ function ma(e, t, r) {
|
|
|
3172
3187
|
void 0,
|
|
3173
3188
|
!0
|
|
3174
3189
|
), !1)), g = (R) => {
|
|
3175
|
-
if (R ===
|
|
3190
|
+
if (R === en) {
|
|
3176
3191
|
let L = -1, B;
|
|
3177
|
-
for (const [
|
|
3178
|
-
|
|
3192
|
+
for (const [j, C] of l)
|
|
3193
|
+
j >= L && (L = j, B = C);
|
|
3179
3194
|
L >= 0 && l.delete(L), B?.onDisplayed?.(B.drawKey);
|
|
3180
3195
|
return;
|
|
3181
3196
|
}
|
|
@@ -3186,16 +3201,16 @@ function ma(e, t, r) {
|
|
|
3186
3201
|
}, I = (R, w, b = !1) => {
|
|
3187
3202
|
if (a) return Promise.resolve();
|
|
3188
3203
|
const L = s++;
|
|
3189
|
-
return new Promise((B,
|
|
3204
|
+
return new Promise((B, j) => {
|
|
3190
3205
|
S.set(L, {
|
|
3191
3206
|
resolve: (C) => B(C),
|
|
3192
|
-
reject:
|
|
3207
|
+
reject: j,
|
|
3193
3208
|
generation: typeof R.generation == "number" ? R.generation : void 0,
|
|
3194
3209
|
expectRenderDone: b
|
|
3195
3210
|
}), m({ ...R, requestId: L });
|
|
3196
3211
|
});
|
|
3197
3212
|
}, _ = (async () => {
|
|
3198
|
-
n = await
|
|
3213
|
+
n = await ma(r), n.onmessage = (R) => {
|
|
3199
3214
|
if (a) return;
|
|
3200
3215
|
const w = R.data;
|
|
3201
3216
|
if (w.type === "status") {
|
|
@@ -3203,9 +3218,9 @@ function ma(e, t, r) {
|
|
|
3203
3218
|
return;
|
|
3204
3219
|
}
|
|
3205
3220
|
if (w.type === "frame") {
|
|
3206
|
-
if (w.generation <= -
|
|
3207
|
-
const B = -w.generation,
|
|
3208
|
-
f.delete(B),
|
|
3221
|
+
if (w.generation <= -Dt) {
|
|
3222
|
+
const B = -w.generation, j = f.get(B);
|
|
3223
|
+
f.delete(B), j?.resolve(w.bitmap);
|
|
3209
3224
|
return;
|
|
3210
3225
|
}
|
|
3211
3226
|
const L = w.generation < 0;
|
|
@@ -3213,18 +3228,18 @@ function ma(e, t, r) {
|
|
|
3213
3228
|
w.bitmap.close();
|
|
3214
3229
|
return;
|
|
3215
3230
|
}
|
|
3216
|
-
if (L && !(w.generation ===
|
|
3217
|
-
const
|
|
3218
|
-
if (!d.isLatestSeq(
|
|
3219
|
-
|
|
3231
|
+
if (L && !(w.generation === en)) {
|
|
3232
|
+
const j = -w.generation;
|
|
3233
|
+
if (!d.isLatestSeq(j)) {
|
|
3234
|
+
We()?.onWorkerStale(), w.bitmap.close();
|
|
3220
3235
|
return;
|
|
3221
3236
|
}
|
|
3222
3237
|
}
|
|
3223
3238
|
if (L && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
3224
|
-
|
|
3239
|
+
We()?.onWorkerStale(), w.bitmap.close();
|
|
3225
3240
|
return;
|
|
3226
3241
|
}
|
|
3227
|
-
|
|
3242
|
+
sr(e, w.bitmap), w.bitmap.close(), L && g(w.generation);
|
|
3228
3243
|
return;
|
|
3229
3244
|
}
|
|
3230
3245
|
const b = S.get(w.requestId);
|
|
@@ -3267,7 +3282,7 @@ function ma(e, t, r) {
|
|
|
3267
3282
|
return await I({
|
|
3268
3283
|
type: "loadAssets",
|
|
3269
3284
|
keyHex: R,
|
|
3270
|
-
urls:
|
|
3285
|
+
urls: As(je())
|
|
3271
3286
|
}) ?? { width: 842, height: 1264 };
|
|
3272
3287
|
},
|
|
3273
3288
|
getVisemeAtlasPaths() {
|
|
@@ -3275,7 +3290,7 @@ function ma(e, t, r) {
|
|
|
3275
3290
|
},
|
|
3276
3291
|
async renderSilOnly() {
|
|
3277
3292
|
if (a || (await _, a)) return;
|
|
3278
|
-
i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c =
|
|
3293
|
+
i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c = Dt;
|
|
3279
3294
|
const R = i;
|
|
3280
3295
|
await I({ type: "cancelLiveDraws" }), await I(
|
|
3281
3296
|
{ type: "renderSil", generation: R },
|
|
@@ -3309,7 +3324,7 @@ function ma(e, t, r) {
|
|
|
3309
3324
|
});
|
|
3310
3325
|
},
|
|
3311
3326
|
blitBitmap(R, w) {
|
|
3312
|
-
|
|
3327
|
+
sr(R, w);
|
|
3313
3328
|
},
|
|
3314
3329
|
drawIdleVideo() {
|
|
3315
3330
|
},
|
|
@@ -3339,7 +3354,7 @@ function ma(e, t, r) {
|
|
|
3339
3354
|
},
|
|
3340
3355
|
dispose() {
|
|
3341
3356
|
if (!a) {
|
|
3342
|
-
a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve: R }) => R(null)), f.clear(), c =
|
|
3357
|
+
a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve: R }) => R(null)), f.clear(), c = Dt;
|
|
3343
3358
|
for (const [, R] of S)
|
|
3344
3359
|
R.resolve();
|
|
3345
3360
|
S.clear(), n?.terminate(), n = null;
|
|
@@ -3347,13 +3362,13 @@ function ma(e, t, r) {
|
|
|
3347
3362
|
}
|
|
3348
3363
|
};
|
|
3349
3364
|
}
|
|
3350
|
-
async function
|
|
3351
|
-
const r = await
|
|
3365
|
+
async function wa(e, t) {
|
|
3366
|
+
const r = await da(e, {
|
|
3352
3367
|
onWebGlContextLost: t.onWebGlContextLost,
|
|
3353
3368
|
maxTextureSize: t.pixiMaxTextureSize
|
|
3354
3369
|
});
|
|
3355
3370
|
let n = 0, s = null, i = !1;
|
|
3356
|
-
const o =
|
|
3371
|
+
const o = kr(async (a, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (We()?.onWorkerStale(), !1) : (r.drawLiveFrame(a), o.isLatestSeq(u)));
|
|
3357
3372
|
return {
|
|
3358
3373
|
usesWorker: !1,
|
|
3359
3374
|
usesPixi: !0,
|
|
@@ -3393,7 +3408,7 @@ async function ha(e, t) {
|
|
|
3393
3408
|
n += 1;
|
|
3394
3409
|
const l = n;
|
|
3395
3410
|
o.reset(), t.onStatus?.(u), r.drawLiveFrame({
|
|
3396
|
-
mouthPath:
|
|
3411
|
+
mouthPath: _t(u),
|
|
3397
3412
|
expressionPath: null
|
|
3398
3413
|
});
|
|
3399
3414
|
},
|
|
@@ -3402,23 +3417,23 @@ async function ha(e, t) {
|
|
|
3402
3417
|
}
|
|
3403
3418
|
};
|
|
3404
3419
|
}
|
|
3405
|
-
function
|
|
3406
|
-
if (!
|
|
3407
|
-
return
|
|
3408
|
-
const r =
|
|
3420
|
+
function nn(e, t) {
|
|
3421
|
+
if (!ha())
|
|
3422
|
+
return rn(e, t);
|
|
3423
|
+
const r = as(t.workerScriptUrl);
|
|
3409
3424
|
try {
|
|
3410
|
-
return
|
|
3425
|
+
return pa(e, t, r);
|
|
3411
3426
|
} catch {
|
|
3412
|
-
return
|
|
3427
|
+
return rn(e, t);
|
|
3413
3428
|
}
|
|
3414
3429
|
}
|
|
3415
|
-
function
|
|
3430
|
+
function ga(e, t = {}) {
|
|
3416
3431
|
if (t.preferLegacyRenderer)
|
|
3417
|
-
return
|
|
3432
|
+
return nn(e, t);
|
|
3418
3433
|
let r = null, n = !1, s = null, i = !1;
|
|
3419
3434
|
const o = () => r ? Promise.resolve(r) : (s || (s = (async () => {
|
|
3420
3435
|
try {
|
|
3421
|
-
const a = await
|
|
3436
|
+
const a = await wa(e, t);
|
|
3422
3437
|
if (i)
|
|
3423
3438
|
throw a.dispose(), new Error("Renderer disposed during Pixi init");
|
|
3424
3439
|
return n = !0, r = a, a;
|
|
@@ -3428,7 +3443,7 @@ function pa(e, t = {}) {
|
|
|
3428
3443
|
return console.warn(
|
|
3429
3444
|
"[AiTwin] Pixi WebGL renderer unavailable, using Canvas2D fallback:",
|
|
3430
3445
|
a
|
|
3431
|
-
), r =
|
|
3446
|
+
), r = nn(e, t), n = !1, r;
|
|
3432
3447
|
}
|
|
3433
3448
|
})()), s);
|
|
3434
3449
|
return {
|
|
@@ -3472,15 +3487,15 @@ function pa(e, t = {}) {
|
|
|
3472
3487
|
}
|
|
3473
3488
|
};
|
|
3474
3489
|
}
|
|
3475
|
-
class
|
|
3490
|
+
class ya extends Error {
|
|
3476
3491
|
constructor(t, r) {
|
|
3477
3492
|
super(`${t} timed out after ${Math.round(r / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
3478
3493
|
}
|
|
3479
3494
|
}
|
|
3480
|
-
function
|
|
3495
|
+
function Xt(e, t, r) {
|
|
3481
3496
|
return new Promise((n, s) => {
|
|
3482
3497
|
const i = globalThis.setTimeout(() => {
|
|
3483
|
-
s(new
|
|
3498
|
+
s(new ya(r, t));
|
|
3484
3499
|
}, t);
|
|
3485
3500
|
e.then(
|
|
3486
3501
|
(o) => {
|
|
@@ -3492,15 +3507,15 @@ function Jt(e, t, r) {
|
|
|
3492
3507
|
);
|
|
3493
3508
|
});
|
|
3494
3509
|
}
|
|
3495
|
-
const
|
|
3510
|
+
const _a = {
|
|
3496
3511
|
position: "relative",
|
|
3497
3512
|
display: "inline-block",
|
|
3498
3513
|
lineHeight: 0
|
|
3499
|
-
},
|
|
3514
|
+
}, va = {
|
|
3500
3515
|
display: "block",
|
|
3501
3516
|
maxWidth: "100%",
|
|
3502
3517
|
height: "auto"
|
|
3503
|
-
},
|
|
3518
|
+
}, Sa = {
|
|
3504
3519
|
position: "absolute",
|
|
3505
3520
|
inset: 0,
|
|
3506
3521
|
display: "flex",
|
|
@@ -3512,22 +3527,22 @@ const ga = {
|
|
|
3512
3527
|
fontSize: "0.875rem",
|
|
3513
3528
|
textAlign: "center"
|
|
3514
3529
|
};
|
|
3515
|
-
function
|
|
3516
|
-
return
|
|
3530
|
+
function wt(e) {
|
|
3531
|
+
return ds(e) ? bn : Sn;
|
|
3517
3532
|
}
|
|
3518
|
-
function
|
|
3533
|
+
function Le(e, t) {
|
|
3519
3534
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
3520
3535
|
}
|
|
3521
|
-
const
|
|
3536
|
+
const Da = $n(function({
|
|
3522
3537
|
id: t,
|
|
3523
3538
|
avatarId: r,
|
|
3524
3539
|
faceId: n,
|
|
3525
3540
|
assets: s,
|
|
3526
3541
|
authToken: i,
|
|
3527
3542
|
apiBase: o,
|
|
3528
|
-
ttsEngineId: a =
|
|
3543
|
+
ttsEngineId: a = tt,
|
|
3529
3544
|
voiceId: u,
|
|
3530
|
-
speakingRate: l =
|
|
3545
|
+
speakingRate: l = Ut,
|
|
3531
3546
|
className: f,
|
|
3532
3547
|
style: c,
|
|
3533
3548
|
canvasStyle: d,
|
|
@@ -3541,66 +3556,66 @@ const Ma = Hn(function({
|
|
|
3541
3556
|
onRealtimeLipsyncDebug: b,
|
|
3542
3557
|
onFrameRenderStats: L,
|
|
3543
3558
|
lipsyncBufferedPlayback: B = !0,
|
|
3544
|
-
lipsyncPlaybackWarmupMs:
|
|
3559
|
+
lipsyncPlaybackWarmupMs: j = 1500,
|
|
3545
3560
|
pixiMaxTextureSize: C
|
|
3546
3561
|
}, k) {
|
|
3547
|
-
const P =
|
|
3548
|
-
|
|
3549
|
-
const
|
|
3550
|
-
|
|
3551
|
-
const
|
|
3562
|
+
const P = $(null), U = $(null), O = $(null), q = $(B);
|
|
3563
|
+
q.current = B;
|
|
3564
|
+
const fe = $(j);
|
|
3565
|
+
fe.current = j;
|
|
3566
|
+
const D = $(0), Y = $(vr()), Q = $(Bi()), de = $(0), ce = $(0), ue = $(0), se = $(null), me = $(null), v = $(!1), E = $(!1), h = $(!1), T = $("sil"), M = $(0), F = $(!1), A = $(
|
|
3552
3567
|
null
|
|
3553
|
-
),
|
|
3554
|
-
|
|
3555
|
-
const y =
|
|
3556
|
-
return
|
|
3568
|
+
), W = $(!1), [J, Z] = Ze("idle"), [ee, Se] = Ze(null), [ye, Be] = Ze(!1), [ot, xe] = Ze(!1), [Wt, Tr] = Ze({ width: 842, height: 1264 }), [p, x] = Ze(0), G = $(!1), X = $(i ?? null), oe = o?.trim() || vt, Ce = $(null), te = $(null), be = $(!1), Ie = $({ width: 842, height: 1264 }), Oe = $(null), ct = $("sil"), Me = $(void 0), Ye = $(/* @__PURE__ */ new Map()), bt = $(I), le = $(S), Ne = $(m), ut = $(R), lt = $(w), Ue = $(b), he = $(L), pe = $(Gi());
|
|
3569
|
+
bt.current = I, le.current = S, Ne.current = m, ut.current = R, lt.current = w, Ue.current = b, he.current = L, $e(() => {
|
|
3570
|
+
const y = pe.current;
|
|
3571
|
+
return zr(y), () => zr(null);
|
|
3557
3572
|
}, []);
|
|
3558
|
-
const
|
|
3573
|
+
const ke = Ae(
|
|
3559
3574
|
(y) => {
|
|
3560
|
-
const N = y?.ttsEngineId ?? a ??
|
|
3561
|
-
return { ttsEngineId: N, voiceId:
|
|
3575
|
+
const N = y?.ttsEngineId ?? a ?? te.current?.ttsEngineId ?? tt, H = y?.voiceId ?? u ?? te.current?.voiceId ?? wt(N);
|
|
3576
|
+
return { ttsEngineId: N, voiceId: H };
|
|
3562
3577
|
},
|
|
3563
3578
|
[a, u]
|
|
3564
|
-
),
|
|
3565
|
-
|
|
3566
|
-
}, []),
|
|
3579
|
+
), _e = Ae((y) => {
|
|
3580
|
+
Se(y), Ne.current?.(y);
|
|
3581
|
+
}, []), Ve = Ae(
|
|
3567
3582
|
(y) => {
|
|
3568
|
-
|
|
3583
|
+
Z(y), g?.(y);
|
|
3569
3584
|
},
|
|
3570
3585
|
[g]
|
|
3571
|
-
),
|
|
3572
|
-
Or(
|
|
3573
|
-
onLipsyncDebug: (y) =>
|
|
3586
|
+
), re = $(
|
|
3587
|
+
Or(Ve, oe, {
|
|
3588
|
+
onLipsyncDebug: (y) => Ue.current?.(y)
|
|
3574
3589
|
})
|
|
3575
|
-
),
|
|
3576
|
-
$e(() => (
|
|
3577
|
-
|
|
3578
|
-
|
|
3590
|
+
), ne = $(null);
|
|
3591
|
+
$e(() => (re.current = Or(
|
|
3592
|
+
Ve,
|
|
3593
|
+
oe,
|
|
3579
3594
|
{
|
|
3580
|
-
onLipsyncDebug: (y) =>
|
|
3595
|
+
onLipsyncDebug: (y) => Ue.current?.(y)
|
|
3581
3596
|
}
|
|
3582
|
-
), i &&
|
|
3583
|
-
|
|
3584
|
-
const y =
|
|
3585
|
-
y && (y.disconnect(),
|
|
3586
|
-
}), [
|
|
3587
|
-
const Er = Ae(() => (
|
|
3588
|
-
|
|
3597
|
+
), i && re.current.setDeveloperToken(i), re.current.setTtsEngineId(a), () => {
|
|
3598
|
+
re.current.stop();
|
|
3599
|
+
const y = ne.current;
|
|
3600
|
+
y && (y.disconnect(), ne.current = null);
|
|
3601
|
+
}), [Ve, i, a, oe]);
|
|
3602
|
+
const Er = Ae(() => (ne.current || (ne.current = ai(
|
|
3603
|
+
Ve,
|
|
3589
3604
|
{
|
|
3590
3605
|
speakingRate: l,
|
|
3591
|
-
onUserTranscript: (y, N) =>
|
|
3592
|
-
onBotOutput: (y) =>
|
|
3593
|
-
onLipsyncDebug: (y) =>
|
|
3606
|
+
onUserTranscript: (y, N) => ut.current?.(y, N),
|
|
3607
|
+
onBotOutput: (y) => lt.current?.(y),
|
|
3608
|
+
onLipsyncDebug: (y) => Ue.current?.(y)
|
|
3594
3609
|
}
|
|
3595
|
-
),
|
|
3596
|
-
|
|
3597
|
-
}, []),
|
|
3598
|
-
|
|
3610
|
+
), ne.current.setTtsEngineId(a)), ne.current), [Ve, l, a]), Te = Ae(() => {
|
|
3611
|
+
se.current != null && (clearTimeout(se.current), se.current = null);
|
|
3612
|
+
}, []), Fe = Ae(() => {
|
|
3613
|
+
me.current != null && (clearTimeout(me.current), me.current = null), h.current = !1;
|
|
3599
3614
|
}, []), Ar = Ae(() => {
|
|
3600
|
-
|
|
3601
|
-
if (
|
|
3602
|
-
|
|
3603
|
-
|
|
3615
|
+
!W.current || !A.current || (Fe(), h.current = !0, me.current = setTimeout(() => {
|
|
3616
|
+
if (me.current = null, Le(
|
|
3617
|
+
re.current,
|
|
3618
|
+
ne.current
|
|
3604
3619
|
).isSpeaking()) {
|
|
3605
3620
|
h.current = !1;
|
|
3606
3621
|
return;
|
|
@@ -3616,556 +3631,556 @@ const Ma = Hn(function({
|
|
|
3616
3631
|
}
|
|
3617
3632
|
y.restart(), y.setActive(!0);
|
|
3618
3633
|
const N = y.getVideo();
|
|
3619
|
-
let
|
|
3620
|
-
const
|
|
3621
|
-
|
|
3622
|
-
},
|
|
3623
|
-
|
|
3634
|
+
let H = !1;
|
|
3635
|
+
const z = () => {
|
|
3636
|
+
H || (H = !0, N.removeEventListener("playing", K), h.current = !1);
|
|
3637
|
+
}, K = () => {
|
|
3638
|
+
z();
|
|
3624
3639
|
};
|
|
3625
|
-
if (N.addEventListener("playing",
|
|
3626
|
-
|
|
3640
|
+
if (N.addEventListener("playing", K, { once: !0 }), N.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !N.paused) {
|
|
3641
|
+
z();
|
|
3627
3642
|
return;
|
|
3628
3643
|
}
|
|
3629
|
-
setTimeout(
|
|
3630
|
-
},
|
|
3631
|
-
}, [
|
|
3632
|
-
if (Te(),
|
|
3644
|
+
setTimeout(z, 300);
|
|
3645
|
+
}, zi));
|
|
3646
|
+
}, [Fe]), Xe = Ae(() => {
|
|
3647
|
+
if (Te(), le.current?.("sil"), v.current = !1, !W.current || !A.current) {
|
|
3633
3648
|
h.current = !1;
|
|
3634
3649
|
return;
|
|
3635
3650
|
}
|
|
3636
3651
|
Ar();
|
|
3637
|
-
}, [Te, Ar]),
|
|
3652
|
+
}, [Te, Ar]), Ht = Ae(
|
|
3638
3653
|
async (y) => {
|
|
3639
|
-
const N =
|
|
3654
|
+
const N = ce.current, H = U.current, z = P.current, K = () => {
|
|
3640
3655
|
y?.fallbackOnly || (v.current = !1);
|
|
3641
3656
|
};
|
|
3642
|
-
if (!
|
|
3643
|
-
|
|
3657
|
+
if (!H || !z || !ye) {
|
|
3658
|
+
K();
|
|
3644
3659
|
return;
|
|
3645
3660
|
}
|
|
3646
|
-
if (
|
|
3647
|
-
|
|
3648
|
-
|
|
3661
|
+
if (Le(
|
|
3662
|
+
re.current,
|
|
3663
|
+
ne.current
|
|
3649
3664
|
).isSpeaking()) {
|
|
3650
|
-
|
|
3665
|
+
K();
|
|
3651
3666
|
return;
|
|
3652
3667
|
}
|
|
3653
3668
|
if (y?.fallbackOnly) {
|
|
3654
|
-
if (!v.current || (Pe(
|
|
3655
|
-
|
|
3656
|
-
|
|
3669
|
+
if (!v.current || (Pe(Y.current), await H.renderSilOnly(), N !== ce.current) || Le(
|
|
3670
|
+
re.current,
|
|
3671
|
+
ne.current
|
|
3657
3672
|
).isSpeaking())
|
|
3658
3673
|
return;
|
|
3659
|
-
|
|
3674
|
+
Xe();
|
|
3660
3675
|
return;
|
|
3661
3676
|
}
|
|
3662
|
-
if (
|
|
3663
|
-
Pe(
|
|
3677
|
+
if (Yr(Y.current)) {
|
|
3678
|
+
Pe(Y.current), Xe();
|
|
3664
3679
|
return;
|
|
3665
3680
|
}
|
|
3666
|
-
if (
|
|
3667
|
-
if (Pe(
|
|
3668
|
-
|
|
3669
|
-
|
|
3681
|
+
if (q.current && H.supportsBufferedPlayback && !y?.fallbackOnly) {
|
|
3682
|
+
if (Pe(Y.current), O.current?.reset(), await H.renderSilOnly(), N !== ce.current || Le(
|
|
3683
|
+
re.current,
|
|
3684
|
+
ne.current
|
|
3670
3685
|
).isSpeaking())
|
|
3671
3686
|
return;
|
|
3672
|
-
|
|
3687
|
+
Xe();
|
|
3673
3688
|
return;
|
|
3674
3689
|
}
|
|
3675
|
-
const Ee =
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3690
|
+
const Ee = Qi(
|
|
3691
|
+
Le(
|
|
3692
|
+
re.current,
|
|
3693
|
+
ne.current
|
|
3679
3694
|
).getVisemeQueue(),
|
|
3680
3695
|
M.current,
|
|
3681
|
-
|
|
3682
|
-
),
|
|
3696
|
+
T.current
|
|
3697
|
+
), dt = Zi(
|
|
3683
3698
|
Ee,
|
|
3684
|
-
|
|
3699
|
+
Oe.current
|
|
3685
3700
|
);
|
|
3686
|
-
if (Pe(
|
|
3687
|
-
if (await
|
|
3688
|
-
|
|
3689
|
-
|
|
3701
|
+
if (Pe(Y.current), !dt) {
|
|
3702
|
+
if (await H.renderSilOnly(), N !== ce.current || Le(
|
|
3703
|
+
re.current,
|
|
3704
|
+
ne.current
|
|
3690
3705
|
).isSpeaking())
|
|
3691
3706
|
return;
|
|
3692
|
-
|
|
3707
|
+
Xe();
|
|
3693
3708
|
return;
|
|
3694
3709
|
}
|
|
3695
3710
|
try {
|
|
3696
|
-
await
|
|
3711
|
+
await H.renderViseme(z, "sil", {
|
|
3697
3712
|
from: Ee,
|
|
3698
|
-
transitionDurationMs:
|
|
3713
|
+
transitionDurationMs: Ln
|
|
3699
3714
|
});
|
|
3700
|
-
} catch (
|
|
3701
|
-
if (
|
|
3702
|
-
throw
|
|
3715
|
+
} catch (Je) {
|
|
3716
|
+
if (Je?.name !== "AbortError")
|
|
3717
|
+
throw Je;
|
|
3703
3718
|
}
|
|
3704
|
-
if (N !==
|
|
3705
|
-
|
|
3719
|
+
if (N !== ce.current) {
|
|
3720
|
+
K();
|
|
3706
3721
|
return;
|
|
3707
3722
|
}
|
|
3708
|
-
if (
|
|
3709
|
-
|
|
3710
|
-
|
|
3723
|
+
if (Le(
|
|
3724
|
+
re.current,
|
|
3725
|
+
ne.current
|
|
3711
3726
|
).isSpeaking()) {
|
|
3712
|
-
|
|
3727
|
+
K();
|
|
3713
3728
|
return;
|
|
3714
3729
|
}
|
|
3715
|
-
|
|
3730
|
+
Xe();
|
|
3716
3731
|
},
|
|
3717
|
-
[
|
|
3718
|
-
),
|
|
3719
|
-
if (
|
|
3720
|
-
|
|
3721
|
-
const y =
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
}),
|
|
3725
|
-
|
|
3726
|
-
},
|
|
3727
|
-
}, [Te,
|
|
3732
|
+
[ye, Xe]
|
|
3733
|
+
), ft = Ae(() => {
|
|
3734
|
+
if (E.current || v.current) return;
|
|
3735
|
+
E.current = !0, v.current = !0, Te();
|
|
3736
|
+
const y = ce.current;
|
|
3737
|
+
Ht().finally(() => {
|
|
3738
|
+
E.current = !1;
|
|
3739
|
+
}), se.current = setTimeout(() => {
|
|
3740
|
+
se.current = null, y === ce.current && Ht({ fallbackOnly: !0 });
|
|
3741
|
+
}, ea());
|
|
3742
|
+
}, [Te, Ht]), Pr = Ae(async () => {
|
|
3728
3743
|
const y = Math.floor(Date.now() / 1e3);
|
|
3729
|
-
if (
|
|
3730
|
-
return
|
|
3731
|
-
const N =
|
|
3732
|
-
|
|
3733
|
-
const
|
|
3734
|
-
return
|
|
3735
|
-
key:
|
|
3736
|
-
expiresAt:
|
|
3737
|
-
},
|
|
3738
|
-
}, [
|
|
3744
|
+
if (Ce.current && y < Ce.current.expiresAt - 60)
|
|
3745
|
+
return Ce.current.key;
|
|
3746
|
+
const N = X.current ?? await zt();
|
|
3747
|
+
X.current = N, re.current.setDeveloperToken(N);
|
|
3748
|
+
const H = await vs(N, oe);
|
|
3749
|
+
return Ce.current = {
|
|
3750
|
+
key: H.value,
|
|
3751
|
+
expiresAt: H.expiresAt
|
|
3752
|
+
}, H.value;
|
|
3753
|
+
}, [oe]);
|
|
3739
3754
|
$e(() => {
|
|
3740
|
-
i && (
|
|
3755
|
+
i && (X.current = i, re.current.setDeveloperToken(i));
|
|
3741
3756
|
}, [i]), $e(() => {
|
|
3742
|
-
|
|
3757
|
+
re.current.setTtsEngineId(a), ne.current?.setTtsEngineId(a), te.current && (te.current.ttsEngineId = a);
|
|
3743
3758
|
}, [a]), $e(() => {
|
|
3744
|
-
const y = u ??
|
|
3745
|
-
|
|
3759
|
+
const y = u ?? wt(a);
|
|
3760
|
+
te.current && (te.current.voiceId = y);
|
|
3746
3761
|
}, [u, a]);
|
|
3747
3762
|
const He = Mr(
|
|
3748
|
-
() =>
|
|
3763
|
+
() => Ts(r, n),
|
|
3749
3764
|
[r, n]
|
|
3750
|
-
),
|
|
3765
|
+
), Vn = Mr(() => s ? JSON.stringify(s) : He ? `face:${He}` : `id:${t ?? ""}`, [s, He, t]);
|
|
3751
3766
|
return $e(() => {
|
|
3752
3767
|
if (!t && !s && !He) {
|
|
3753
|
-
|
|
3768
|
+
_e("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
3754
3769
|
return;
|
|
3755
3770
|
}
|
|
3756
3771
|
let y = !1;
|
|
3757
|
-
|
|
3772
|
+
be.current = !1, Be(!1), xe(!1), Se(null), te.current = null, A.current = null, W.current = !1;
|
|
3758
3773
|
const N = P.current;
|
|
3759
3774
|
if (!N) return;
|
|
3760
|
-
let
|
|
3775
|
+
let H = null;
|
|
3761
3776
|
return (async () => {
|
|
3762
3777
|
try {
|
|
3763
|
-
let
|
|
3778
|
+
let z, K, ve, Ee;
|
|
3764
3779
|
if (s)
|
|
3765
|
-
|
|
3780
|
+
z = s, K = a, ve = u ?? wt(K);
|
|
3766
3781
|
else if (He)
|
|
3767
|
-
|
|
3782
|
+
le.current?.("loadFace"), z = Br(He), K = a, ve = u ?? wt(K);
|
|
3768
3783
|
else {
|
|
3769
|
-
|
|
3770
|
-
const V = await
|
|
3771
|
-
|
|
3784
|
+
le.current?.("getAiTwin");
|
|
3785
|
+
const V = await Xt(
|
|
3786
|
+
hs(t),
|
|
3772
3787
|
3e4,
|
|
3773
3788
|
"getAiTwin"
|
|
3774
3789
|
);
|
|
3775
3790
|
if (y) return;
|
|
3776
3791
|
if (!V.faceId?.trim())
|
|
3777
3792
|
throw new Error("getAiTwin returned no faceId");
|
|
3778
|
-
|
|
3793
|
+
K = V.ttsEngineId, ve = u ?? V.voiceId ?? wt(K), Ee = V.knowledgeContextId?.trim() || void 0, z = Br(V.faceId);
|
|
3779
3794
|
}
|
|
3780
|
-
|
|
3781
|
-
const
|
|
3782
|
-
|
|
3783
|
-
preferLegacyRenderer:
|
|
3795
|
+
te.current = { ttsEngineId: K, voiceId: ve, personaId: Ee }, Es(z), A.current = Ci();
|
|
3796
|
+
const dt = !!(s && !ze(s));
|
|
3797
|
+
H = ga(N, {
|
|
3798
|
+
preferLegacyRenderer: dt,
|
|
3784
3799
|
pixiMaxTextureSize: C,
|
|
3785
3800
|
onStatus: (V) => {
|
|
3786
|
-
y ||
|
|
3801
|
+
y || le.current?.(V);
|
|
3787
3802
|
},
|
|
3788
3803
|
onError: (V) => {
|
|
3789
|
-
y ||
|
|
3804
|
+
y || _e(V);
|
|
3790
3805
|
},
|
|
3791
3806
|
shouldAcceptLiveFrame: () => {
|
|
3792
|
-
const V =
|
|
3793
|
-
|
|
3794
|
-
|
|
3807
|
+
const V = Le(
|
|
3808
|
+
re.current,
|
|
3809
|
+
ne.current
|
|
3795
3810
|
);
|
|
3796
3811
|
return (V.isSpeaking() || V.isWarmingUp()) && !v.current;
|
|
3797
3812
|
},
|
|
3798
3813
|
onWebGlContextLost: () => {
|
|
3799
|
-
y ||
|
|
3800
|
-
y ||
|
|
3814
|
+
y || G.current || (G.current = !0, queueMicrotask(() => {
|
|
3815
|
+
y || x((V) => V + 1);
|
|
3801
3816
|
}));
|
|
3802
3817
|
}
|
|
3803
|
-
}),
|
|
3818
|
+
}), U.current = H, O.current = ia(H), G.current = !1, ((V) => {
|
|
3804
3819
|
const ae = () => {
|
|
3805
|
-
if (!V ||
|
|
3820
|
+
if (!V || fe.current <= 0)
|
|
3806
3821
|
return !1;
|
|
3807
|
-
const
|
|
3808
|
-
return
|
|
3822
|
+
const ge = U.current;
|
|
3823
|
+
return ge ? q.current && ge.supportsBufferedPlayback ? !0 : ge.usesPixi : !1;
|
|
3809
3824
|
};
|
|
3810
|
-
|
|
3811
|
-
})(!0),
|
|
3812
|
-
const
|
|
3825
|
+
re.current.setLipsyncWarmupHold(V, ae), ne.current?.setLipsyncWarmupHold(V, ae);
|
|
3826
|
+
})(!0), le.current?.("auth");
|
|
3827
|
+
const mt = X.current ?? i ?? await Xt(zt(), 3e4, "getAuthToken");
|
|
3813
3828
|
if (y) return;
|
|
3814
|
-
|
|
3815
|
-
const
|
|
3829
|
+
X.current = mt, re.current.setDeveloperToken(mt), re.current.setTtsEngineId(K);
|
|
3830
|
+
const kt = St() ? await Pr() : void 0;
|
|
3816
3831
|
if (y) return;
|
|
3817
|
-
|
|
3818
|
-
const
|
|
3819
|
-
|
|
3832
|
+
le.current?.("loadAssets");
|
|
3833
|
+
const ie = await Xt(
|
|
3834
|
+
H.loadAssets(kt),
|
|
3820
3835
|
18e4,
|
|
3821
3836
|
"load face assets"
|
|
3822
3837
|
);
|
|
3823
|
-
if (!y &&
|
|
3824
|
-
|
|
3825
|
-
y ||
|
|
3838
|
+
if (!y && ie.width > 0 && ie.height > 0 && (Ie.current = ie, Tr(ie)), y) return;
|
|
3839
|
+
Oe.current = H.getVisemeAtlasPaths(), be.current = !0, Be(!0), bt.current?.(), H.renderSilOnly().then(() => {
|
|
3840
|
+
y || le.current?.("sil");
|
|
3826
3841
|
}), (async () => {
|
|
3827
3842
|
try {
|
|
3828
|
-
const V = await
|
|
3843
|
+
const V = await di(kt);
|
|
3829
3844
|
if (await A.current.load(V), y) return;
|
|
3830
|
-
|
|
3845
|
+
W.current = !0, xe(!0), Pe(Y.current), A.current.setActive(!0);
|
|
3831
3846
|
const ae = A.current.getVideo();
|
|
3832
|
-
|
|
3847
|
+
H.usesPixi ? H.drawIdleVideo(ae) : await Gr(
|
|
3833
3848
|
N,
|
|
3834
3849
|
ae,
|
|
3835
3850
|
null,
|
|
3836
3851
|
void 0,
|
|
3837
|
-
|
|
3838
|
-
), y ||
|
|
3852
|
+
Ie.current
|
|
3853
|
+
), y || le.current?.("idle");
|
|
3839
3854
|
} catch (V) {
|
|
3840
3855
|
if (y) return;
|
|
3841
|
-
|
|
3856
|
+
W.current = !1, xe(!1), console.warn("[AiTwin] Idle video unavailable:", V);
|
|
3842
3857
|
}
|
|
3843
3858
|
})();
|
|
3844
|
-
} catch (
|
|
3859
|
+
} catch (z) {
|
|
3845
3860
|
if (y) return;
|
|
3846
|
-
if (
|
|
3847
|
-
|
|
3861
|
+
if (z instanceof Jt) {
|
|
3862
|
+
_e(z.message);
|
|
3848
3863
|
return;
|
|
3849
3864
|
}
|
|
3850
|
-
|
|
3865
|
+
_e(z instanceof Error ? z.message : "Failed to load AI twin");
|
|
3851
3866
|
}
|
|
3852
3867
|
})(), () => {
|
|
3853
|
-
y = !0, A.current?.dispose(),
|
|
3868
|
+
y = !0, A.current?.dispose(), H?.dispose(), U.current = null;
|
|
3854
3869
|
};
|
|
3855
|
-
}, [
|
|
3870
|
+
}, [Vn, s, He, t, a, u, i, C, Pr, _e, p]), $e(() => {
|
|
3856
3871
|
const y = { current: !1 }, N = () => {
|
|
3857
|
-
const
|
|
3858
|
-
|
|
3859
|
-
|
|
3872
|
+
const H = P.current, z = U.current, K = Le(
|
|
3873
|
+
re.current,
|
|
3874
|
+
ne.current
|
|
3860
3875
|
);
|
|
3861
|
-
if (!
|
|
3862
|
-
|
|
3876
|
+
if (!H || !z || !ye) {
|
|
3877
|
+
de.current = requestAnimationFrame(N);
|
|
3863
3878
|
return;
|
|
3864
3879
|
}
|
|
3865
3880
|
if (document.hidden) {
|
|
3866
|
-
A.current?.setActive(!1),
|
|
3881
|
+
A.current?.setActive(!1), de.current = requestAnimationFrame(N);
|
|
3867
3882
|
return;
|
|
3868
3883
|
}
|
|
3869
|
-
const
|
|
3870
|
-
|
|
3871
|
-
const
|
|
3884
|
+
const ve = K.isSpeaking(), Ee = K.isWarmingUp(), dt = ve && !F.current, Je = F.current && !ve;
|
|
3885
|
+
dt && (Te(), Fe(), v.current = !1, E.current = !1, Pe(Y.current), O.current?.reset(), pe.current.reset(), Me.current = void 0, ue.current = 0, T.current = "sil", M.current = 0, A.current?.setActive(!1)), Je && (Q.current.reset(), A.current?.setActive(!1), O.current?.reset(), ft());
|
|
3886
|
+
const mt = Je || v.current || h.current, kt = B && z.supportsBufferedPlayback;
|
|
3872
3887
|
if (Ee) {
|
|
3873
|
-
|
|
3874
|
-
const
|
|
3875
|
-
|
|
3876
|
-
const V =
|
|
3877
|
-
queue:
|
|
3888
|
+
W.current && A.current?.setActive(!1);
|
|
3889
|
+
const ie = K.getVisemeQueue();
|
|
3890
|
+
ie.length > 0 && D.current === 0 && (D.current = performance.now()), Q.current.advance(performance.now());
|
|
3891
|
+
const V = Q.current.getExpressionPath(), ae = Q.current.getDrawKey(), ge = {
|
|
3892
|
+
queue: ie,
|
|
3878
3893
|
elapsedMs: 0,
|
|
3879
3894
|
expressionPath: V,
|
|
3880
3895
|
expressionDrawKey: ae,
|
|
3881
|
-
availablePaths:
|
|
3896
|
+
availablePaths: Oe.current
|
|
3882
3897
|
};
|
|
3883
|
-
let
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
)) :
|
|
3888
|
-
|
|
3889
|
-
|
|
3898
|
+
let Re = !1;
|
|
3899
|
+
kt && O.current ? (O.current.warmupTick(ge), Re = O.current.isWarmupReady(
|
|
3900
|
+
ge,
|
|
3901
|
+
fe.current
|
|
3902
|
+
)) : z.usesPixi && Xr(
|
|
3903
|
+
H,
|
|
3904
|
+
ie,
|
|
3890
3905
|
0,
|
|
3891
3906
|
V,
|
|
3892
3907
|
ae,
|
|
3893
|
-
|
|
3894
|
-
(
|
|
3895
|
-
|
|
3896
|
-
|
|
3908
|
+
Y.current,
|
|
3909
|
+
(ht, Tt, $t, Et) => {
|
|
3910
|
+
z.drawLiveFrame(ht, Tt, $t, (De) => {
|
|
3911
|
+
Et?.(De), K.isWarmingUp() && De !== "" && !Yr({ lastDrawnKey: De }) && (D.current = 0, K.releaseWarmupHold());
|
|
3897
3912
|
});
|
|
3898
3913
|
},
|
|
3899
|
-
(
|
|
3900
|
-
|
|
3914
|
+
(ht) => {
|
|
3915
|
+
le.current?.(ht.label);
|
|
3901
3916
|
},
|
|
3902
|
-
|
|
3917
|
+
Oe.current
|
|
3903
3918
|
);
|
|
3904
|
-
const
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
), (
|
|
3919
|
+
const Qe = D.current > 0 && performance.now() - D.current > cs;
|
|
3920
|
+
le.current?.(
|
|
3921
|
+
Re ? "buffer ready" : "buffering lipsync…"
|
|
3922
|
+
), (Re || Qe) && (D.current = 0, K.releaseWarmupHold()), F.current = K.isSpeaking(), de.current = requestAnimationFrame(N);
|
|
3908
3923
|
return;
|
|
3909
3924
|
}
|
|
3910
|
-
if (
|
|
3911
|
-
|
|
3912
|
-
const
|
|
3913
|
-
|
|
3914
|
-
const ae =
|
|
3915
|
-
ae !== "sil" && (
|
|
3916
|
-
const
|
|
3925
|
+
if (ve) {
|
|
3926
|
+
W.current && A.current?.setActive(!1);
|
|
3927
|
+
const ie = K.getVisemeQueue(), V = K.getPlaybackElapsedMs();
|
|
3928
|
+
Ys(ie, V), M.current = V;
|
|
3929
|
+
const ae = ie.length > 0 ? Nt(ie, V) : "sil";
|
|
3930
|
+
ae !== "sil" && (T.current = ae);
|
|
3931
|
+
const ge = Ni(
|
|
3917
3932
|
V,
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3933
|
+
K.getSentenceEmotions(),
|
|
3934
|
+
K.getWordQueue(),
|
|
3935
|
+
K.getStreamMood()
|
|
3921
3936
|
);
|
|
3922
|
-
|
|
3923
|
-
|
|
3937
|
+
Q.current.setTargetEmotion(ge), Q.current.setTargetEyebrow(
|
|
3938
|
+
Di(
|
|
3924
3939
|
V,
|
|
3925
|
-
|
|
3926
|
-
|
|
3940
|
+
K.getWordQueue(),
|
|
3941
|
+
wr(ge)
|
|
3927
3942
|
)
|
|
3928
|
-
),
|
|
3929
|
-
const
|
|
3943
|
+
), Q.current.advance(performance.now());
|
|
3944
|
+
const Re = Q.current.getExpressionPath(), Qe = Q.current.getDrawKey(), ht = (De, qt, pt, Kt) => {
|
|
3930
3945
|
const xr = {
|
|
3931
|
-
label:
|
|
3946
|
+
label: ct.current,
|
|
3932
3947
|
elapsedMs: V,
|
|
3933
|
-
mouthPath:
|
|
3934
|
-
transitionMeta:
|
|
3948
|
+
mouthPath: qt.mouthPath,
|
|
3949
|
+
transitionMeta: Me.current
|
|
3935
3950
|
};
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
),
|
|
3940
|
-
const
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
),
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
),
|
|
3951
|
+
Ye.current.set(pt, xr), O.current?.markExternallyDisplayed(
|
|
3952
|
+
pt,
|
|
3953
|
+
Re
|
|
3954
|
+
), z.drawLiveFrame(De, qt, pt, (At) => {
|
|
3955
|
+
const Wn = Ye.current.get(At) ?? xr;
|
|
3956
|
+
Ye.current.delete(At), pe.current.onDrawDisplayed(
|
|
3957
|
+
Wn,
|
|
3958
|
+
ie
|
|
3959
|
+
), O.current?.markExternallyDisplayed(
|
|
3960
|
+
At,
|
|
3961
|
+
Re
|
|
3962
|
+
), Kt?.(At);
|
|
3948
3963
|
});
|
|
3949
|
-
},
|
|
3950
|
-
|
|
3951
|
-
},
|
|
3952
|
-
let
|
|
3953
|
-
|
|
3954
|
-
canvas:
|
|
3955
|
-
queue:
|
|
3964
|
+
}, Tt = (De) => {
|
|
3965
|
+
ct.current = De.label, Me.current = De.transitionMeta, le.current?.(De.label);
|
|
3966
|
+
}, $t = B && z.supportsBufferedPlayback;
|
|
3967
|
+
let Et = !1;
|
|
3968
|
+
$t && O.current && (Et = O.current.tick({
|
|
3969
|
+
canvas: H,
|
|
3970
|
+
queue: ie,
|
|
3956
3971
|
elapsedMs: V,
|
|
3957
|
-
expressionPath:
|
|
3958
|
-
expressionDrawKey:
|
|
3959
|
-
playbackState:
|
|
3960
|
-
availablePaths:
|
|
3961
|
-
onStatus:
|
|
3962
|
-
onDisplayed: (
|
|
3963
|
-
|
|
3972
|
+
expressionPath: Re,
|
|
3973
|
+
expressionDrawKey: Qe,
|
|
3974
|
+
playbackState: Y.current,
|
|
3975
|
+
availablePaths: Oe.current,
|
|
3976
|
+
onStatus: Tt,
|
|
3977
|
+
onDisplayed: (qt, pt, Kt) => {
|
|
3978
|
+
pe.current.onDrawDisplayed(
|
|
3964
3979
|
{
|
|
3965
|
-
label:
|
|
3980
|
+
label: Kt,
|
|
3966
3981
|
elapsedMs: V,
|
|
3967
|
-
mouthPath:
|
|
3968
|
-
transitionMeta:
|
|
3982
|
+
mouthPath: pt,
|
|
3983
|
+
transitionMeta: Me.current
|
|
3969
3984
|
},
|
|
3970
|
-
|
|
3985
|
+
ie
|
|
3971
3986
|
);
|
|
3972
3987
|
}
|
|
3973
|
-
}).usedBuffer),
|
|
3974
|
-
|
|
3975
|
-
|
|
3988
|
+
}).usedBuffer), Et || Xr(
|
|
3989
|
+
H,
|
|
3990
|
+
ie,
|
|
3976
3991
|
V,
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
),
|
|
3984
|
-
|
|
3992
|
+
Re,
|
|
3993
|
+
Qe,
|
|
3994
|
+
Y.current,
|
|
3995
|
+
ht,
|
|
3996
|
+
Tt,
|
|
3997
|
+
Oe.current
|
|
3998
|
+
), pe.current.onRafTickSpeaking(), he.current?.(
|
|
3999
|
+
pe.current.snapshot(ie, V)
|
|
3985
4000
|
);
|
|
3986
|
-
} else if (!
|
|
3987
|
-
const
|
|
4001
|
+
} else if (!mt && W.current && A.current) {
|
|
4002
|
+
const ie = A.current, V = ie.getVideo();
|
|
3988
4003
|
if (V.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
3989
|
-
|
|
3990
|
-
const ae = () => !
|
|
3991
|
-
|
|
3992
|
-
|
|
4004
|
+
ie.setActive(!0);
|
|
4005
|
+
const ae = () => !K.isSpeaking() && !v.current && !h.current;
|
|
4006
|
+
z.usesPixi ? (z.drawIdleVideo(V, ae), ae() && le.current?.("idle")) : y.current || (y.current = !0, Gr(
|
|
4007
|
+
H,
|
|
3993
4008
|
V,
|
|
3994
4009
|
null,
|
|
3995
4010
|
void 0,
|
|
3996
|
-
|
|
4011
|
+
Ie.current,
|
|
3997
4012
|
ae
|
|
3998
|
-
).then(() =>
|
|
4013
|
+
).then(() => le.current?.("idle")).finally(() => {
|
|
3999
4014
|
y.current = !1;
|
|
4000
4015
|
}));
|
|
4001
4016
|
} else
|
|
4002
|
-
|
|
4003
|
-
|
|
4017
|
+
Jr(
|
|
4018
|
+
H,
|
|
4004
4019
|
null,
|
|
4005
4020
|
"__sil__",
|
|
4006
|
-
|
|
4007
|
-
(ae,
|
|
4008
|
-
(ae) =>
|
|
4021
|
+
Y.current,
|
|
4022
|
+
(ae, ge, Re, Qe) => z.drawLiveFrame(ae, ge, Re, Qe),
|
|
4023
|
+
(ae) => le.current?.(ae)
|
|
4009
4024
|
);
|
|
4010
|
-
} else
|
|
4011
|
-
|
|
4025
|
+
} else mt || Jr(
|
|
4026
|
+
H,
|
|
4012
4027
|
null,
|
|
4013
4028
|
"__sil__",
|
|
4014
|
-
|
|
4015
|
-
(
|
|
4016
|
-
(
|
|
4029
|
+
Y.current,
|
|
4030
|
+
(ie, V, ae, ge) => z.drawLiveFrame(ie, V, ae, ge),
|
|
4031
|
+
(ie) => le.current?.(ie)
|
|
4017
4032
|
);
|
|
4018
|
-
F.current =
|
|
4033
|
+
F.current = ve, de.current = requestAnimationFrame(N);
|
|
4019
4034
|
};
|
|
4020
|
-
return
|
|
4021
|
-
cancelAnimationFrame(
|
|
4035
|
+
return de.current = requestAnimationFrame(N), () => {
|
|
4036
|
+
cancelAnimationFrame(de.current), Te(), Fe(), re.current.stop(), ne.current?.stop();
|
|
4022
4037
|
};
|
|
4023
4038
|
}, [
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4039
|
+
ye,
|
|
4040
|
+
ot,
|
|
4041
|
+
ft,
|
|
4027
4042
|
Te,
|
|
4028
|
-
|
|
4029
|
-
]),
|
|
4043
|
+
Fe
|
|
4044
|
+
]), qn(
|
|
4030
4045
|
k,
|
|
4031
4046
|
() => ({
|
|
4032
4047
|
speakText: async (y, N) => {
|
|
4033
|
-
const
|
|
4034
|
-
if (!
|
|
4035
|
-
const
|
|
4036
|
-
if (!
|
|
4048
|
+
const H = y.trim();
|
|
4049
|
+
if (!H) return;
|
|
4050
|
+
const z = U.current;
|
|
4051
|
+
if (!z || !be.current && !ye)
|
|
4037
4052
|
throw new Error("AI twin is not ready");
|
|
4038
|
-
const { ttsEngineId:
|
|
4039
|
-
|
|
4053
|
+
const { ttsEngineId: K, voiceId: ve } = ke(N);
|
|
4054
|
+
Se(null), ce.current += 1, Te(), Fe(), v.current = !1, E.current = !1, T.current = "sil", M.current = 0, Pe(Y.current), Q.current.reset(), F.current = !1;
|
|
4040
4055
|
try {
|
|
4041
|
-
|
|
4042
|
-
voiceId:
|
|
4056
|
+
W.current ? (A.current?.setActive(!1), A.current?.restart(), Pe(Y.current)) : await z.renderSilOnly(), await re.current.speak(H, {
|
|
4057
|
+
voiceId: ve,
|
|
4043
4058
|
speakingRate: N?.speakingRate ?? l,
|
|
4044
|
-
ttsEngineId:
|
|
4059
|
+
ttsEngineId: K
|
|
4045
4060
|
});
|
|
4046
4061
|
} catch (Ee) {
|
|
4047
|
-
throw
|
|
4062
|
+
throw _e(Ee instanceof Error ? Ee.message : "TTS failed"), Ee;
|
|
4048
4063
|
}
|
|
4049
4064
|
},
|
|
4050
4065
|
stop: () => {
|
|
4051
|
-
|
|
4066
|
+
ce.current += 1, Te(), Fe(), v.current = !1, E.current = !1, re.current.stop(), ne.current?.stop(), Pe(Y.current), O.current?.reset(), D.current = 0, F.current = !1, ft();
|
|
4052
4067
|
},
|
|
4053
4068
|
setTtsEngineId: (y) => {
|
|
4054
|
-
|
|
4069
|
+
re.current.setTtsEngineId(y), ne.current?.setTtsEngineId(y), te.current && (te.current.ttsEngineId = y);
|
|
4055
4070
|
},
|
|
4056
4071
|
renderViseme: async (y, N) => {
|
|
4057
|
-
const
|
|
4058
|
-
if (!
|
|
4072
|
+
const H = U.current, z = P.current;
|
|
4073
|
+
if (!H || !z || !be.current)
|
|
4059
4074
|
throw new Error("AI twin is not ready");
|
|
4060
|
-
await
|
|
4075
|
+
await H.renderViseme(z, y, {
|
|
4061
4076
|
from: N?.from,
|
|
4062
4077
|
transitionDurationMs: N?.transitionDurationMs,
|
|
4063
4078
|
gapMs: N?.gapMs,
|
|
4064
|
-
onStatus: (
|
|
4079
|
+
onStatus: (K) => le.current?.(K)
|
|
4065
4080
|
});
|
|
4066
4081
|
},
|
|
4067
|
-
isReady: () =>
|
|
4068
|
-
getStatus: () =>
|
|
4082
|
+
isReady: () => be.current,
|
|
4083
|
+
getStatus: () => J,
|
|
4069
4084
|
connect: async (y = {}) => {
|
|
4070
|
-
|
|
4085
|
+
Se(null);
|
|
4071
4086
|
try {
|
|
4072
4087
|
let N = y.authToken?.trim();
|
|
4073
|
-
N || (N =
|
|
4074
|
-
const
|
|
4075
|
-
await
|
|
4088
|
+
N || (N = X.current ?? i ?? await zt(), X.current = N);
|
|
4089
|
+
const H = y.voiceId?.trim() ?? u ?? te.current?.voiceId, z = y.personaId?.trim() ?? te.current?.personaId, K = Er();
|
|
4090
|
+
await K.unlockAudio(), await K.connect({
|
|
4076
4091
|
...y,
|
|
4077
|
-
apiBase: y.apiBase?.trim() ||
|
|
4092
|
+
apiBase: y.apiBase?.trim() || oe,
|
|
4078
4093
|
authToken: N,
|
|
4079
|
-
voiceId:
|
|
4080
|
-
personaId:
|
|
4094
|
+
voiceId: H,
|
|
4095
|
+
personaId: z,
|
|
4081
4096
|
speakingRate: y.speakingRate ?? l
|
|
4082
4097
|
});
|
|
4083
4098
|
} catch (N) {
|
|
4084
|
-
throw
|
|
4099
|
+
throw _e(
|
|
4085
4100
|
N instanceof Error ? N.message : "Voice connect failed"
|
|
4086
4101
|
), N;
|
|
4087
4102
|
}
|
|
4088
4103
|
},
|
|
4089
4104
|
disconnect: async () => {
|
|
4090
|
-
const y =
|
|
4091
|
-
y && (
|
|
4105
|
+
const y = ne.current;
|
|
4106
|
+
y && (ce.current += 1, Te(), Fe(), v.current = !1, E.current = !1, Pe(Y.current), O.current?.reset(), D.current = 0, F.current = !1, await y.disconnect(), ft());
|
|
4092
4107
|
},
|
|
4093
|
-
isConnected: () =>
|
|
4094
|
-
getVoiceStream: () =>
|
|
4108
|
+
isConnected: () => ne.current?.isConnected() ?? !1,
|
|
4109
|
+
getVoiceStream: () => ne.current?.getVoiceStream() ?? re.current?.getVoiceStream() ?? null
|
|
4095
4110
|
}),
|
|
4096
4111
|
[
|
|
4097
|
-
|
|
4112
|
+
ye,
|
|
4098
4113
|
l,
|
|
4099
4114
|
i,
|
|
4100
4115
|
u,
|
|
4101
4116
|
Te,
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4117
|
+
Fe,
|
|
4118
|
+
ft,
|
|
4119
|
+
_e,
|
|
4120
|
+
ke,
|
|
4106
4121
|
Er,
|
|
4107
|
-
|
|
4122
|
+
J
|
|
4108
4123
|
]
|
|
4109
|
-
), /* @__PURE__ */
|
|
4124
|
+
), /* @__PURE__ */ Hn("div", { className: f, style: { ..._a, ...c }, children: [
|
|
4110
4125
|
/* @__PURE__ */ Ir(
|
|
4111
4126
|
"canvas",
|
|
4112
4127
|
{
|
|
4113
4128
|
ref: P,
|
|
4114
|
-
width:
|
|
4115
|
-
height:
|
|
4116
|
-
style: { ...
|
|
4129
|
+
width: Wt.width,
|
|
4130
|
+
height: Wt.height,
|
|
4131
|
+
style: { ...va, ...d },
|
|
4117
4132
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
4118
4133
|
}
|
|
4119
4134
|
),
|
|
4120
|
-
_ &&
|
|
4135
|
+
_ && ee ? /* @__PURE__ */ Ir("div", { style: Sa, children: ee }) : null
|
|
4121
4136
|
] });
|
|
4122
|
-
}),
|
|
4123
|
-
function
|
|
4137
|
+
}), ba = "thumbnail.webp";
|
|
4138
|
+
function Ba(e, t = ir) {
|
|
4124
4139
|
const r = e.trim();
|
|
4125
4140
|
if (!r)
|
|
4126
4141
|
throw new Error("faceId is required");
|
|
4127
|
-
return `${t.replace(/\/$/, "")}/${r}/${
|
|
4142
|
+
return `${t.replace(/\/$/, "")}/${r}/${ba}`;
|
|
4128
4143
|
}
|
|
4129
|
-
const
|
|
4130
|
-
function
|
|
4144
|
+
const ka = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
4145
|
+
function Ta(e = ".png") {
|
|
4131
4146
|
const t = e.toLowerCase();
|
|
4132
|
-
return
|
|
4147
|
+
return ka.has(t) ? `source${t}` : "source.png";
|
|
4133
4148
|
}
|
|
4134
|
-
function
|
|
4149
|
+
function Ca(e, t = ir, r = ".png") {
|
|
4135
4150
|
const n = e.trim();
|
|
4136
4151
|
if (!n)
|
|
4137
4152
|
throw new Error("faceId is required");
|
|
4138
|
-
return `${t.replace(/\/$/, "")}/${n}/${
|
|
4153
|
+
return `${t.replace(/\/$/, "")}/${n}/${Ta(r)}`;
|
|
4139
4154
|
}
|
|
4140
4155
|
export {
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4156
|
+
ba as AI_TWIN_THUMBNAIL_FILENAME,
|
|
4157
|
+
Da as AiTwin,
|
|
4158
|
+
Jt as AiTwinNotFoundError,
|
|
4159
|
+
tt as DEFAULT_TTS_ENGINE_ID,
|
|
4160
|
+
kn as MIC_SAMPLE_RATE,
|
|
4161
|
+
xs as OCULUS_VISEME_IDS,
|
|
4162
|
+
Tn as PLAYBACK_SAMPLE_RATE,
|
|
4163
|
+
fr as SPEAKING_RATE_MAX,
|
|
4164
|
+
lr as SPEAKING_RATE_MIN,
|
|
4165
|
+
it as TTS_ENGINE_CARTESIA,
|
|
4166
|
+
an as TTS_ENGINE_GOOGLE,
|
|
4167
|
+
or as TTS_ENGINE_INWORLD,
|
|
4168
|
+
Ra as VISEME_IDS,
|
|
4169
|
+
bn as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
4170
|
+
Ut as VISEME_TEST_SPEAKING_RATE,
|
|
4171
|
+
Sn as VISEME_TEST_VOICE_ID,
|
|
4172
|
+
Ta as aiTwinSourceFilename,
|
|
4173
|
+
ni as buildVoiceWebSocketUrl,
|
|
4159
4174
|
Or as createAvatarTtsLipsyncController,
|
|
4160
|
-
|
|
4175
|
+
ai as createRealtimeVoiceLipsyncController,
|
|
4161
4176
|
Br as faceAssetUrls,
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4177
|
+
hs as fetchAiTwin,
|
|
4178
|
+
zt as fetchDevAuthToken,
|
|
4179
|
+
Ca as getAiTwinSourceUrl,
|
|
4180
|
+
Ba as getAiTwinThumbnailUrl,
|
|
4181
|
+
Ms as normalizeOculusViseme,
|
|
4182
|
+
Ts as resolveDirectFaceId,
|
|
4183
|
+
Nt as resolveVisemeAtTime,
|
|
4184
|
+
Ma as resolveWordAtTime,
|
|
4185
|
+
Es as setActiveTwinAssets
|
|
4171
4186
|
};
|