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