@streamoji/aitwin 0.3.6 → 0.3.7
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 +3 -3
- package/dist/aitwin.js +1459 -1402
- package/package.json +1 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { PipecatClient as
|
|
4
|
-
import { WebSocketTransport as
|
|
5
|
-
const
|
|
6
|
-
publicBase:
|
|
7
|
-
},
|
|
8
|
-
version:
|
|
9
|
-
},
|
|
10
|
-
function
|
|
1
|
+
import { jsxs as yr, jsx as yn } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as _r, useRef as O, useState as at, useEffect as Ce, useCallback as Se, useMemo as _n, useImperativeHandle as Sr } from "react";
|
|
3
|
+
import { PipecatClient as kr } from "@pipecat-ai/client-js";
|
|
4
|
+
import { WebSocketTransport as br, DailyMediaManager as vr, ProtobufFrameSerializer as Er } from "@pipecat-ai/websocket-transport";
|
|
5
|
+
const Tr = "https://aitwin.bubu.social", Wn = {
|
|
6
|
+
publicBase: Tr
|
|
7
|
+
}, Ar = "0.3.7", Ir = {
|
|
8
|
+
version: Ar
|
|
9
|
+
}, Mr = {}, lt = "https://ai.aitwin.me", jt = `${Wn.publicBase}/custom-faces`, Pr = `${Wn.publicBase}/aitwin-workers/v${Ir.version}/visemeDiffPreview.worker.js`;
|
|
10
|
+
function Rr(e) {
|
|
11
11
|
if (e) return e;
|
|
12
|
-
const t = typeof import.meta < "u" ?
|
|
13
|
-
return t?.trim() ? t.trim() :
|
|
14
|
-
}
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
]),
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
},
|
|
23
|
-
google:
|
|
24
|
-
inworld:
|
|
25
|
-
cartesia:
|
|
12
|
+
const t = typeof import.meta < "u" ? Mr?.VITE_AITWIN_WORKER_URL : void 0;
|
|
13
|
+
return t?.trim() ? t.trim() : Pr;
|
|
14
|
+
}
|
|
15
|
+
const Dr = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Ct = 3e3, ut = 16, Sn = 3e3, xr = 4e3, Br = 0.85, Cr = 8, zt = 400, Hn = "eng_a7f2b9c1", Yt = "eng_d4e8f3a2", Xe = "eng_c9b1e6d4", je = Xe, $n = /* @__PURE__ */ new Set([
|
|
16
|
+
Yt,
|
|
17
|
+
Xe
|
|
18
|
+
]), qn = {
|
|
19
|
+
[Hn]: "oculus_direct",
|
|
20
|
+
[Xe]: "oculus_direct",
|
|
21
|
+
[Yt]: "inworld_word"
|
|
22
|
+
}, kn = {
|
|
23
|
+
google: Hn,
|
|
24
|
+
inworld: Yt,
|
|
25
|
+
cartesia: Xe
|
|
26
26
|
};
|
|
27
|
-
function
|
|
28
|
-
return
|
|
27
|
+
function Fr(e) {
|
|
28
|
+
return qn[e];
|
|
29
29
|
}
|
|
30
|
-
function
|
|
31
|
-
return e ===
|
|
30
|
+
function Lr(e) {
|
|
31
|
+
return e === Xe;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
if (e.ttsEngineId && e.ttsEngineId in
|
|
33
|
+
function Or(e) {
|
|
34
|
+
if (e.ttsEngineId && e.ttsEngineId in qn)
|
|
35
35
|
return e.ttsEngineId;
|
|
36
36
|
const t = e.tts?.toLowerCase();
|
|
37
|
-
return t && t in
|
|
37
|
+
return t && t in kn ? kn[t] : je;
|
|
38
38
|
}
|
|
39
39
|
class Ut extends Error {
|
|
40
40
|
constructor(t = "AI twin not found") {
|
|
41
41
|
super(t), this.name = "AiTwinNotFoundError";
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
async function
|
|
44
|
+
async function Nr(e, t = Dr) {
|
|
45
45
|
const n = new URL(t);
|
|
46
46
|
n.searchParams.set("id", e);
|
|
47
47
|
const r = await fetch(n.toString());
|
|
@@ -55,22 +55,22 @@ async function xr(e, t = Tr) {
|
|
|
55
55
|
const { tts: i, token: a, ...o } = s.data, f = String(o.authToken ?? a ?? "").trim() || void 0;
|
|
56
56
|
return {
|
|
57
57
|
...o,
|
|
58
|
-
ttsEngineId:
|
|
58
|
+
ttsEngineId: Or(s.data),
|
|
59
59
|
authToken: f
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
const
|
|
62
|
+
const Ur = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Vr = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", Wr = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hr = "6TNvp3SCs4Og0a1ijm9TommXLql1", $r = "Swaraj Mali";
|
|
63
63
|
async function Ft() {
|
|
64
|
-
const e = await fetch(
|
|
64
|
+
const e = await fetch(Ur, {
|
|
65
65
|
method: "POST",
|
|
66
66
|
headers: {
|
|
67
67
|
"Content-Type": "application/json",
|
|
68
|
-
"Client-Id":
|
|
69
|
-
"Client-Secret":
|
|
68
|
+
"Client-Id": Vr,
|
|
69
|
+
"Client-Secret": Wr
|
|
70
70
|
},
|
|
71
71
|
body: JSON.stringify({
|
|
72
|
-
userId:
|
|
73
|
-
userName:
|
|
72
|
+
userId: Hr,
|
|
73
|
+
userName: $r
|
|
74
74
|
})
|
|
75
75
|
});
|
|
76
76
|
if (!e.ok)
|
|
@@ -80,7 +80,7 @@ async function Ft() {
|
|
|
80
80
|
throw new Error("getAuthToken returned no token");
|
|
81
81
|
return n;
|
|
82
82
|
}
|
|
83
|
-
async function
|
|
83
|
+
async function qr(e, t = lt) {
|
|
84
84
|
const n = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
85
85
|
headers: { Authorization: `Bearer ${e}` }
|
|
86
86
|
});
|
|
@@ -90,7 +90,7 @@ async function Nr(e, t = dt) {
|
|
|
90
90
|
if (!r.value) throw new Error("Session value response missing value");
|
|
91
91
|
return r;
|
|
92
92
|
}
|
|
93
|
-
function
|
|
93
|
+
function Kr(e) {
|
|
94
94
|
const t = e.trim();
|
|
95
95
|
if (t.length % 2 !== 0) throw new Error("Invalid hex key");
|
|
96
96
|
const n = new Uint8Array(t.length / 2);
|
|
@@ -98,20 +98,20 @@ function Ur(e) {
|
|
|
98
98
|
n[r / 2] = Number.parseInt(t.slice(r, r + 2), 16);
|
|
99
99
|
return n;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function gt(e) {
|
|
102
102
|
return Uint8Array.from(e);
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function Gr(e, t) {
|
|
105
105
|
const n = new Uint8Array(e.length + t.length);
|
|
106
106
|
return n.set(e, 0), n.set(t, e.length), n;
|
|
107
107
|
}
|
|
108
|
-
async function
|
|
108
|
+
async function jr(e, t) {
|
|
109
109
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
110
110
|
if (e.byteLength < 28)
|
|
111
111
|
throw new Error("Encrypted payload too small");
|
|
112
|
-
const n = new Uint8Array(e), r =
|
|
112
|
+
const n = new Uint8Array(e), r = gt(n.subarray(0, 12)), s = gt(n.subarray(12, 28)), i = gt(n.subarray(28)), a = gt(Gr(i, s)), o = await crypto.subtle.importKey(
|
|
113
113
|
"raw",
|
|
114
|
-
|
|
114
|
+
Kr(t),
|
|
115
115
|
{ name: "AES-GCM" },
|
|
116
116
|
!1,
|
|
117
117
|
["decrypt"]
|
|
@@ -124,33 +124,33 @@ async function Wr(e, t) {
|
|
|
124
124
|
}
|
|
125
125
|
let Vt = null;
|
|
126
126
|
const Wt = /* @__PURE__ */ new Set();
|
|
127
|
-
function
|
|
127
|
+
function yt(e) {
|
|
128
128
|
return e.includes("/custom-faces/");
|
|
129
129
|
}
|
|
130
|
-
function
|
|
130
|
+
function bt(e) {
|
|
131
131
|
const t = e.binBase.trim().replace(/\/$/, ""), n = e.twinBase.trim().replace(/\/$/, "");
|
|
132
|
-
if (!(e.encrypted ||
|
|
132
|
+
if (!(e.encrypted || yt(t) || yt(n)))
|
|
133
133
|
return { twinBase: n, binBase: t, encrypted: !1 };
|
|
134
|
-
const s =
|
|
134
|
+
const s = yt(t) ? t : yt(n) ? n : t;
|
|
135
135
|
return { twinBase: s, binBase: s, encrypted: !0 };
|
|
136
136
|
}
|
|
137
|
-
function
|
|
138
|
-
return
|
|
137
|
+
function Qe(e) {
|
|
138
|
+
return bt(e).encrypted;
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function bn(e, t = jt) {
|
|
141
141
|
const n = `${t.replace(/\/$/, "")}/${e}`;
|
|
142
142
|
return { twinBase: n, binBase: n, encrypted: !0 };
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function zr(e, t) {
|
|
145
145
|
return (e ?? t)?.trim() || void 0;
|
|
146
146
|
}
|
|
147
|
-
function
|
|
148
|
-
Vt =
|
|
147
|
+
function Yr(e) {
|
|
148
|
+
Vt = bt(e);
|
|
149
149
|
for (const t of Wt) t();
|
|
150
150
|
}
|
|
151
|
-
function
|
|
151
|
+
function Jr(e, t) {
|
|
152
152
|
const n = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
153
|
-
if (!n) return
|
|
153
|
+
if (!n) return bt(e);
|
|
154
154
|
const r = (s) => {
|
|
155
155
|
try {
|
|
156
156
|
return new URL(s, n).href.replace(/\/$/, "");
|
|
@@ -158,7 +158,7 @@ function qr(e, t) {
|
|
|
158
158
|
return s;
|
|
159
159
|
}
|
|
160
160
|
};
|
|
161
|
-
return
|
|
161
|
+
return bt({
|
|
162
162
|
twinBase: r(e.twinBase),
|
|
163
163
|
binBase: r(e.binBase),
|
|
164
164
|
encrypted: e.encrypted
|
|
@@ -169,33 +169,33 @@ function Ue() {
|
|
|
169
169
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
170
170
|
return Vt;
|
|
171
171
|
}
|
|
172
|
-
function
|
|
172
|
+
function Xr(e) {
|
|
173
173
|
return Wt.add(e), () => Wt.delete(e);
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function vn() {
|
|
176
176
|
const e = Ue();
|
|
177
|
-
return
|
|
177
|
+
return Qe(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function Qr() {
|
|
180
180
|
const e = Ue();
|
|
181
|
-
return
|
|
181
|
+
return Qe(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
182
182
|
}
|
|
183
|
-
function
|
|
183
|
+
function Zr() {
|
|
184
184
|
const e = Ue();
|
|
185
|
-
return
|
|
185
|
+
return Qe(e) ? e.binBase : e.twinBase;
|
|
186
186
|
}
|
|
187
|
-
function
|
|
188
|
-
return
|
|
187
|
+
function It() {
|
|
188
|
+
return Qe(Ue());
|
|
189
189
|
}
|
|
190
|
-
function
|
|
190
|
+
function es() {
|
|
191
191
|
const e = Ue();
|
|
192
|
-
return
|
|
192
|
+
return Qe(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
193
193
|
}
|
|
194
|
-
function
|
|
194
|
+
function ts() {
|
|
195
195
|
const e = Ue();
|
|
196
|
-
return
|
|
196
|
+
return Qe(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
197
197
|
}
|
|
198
|
-
function
|
|
198
|
+
function Kn(e) {
|
|
199
199
|
const t = e.split(/\r?\n/);
|
|
200
200
|
let n = "", r = "";
|
|
201
201
|
for (const i of t)
|
|
@@ -210,7 +210,7 @@ function Hn(e) {
|
|
|
210
210
|
}
|
|
211
211
|
return { event: n, data: s };
|
|
212
212
|
}
|
|
213
|
-
const
|
|
213
|
+
const ns = [
|
|
214
214
|
"aa",
|
|
215
215
|
"CH",
|
|
216
216
|
"DD",
|
|
@@ -226,14 +226,14 @@ const Jr = [
|
|
|
226
226
|
"kk",
|
|
227
227
|
"nn",
|
|
228
228
|
"sil"
|
|
229
|
-
],
|
|
230
|
-
|
|
229
|
+
], rs = new Map(
|
|
230
|
+
ns.map((e) => [e.toLowerCase(), e])
|
|
231
231
|
);
|
|
232
|
-
function
|
|
232
|
+
function ss(e) {
|
|
233
233
|
const t = (e ?? "").trim();
|
|
234
|
-
return t ?
|
|
234
|
+
return t ? rs.get(t.toLowerCase()) ?? "sil" : "sil";
|
|
235
235
|
}
|
|
236
|
-
const
|
|
236
|
+
const is = {
|
|
237
237
|
aei: ["aa", "E", "I"],
|
|
238
238
|
o: ["O", "U"],
|
|
239
239
|
ee: ["I"],
|
|
@@ -245,12 +245,12 @@ const Zr = {
|
|
|
245
245
|
qw: ["U", "O"],
|
|
246
246
|
cdgknstxyz: ["DD", "SS", "kk", "CH"]
|
|
247
247
|
};
|
|
248
|
-
function
|
|
248
|
+
function as(e) {
|
|
249
249
|
if (!e) return ["sil"];
|
|
250
250
|
const t = e.toLowerCase();
|
|
251
|
-
return
|
|
251
|
+
return is[t] ?? ["sil"];
|
|
252
252
|
}
|
|
253
|
-
function
|
|
253
|
+
function os(e, t) {
|
|
254
254
|
const n = e.word.length;
|
|
255
255
|
if (n <= 0) return 0;
|
|
256
256
|
const r = e.wduration;
|
|
@@ -258,40 +258,40 @@ function ts(e, t) {
|
|
|
258
258
|
const s = Math.max(0, Math.min(1, (t - e.wtime) / r));
|
|
259
259
|
return Math.min(n - 1, Math.floor(s * n));
|
|
260
260
|
}
|
|
261
|
-
function
|
|
261
|
+
function ze(e, t) {
|
|
262
262
|
const n = Math.max(0, Math.min(e.length - 1, t));
|
|
263
263
|
return e[n] ?? "";
|
|
264
264
|
}
|
|
265
|
-
function
|
|
265
|
+
function Jt(e, t) {
|
|
266
266
|
const n = e.toLowerCase().replace(/[^a-z']/g, "");
|
|
267
|
-
return !n ||
|
|
267
|
+
return !n || ze(n, t) !== "w" || t > 0 && ze(n, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(n);
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
const n = e.toLowerCase(), r =
|
|
269
|
+
function cs(e, t) {
|
|
270
|
+
const n = e.toLowerCase(), r = ze(n, t), s = n.slice(Math.max(0, t - 1), t + 2);
|
|
271
271
|
return r === "i" || r === "y" ? "I" : s.includes("ee") || r === "e" || n.includes("ea") ? "E" : "aa";
|
|
272
272
|
}
|
|
273
|
-
function
|
|
273
|
+
function us(e, t) {
|
|
274
274
|
const n = e.toLowerCase(), r = n.slice(
|
|
275
275
|
Math.max(0, t - 1),
|
|
276
276
|
Math.min(n.length, t + 3)
|
|
277
277
|
);
|
|
278
278
|
if (/oo|ou|uw/.test(r)) return "U";
|
|
279
|
-
if (
|
|
280
|
-
const s =
|
|
279
|
+
if (Jt(n, t)) return "FF";
|
|
280
|
+
const s = ze(n, t);
|
|
281
281
|
return s === "u" || s === "w" ? "U" : "O";
|
|
282
282
|
}
|
|
283
|
-
function
|
|
283
|
+
function ls(e, t) {
|
|
284
284
|
const n = e.toLowerCase();
|
|
285
|
-
if (
|
|
285
|
+
if (Jt(n, t)) return "FF";
|
|
286
286
|
const r = n.slice(Math.max(0, t - 2), t + 1);
|
|
287
287
|
if (/qu/.test(r)) return "U";
|
|
288
288
|
const s = n.slice(
|
|
289
289
|
Math.max(0, t - 1),
|
|
290
290
|
Math.min(n.length, t + 3)
|
|
291
291
|
);
|
|
292
|
-
return /wo|wh/.test(s) ||
|
|
292
|
+
return /wo|wh/.test(s) || ze(n, t) === "o" ? "O" : "U";
|
|
293
293
|
}
|
|
294
|
-
const
|
|
294
|
+
const _t = {
|
|
295
295
|
d: "DD",
|
|
296
296
|
t: "DD",
|
|
297
297
|
n: "DD",
|
|
@@ -303,50 +303,121 @@ const yt = {
|
|
|
303
303
|
x: "CH",
|
|
304
304
|
j: "CH"
|
|
305
305
|
};
|
|
306
|
-
function
|
|
307
|
-
const n = e.toLowerCase(), r =
|
|
308
|
-
if (
|
|
306
|
+
function fs(e, t) {
|
|
307
|
+
const n = e.toLowerCase(), r = ze(n, t);
|
|
308
|
+
if (_t[r]) return _t[r];
|
|
309
309
|
for (let s = 0; s < n.length; s++) {
|
|
310
310
|
const i = n[s];
|
|
311
|
-
if (
|
|
311
|
+
if (_t[i]) return _t[i];
|
|
312
312
|
}
|
|
313
313
|
return "DD";
|
|
314
314
|
}
|
|
315
|
-
function
|
|
316
|
-
const r =
|
|
315
|
+
function ds(e, t, n) {
|
|
316
|
+
const r = as(e);
|
|
317
317
|
if (r.length === 1) return r[0];
|
|
318
318
|
const s = t.trim();
|
|
319
319
|
if (!s) return r[0];
|
|
320
320
|
const i = (e ?? "").toLowerCase(), a = Math.max(0, n);
|
|
321
321
|
switch (i) {
|
|
322
322
|
case "aei":
|
|
323
|
-
return
|
|
323
|
+
return cs(s, a);
|
|
324
324
|
case "o":
|
|
325
|
-
return
|
|
325
|
+
return us(s, a);
|
|
326
326
|
case "qw":
|
|
327
|
-
return
|
|
327
|
+
return ls(s, a);
|
|
328
328
|
case "cdgknstxyz":
|
|
329
|
-
return
|
|
329
|
+
return fs(s, a);
|
|
330
330
|
default:
|
|
331
331
|
return r[0];
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
const
|
|
335
|
-
function
|
|
334
|
+
const ms = 32;
|
|
335
|
+
function Gn(e) {
|
|
336
|
+
let t = 0;
|
|
337
|
+
for (const n of e)
|
|
338
|
+
t = Math.max(t, n.vtime + n.vduration);
|
|
339
|
+
return t;
|
|
340
|
+
}
|
|
341
|
+
function jn(e) {
|
|
342
|
+
let t = null, n = -1;
|
|
343
|
+
for (const r of e) {
|
|
344
|
+
if (r.viseme === "sil") continue;
|
|
345
|
+
const s = r.vtime + r.vduration;
|
|
346
|
+
s > n && (t = r, n = s);
|
|
347
|
+
}
|
|
348
|
+
return t;
|
|
349
|
+
}
|
|
350
|
+
function hs(e) {
|
|
351
|
+
return zn(e).find((n) => n.viseme !== "sil") ?? null;
|
|
352
|
+
}
|
|
353
|
+
function Fe(e) {
|
|
354
|
+
const t = Gn(e);
|
|
355
|
+
return jn(e) ? t + zt : t;
|
|
356
|
+
}
|
|
357
|
+
function ps(e) {
|
|
358
|
+
const t = [], n = hs(e);
|
|
359
|
+
n && n.vtime > 0 && t.push({
|
|
360
|
+
from: "sil",
|
|
361
|
+
to: n.viseme,
|
|
362
|
+
fromVtime: 0,
|
|
363
|
+
toVtime: n.vtime
|
|
364
|
+
});
|
|
365
|
+
const r = jn(e), s = Gn(e);
|
|
366
|
+
return r && t.push({
|
|
367
|
+
from: r.viseme,
|
|
368
|
+
to: "sil",
|
|
369
|
+
fromVtime: s,
|
|
370
|
+
toVtime: s + zt
|
|
371
|
+
}), t;
|
|
372
|
+
}
|
|
373
|
+
function zn(e) {
|
|
374
|
+
const t = /* @__PURE__ */ new Map();
|
|
375
|
+
for (const n of e)
|
|
376
|
+
t.has(n.vtime) || t.set(n.vtime, n);
|
|
377
|
+
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
378
|
+
}
|
|
379
|
+
function ws(e) {
|
|
380
|
+
const t = zn(e), n = [];
|
|
381
|
+
for (let r = 0; r < t.length - 1; r++) {
|
|
382
|
+
const s = t[r].viseme, i = t[r + 1].viseme, a = t[r].vtime, o = t[r + 1].vtime;
|
|
383
|
+
s === i || o <= a || n.push({ from: s, to: i, fromVtime: a, toVtime: o });
|
|
384
|
+
}
|
|
385
|
+
return n;
|
|
386
|
+
}
|
|
387
|
+
function gs(e) {
|
|
388
|
+
return e.length === 0 ? [] : [
|
|
389
|
+
...ps(e),
|
|
390
|
+
...ws(e)
|
|
391
|
+
];
|
|
392
|
+
}
|
|
393
|
+
function ys(e, t) {
|
|
394
|
+
let n = null;
|
|
395
|
+
for (const r of e) {
|
|
396
|
+
const { transEnd: s } = Yn(r.fromVtime, r.toVtime);
|
|
397
|
+
t >= r.fromVtime && t < s && (n = r);
|
|
398
|
+
}
|
|
399
|
+
return n;
|
|
400
|
+
}
|
|
401
|
+
function Yn(e, t) {
|
|
402
|
+
const n = Math.max(0, t - e), r = n > 0 ? Math.max(n, ms) : 0, s = e, i = e + r;
|
|
403
|
+
return { gapMs: n, effectiveGapMs: r, holdEnd: e, transStart: s, transEnd: i };
|
|
404
|
+
}
|
|
405
|
+
const Xt = 16e3;
|
|
406
|
+
function Jn(e) {
|
|
336
407
|
const t = Number(e);
|
|
337
|
-
return Number.isFinite(t) && t > 0 ? t :
|
|
408
|
+
return Number.isFinite(t) && t > 0 ? t : Xt;
|
|
338
409
|
}
|
|
339
|
-
function
|
|
410
|
+
function _s(e) {
|
|
340
411
|
let t = e.trim();
|
|
341
412
|
const n = t.indexOf(",");
|
|
342
413
|
t.startsWith("data:") && n >= 0 && (t = t.slice(n + 1)), t = t.replace(/\s+/g, "").replace(/-/g, "+").replace(/_/g, "/");
|
|
343
414
|
const r = t.length % 4;
|
|
344
415
|
return r !== 0 && (t += "=".repeat(4 - r)), t;
|
|
345
416
|
}
|
|
346
|
-
function
|
|
417
|
+
function Ss(e) {
|
|
347
418
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
348
419
|
}
|
|
349
|
-
function
|
|
420
|
+
function En(e, t, n = Xt) {
|
|
350
421
|
const r = t.byteOffset % 2 === 0 ? t : t.slice(), s = new Int16Array(
|
|
351
422
|
r.buffer,
|
|
352
423
|
r.byteOffset,
|
|
@@ -357,15 +428,15 @@ function bn(e, t, n = Jt) {
|
|
|
357
428
|
const a = e.createBuffer(1, i.length, n);
|
|
358
429
|
return a.copyToChannel(i, 0), a;
|
|
359
430
|
}
|
|
360
|
-
function
|
|
361
|
-
const t =
|
|
431
|
+
function ks(e) {
|
|
432
|
+
const t = _s(e), n = window.atob(t), r = new Uint8Array(n.length);
|
|
362
433
|
for (let s = 0; s < n.length; s++)
|
|
363
434
|
r[s] = n.charCodeAt(s);
|
|
364
435
|
return r;
|
|
365
436
|
}
|
|
366
|
-
async function
|
|
367
|
-
const r =
|
|
368
|
-
if (
|
|
437
|
+
async function bs(e, t, n = Xt) {
|
|
438
|
+
const r = ks(t), s = Jn(n);
|
|
439
|
+
if (Ss(r)) {
|
|
369
440
|
const i = r.buffer.slice(
|
|
370
441
|
r.byteOffset,
|
|
371
442
|
r.byteOffset + r.byteLength
|
|
@@ -373,7 +444,7 @@ async function ls(e, t, n = Jt) {
|
|
|
373
444
|
return e.decodeAudioData(i);
|
|
374
445
|
}
|
|
375
446
|
if (r.length >= 2 && r.length % 2 === 0)
|
|
376
|
-
return
|
|
447
|
+
return En(e, r, s);
|
|
377
448
|
try {
|
|
378
449
|
const i = r.buffer.slice(
|
|
379
450
|
r.byteOffset,
|
|
@@ -381,166 +452,166 @@ async function ls(e, t, n = Jt) {
|
|
|
381
452
|
);
|
|
382
453
|
return await e.decodeAudioData(i);
|
|
383
454
|
} catch {
|
|
384
|
-
return
|
|
455
|
+
return En(e, r, s);
|
|
385
456
|
}
|
|
386
457
|
}
|
|
387
|
-
function
|
|
458
|
+
function Tn(e) {
|
|
388
459
|
let t = 0;
|
|
389
460
|
for (const n of e)
|
|
390
461
|
t = Math.max(t, n.vtime + n.vduration);
|
|
391
462
|
return t;
|
|
392
463
|
}
|
|
393
|
-
function
|
|
464
|
+
function vs(e, t) {
|
|
394
465
|
for (const n of e)
|
|
395
466
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
396
467
|
return n;
|
|
397
468
|
return null;
|
|
398
469
|
}
|
|
399
|
-
function
|
|
470
|
+
function Xn(e, t) {
|
|
400
471
|
const n = [], r = [];
|
|
401
|
-
let s = null, i = !1, a = !1, o = !1, f = !1, d = 0, u = 0, c = 0, m = 0,
|
|
402
|
-
const F = [],
|
|
403
|
-
v = !1,
|
|
404
|
-
},
|
|
405
|
-
|
|
472
|
+
let s = null, i = !1, a = !1, o = !1, f = !1, d = 0, u = 0, c = 0, m = 0, w = null, b = 1, h = t, I = !1, E = null, _ = 0, p = !1, v = !1, N = 0;
|
|
473
|
+
const F = [], j = () => {
|
|
474
|
+
v = !1, N = 0, F.length = 0;
|
|
475
|
+
}, R = () => {
|
|
476
|
+
w != null && (clearTimeout(w), w = null);
|
|
406
477
|
}, S = () => {
|
|
407
|
-
for (const
|
|
478
|
+
for (const y of r) {
|
|
408
479
|
try {
|
|
409
|
-
|
|
480
|
+
y.onended = null, y.stop(0);
|
|
410
481
|
} catch {
|
|
411
482
|
}
|
|
412
483
|
try {
|
|
413
|
-
|
|
484
|
+
y.disconnect();
|
|
414
485
|
} catch {
|
|
415
486
|
}
|
|
416
487
|
}
|
|
417
488
|
r.length = 0;
|
|
418
|
-
},
|
|
419
|
-
for (const
|
|
420
|
-
|
|
489
|
+
}, M = () => {
|
|
490
|
+
for (const y of r)
|
|
491
|
+
y.playbackRate.value = b;
|
|
421
492
|
}, T = () => {
|
|
422
|
-
if (!(
|
|
493
|
+
if (!(I || !f || i || r.length > 0 || n.length > 0)) {
|
|
423
494
|
if (o && s && u > 0) {
|
|
424
|
-
const
|
|
425
|
-
if (
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}, Math.max(0,
|
|
495
|
+
const y = (s.currentTime - u) * 1e3;
|
|
496
|
+
if (y < _) {
|
|
497
|
+
R();
|
|
498
|
+
const A = b > 0 ? (_ - y) / b : _ - y;
|
|
499
|
+
w = setTimeout(() => {
|
|
500
|
+
I || (a = !1, w = null, e.onSpeakingDone(), e.onNotify());
|
|
501
|
+
}, Math.max(0, A));
|
|
431
502
|
return;
|
|
432
503
|
}
|
|
433
504
|
}
|
|
434
|
-
a = !1,
|
|
505
|
+
a = !1, R(), e.onSpeakingDone(), e.onNotify();
|
|
435
506
|
}
|
|
436
|
-
},
|
|
437
|
-
const
|
|
438
|
-
if (
|
|
507
|
+
}, Z = (y) => {
|
|
508
|
+
const A = Fe(y);
|
|
509
|
+
if (A <= 0) {
|
|
439
510
|
e.onSpeakingDone(), e.onNotify();
|
|
440
511
|
return;
|
|
441
512
|
}
|
|
442
|
-
a = !0, d = performance.now(), e.onSpeakingStart(), e.onNotify(),
|
|
443
|
-
const q = b > 0 ?
|
|
444
|
-
|
|
445
|
-
|
|
513
|
+
a = !0, d = performance.now(), e.onSpeakingStart(), e.onNotify(), R();
|
|
514
|
+
const q = b > 0 ? A / b : A;
|
|
515
|
+
w = setTimeout(() => {
|
|
516
|
+
I || (a = !1, w = null, e.onSpeakingDone(), e.onNotify());
|
|
446
517
|
}, q);
|
|
447
|
-
},
|
|
448
|
-
|
|
449
|
-
const
|
|
450
|
-
if (!
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
word:
|
|
454
|
-
wtime: c +
|
|
455
|
-
wduration:
|
|
456
|
-
queueIndex:
|
|
457
|
-
gesture:
|
|
458
|
-
emphasis:
|
|
518
|
+
}, D = (y, A, q, x) => {
|
|
519
|
+
A.length !== 0 && (x && (c = q), A.forEach((P) => {
|
|
520
|
+
const C = String(P.word ?? "").trim();
|
|
521
|
+
if (!C) return;
|
|
522
|
+
const B = Math.round((P.start ?? 0) * 1e3), Y = P.duration != null ? Math.round(P.duration * 1e3) : P.end != null ? Math.max(1, Math.round((P.end - (P.start ?? 0)) * 1e3)) : 0;
|
|
523
|
+
y.push({
|
|
524
|
+
word: C,
|
|
525
|
+
wtime: c + B,
|
|
526
|
+
wduration: Y,
|
|
527
|
+
queueIndex: y.length,
|
|
528
|
+
gesture: P.gesture ?? null,
|
|
529
|
+
emphasis: P.emphasis === !0
|
|
459
530
|
});
|
|
460
531
|
}));
|
|
461
|
-
},
|
|
462
|
-
q.length !== 0 && (
|
|
463
|
-
const
|
|
464
|
-
if (!
|
|
465
|
-
const
|
|
466
|
-
let
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
),
|
|
472
|
-
viseme:
|
|
532
|
+
}, X = (y, A, q, x, P, $) => {
|
|
533
|
+
q.length !== 0 && (P && (c = x), q.forEach((C) => {
|
|
534
|
+
const B = String(C.symbol ?? C.viseme ?? "").trim();
|
|
535
|
+
if (!B) return;
|
|
536
|
+
const Y = Math.round((C.start ?? 0) * 1e3), ee = Math.max(1, Math.round((C.duration ?? 0) * 1e3)), pe = c + Y, me = vs(A, pe), le = me ? os(me, pe) : 0;
|
|
537
|
+
let fe;
|
|
538
|
+
Fr($) === "oculus_direct" ? (fe = ss(B), fe === "U" && me && Jt(me.word, le) && (fe = "FF")) : fe = ds(
|
|
539
|
+
B,
|
|
540
|
+
me?.word ?? "",
|
|
541
|
+
le
|
|
542
|
+
), y.push({
|
|
543
|
+
viseme: fe,
|
|
473
544
|
weight: 1,
|
|
474
|
-
vtime:
|
|
545
|
+
vtime: pe,
|
|
475
546
|
vduration: ee
|
|
476
547
|
});
|
|
477
548
|
}), e.onNotify());
|
|
478
|
-
},
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
549
|
+
}, z = (y, A, q, x, P, $, C) => {
|
|
550
|
+
D(A, x, P, $), X(
|
|
551
|
+
y,
|
|
552
|
+
A,
|
|
482
553
|
q,
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
554
|
+
P,
|
|
555
|
+
$,
|
|
556
|
+
C
|
|
486
557
|
);
|
|
487
|
-
},
|
|
558
|
+
}, se = (y, A) => {
|
|
488
559
|
if (!s) return;
|
|
489
|
-
const q = s,
|
|
490
|
-
let
|
|
491
|
-
const
|
|
492
|
-
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
560
|
+
const q = s, x = q.currentTime;
|
|
561
|
+
let P = A?.startTime ?? m;
|
|
562
|
+
const $ = A?.isFirstAudio ?? !a;
|
|
563
|
+
P < x && (P = x + 0.1), m = P + y.duration;
|
|
564
|
+
const C = q.createBufferSource();
|
|
565
|
+
if (C.buffer = y, C.playbackRate.value = b, C.connect(q.destination), E && C.connect(E), r.push(C), I) {
|
|
495
566
|
r.pop();
|
|
496
567
|
return;
|
|
497
568
|
}
|
|
498
|
-
if (
|
|
499
|
-
a = !0, e.onSpeakingStart(),
|
|
500
|
-
const
|
|
501
|
-
d = performance.now() +
|
|
569
|
+
if ($) {
|
|
570
|
+
a = !0, e.onSpeakingStart(), A?.isFirstOfStream ? (u = P, c = 0, A.onNewStream?.()) : u <= 0 && (u = P);
|
|
571
|
+
const B = (P - x) * 1e3;
|
|
572
|
+
d = performance.now() + B;
|
|
502
573
|
}
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
},
|
|
507
|
-
},
|
|
574
|
+
C.onended = () => {
|
|
575
|
+
const B = r.indexOf(C);
|
|
576
|
+
B >= 0 && r.splice(B, 1), T(), e.onNotify();
|
|
577
|
+
}, C.start(P);
|
|
578
|
+
}, ne = () => {
|
|
508
579
|
if (!v || F.length === 0) return;
|
|
509
580
|
v = !1;
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
for (let
|
|
513
|
-
|
|
514
|
-
isFirstAudio:
|
|
515
|
-
isFirstOfStream:
|
|
581
|
+
const y = F.splice(0);
|
|
582
|
+
N = 0;
|
|
583
|
+
for (let A = 0; A < y.length; A++)
|
|
584
|
+
se(y[A].audioBuffer, {
|
|
585
|
+
isFirstAudio: A === 0 && !a,
|
|
586
|
+
isFirstOfStream: A === 0
|
|
516
587
|
});
|
|
517
588
|
e.onNotify();
|
|
518
|
-
},
|
|
519
|
-
if (
|
|
520
|
-
const
|
|
589
|
+
}, de = async (y, A, q, x, P, $, C) => {
|
|
590
|
+
if (I) return;
|
|
591
|
+
const B = Jn(C?.sampleRate), Y = C?.newStream === !0;
|
|
521
592
|
if (!q?.trim()) {
|
|
522
|
-
if (
|
|
523
|
-
|
|
593
|
+
if (x.length === 0 && P.length === 0) return;
|
|
594
|
+
Y && (c = 0, _ = 0, y.length = 0, A.length = 0, C?.onNewStream?.());
|
|
524
595
|
let ee = c;
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
596
|
+
$ && y.length > 0 && !Y && (ee = Tn(y)), z(
|
|
597
|
+
y,
|
|
598
|
+
A,
|
|
599
|
+
x,
|
|
600
|
+
P,
|
|
530
601
|
ee,
|
|
531
|
-
|
|
602
|
+
$,
|
|
532
603
|
h
|
|
533
|
-
), _ = Math.max(_,
|
|
604
|
+
), _ = Math.max(_, Fe(y)), !a && _ > 0 && Z(y), e.onNotify();
|
|
534
605
|
return;
|
|
535
606
|
}
|
|
536
607
|
if (i) {
|
|
537
608
|
n.push({
|
|
538
609
|
audio: q,
|
|
539
|
-
visemes:
|
|
540
|
-
words:
|
|
541
|
-
isNewSegment:
|
|
542
|
-
sampleRate:
|
|
543
|
-
newStream:
|
|
610
|
+
visemes: x,
|
|
611
|
+
words: P,
|
|
612
|
+
isNewSegment: $,
|
|
613
|
+
sampleRate: B,
|
|
614
|
+
newStream: Y
|
|
544
615
|
});
|
|
545
616
|
return;
|
|
546
617
|
}
|
|
@@ -548,53 +619,53 @@ function qn(e, t) {
|
|
|
548
619
|
try {
|
|
549
620
|
const ee = window.AudioContext || window.webkitAudioContext;
|
|
550
621
|
s || (s = new ee());
|
|
551
|
-
const
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
|
|
622
|
+
const pe = s;
|
|
623
|
+
pe.state === "suspended" && await pe.resume(), E || (E = pe.createMediaStreamDestination());
|
|
624
|
+
const me = await bs(
|
|
625
|
+
pe,
|
|
555
626
|
q,
|
|
556
|
-
|
|
627
|
+
B
|
|
557
628
|
);
|
|
558
629
|
o = !0;
|
|
559
|
-
const
|
|
560
|
-
if (p && (e.shouldHoldForWarmup?.() ?? !1) && (v ||
|
|
561
|
-
v || (v = !0,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
O,
|
|
630
|
+
const le = !a;
|
|
631
|
+
if (p && (e.shouldHoldForWarmup?.() ?? !1) && (v || le && Y)) {
|
|
632
|
+
v || (v = !0, N = 0, F.length = 0, Y && (c = 0, _ = 0, y.length = 0, A.length = 0, C?.onNewStream?.())), z(
|
|
633
|
+
y,
|
|
634
|
+
A,
|
|
635
|
+
x,
|
|
636
|
+
P,
|
|
567
637
|
N,
|
|
638
|
+
$,
|
|
568
639
|
h
|
|
569
|
-
),
|
|
640
|
+
), N += Math.round(me.duration * 1e3), F.push({ audioBuffer: me }), _ = Math.max(_, Fe(y)), e.onNotify();
|
|
570
641
|
return;
|
|
571
642
|
}
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
let
|
|
575
|
-
|
|
576
|
-
const
|
|
577
|
-
|
|
578
|
-
startTime:
|
|
579
|
-
isFirstAudio:
|
|
580
|
-
isFirstOfStream:
|
|
581
|
-
}),
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
643
|
+
le && Y && (_ = 0, y.length = 0, A.length = 0, c = 0, C?.onNewStream?.());
|
|
644
|
+
const Ve = pe.currentTime;
|
|
645
|
+
let xe = m;
|
|
646
|
+
xe < Ve && (xe = Ve + 0.1);
|
|
647
|
+
const We = le && Y ? 0 : u > 0 ? Math.max(0, (xe - u) * 1e3) : 0;
|
|
648
|
+
se(me, {
|
|
649
|
+
startTime: xe,
|
|
650
|
+
isFirstAudio: le,
|
|
651
|
+
isFirstOfStream: le && Y
|
|
652
|
+
}), z(
|
|
653
|
+
y,
|
|
654
|
+
A,
|
|
655
|
+
x,
|
|
656
|
+
P,
|
|
657
|
+
We,
|
|
658
|
+
$,
|
|
588
659
|
h
|
|
589
|
-
), _ = Math.max(_,
|
|
660
|
+
), _ = Math.max(_, Fe(y));
|
|
590
661
|
} catch (ee) {
|
|
591
662
|
console.error("[avatarChunkPlayback] audio chunk failed:", ee);
|
|
592
663
|
} finally {
|
|
593
|
-
if (i = !1,
|
|
664
|
+
if (i = !1, I) return;
|
|
594
665
|
const ee = n.shift();
|
|
595
|
-
ee ? await
|
|
596
|
-
|
|
597
|
-
|
|
666
|
+
ee ? await de(
|
|
667
|
+
y,
|
|
668
|
+
A,
|
|
598
669
|
ee.audio,
|
|
599
670
|
ee.visemes,
|
|
600
671
|
ee.words,
|
|
@@ -602,63 +673,63 @@ function qn(e, t) {
|
|
|
602
673
|
{
|
|
603
674
|
sampleRate: ee.sampleRate,
|
|
604
675
|
newStream: ee.newStream,
|
|
605
|
-
onNewStream:
|
|
676
|
+
onNewStream: C?.onNewStream
|
|
606
677
|
}
|
|
607
678
|
) : T();
|
|
608
679
|
}
|
|
609
680
|
};
|
|
610
681
|
return {
|
|
611
|
-
setStreamTtsEngineId: (
|
|
612
|
-
h =
|
|
682
|
+
setStreamTtsEngineId: (y) => {
|
|
683
|
+
h = y;
|
|
613
684
|
},
|
|
614
|
-
setPlaybackSpeed: (
|
|
615
|
-
b = Math.max(0.1, Math.min(1,
|
|
685
|
+
setPlaybackSpeed: (y) => {
|
|
686
|
+
b = Math.max(0.1, Math.min(1, y)), M();
|
|
616
687
|
},
|
|
617
688
|
getPlaybackSpeed: () => b,
|
|
618
|
-
setLipsyncWarmupHoldEnabled: (
|
|
619
|
-
p =
|
|
689
|
+
setLipsyncWarmupHoldEnabled: (y) => {
|
|
690
|
+
p = y, y || j();
|
|
620
691
|
},
|
|
621
692
|
isWarmingUp: () => v,
|
|
622
|
-
releaseWarmupHold:
|
|
623
|
-
resetForNewStream: (
|
|
624
|
-
|
|
693
|
+
releaseWarmupHold: ne,
|
|
694
|
+
resetForNewStream: (y) => {
|
|
695
|
+
I = !1, f = !1, h = y, _ = 0;
|
|
625
696
|
},
|
|
626
697
|
/** Next sentence in the same bot turn — keep viseme tail, allow more chunks. */
|
|
627
698
|
resumeBotStream: () => {
|
|
628
|
-
|
|
699
|
+
I = !1, f = !1;
|
|
629
700
|
},
|
|
630
701
|
/** After interrupt — allow the next utterance to queue/play again. */
|
|
631
702
|
clearAborted: () => {
|
|
632
|
-
|
|
703
|
+
I = !1;
|
|
633
704
|
},
|
|
634
705
|
/** Call from a user gesture before bot audio (connect / unlock). */
|
|
635
706
|
primeAudioContext: async () => {
|
|
636
|
-
const
|
|
637
|
-
s || (s = new
|
|
707
|
+
const y = window.AudioContext || window.webkitAudioContext;
|
|
708
|
+
s || (s = new y()), s.state === "suspended" && await s.resume(), s && !E && (E = s.createMediaStreamDestination());
|
|
638
709
|
},
|
|
639
710
|
stop: () => {
|
|
640
|
-
|
|
711
|
+
I = !0, R(), S(), n.length = 0, i = !1, a = !1, o = !1, f = !1, c = 0, m = 0, u = 0, d = 0, _ = 0, j();
|
|
641
712
|
},
|
|
642
|
-
markStreamComplete: (
|
|
643
|
-
if (_ = Math.max(_,
|
|
644
|
-
|
|
713
|
+
markStreamComplete: (y) => {
|
|
714
|
+
if (_ = Math.max(_, Fe(y)), f = !0, !o && y.length > 0) {
|
|
715
|
+
Z(y);
|
|
645
716
|
return;
|
|
646
717
|
}
|
|
647
718
|
T();
|
|
648
719
|
},
|
|
649
|
-
playAudioChunk:
|
|
650
|
-
queueTimingsOnly: (
|
|
651
|
-
if (
|
|
652
|
-
let
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
720
|
+
playAudioChunk: de,
|
|
721
|
+
queueTimingsOnly: (y, A, q, x, P) => {
|
|
722
|
+
if (I) return;
|
|
723
|
+
let $ = c;
|
|
724
|
+
P && y.length > 0 && ($ = Tn(y)), z(
|
|
725
|
+
y,
|
|
726
|
+
A,
|
|
656
727
|
q,
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
728
|
+
x,
|
|
729
|
+
$,
|
|
730
|
+
P,
|
|
660
731
|
h
|
|
661
|
-
), _ = Math.max(_,
|
|
732
|
+
), _ = Math.max(_, Fe(y));
|
|
662
733
|
},
|
|
663
734
|
getPlaybackElapsedMs: () => o && s && u > 0 ? Math.max(
|
|
664
735
|
0,
|
|
@@ -669,21 +740,21 @@ function qn(e, t) {
|
|
|
669
740
|
getPlaybackStartPerf: () => d,
|
|
670
741
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
671
742
|
bargeIn: () => {
|
|
672
|
-
|
|
743
|
+
I = !0, f = !1, R(), S(), n.length = 0, i = !1, a = !1, o = !1, c = 0, m = 0, u = 0, d = 0, _ = 0, j();
|
|
673
744
|
},
|
|
674
745
|
interrupt: () => {
|
|
675
|
-
|
|
746
|
+
I = !0, f = !1, R(), S(), n.length = 0, i = !1, a = !1, o = !1, c = 0, m = 0, u = 0, d = 0, _ = 0, j();
|
|
676
747
|
}
|
|
677
748
|
};
|
|
678
749
|
}
|
|
679
|
-
function
|
|
750
|
+
function Mt(e, t) {
|
|
680
751
|
let n = null;
|
|
681
752
|
for (const r of e)
|
|
682
753
|
t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
|
|
683
754
|
return n ? n.viseme : "sil";
|
|
684
755
|
}
|
|
685
|
-
function
|
|
686
|
-
const r =
|
|
756
|
+
function Qn(e, t, n = 120) {
|
|
757
|
+
const r = Mt(e, t);
|
|
687
758
|
if (r !== "sil") return r;
|
|
688
759
|
let s = null;
|
|
689
760
|
for (const i of e) {
|
|
@@ -693,7 +764,7 @@ function Kn(e, t, n = 120) {
|
|
|
693
764
|
}
|
|
694
765
|
return s?.viseme ?? "sil";
|
|
695
766
|
}
|
|
696
|
-
function
|
|
767
|
+
function Es(e, t, n = 400) {
|
|
697
768
|
const r = t - n;
|
|
698
769
|
let s = 0;
|
|
699
770
|
for (const i of e)
|
|
@@ -701,13 +772,13 @@ function ds(e, t, n = 400) {
|
|
|
701
772
|
else break;
|
|
702
773
|
s > 0 && e.splice(0, s);
|
|
703
774
|
}
|
|
704
|
-
function
|
|
775
|
+
function ea(e, t) {
|
|
705
776
|
for (const n of e)
|
|
706
777
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
707
778
|
return n;
|
|
708
779
|
return null;
|
|
709
780
|
}
|
|
710
|
-
function
|
|
781
|
+
function Ts(e, t) {
|
|
711
782
|
const n = e.trim();
|
|
712
783
|
if (!n) return null;
|
|
713
784
|
try {
|
|
@@ -717,64 +788,64 @@ function ms(e, t) {
|
|
|
717
788
|
return null;
|
|
718
789
|
}
|
|
719
790
|
}
|
|
720
|
-
const
|
|
721
|
-
function
|
|
791
|
+
const Qt = 0.5, Zt = 1.5, Zn = "Olivia", er = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Pt = 0.85;
|
|
792
|
+
function An(e, t = lt, n = {}) {
|
|
722
793
|
const r = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], a = [], o = [];
|
|
723
|
-
let f = "", d = "neutral", u = "", c =
|
|
794
|
+
let f = "", d = "neutral", u = "", c = je;
|
|
724
795
|
const m = /* @__PURE__ */ new Set();
|
|
725
|
-
let
|
|
726
|
-
const h = () => m.forEach((
|
|
727
|
-
let
|
|
728
|
-
const E =
|
|
796
|
+
let w = 0, b = null;
|
|
797
|
+
const h = () => m.forEach((R) => R());
|
|
798
|
+
let I = () => !1;
|
|
799
|
+
const E = Xn(
|
|
729
800
|
{
|
|
730
801
|
onSpeakingStart: () => e("speaking"),
|
|
731
802
|
onSpeakingDone: () => e("done"),
|
|
732
803
|
onNotify: h,
|
|
733
|
-
shouldHoldForWarmup: () =>
|
|
804
|
+
shouldHoldForWarmup: () => I()
|
|
734
805
|
},
|
|
735
|
-
|
|
736
|
-
), _ = () => E.getPlaybackElapsedMs(), p = (
|
|
806
|
+
je
|
|
807
|
+
), _ = () => E.getPlaybackElapsedMs(), p = (R, S = f) => {
|
|
737
808
|
if (!n.onLipsyncDebug) return;
|
|
738
|
-
const
|
|
809
|
+
const M = _(), T = s;
|
|
739
810
|
n.onLipsyncDebug({
|
|
740
|
-
event:
|
|
811
|
+
event: R,
|
|
741
812
|
spokenText: S,
|
|
742
813
|
mood: d,
|
|
743
814
|
playbackAnchorPerf: E.getPlaybackStartPerf(),
|
|
744
|
-
playbackElapsedMs:
|
|
815
|
+
playbackElapsedMs: M,
|
|
745
816
|
queueLength: T.length,
|
|
746
|
-
activeViseme:
|
|
747
|
-
segments: o.map((
|
|
748
|
-
...
|
|
749
|
-
visemes: [...
|
|
817
|
+
activeViseme: Mt(T, M),
|
|
818
|
+
segments: o.map((Z) => ({
|
|
819
|
+
...Z,
|
|
820
|
+
visemes: [...Z.visemes]
|
|
750
821
|
}))
|
|
751
822
|
});
|
|
752
|
-
}, v = (
|
|
753
|
-
n.onLipsyncDebug && (b = { event:
|
|
754
|
-
|
|
755
|
-
const
|
|
756
|
-
b = null,
|
|
823
|
+
}, v = (R, S) => {
|
|
824
|
+
n.onLipsyncDebug && (b = { event: R, spokenText: S }, w === 0 && (w = requestAnimationFrame(() => {
|
|
825
|
+
w = 0;
|
|
826
|
+
const M = b;
|
|
827
|
+
b = null, M && p(M.event, M.spokenText);
|
|
757
828
|
})));
|
|
758
|
-
},
|
|
829
|
+
}, N = (R, S, M, T, Z) => {
|
|
759
830
|
if (!n.onLipsyncDebug) return;
|
|
760
|
-
const
|
|
761
|
-
(
|
|
831
|
+
const D = s.slice(S), X = M.filter(
|
|
832
|
+
(z) => String(z.symbol ?? z.viseme ?? "").trim()
|
|
762
833
|
);
|
|
763
834
|
o.push({
|
|
764
|
-
spokenText:
|
|
765
|
-
audioOffsetMs:
|
|
835
|
+
spokenText: R,
|
|
836
|
+
audioOffsetMs: D[0]?.vtime ?? 0,
|
|
766
837
|
isNewSegment: T,
|
|
767
|
-
chunkDurationMs:
|
|
838
|
+
chunkDurationMs: Z,
|
|
768
839
|
receivedAtMs: performance.now(),
|
|
769
|
-
visemes:
|
|
770
|
-
const
|
|
840
|
+
visemes: D.map((z, se) => {
|
|
841
|
+
const ne = X[se];
|
|
771
842
|
return {
|
|
772
|
-
rawSymbol: String(
|
|
773
|
-
viseme:
|
|
774
|
-
startSec: Number(
|
|
775
|
-
durationSec: Number(
|
|
776
|
-
vtimeMs:
|
|
777
|
-
vdurationMs:
|
|
843
|
+
rawSymbol: String(ne?.symbol ?? ne?.viseme ?? z.viseme).trim(),
|
|
844
|
+
viseme: z.viseme,
|
|
845
|
+
startSec: Number(ne?.start ?? 0),
|
|
846
|
+
durationSec: Number(ne?.duration ?? 0),
|
|
847
|
+
vtimeMs: z.vtime,
|
|
848
|
+
vdurationMs: z.vduration
|
|
778
849
|
};
|
|
779
850
|
})
|
|
780
851
|
});
|
|
@@ -782,118 +853,118 @@ function vn(e, t = dt, n = {}) {
|
|
|
782
853
|
E.stop(), s.length = 0, i.length = 0, a.length = 0, d = "neutral", o.length = 0, f = "", e("idle"), v("reset"), h();
|
|
783
854
|
};
|
|
784
855
|
return {
|
|
785
|
-
setDeveloperToken: (
|
|
786
|
-
u =
|
|
856
|
+
setDeveloperToken: (R) => {
|
|
857
|
+
u = R;
|
|
787
858
|
},
|
|
788
|
-
setTtsEngineId: (
|
|
789
|
-
c =
|
|
859
|
+
setTtsEngineId: (R) => {
|
|
860
|
+
c = R;
|
|
790
861
|
},
|
|
791
862
|
getTtsEngineId: () => c,
|
|
792
|
-
speak: async (
|
|
793
|
-
F(), e("loading"), f =
|
|
794
|
-
const
|
|
795
|
-
if (!
|
|
863
|
+
speak: async (R, S) => {
|
|
864
|
+
F(), e("loading"), f = R, o.length = 0;
|
|
865
|
+
const M = u.trim();
|
|
866
|
+
if (!M)
|
|
796
867
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
797
|
-
const T = S?.ttsEngineId ?? c ??
|
|
868
|
+
const T = S?.ttsEngineId ?? c ?? je;
|
|
798
869
|
E.resetForNewStream(T), E.setStreamTtsEngineId(T);
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
Math.min(
|
|
802
|
-
),
|
|
803
|
-
user_query:
|
|
870
|
+
const Z = S?.voiceId ?? Zn, D = S?.speakingRate ?? Pt, X = Math.max(
|
|
871
|
+
Qt,
|
|
872
|
+
Math.min(Zt, D)
|
|
873
|
+
), z = {
|
|
874
|
+
user_query: R,
|
|
804
875
|
ttsEngineId: T,
|
|
805
|
-
speakingRate:
|
|
876
|
+
speakingRate: X,
|
|
806
877
|
tenant: "aiTwin"
|
|
807
878
|
};
|
|
808
|
-
|
|
879
|
+
$n.has(T) && (z.voice_id = Z);
|
|
809
880
|
try {
|
|
810
|
-
const
|
|
881
|
+
const se = await fetch(r, {
|
|
811
882
|
method: "POST",
|
|
812
883
|
headers: {
|
|
813
884
|
"Content-Type": "application/json",
|
|
814
|
-
Authorization: `Bearer ${
|
|
885
|
+
Authorization: `Bearer ${M}`
|
|
815
886
|
},
|
|
816
|
-
body: JSON.stringify(
|
|
887
|
+
body: JSON.stringify(z)
|
|
817
888
|
});
|
|
818
|
-
if (!
|
|
819
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
820
|
-
const
|
|
821
|
-
if (!
|
|
822
|
-
const
|
|
823
|
-
let
|
|
824
|
-
const
|
|
825
|
-
const
|
|
826
|
-
if (
|
|
827
|
-
if (
|
|
828
|
-
const
|
|
829
|
-
|
|
889
|
+
if (!se.ok)
|
|
890
|
+
throw new Error(`avatar_ttsWithPoses failed (${se.status})`);
|
|
891
|
+
const ne = se.body;
|
|
892
|
+
if (!ne) throw new Error("No response body");
|
|
893
|
+
const de = ne.getReader(), ue = new TextDecoder();
|
|
894
|
+
let y = "";
|
|
895
|
+
const A = async (q) => {
|
|
896
|
+
const x = Kn(q);
|
|
897
|
+
if (x) {
|
|
898
|
+
if (x.event === "audio") {
|
|
899
|
+
const P = x.data.chunk, $ = x.data.visemes ?? [], C = x.data.words ?? [], B = x.data.is_new_segment ?? !1, Y = x.data.sample_rate, ee = s.length;
|
|
900
|
+
P ? (await E.playAudioChunk(
|
|
830
901
|
s,
|
|
831
902
|
i,
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
{ sampleRate:
|
|
837
|
-
),
|
|
838
|
-
|
|
903
|
+
P,
|
|
904
|
+
$,
|
|
905
|
+
C,
|
|
906
|
+
B,
|
|
907
|
+
{ sampleRate: Y }
|
|
908
|
+
), N(
|
|
909
|
+
R,
|
|
839
910
|
ee,
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
), v("audio_chunk",
|
|
911
|
+
$,
|
|
912
|
+
B,
|
|
913
|
+
Ts(P, Y)
|
|
914
|
+
), v("audio_chunk", R)) : ($.length > 0 || C.length > 0) && (E.queueTimingsOnly(
|
|
844
915
|
s,
|
|
845
916
|
i,
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
),
|
|
850
|
-
|
|
917
|
+
$,
|
|
918
|
+
C,
|
|
919
|
+
B
|
|
920
|
+
), N(
|
|
921
|
+
R,
|
|
851
922
|
ee,
|
|
852
|
-
|
|
853
|
-
|
|
923
|
+
$,
|
|
924
|
+
B,
|
|
854
925
|
null
|
|
855
|
-
), v("audio_chunk",
|
|
856
|
-
} else if (
|
|
857
|
-
const
|
|
858
|
-
typeof
|
|
859
|
-
const
|
|
860
|
-
if (Array.isArray(
|
|
926
|
+
), v("audio_chunk", R));
|
|
927
|
+
} else if (x.event === "metadata") {
|
|
928
|
+
const P = x.data.mood;
|
|
929
|
+
typeof P == "string" && P.trim() && (d = P.trim());
|
|
930
|
+
const $ = x.data.sentence_emotions;
|
|
931
|
+
if (Array.isArray($)) {
|
|
861
932
|
a.length = 0;
|
|
862
|
-
for (const
|
|
863
|
-
if (!
|
|
864
|
-
const
|
|
933
|
+
for (const C of $) {
|
|
934
|
+
if (!C || typeof C != "object") continue;
|
|
935
|
+
const B = C;
|
|
865
936
|
a.push({
|
|
866
|
-
sentence_index: Number(
|
|
867
|
-
text: String(
|
|
868
|
-
sentiment: typeof
|
|
869
|
-
emotion: String(
|
|
870
|
-
start_word: Number(
|
|
871
|
-
end_word: Number(
|
|
937
|
+
sentence_index: Number(B.sentence_index ?? 0),
|
|
938
|
+
text: String(B.text ?? ""),
|
|
939
|
+
sentiment: typeof B.sentiment == "string" ? B.sentiment : void 0,
|
|
940
|
+
emotion: String(B.emotion ?? d),
|
|
941
|
+
start_word: Number(B.start_word ?? 0),
|
|
942
|
+
end_word: Number(B.end_word ?? 0)
|
|
872
943
|
});
|
|
873
944
|
}
|
|
874
945
|
}
|
|
875
|
-
h(), v("metadata",
|
|
876
|
-
} else if (
|
|
946
|
+
h(), v("metadata", R);
|
|
947
|
+
} else if (x.event === "error")
|
|
877
948
|
throw new Error(
|
|
878
|
-
String(
|
|
949
|
+
String(x.data.message ?? "avatar_ttsWithPoses stream error")
|
|
879
950
|
);
|
|
880
951
|
}
|
|
881
952
|
};
|
|
882
953
|
for (; ; ) {
|
|
883
|
-
const { done: q, value:
|
|
884
|
-
|
|
885
|
-
const
|
|
954
|
+
const { done: q, value: x } = await de.read();
|
|
955
|
+
x && (y += ue.decode(x, { stream: !0 }));
|
|
956
|
+
const P = y.split(`
|
|
886
957
|
|
|
887
958
|
`);
|
|
888
|
-
|
|
889
|
-
for (const
|
|
959
|
+
y = P.pop() ?? "";
|
|
960
|
+
for (const $ of P) await A($);
|
|
890
961
|
if (q) {
|
|
891
|
-
|
|
962
|
+
y.trim() && await A(y.trim()), E.markStreamComplete(s), v("bot_stopped", R);
|
|
892
963
|
break;
|
|
893
964
|
}
|
|
894
965
|
}
|
|
895
|
-
} catch (
|
|
896
|
-
throw console.error("[avatarTtsLipsync]",
|
|
966
|
+
} catch (se) {
|
|
967
|
+
throw console.error("[avatarTtsLipsync]", se), F(), e("error"), se;
|
|
897
968
|
}
|
|
898
969
|
},
|
|
899
970
|
stop: F,
|
|
@@ -905,19 +976,19 @@ function vn(e, t = dt, n = {}) {
|
|
|
905
976
|
isSpeaking: () => E.isSpeaking(),
|
|
906
977
|
isWarmingUp: () => E.isWarmingUp(),
|
|
907
978
|
releaseWarmupHold: () => E.releaseWarmupHold(),
|
|
908
|
-
setLipsyncWarmupHold: (
|
|
909
|
-
S && (
|
|
979
|
+
setLipsyncWarmupHold: (R, S) => {
|
|
980
|
+
S && (I = S), E.setLipsyncWarmupHoldEnabled(R);
|
|
910
981
|
},
|
|
911
982
|
getVoiceStream: () => E.getVoiceStream(),
|
|
912
|
-
setPlaybackSpeed: (
|
|
913
|
-
E.setPlaybackSpeed(
|
|
983
|
+
setPlaybackSpeed: (R) => {
|
|
984
|
+
E.setPlaybackSpeed(R);
|
|
914
985
|
},
|
|
915
986
|
getPlaybackSpeed: () => E.getPlaybackSpeed(),
|
|
916
|
-
subscribe: (
|
|
987
|
+
subscribe: (R) => (m.add(R), () => m.delete(R))
|
|
917
988
|
};
|
|
918
989
|
}
|
|
919
|
-
const
|
|
920
|
-
class
|
|
990
|
+
const tr = 16e3, nr = 16e3;
|
|
991
|
+
class As extends Er {
|
|
921
992
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
922
993
|
async deserialize(t) {
|
|
923
994
|
try {
|
|
@@ -929,7 +1000,7 @@ class hs extends yr {
|
|
|
929
1000
|
}
|
|
930
1001
|
}
|
|
931
1002
|
}
|
|
932
|
-
class
|
|
1003
|
+
class Is extends vr {
|
|
933
1004
|
constructor() {
|
|
934
1005
|
super(
|
|
935
1006
|
!0,
|
|
@@ -937,39 +1008,39 @@ class ps extends gr {
|
|
|
937
1008
|
void 0,
|
|
938
1009
|
void 0,
|
|
939
1010
|
512,
|
|
940
|
-
|
|
941
|
-
|
|
1011
|
+
tr,
|
|
1012
|
+
nr
|
|
942
1013
|
);
|
|
943
1014
|
}
|
|
944
1015
|
/** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
|
|
945
1016
|
bufferBotAudio(t, n) {
|
|
946
1017
|
}
|
|
947
1018
|
}
|
|
948
|
-
const
|
|
949
|
-
function
|
|
950
|
-
return
|
|
1019
|
+
const Ms = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1020
|
+
function Ps(e) {
|
|
1021
|
+
return Ms.test(e.trim());
|
|
951
1022
|
}
|
|
952
|
-
function
|
|
1023
|
+
function Rs(e) {
|
|
953
1024
|
const t = e.replace(/\/$/, "");
|
|
954
1025
|
return t.startsWith("https://") ? `wss://${t.slice(8)}` : t.startsWith("http://") ? `ws://${t.slice(7)}` : t;
|
|
955
1026
|
}
|
|
956
|
-
function
|
|
1027
|
+
function Ds(e) {
|
|
957
1028
|
if (e.wsUrl?.trim()) return e.wsUrl.trim();
|
|
958
1029
|
const t = e.authToken?.trim();
|
|
959
1030
|
if (!t)
|
|
960
1031
|
throw new Error(
|
|
961
1032
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
962
1033
|
);
|
|
963
|
-
const n = e.apiBase ??
|
|
1034
|
+
const n = e.apiBase ?? lt, r = new URL(`${Rs(n)}/ws/voice`);
|
|
964
1035
|
r.searchParams.set("authToken", t), r.searchParams.set("tenant", "aiTwin");
|
|
965
1036
|
const s = e.voiceId?.trim();
|
|
966
|
-
s &&
|
|
1037
|
+
s && Ps(s) && r.searchParams.set("voiceId", s);
|
|
967
1038
|
const i = e.personaId?.trim();
|
|
968
1039
|
i && r.searchParams.set("personaId", i);
|
|
969
|
-
const a = e.speakingRate ??
|
|
1040
|
+
const a = e.speakingRate ?? Pt;
|
|
970
1041
|
return r.searchParams.set(
|
|
971
1042
|
"speaking_rate",
|
|
972
|
-
String(Math.max(
|
|
1043
|
+
String(Math.max(Qt, Math.min(Zt, a)))
|
|
973
1044
|
), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
|
|
974
1045
|
}
|
|
975
1046
|
function Lt(e, t) {
|
|
@@ -986,7 +1057,7 @@ function Lt(e, t) {
|
|
|
986
1057
|
});
|
|
987
1058
|
return n;
|
|
988
1059
|
}
|
|
989
|
-
function
|
|
1060
|
+
function xs(e) {
|
|
990
1061
|
if (!e || typeof e != "object") return null;
|
|
991
1062
|
const t = e, r = (t.data && typeof t.data == "object" && !Array.isArray(t.data) ? t.data : null) || t;
|
|
992
1063
|
return {
|
|
@@ -997,63 +1068,63 @@ function Ss(e) {
|
|
|
997
1068
|
function Ot(e) {
|
|
998
1069
|
return e.is_new_segment === !0 || Number(e.audio_offset_ms ?? -1) === 0 ? !0 : Number(e.chunk_index ?? -1) === 0;
|
|
999
1070
|
}
|
|
1000
|
-
function
|
|
1071
|
+
function Bs(e) {
|
|
1001
1072
|
return e?.transport?._mediaManager?._wavStreamPlayer ?? null;
|
|
1002
1073
|
}
|
|
1003
|
-
function
|
|
1074
|
+
function Cs(e, t = {}) {
|
|
1004
1075
|
const n = [], r = [], s = [], i = [];
|
|
1005
|
-
let a = "", o = "neutral", f =
|
|
1006
|
-
const h = /* @__PURE__ */ new Set(),
|
|
1076
|
+
let a = "", o = "neutral", f = Xe, d = !1, u = null, c = null, m = { ...t }, w = 0, b = null;
|
|
1077
|
+
const h = /* @__PURE__ */ new Set(), I = [];
|
|
1007
1078
|
let E = !1, _ = null, p = !0, v = "default";
|
|
1008
|
-
const
|
|
1009
|
-
let F = null,
|
|
1010
|
-
const
|
|
1079
|
+
const N = /* @__PURE__ */ new Set();
|
|
1080
|
+
let F = null, j = 0, R = !1, S = null;
|
|
1081
|
+
const M = () => {
|
|
1011
1082
|
S != null && (clearTimeout(S), S = null);
|
|
1012
1083
|
}, T = () => h.forEach((l) => l());
|
|
1013
|
-
let
|
|
1014
|
-
const
|
|
1084
|
+
let Z = () => !1;
|
|
1085
|
+
const D = Xn(
|
|
1015
1086
|
{
|
|
1016
1087
|
onSpeakingStart: () => e("speaking"),
|
|
1017
1088
|
onSpeakingDone: () => e("done"),
|
|
1018
1089
|
onNotify: T,
|
|
1019
|
-
shouldHoldForWarmup: () =>
|
|
1090
|
+
shouldHoldForWarmup: () => Z()
|
|
1020
1091
|
},
|
|
1021
1092
|
f
|
|
1022
|
-
),
|
|
1093
|
+
), X = () => {
|
|
1023
1094
|
if (_) return _;
|
|
1024
1095
|
const l = new MessageChannel();
|
|
1025
1096
|
return l.port1.onmessage = () => {
|
|
1026
|
-
const k =
|
|
1027
|
-
k !== void 0 &&
|
|
1097
|
+
const k = I.shift();
|
|
1098
|
+
k !== void 0 && le(k), I.length > 0 ? l.port2.postMessage(null) : E = !1;
|
|
1028
1099
|
}, _ = l, l;
|
|
1029
|
-
},
|
|
1030
|
-
|
|
1031
|
-
},
|
|
1100
|
+
}, z = (l) => {
|
|
1101
|
+
I.push(l), !E && (E = !0, X().port2.postMessage(null));
|
|
1102
|
+
}, se = () => D.getPlaybackElapsedMs(), ne = (l, k = a) => {
|
|
1032
1103
|
if (!m.onLipsyncDebug) return;
|
|
1033
|
-
const
|
|
1104
|
+
const V = se(), K = n;
|
|
1034
1105
|
m.onLipsyncDebug({
|
|
1035
1106
|
event: l,
|
|
1036
1107
|
spokenText: k,
|
|
1037
1108
|
mood: o,
|
|
1038
|
-
playbackAnchorPerf:
|
|
1039
|
-
playbackElapsedMs:
|
|
1040
|
-
queueLength:
|
|
1041
|
-
activeViseme:
|
|
1042
|
-
segments: i.map((
|
|
1043
|
-
...
|
|
1044
|
-
visemes: [...
|
|
1109
|
+
playbackAnchorPerf: D.getPlaybackStartPerf(),
|
|
1110
|
+
playbackElapsedMs: V,
|
|
1111
|
+
queueLength: K.length,
|
|
1112
|
+
activeViseme: Mt(K, V),
|
|
1113
|
+
segments: i.map((ie) => ({
|
|
1114
|
+
...ie,
|
|
1115
|
+
visemes: [...ie.visemes]
|
|
1045
1116
|
}))
|
|
1046
1117
|
});
|
|
1047
|
-
},
|
|
1048
|
-
m.onLipsyncDebug && (b = { event: l, spokenText: k },
|
|
1049
|
-
|
|
1050
|
-
const
|
|
1051
|
-
b = null,
|
|
1118
|
+
}, de = (l, k) => {
|
|
1119
|
+
m.onLipsyncDebug && (b = { event: l, spokenText: k }, w === 0 && (w = requestAnimationFrame(() => {
|
|
1120
|
+
w = 0;
|
|
1121
|
+
const V = b;
|
|
1122
|
+
b = null, V && ne(V.event, V.spokenText);
|
|
1052
1123
|
})));
|
|
1053
|
-
},
|
|
1054
|
-
p = !0,
|
|
1055
|
-
},
|
|
1056
|
-
const l =
|
|
1124
|
+
}, ue = () => {
|
|
1125
|
+
p = !0, N.clear(), D.clearAborted();
|
|
1126
|
+
}, y = () => {
|
|
1127
|
+
const l = Bs(u);
|
|
1057
1128
|
if (l) {
|
|
1058
1129
|
v = `bot-${Date.now()}`, l.interruptedTrackIds = { [v]: !0 };
|
|
1059
1130
|
try {
|
|
@@ -1066,225 +1137,225 @@ function bs(e, t = {}) {
|
|
|
1066
1137
|
k?.interrupt?.();
|
|
1067
1138
|
} catch {
|
|
1068
1139
|
}
|
|
1069
|
-
},
|
|
1140
|
+
}, A = (l) => {
|
|
1070
1141
|
const k = l.context_id?.trim();
|
|
1071
|
-
return k &&
|
|
1142
|
+
return k && N.has(k) ? !0 : p ? !1 : !(l.type === "avatar_metadata" || Ot(l));
|
|
1072
1143
|
}, q = (l) => {
|
|
1073
1144
|
p = !1;
|
|
1074
1145
|
const k = l.context_id?.trim();
|
|
1075
|
-
k &&
|
|
1076
|
-
},
|
|
1146
|
+
k && N.add(k), M(), R = !1, I.length = 0, E = !1, F?.abort(), F = null, j += 1, y(), D.bargeIn(), x(), e("idle"), de("interrupt"), T();
|
|
1147
|
+
}, x = () => {
|
|
1077
1148
|
n.length = 0, r.length = 0, i.length = 0, a = "", o = "neutral", s.length = 0;
|
|
1078
|
-
},
|
|
1079
|
-
|
|
1080
|
-
},
|
|
1081
|
-
|
|
1082
|
-
},
|
|
1149
|
+
}, P = () => {
|
|
1150
|
+
D.stop(), x(), de("reset"), T();
|
|
1151
|
+
}, $ = () => {
|
|
1152
|
+
P(), e("idle"), T();
|
|
1153
|
+
}, C = (l, k) => {
|
|
1083
1154
|
typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), Array.isArray(l.sentence_emotions) && l.sentence_emotions.length > 0 && (k && (s.length = 0), s.push(
|
|
1084
1155
|
...Lt(l.sentence_emotions, o)
|
|
1085
1156
|
));
|
|
1086
|
-
},
|
|
1087
|
-
if (
|
|
1157
|
+
}, B = (l) => {
|
|
1158
|
+
if (A({ ...l, type: "avatar_metadata" }))
|
|
1088
1159
|
return;
|
|
1089
|
-
|
|
1160
|
+
ue(), R = !0;
|
|
1090
1161
|
const k = String(l.spoken_text ?? l.text ?? "").trim();
|
|
1091
|
-
k && (a = k),
|
|
1162
|
+
k && (a = k), D.resetForNewStream(f), typeof l.mood == "string" && l.mood.trim() && (o = l.mood.trim()), s.length = 0, s.push(
|
|
1092
1163
|
...Lt(l.sentence_emotions, o)
|
|
1093
|
-
), Array.isArray(l.gestures) && l.gestures,
|
|
1094
|
-
},
|
|
1164
|
+
), Array.isArray(l.gestures) && l.gestures, de("metadata", k), T();
|
|
1165
|
+
}, Y = (l, k, V, K) => {
|
|
1095
1166
|
if (!m.onLipsyncDebug) return;
|
|
1096
|
-
const
|
|
1097
|
-
(
|
|
1167
|
+
const ie = n.slice(V), Pe = K.filter(
|
|
1168
|
+
(ae) => String(ae.symbol ?? ae.viseme ?? "").trim()
|
|
1098
1169
|
);
|
|
1099
1170
|
i.push({
|
|
1100
1171
|
spokenText: k,
|
|
1101
|
-
audioOffsetMs:
|
|
1172
|
+
audioOffsetMs: ie[0]?.vtime ?? 0,
|
|
1102
1173
|
isNewSegment: !!l.is_new_segment,
|
|
1103
1174
|
chunkDurationMs: l.chunk_duration_ms != null ? Number(l.chunk_duration_ms) : null,
|
|
1104
1175
|
receivedAtMs: performance.now(),
|
|
1105
|
-
visemes:
|
|
1106
|
-
const
|
|
1176
|
+
visemes: ie.map((ae, Re) => {
|
|
1177
|
+
const ge = Pe[Re];
|
|
1107
1178
|
return {
|
|
1108
|
-
rawSymbol: String(
|
|
1109
|
-
viseme:
|
|
1110
|
-
startSec: Number(
|
|
1111
|
-
durationSec: Number(
|
|
1112
|
-
vtimeMs:
|
|
1113
|
-
vdurationMs:
|
|
1179
|
+
rawSymbol: String(ge?.symbol ?? ge?.viseme ?? ae.viseme).trim(),
|
|
1180
|
+
viseme: ae.viseme,
|
|
1181
|
+
startSec: Number(ge?.start ?? 0),
|
|
1182
|
+
durationSec: Number(ge?.duration ?? 0),
|
|
1183
|
+
vtimeMs: ae.vtime,
|
|
1184
|
+
vdurationMs: ae.vduration
|
|
1114
1185
|
};
|
|
1115
1186
|
})
|
|
1116
1187
|
});
|
|
1117
1188
|
}, ee = (l) => {
|
|
1118
|
-
if (
|
|
1119
|
-
|
|
1120
|
-
const k = String(l.spoken_text ?? l.text ?? "").trim(),
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1123
|
-
|
|
1189
|
+
if (A(l)) return;
|
|
1190
|
+
M(), Ot(l) && ue();
|
|
1191
|
+
const k = String(l.spoken_text ?? l.text ?? "").trim(), V = Ot(l), K = l.visemes ?? [], ie = l.words ?? [], Pe = String(l.chunk ?? "").trim(), ae = R;
|
|
1192
|
+
ae && (R = !1), k && (a = k), C(l, V), ae ? D.resetForNewStream(f) : V && D.resumeBotStream();
|
|
1193
|
+
const Re = n.length;
|
|
1194
|
+
D.playAudioChunk(
|
|
1124
1195
|
n,
|
|
1125
1196
|
r,
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1197
|
+
Pe,
|
|
1198
|
+
K,
|
|
1199
|
+
ie,
|
|
1200
|
+
V,
|
|
1130
1201
|
{
|
|
1131
1202
|
sampleRate: l.sample_rate,
|
|
1132
|
-
newStream:
|
|
1203
|
+
newStream: ae,
|
|
1133
1204
|
onNewStream: () => {
|
|
1134
1205
|
i.length = 0;
|
|
1135
1206
|
}
|
|
1136
1207
|
}
|
|
1137
1208
|
).then(() => {
|
|
1138
|
-
|
|
1209
|
+
Y(l, k, Re, K), de("audio_chunk", k);
|
|
1139
1210
|
});
|
|
1140
|
-
},
|
|
1141
|
-
if (
|
|
1142
|
-
(l.is_new_segment || Number(l.audio_offset_ms ?? -1) === 0) &&
|
|
1211
|
+
}, pe = (l) => {
|
|
1212
|
+
if (A(l)) return;
|
|
1213
|
+
(l.is_new_segment || Number(l.audio_offset_ms ?? -1) === 0) && ue(), console.warn(
|
|
1143
1214
|
"[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
|
|
1144
1215
|
);
|
|
1145
1216
|
const k = String(l.spoken_text ?? l.text ?? "").trim();
|
|
1146
|
-
k && (a = k),
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1217
|
+
k && (a = k), C(l, !!l.is_new_segment);
|
|
1218
|
+
const V = n.length;
|
|
1219
|
+
D.queueTimingsOnly(
|
|
1149
1220
|
n,
|
|
1150
1221
|
r,
|
|
1151
1222
|
l.visemes ?? [],
|
|
1152
1223
|
l.words ?? [],
|
|
1153
1224
|
!!l.is_new_segment
|
|
1154
|
-
),
|
|
1225
|
+
), Y(
|
|
1155
1226
|
l,
|
|
1156
1227
|
k,
|
|
1157
|
-
|
|
1228
|
+
V,
|
|
1158
1229
|
l.visemes ?? []
|
|
1159
|
-
),
|
|
1160
|
-
},
|
|
1230
|
+
), de("lipsync", k), T();
|
|
1231
|
+
}, me = async (l) => {
|
|
1161
1232
|
const k = String(l.text ?? "").trim();
|
|
1162
1233
|
if (!k) return;
|
|
1163
|
-
const
|
|
1164
|
-
if (!
|
|
1234
|
+
const V = m.authToken?.trim();
|
|
1235
|
+
if (!V) {
|
|
1165
1236
|
console.error("[realtimeVoice] avatar_speak requires authToken");
|
|
1166
1237
|
return;
|
|
1167
1238
|
}
|
|
1168
1239
|
F?.abort();
|
|
1169
|
-
const
|
|
1170
|
-
F =
|
|
1171
|
-
const
|
|
1172
|
-
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
-
Math.min(
|
|
1176
|
-
),
|
|
1240
|
+
const K = new AbortController();
|
|
1241
|
+
F = K;
|
|
1242
|
+
const ie = ++j;
|
|
1243
|
+
ue(), D.resetForNewStream(f), a = k;
|
|
1244
|
+
const ae = `${(m.apiBase ?? lt).replace(/\/$/, "")}/avatar_ttsWithPoses`, Re = m.voiceId?.trim() || er, ge = m.speakingRate ?? Pt, Ze = Math.max(
|
|
1245
|
+
Qt,
|
|
1246
|
+
Math.min(Zt, ge)
|
|
1247
|
+
), et = {
|
|
1177
1248
|
user_query: k,
|
|
1178
1249
|
ttsEngineId: f,
|
|
1179
|
-
speakingRate:
|
|
1250
|
+
speakingRate: Ze,
|
|
1180
1251
|
tenant: "aiTwin"
|
|
1181
1252
|
};
|
|
1182
|
-
|
|
1253
|
+
$n.has(f) && (et.voice_id = Re);
|
|
1183
1254
|
try {
|
|
1184
|
-
const
|
|
1255
|
+
const re = await fetch(ae, {
|
|
1185
1256
|
method: "POST",
|
|
1186
1257
|
headers: {
|
|
1187
1258
|
"Content-Type": "application/json",
|
|
1188
|
-
Authorization: `Bearer ${
|
|
1259
|
+
Authorization: `Bearer ${V}`
|
|
1189
1260
|
},
|
|
1190
|
-
body: JSON.stringify(
|
|
1191
|
-
signal:
|
|
1261
|
+
body: JSON.stringify(et),
|
|
1262
|
+
signal: K.signal
|
|
1192
1263
|
});
|
|
1193
|
-
if (!
|
|
1194
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
1195
|
-
const
|
|
1196
|
-
if (!
|
|
1197
|
-
const
|
|
1198
|
-
let
|
|
1199
|
-
const
|
|
1200
|
-
if (
|
|
1264
|
+
if (!re.ok)
|
|
1265
|
+
throw new Error(`avatar_ttsWithPoses failed (${re.status})`);
|
|
1266
|
+
const tt = re.body;
|
|
1267
|
+
if (!tt) throw new Error("No response body");
|
|
1268
|
+
const dt = tt.getReader(), mt = new TextDecoder();
|
|
1269
|
+
let be = "";
|
|
1270
|
+
const nt = async (ve) => {
|
|
1271
|
+
if (ie !== j || K.signal.aborted || !p)
|
|
1201
1272
|
return;
|
|
1202
|
-
const
|
|
1203
|
-
if (
|
|
1204
|
-
if (
|
|
1205
|
-
const
|
|
1206
|
-
|
|
1273
|
+
const oe = Kn(ve);
|
|
1274
|
+
if (oe) {
|
|
1275
|
+
if (oe.event === "audio") {
|
|
1276
|
+
const ce = oe.data.chunk, he = oe.data.visemes ?? [], J = oe.data.words ?? [], Q = oe.data.is_new_segment ?? !1, ht = oe.data.sample_rate;
|
|
1277
|
+
ce ? await D.playAudioChunk(
|
|
1207
1278
|
n,
|
|
1208
1279
|
r,
|
|
1209
|
-
|
|
1210
|
-
|
|
1280
|
+
ce,
|
|
1281
|
+
he,
|
|
1211
1282
|
J,
|
|
1212
|
-
|
|
1213
|
-
{ sampleRate:
|
|
1214
|
-
) : (
|
|
1283
|
+
Q,
|
|
1284
|
+
{ sampleRate: ht }
|
|
1285
|
+
) : (he.length > 0 || J.length > 0) && D.queueTimingsOnly(
|
|
1215
1286
|
n,
|
|
1216
1287
|
r,
|
|
1217
|
-
|
|
1288
|
+
he,
|
|
1218
1289
|
J,
|
|
1219
|
-
|
|
1290
|
+
Q
|
|
1220
1291
|
);
|
|
1221
|
-
} else if (
|
|
1222
|
-
const
|
|
1223
|
-
typeof
|
|
1224
|
-
const
|
|
1225
|
-
Array.isArray(
|
|
1226
|
-
...Lt(
|
|
1292
|
+
} else if (oe.event === "metadata") {
|
|
1293
|
+
const ce = oe.data.mood;
|
|
1294
|
+
typeof ce == "string" && ce.trim() && (o = ce.trim());
|
|
1295
|
+
const he = oe.data.sentence_emotions;
|
|
1296
|
+
Array.isArray(he) && (s.length = 0, s.push(
|
|
1297
|
+
...Lt(he, o)
|
|
1227
1298
|
)), T();
|
|
1228
|
-
} else if (
|
|
1299
|
+
} else if (oe.event === "error")
|
|
1229
1300
|
throw new Error(
|
|
1230
|
-
String(
|
|
1301
|
+
String(oe.data.message ?? "avatar_ttsWithPoses stream error")
|
|
1231
1302
|
);
|
|
1232
1303
|
}
|
|
1233
1304
|
};
|
|
1234
|
-
for (; !(
|
|
1235
|
-
const { done:
|
|
1236
|
-
|
|
1237
|
-
const
|
|
1305
|
+
for (; !(ie !== j || K.signal.aborted || !p); ) {
|
|
1306
|
+
const { done: ve, value: oe } = await dt.read();
|
|
1307
|
+
oe && (be += mt.decode(oe, { stream: !0 }));
|
|
1308
|
+
const ce = be.split(`
|
|
1238
1309
|
|
|
1239
1310
|
`);
|
|
1240
|
-
|
|
1241
|
-
for (const
|
|
1242
|
-
if (
|
|
1243
|
-
|
|
1311
|
+
be = ce.pop() ?? "";
|
|
1312
|
+
for (const he of ce) await nt(he);
|
|
1313
|
+
if (ve) {
|
|
1314
|
+
be.trim() && await nt(be.trim()), ie === j && !K.signal.aborted && p && D.markStreamComplete(n);
|
|
1244
1315
|
break;
|
|
1245
1316
|
}
|
|
1246
1317
|
}
|
|
1247
|
-
} catch (
|
|
1248
|
-
if (
|
|
1249
|
-
console.error("[realtimeVoice] avatar_speak failed:",
|
|
1318
|
+
} catch (re) {
|
|
1319
|
+
if (K.signal.aborted || !p) return;
|
|
1320
|
+
console.error("[realtimeVoice] avatar_speak failed:", re), e("error"), T();
|
|
1250
1321
|
} finally {
|
|
1251
|
-
F ===
|
|
1322
|
+
F === K && (F = null);
|
|
1252
1323
|
}
|
|
1253
|
-
},
|
|
1254
|
-
const k =
|
|
1324
|
+
}, le = (l) => {
|
|
1325
|
+
const k = xs(l);
|
|
1255
1326
|
if (!k) {
|
|
1256
1327
|
console.warn("[realtimeVoice] server message with no payload", l);
|
|
1257
1328
|
return;
|
|
1258
1329
|
}
|
|
1259
|
-
const
|
|
1260
|
-
switch (
|
|
1330
|
+
const V = String(k.type ?? "unknown");
|
|
1331
|
+
switch (V !== "avatar_metadata" && V !== "avatar_audio_chunk" && V !== "avatar_lipsync" && V !== "avatar_interrupt" && V !== "error" && console.debug("[realtimeVoice] server message", V, k), V) {
|
|
1261
1332
|
case "avatar_metadata":
|
|
1262
|
-
|
|
1333
|
+
B(k);
|
|
1263
1334
|
break;
|
|
1264
1335
|
case "avatar_audio_chunk":
|
|
1265
1336
|
ee(k);
|
|
1266
1337
|
break;
|
|
1267
1338
|
case "avatar_lipsync":
|
|
1268
|
-
|
|
1339
|
+
pe(k);
|
|
1269
1340
|
break;
|
|
1270
1341
|
case "avatar_interrupt":
|
|
1271
1342
|
q(k);
|
|
1272
1343
|
break;
|
|
1273
1344
|
case "error": {
|
|
1274
|
-
const
|
|
1275
|
-
console.error("[realtimeVoice] server error:",
|
|
1345
|
+
const K = String(k.message ?? "Voice session error");
|
|
1346
|
+
console.error("[realtimeVoice] server error:", K), e("error"), T();
|
|
1276
1347
|
break;
|
|
1277
1348
|
}
|
|
1278
1349
|
case "avatar_speak":
|
|
1279
|
-
|
|
1350
|
+
me(k);
|
|
1280
1351
|
break;
|
|
1281
1352
|
}
|
|
1282
|
-
},
|
|
1283
|
-
transport: new
|
|
1353
|
+
}, fe = () => u || (c = new Is(), u = new kr({
|
|
1354
|
+
transport: new br({
|
|
1284
1355
|
mediaManager: c,
|
|
1285
|
-
serializer: new
|
|
1286
|
-
recorderSampleRate:
|
|
1287
|
-
playerSampleRate:
|
|
1356
|
+
serializer: new As(),
|
|
1357
|
+
recorderSampleRate: tr,
|
|
1358
|
+
playerSampleRate: nr
|
|
1288
1359
|
}),
|
|
1289
1360
|
enableCam: !1,
|
|
1290
1361
|
enableMic: !0,
|
|
@@ -1293,7 +1364,7 @@ function bs(e, t = {}) {
|
|
|
1293
1364
|
d = !0, e("idle"), T();
|
|
1294
1365
|
},
|
|
1295
1366
|
onDisconnected: () => {
|
|
1296
|
-
d = !1,
|
|
1367
|
+
d = !1, $();
|
|
1297
1368
|
},
|
|
1298
1369
|
onError: (l) => {
|
|
1299
1370
|
const k = typeof l == "object" && l !== null && "data" in l ? String(l.data ?? l) : String(l);
|
|
@@ -1303,17 +1374,17 @@ function bs(e, t = {}) {
|
|
|
1303
1374
|
l === "error" && (e("error"), T());
|
|
1304
1375
|
},
|
|
1305
1376
|
onServerMessage: (l) => {
|
|
1306
|
-
|
|
1377
|
+
z(l);
|
|
1307
1378
|
},
|
|
1308
1379
|
onUserStartedSpeaking: () => {
|
|
1309
1380
|
q({});
|
|
1310
1381
|
},
|
|
1311
1382
|
onBotStartedSpeaking: () => {
|
|
1312
|
-
|
|
1383
|
+
ue(), de("bot_started");
|
|
1313
1384
|
},
|
|
1314
1385
|
onBotStoppedSpeaking: () => {
|
|
1315
|
-
p && (
|
|
1316
|
-
S = null, p && (
|
|
1386
|
+
p && (M(), S = setTimeout(() => {
|
|
1387
|
+
S = null, p && (D.markStreamComplete(n), de("bot_stopped"));
|
|
1317
1388
|
}, 450));
|
|
1318
1389
|
},
|
|
1319
1390
|
onUserTranscript: (l) => {
|
|
@@ -1328,21 +1399,21 @@ function bs(e, t = {}) {
|
|
|
1328
1399
|
setDeveloperToken: (l) => {
|
|
1329
1400
|
},
|
|
1330
1401
|
setTtsEngineId: (l) => {
|
|
1331
|
-
f = l,
|
|
1402
|
+
f = l, D.setStreamTtsEngineId(l);
|
|
1332
1403
|
},
|
|
1333
1404
|
getTtsEngineId: () => f,
|
|
1334
1405
|
speak: async (l, k) => {
|
|
1335
|
-
const
|
|
1336
|
-
if (
|
|
1406
|
+
const V = l.trim();
|
|
1407
|
+
if (V) {
|
|
1337
1408
|
if (!u || !d)
|
|
1338
1409
|
throw new Error(
|
|
1339
1410
|
"Realtime voice is not connected. Call connect() first."
|
|
1340
1411
|
);
|
|
1341
|
-
|
|
1412
|
+
P(), await u.sendText(V);
|
|
1342
1413
|
}
|
|
1343
1414
|
},
|
|
1344
1415
|
stop: () => {
|
|
1345
|
-
F?.abort(), F = null,
|
|
1416
|
+
F?.abort(), F = null, j += 1, ue(), P(), e("idle"), T();
|
|
1346
1417
|
},
|
|
1347
1418
|
connect: async (l) => {
|
|
1348
1419
|
if (l && (m = { ...m, ...l }), !m.authToken?.trim())
|
|
@@ -1350,58 +1421,58 @@ function bs(e, t = {}) {
|
|
|
1350
1421
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1351
1422
|
);
|
|
1352
1423
|
e("loading");
|
|
1353
|
-
const k =
|
|
1424
|
+
const k = fe();
|
|
1354
1425
|
await k.initDevices();
|
|
1355
|
-
const
|
|
1356
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1426
|
+
const V = Ds(m);
|
|
1427
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", V);
|
|
1357
1428
|
try {
|
|
1358
|
-
await k.connect({ wsUrl:
|
|
1359
|
-
} catch (
|
|
1429
|
+
await k.connect({ wsUrl: V });
|
|
1430
|
+
} catch (K) {
|
|
1360
1431
|
d = !1, e("error"), T();
|
|
1361
|
-
const
|
|
1362
|
-
throw new Error(`${
|
|
1432
|
+
const ie = K instanceof Error ? K.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
|
|
1433
|
+
throw new Error(`${ie} — ${V}`);
|
|
1363
1434
|
}
|
|
1364
1435
|
d = !0, e("idle"), T();
|
|
1365
1436
|
},
|
|
1366
1437
|
disconnect: async () => {
|
|
1367
|
-
if (
|
|
1438
|
+
if (M(), R = !1, I.length = 0, E = !1, F?.abort(), F = null, j += 1, ue(), u)
|
|
1368
1439
|
try {
|
|
1369
1440
|
await u.disconnect();
|
|
1370
1441
|
} catch (l) {
|
|
1371
1442
|
console.error("[realtimeVoice] disconnect failed:", l);
|
|
1372
1443
|
}
|
|
1373
|
-
d = !1,
|
|
1444
|
+
d = !1, $();
|
|
1374
1445
|
},
|
|
1375
1446
|
isConnected: () => d,
|
|
1376
1447
|
unlockAudio: async () => {
|
|
1377
|
-
await
|
|
1448
|
+
await D.primeAudioContext();
|
|
1378
1449
|
},
|
|
1379
1450
|
getVisemeQueue: () => n,
|
|
1380
1451
|
getWordQueue: () => r,
|
|
1381
1452
|
getSentenceEmotions: () => s,
|
|
1382
1453
|
getStreamMood: () => o,
|
|
1383
|
-
getPlaybackElapsedMs:
|
|
1384
|
-
isSpeaking: () =>
|
|
1385
|
-
isWarmingUp: () =>
|
|
1386
|
-
releaseWarmupHold: () =>
|
|
1454
|
+
getPlaybackElapsedMs: se,
|
|
1455
|
+
isSpeaking: () => D.isSpeaking(),
|
|
1456
|
+
isWarmingUp: () => D.isWarmingUp(),
|
|
1457
|
+
releaseWarmupHold: () => D.releaseWarmupHold(),
|
|
1387
1458
|
setLipsyncWarmupHold: (l, k) => {
|
|
1388
|
-
k && (
|
|
1459
|
+
k && (Z = k), D.setLipsyncWarmupHoldEnabled(l);
|
|
1389
1460
|
},
|
|
1390
|
-
getVoiceStream: () =>
|
|
1461
|
+
getVoiceStream: () => D.getVoiceStream(),
|
|
1391
1462
|
setPlaybackSpeed: (l) => {
|
|
1392
|
-
|
|
1463
|
+
D.setPlaybackSpeed(l);
|
|
1393
1464
|
},
|
|
1394
|
-
getPlaybackSpeed: () =>
|
|
1465
|
+
getPlaybackSpeed: () => D.getPlaybackSpeed(),
|
|
1395
1466
|
subscribe: (l) => (h.add(l), () => h.delete(l))
|
|
1396
1467
|
};
|
|
1397
1468
|
}
|
|
1398
|
-
function
|
|
1469
|
+
function Fs(e, t, n) {
|
|
1399
1470
|
return {
|
|
1400
1471
|
width: e.crop?.source_width ?? t,
|
|
1401
1472
|
height: e.crop?.source_height ?? n
|
|
1402
1473
|
};
|
|
1403
1474
|
}
|
|
1404
|
-
function
|
|
1475
|
+
function Ls(e, t) {
|
|
1405
1476
|
const n = e.crop;
|
|
1406
1477
|
return {
|
|
1407
1478
|
x: t?.source_x ?? n?.x ?? 0,
|
|
@@ -1410,21 +1481,21 @@ function Es(e, t) {
|
|
|
1410
1481
|
height: t?.source_h ?? n?.height ?? e.frame_height ?? 0
|
|
1411
1482
|
};
|
|
1412
1483
|
}
|
|
1413
|
-
function
|
|
1484
|
+
function Os(e) {
|
|
1414
1485
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
1415
1486
|
}
|
|
1416
|
-
async function
|
|
1487
|
+
async function Rt(e, t) {
|
|
1417
1488
|
const n = await fetch(e);
|
|
1418
1489
|
if (!n.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
|
|
1419
1490
|
const r = await n.arrayBuffer();
|
|
1420
|
-
return
|
|
1491
|
+
return jr(r, t);
|
|
1421
1492
|
}
|
|
1422
|
-
async function
|
|
1493
|
+
async function Ns(e, t) {
|
|
1423
1494
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
1424
|
-
const n = await
|
|
1495
|
+
const n = await Rt(e, t), r = new TextDecoder().decode(n);
|
|
1425
1496
|
return JSON.parse(r);
|
|
1426
1497
|
}
|
|
1427
|
-
async function
|
|
1498
|
+
async function Us(e) {
|
|
1428
1499
|
const t = new Blob([e], { type: "image/webp" }), n = URL.createObjectURL(t);
|
|
1429
1500
|
return new Promise((r, s) => {
|
|
1430
1501
|
const i = new Image();
|
|
@@ -1435,7 +1506,7 @@ async function Is(e) {
|
|
|
1435
1506
|
}, i.src = n;
|
|
1436
1507
|
});
|
|
1437
1508
|
}
|
|
1438
|
-
async function
|
|
1509
|
+
async function Vs(e) {
|
|
1439
1510
|
const t = new Blob([e], { type: "image/png" }), n = URL.createObjectURL(t);
|
|
1440
1511
|
return new Promise((r, s) => {
|
|
1441
1512
|
const i = new Image();
|
|
@@ -1446,28 +1517,28 @@ async function Ms(e) {
|
|
|
1446
1517
|
}, i.src = n;
|
|
1447
1518
|
});
|
|
1448
1519
|
}
|
|
1449
|
-
function
|
|
1520
|
+
function Ws(e) {
|
|
1450
1521
|
const t = new Blob([e], { type: "video/mp4" });
|
|
1451
1522
|
return URL.createObjectURL(t);
|
|
1452
1523
|
}
|
|
1453
|
-
async function
|
|
1454
|
-
const t =
|
|
1455
|
-
if (!
|
|
1524
|
+
async function Hs(e) {
|
|
1525
|
+
const t = Qr();
|
|
1526
|
+
if (!It()) return t;
|
|
1456
1527
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
1457
|
-
const n = await
|
|
1458
|
-
return
|
|
1528
|
+
const n = await Rt(t, e);
|
|
1529
|
+
return Ws(n);
|
|
1459
1530
|
}
|
|
1460
|
-
function
|
|
1531
|
+
function en(e, t) {
|
|
1461
1532
|
return `${e}/${t}_minus_sil.png`;
|
|
1462
1533
|
}
|
|
1463
|
-
const
|
|
1464
|
-
function
|
|
1534
|
+
const rr = 5;
|
|
1535
|
+
function tn(e) {
|
|
1465
1536
|
const t = e?.composite_threshold;
|
|
1466
1537
|
if (typeof t == "number" && t > 0) return t;
|
|
1467
1538
|
const n = e?.crop?.content_threshold;
|
|
1468
|
-
return typeof n == "number" && n > 0 ? n :
|
|
1539
|
+
return typeof n == "number" && n > 0 ? n : rr;
|
|
1469
1540
|
}
|
|
1470
|
-
const
|
|
1541
|
+
const ta = [
|
|
1471
1542
|
"aa",
|
|
1472
1543
|
"E",
|
|
1473
1544
|
"I",
|
|
@@ -1486,7 +1557,7 @@ const ji = [
|
|
|
1486
1557
|
"t01_0.25",
|
|
1487
1558
|
"t02_0.50",
|
|
1488
1559
|
"t03_0.75"
|
|
1489
|
-
],
|
|
1560
|
+
], $s = Ht.length, In = /* @__PURE__ */ new Set([
|
|
1490
1561
|
"aa__kk",
|
|
1491
1562
|
"aa__nn",
|
|
1492
1563
|
"aa__sil",
|
|
@@ -1593,75 +1664,75 @@ const ji = [
|
|
|
1593
1664
|
"U__nn",
|
|
1594
1665
|
"U__sil"
|
|
1595
1666
|
]);
|
|
1596
|
-
function
|
|
1667
|
+
function Mn(e, t) {
|
|
1597
1668
|
return `${e}__${t}`;
|
|
1598
1669
|
}
|
|
1599
|
-
function
|
|
1670
|
+
function Pn(e, t) {
|
|
1600
1671
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1601
1672
|
}
|
|
1602
|
-
function
|
|
1673
|
+
function vt(e) {
|
|
1603
1674
|
return `${e}_minus_sil.png`;
|
|
1604
1675
|
}
|
|
1605
|
-
function
|
|
1676
|
+
function sr(e, t) {
|
|
1606
1677
|
if (t.has(e)) return e;
|
|
1607
1678
|
const n = /^pairs\/([^/]+)\//.exec(e);
|
|
1608
1679
|
if (!n) return null;
|
|
1609
1680
|
const r = n[1].split("__")[1];
|
|
1610
1681
|
if (!r || r === "sil") return null;
|
|
1611
|
-
const s =
|
|
1682
|
+
const s = vt(r);
|
|
1612
1683
|
return t.has(s) ? s : null;
|
|
1613
1684
|
}
|
|
1614
|
-
function
|
|
1685
|
+
function ir(e, t) {
|
|
1615
1686
|
return e.filter((n) => t.has(n));
|
|
1616
1687
|
}
|
|
1617
|
-
function
|
|
1618
|
-
const r =
|
|
1619
|
-
return
|
|
1688
|
+
function qs(e, t, n) {
|
|
1689
|
+
const r = nn(e, t);
|
|
1690
|
+
return ir(r, n).length > 0;
|
|
1620
1691
|
}
|
|
1621
|
-
function
|
|
1692
|
+
function nn(e, t) {
|
|
1622
1693
|
if (e === t) return [];
|
|
1623
|
-
const n = [], r =
|
|
1624
|
-
if (
|
|
1694
|
+
const n = [], r = Mn(e, t);
|
|
1695
|
+
if (In.has(r)) {
|
|
1625
1696
|
for (const i of Ht)
|
|
1626
|
-
n.push(
|
|
1697
|
+
n.push(Pn(r, i));
|
|
1627
1698
|
return n;
|
|
1628
1699
|
}
|
|
1629
|
-
const s =
|
|
1630
|
-
if (
|
|
1631
|
-
for (let i =
|
|
1632
|
-
n.push(
|
|
1700
|
+
const s = Mn(t, e);
|
|
1701
|
+
if (In.has(s)) {
|
|
1702
|
+
for (let i = $s - 1; i >= 0; i--)
|
|
1703
|
+
n.push(Pn(s, Ht[i]));
|
|
1633
1704
|
return n;
|
|
1634
1705
|
}
|
|
1635
1706
|
return [];
|
|
1636
1707
|
}
|
|
1637
|
-
function
|
|
1708
|
+
function Ks(e) {
|
|
1638
1709
|
return e < 16 ? [1] : e < 24 ? [1] : e < 35 ? [0, 1, 2] : [0, 1, 2];
|
|
1639
1710
|
}
|
|
1640
|
-
function
|
|
1641
|
-
return
|
|
1711
|
+
function Gs(e, t) {
|
|
1712
|
+
return Ks(t).map((r) => e[r]).filter((r) => r != null);
|
|
1642
1713
|
}
|
|
1643
|
-
function
|
|
1714
|
+
function js(e, t, n, r) {
|
|
1644
1715
|
if (r <= 0) return 0;
|
|
1645
1716
|
const i = Math.max(1, n - t) / r, a = e - t, o = Math.floor(a / i);
|
|
1646
1717
|
return Math.min(r - 1, Math.max(0, o));
|
|
1647
1718
|
}
|
|
1648
|
-
function
|
|
1719
|
+
function zs(e, t, n) {
|
|
1649
1720
|
if (!n) return `${e}/${t}`;
|
|
1650
1721
|
const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
|
|
1651
1722
|
return `${e}/${s}.bin`;
|
|
1652
1723
|
}
|
|
1653
|
-
const
|
|
1724
|
+
const Ys = [0.32, 0.24, 0.16, 0.08, 0], Js = Ys.map(
|
|
1654
1725
|
(e) => `eyes_${e.toFixed(2)}`
|
|
1655
|
-
),
|
|
1726
|
+
), Xs = [
|
|
1656
1727
|
"eyes_0.32",
|
|
1657
1728
|
"eyes_0.16",
|
|
1658
1729
|
"eyes_0.00"
|
|
1659
|
-
],
|
|
1730
|
+
], Qs = [
|
|
1660
1731
|
"eyes_0.32",
|
|
1661
1732
|
"eyes_0.16",
|
|
1662
1733
|
"eyes_0.08",
|
|
1663
1734
|
"eyes_0.00"
|
|
1664
|
-
],
|
|
1735
|
+
], Rn = 2, Zs = -30, $t = 20, ei = {
|
|
1665
1736
|
fear: -30,
|
|
1666
1737
|
anger: -20,
|
|
1667
1738
|
sad: -10,
|
|
@@ -1670,24 +1741,24 @@ const Os = [0.32, 0.24, 0.16, 0.08, 0], Ns = Os.map(
|
|
|
1670
1741
|
happy: 0,
|
|
1671
1742
|
disgust: 20
|
|
1672
1743
|
};
|
|
1673
|
-
function
|
|
1744
|
+
function rn(e) {
|
|
1674
1745
|
return `brow_${e}`;
|
|
1675
1746
|
}
|
|
1676
|
-
function
|
|
1677
|
-
return
|
|
1747
|
+
function sn(e) {
|
|
1748
|
+
return ei[e];
|
|
1678
1749
|
}
|
|
1679
1750
|
function Oe(e) {
|
|
1680
|
-
return Math.max(
|
|
1751
|
+
return Math.max(Zs, Math.min($t, e));
|
|
1681
1752
|
}
|
|
1682
|
-
function
|
|
1753
|
+
function ti(e, t) {
|
|
1683
1754
|
if (e === t) return [];
|
|
1684
|
-
const n = e < t ?
|
|
1755
|
+
const n = e < t ? Rn : -Rn, r = [];
|
|
1685
1756
|
let s = e;
|
|
1686
1757
|
for (; s !== t; )
|
|
1687
1758
|
s += n, r.push(s);
|
|
1688
1759
|
return r;
|
|
1689
1760
|
}
|
|
1690
|
-
const
|
|
1761
|
+
const ni = {
|
|
1691
1762
|
fear: "fear",
|
|
1692
1763
|
afraid: "fear",
|
|
1693
1764
|
anxiety: "fear",
|
|
@@ -1710,63 +1781,63 @@ const qs = {
|
|
|
1710
1781
|
disgust: "disgust",
|
|
1711
1782
|
disgusted: "disgust"
|
|
1712
1783
|
};
|
|
1713
|
-
function
|
|
1784
|
+
function Ge(e, t = "neutral") {
|
|
1714
1785
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1715
|
-
return n ?
|
|
1786
|
+
return n ? ni[n] ?? t : t;
|
|
1716
1787
|
}
|
|
1717
|
-
function
|
|
1718
|
-
return e === 0 ? null :
|
|
1788
|
+
function ar(e) {
|
|
1789
|
+
return e === 0 ? null : en(rn(e), "eyes_standard");
|
|
1719
1790
|
}
|
|
1720
|
-
function
|
|
1721
|
-
return
|
|
1791
|
+
function or(e) {
|
|
1792
|
+
return ar(sn(e));
|
|
1722
1793
|
}
|
|
1723
|
-
function
|
|
1724
|
-
const n =
|
|
1725
|
-
return !t || t === "eyes_standard" ?
|
|
1794
|
+
function Dn(e, t) {
|
|
1795
|
+
const n = rn(sn(e));
|
|
1796
|
+
return !t || t === "eyes_standard" ? or(e) : e === "neutral" && t === "eyes_standard" ? null : en(n, t);
|
|
1726
1797
|
}
|
|
1727
|
-
function
|
|
1798
|
+
function ri(e, t) {
|
|
1728
1799
|
const n = [];
|
|
1729
1800
|
for (const r of t)
|
|
1730
|
-
n.push(
|
|
1801
|
+
n.push(Dn(e, r));
|
|
1731
1802
|
for (let r = t.length - 2; r >= 0; r--)
|
|
1732
|
-
n.push(
|
|
1733
|
-
return n.push(
|
|
1803
|
+
n.push(Dn(e, t[r]));
|
|
1804
|
+
return n.push(or(e)), n;
|
|
1734
1805
|
}
|
|
1735
|
-
function
|
|
1736
|
-
return e === 0 ? null :
|
|
1806
|
+
function si(e) {
|
|
1807
|
+
return e === 0 ? null : en(rn(e), "eyes_standard");
|
|
1737
1808
|
}
|
|
1738
|
-
function
|
|
1739
|
-
return
|
|
1809
|
+
function ii(e, t) {
|
|
1810
|
+
return ti(e, t).map(si).filter((n) => n != null);
|
|
1740
1811
|
}
|
|
1741
|
-
const
|
|
1742
|
-
function
|
|
1812
|
+
const ai = 6;
|
|
1813
|
+
function oi(e, t) {
|
|
1743
1814
|
for (const n of e)
|
|
1744
1815
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
1745
1816
|
return n;
|
|
1746
1817
|
return null;
|
|
1747
1818
|
}
|
|
1748
|
-
function
|
|
1819
|
+
function ci(e) {
|
|
1749
1820
|
const t = Oe(e);
|
|
1750
|
-
return t >= $t ? $t : Oe(t +
|
|
1821
|
+
return t >= $t ? $t : Oe(t + ai);
|
|
1751
1822
|
}
|
|
1752
|
-
function
|
|
1823
|
+
function ui(e, t, n) {
|
|
1753
1824
|
const r = Oe(n);
|
|
1754
|
-
return
|
|
1825
|
+
return oi(t, e)?.emphasis ? ci(r) : r;
|
|
1755
1826
|
}
|
|
1756
|
-
function
|
|
1827
|
+
function xn(e) {
|
|
1757
1828
|
if (!e) return 0;
|
|
1758
1829
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1759
1830
|
if (!t?.[1]) return null;
|
|
1760
1831
|
const n = Number.parseInt(t[1], 10);
|
|
1761
1832
|
return Number.isFinite(n) ? Oe(n) : null;
|
|
1762
1833
|
}
|
|
1763
|
-
function
|
|
1834
|
+
function ct(e, t) {
|
|
1764
1835
|
return e + Math.random() * (t - e);
|
|
1765
1836
|
}
|
|
1766
|
-
function
|
|
1767
|
-
return
|
|
1837
|
+
function St() {
|
|
1838
|
+
return ct(14, 32);
|
|
1768
1839
|
}
|
|
1769
|
-
function
|
|
1840
|
+
function li(e = {}) {
|
|
1770
1841
|
const {
|
|
1771
1842
|
initialDelayMs: t = 800 + Math.random() * 1200,
|
|
1772
1843
|
intervalMinMs: n = 2200,
|
|
@@ -1778,78 +1849,78 @@ function Qs(e = {}) {
|
|
|
1778
1849
|
postEmotionChangeDelayMs: f = 380,
|
|
1779
1850
|
minDwellMs: d = 550
|
|
1780
1851
|
} = e;
|
|
1781
|
-
let u = "neutral", c = "neutral", m = 0,
|
|
1852
|
+
let u = "neutral", c = "neutral", m = 0, w = 0, b = 0, h = {
|
|
1782
1853
|
kind: "idle",
|
|
1783
1854
|
nextBlinkAt: performance.now() + t
|
|
1784
|
-
},
|
|
1855
|
+
}, I = null, E = "__eyes_open__|neutral|brow:0";
|
|
1785
1856
|
function _(S = u) {
|
|
1786
|
-
E = `${
|
|
1857
|
+
E = `${I ?? "__eyes_open__"}|${S}|brow:${w}`;
|
|
1787
1858
|
}
|
|
1788
|
-
function p(S,
|
|
1789
|
-
|
|
1790
|
-
const T =
|
|
1791
|
-
T != null ?
|
|
1859
|
+
function p(S, M = u) {
|
|
1860
|
+
I = S;
|
|
1861
|
+
const T = xn(S);
|
|
1862
|
+
T != null ? w = T : S == null && (w = 0), _(M);
|
|
1792
1863
|
}
|
|
1793
1864
|
function v(S) {
|
|
1794
|
-
return
|
|
1865
|
+
return ar(S);
|
|
1795
1866
|
}
|
|
1796
|
-
function
|
|
1797
|
-
const
|
|
1798
|
-
if (m =
|
|
1799
|
-
p(v(
|
|
1867
|
+
function N(S, M, T) {
|
|
1868
|
+
const Z = Oe(M), D = Oe(T);
|
|
1869
|
+
if (m = D, Z === D) {
|
|
1870
|
+
p(v(D));
|
|
1800
1871
|
return;
|
|
1801
1872
|
}
|
|
1802
|
-
const
|
|
1803
|
-
...
|
|
1804
|
-
v(
|
|
1873
|
+
const X = [
|
|
1874
|
+
...ii(Z, D),
|
|
1875
|
+
v(D)
|
|
1805
1876
|
];
|
|
1806
1877
|
h = {
|
|
1807
1878
|
kind: "browBlend",
|
|
1808
|
-
paths:
|
|
1879
|
+
paths: X,
|
|
1809
1880
|
index: 0,
|
|
1810
|
-
holdUntil: S +
|
|
1811
|
-
targetBrow:
|
|
1812
|
-
}, p(
|
|
1881
|
+
holdUntil: S + St(),
|
|
1882
|
+
targetBrow: D
|
|
1883
|
+
}, p(X[0] ?? null);
|
|
1813
1884
|
}
|
|
1814
|
-
function F(S,
|
|
1885
|
+
function F(S, M) {
|
|
1815
1886
|
h = {
|
|
1816
1887
|
kind: "idle",
|
|
1817
|
-
nextBlinkAt: S +
|
|
1818
|
-
}, c =
|
|
1888
|
+
nextBlinkAt: S + ct(n, r)
|
|
1889
|
+
}, c = M, p(v(m), M);
|
|
1819
1890
|
}
|
|
1820
|
-
function
|
|
1821
|
-
const
|
|
1891
|
+
function j(S, M, T) {
|
|
1892
|
+
const Z = T ? Xs : Math.random() < o ? Js : Qs;
|
|
1822
1893
|
h = {
|
|
1823
1894
|
kind: "playing",
|
|
1824
|
-
paths:
|
|
1895
|
+
paths: ri(M, Z),
|
|
1825
1896
|
index: 0,
|
|
1826
|
-
holdUntil: S +
|
|
1897
|
+
holdUntil: S + St(),
|
|
1827
1898
|
after: "idle",
|
|
1828
|
-
blinkEmotion:
|
|
1829
|
-
}, c =
|
|
1899
|
+
blinkEmotion: M
|
|
1900
|
+
}, c = M, p(h.paths[0] ?? null, M);
|
|
1830
1901
|
}
|
|
1831
|
-
function
|
|
1902
|
+
function R(S) {
|
|
1832
1903
|
if (h.kind === "browBlend") {
|
|
1833
1904
|
for (; S >= h.holdUntil && h.index < h.paths.length - 1; )
|
|
1834
|
-
h.index += 1, h.holdUntil = S +
|
|
1835
|
-
const
|
|
1836
|
-
p(
|
|
1905
|
+
h.index += 1, h.holdUntil = S + St();
|
|
1906
|
+
const M = h.paths[h.index] ?? null;
|
|
1907
|
+
p(M), S >= h.holdUntil && h.index >= h.paths.length - 1 && (w = h.targetBrow, m = h.targetBrow, p(v(h.targetBrow)), h = {
|
|
1837
1908
|
kind: "idle",
|
|
1838
1909
|
nextBlinkAt: S + f
|
|
1839
1910
|
});
|
|
1840
1911
|
return;
|
|
1841
1912
|
}
|
|
1842
1913
|
if (h.kind === "idle") {
|
|
1843
|
-
p(v(m), c), S >= h.nextBlinkAt &&
|
|
1914
|
+
p(v(m), c), S >= h.nextBlinkAt && j(S, c, !1);
|
|
1844
1915
|
return;
|
|
1845
1916
|
}
|
|
1846
1917
|
if (h.kind === "doublePause") {
|
|
1847
|
-
p(v(m), h.blinkEmotion), S >= h.resumeAt &&
|
|
1918
|
+
p(v(m), h.blinkEmotion), S >= h.resumeAt && j(S, h.blinkEmotion, !0);
|
|
1848
1919
|
return;
|
|
1849
1920
|
}
|
|
1850
1921
|
if (h.kind === "playing") {
|
|
1851
1922
|
for (; S >= h.holdUntil && h.index < h.paths.length - 1; )
|
|
1852
|
-
h.index += 1, h.holdUntil = S +
|
|
1923
|
+
h.index += 1, h.holdUntil = S + St();
|
|
1853
1924
|
if (p(h.paths[h.index] ?? null, h.blinkEmotion), S >= h.holdUntil && h.index >= h.paths.length - 1) {
|
|
1854
1925
|
if (h.after === "resumeIdle") {
|
|
1855
1926
|
F(S + f, u);
|
|
@@ -1858,7 +1929,7 @@ function Qs(e = {}) {
|
|
|
1858
1929
|
if (h.after === "doublePause") {
|
|
1859
1930
|
h = {
|
|
1860
1931
|
kind: "doublePause",
|
|
1861
|
-
resumeAt: S +
|
|
1932
|
+
resumeAt: S + ct(i, a),
|
|
1862
1933
|
blinkEmotion: h.blinkEmotion
|
|
1863
1934
|
}, p(v(m), h.blinkEmotion);
|
|
1864
1935
|
return;
|
|
@@ -1866,7 +1937,7 @@ function Qs(e = {}) {
|
|
|
1866
1937
|
if (h.after === "idle" && Math.random() < s) {
|
|
1867
1938
|
h = {
|
|
1868
1939
|
kind: "doublePause",
|
|
1869
|
-
resumeAt: S +
|
|
1940
|
+
resumeAt: S + ct(i, a),
|
|
1870
1941
|
blinkEmotion: h.blinkEmotion
|
|
1871
1942
|
}, p(v(m), h.blinkEmotion);
|
|
1872
1943
|
return;
|
|
@@ -1876,32 +1947,32 @@ function Qs(e = {}) {
|
|
|
1876
1947
|
}
|
|
1877
1948
|
}
|
|
1878
1949
|
return {
|
|
1879
|
-
advance:
|
|
1950
|
+
advance: R,
|
|
1880
1951
|
setTargetEmotion(S) {
|
|
1881
|
-
const
|
|
1882
|
-
if (
|
|
1952
|
+
const M = Ge(S, u);
|
|
1953
|
+
if (M === u) return;
|
|
1883
1954
|
const T = performance.now();
|
|
1884
|
-
d > 0 &&
|
|
1955
|
+
d > 0 && M !== u && !(u === "neutral" && M !== "neutral") && T - b < d || (u = M, c = M, b = T);
|
|
1885
1956
|
},
|
|
1886
1957
|
setTargetEyebrow(S) {
|
|
1887
|
-
const
|
|
1888
|
-
if (
|
|
1889
|
-
const T = performance.now(),
|
|
1890
|
-
m =
|
|
1958
|
+
const M = Oe(S);
|
|
1959
|
+
if (M === m) return;
|
|
1960
|
+
const T = performance.now(), Z = h.kind === "browBlend" ? xn(I) ?? w : w;
|
|
1961
|
+
m = M, !(M === Z && h.kind !== "browBlend") && (h.kind === "playing" || h.kind === "doublePause" || N(T, Z, M));
|
|
1891
1962
|
},
|
|
1892
1963
|
getTargetEmotion: () => u,
|
|
1893
1964
|
getTargetEyebrow: () => m,
|
|
1894
|
-
getExpressionPath: () =>
|
|
1965
|
+
getExpressionPath: () => I,
|
|
1895
1966
|
getDrawKey: () => E,
|
|
1896
1967
|
reset() {
|
|
1897
|
-
u = "neutral", c = "neutral", m = 0,
|
|
1898
|
-
performance.now() +
|
|
1968
|
+
u = "neutral", c = "neutral", m = 0, w = 0, b = 0, F(
|
|
1969
|
+
performance.now() + ct(n, r),
|
|
1899
1970
|
"neutral"
|
|
1900
1971
|
);
|
|
1901
1972
|
}
|
|
1902
1973
|
};
|
|
1903
1974
|
}
|
|
1904
|
-
function
|
|
1975
|
+
function fi() {
|
|
1905
1976
|
const e = document.createElement("video");
|
|
1906
1977
|
e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
|
|
1907
1978
|
let t = !1, n = null, r = "";
|
|
@@ -1944,17 +2015,17 @@ function Zs() {
|
|
|
1944
2015
|
}
|
|
1945
2016
|
};
|
|
1946
2017
|
}
|
|
1947
|
-
const
|
|
1948
|
-
function
|
|
2018
|
+
const di = 50, cr = 400;
|
|
2019
|
+
function mi(e, t, n) {
|
|
1949
2020
|
return e.filter((r) => {
|
|
1950
2021
|
const s = r.queueIndex ?? -1;
|
|
1951
2022
|
return s >= t && s <= n;
|
|
1952
2023
|
});
|
|
1953
2024
|
}
|
|
1954
|
-
function
|
|
2025
|
+
function hi(e, t) {
|
|
1955
2026
|
const n = [];
|
|
1956
2027
|
for (const r of e) {
|
|
1957
|
-
const s =
|
|
2028
|
+
const s = mi(
|
|
1958
2029
|
t,
|
|
1959
2030
|
r.start_word,
|
|
1960
2031
|
r.end_word
|
|
@@ -1963,30 +2034,30 @@ function ni(e, t) {
|
|
|
1963
2034
|
const i = s[0], a = s[s.length - 1];
|
|
1964
2035
|
n.push({
|
|
1965
2036
|
sentence: r,
|
|
1966
|
-
startMs: Math.max(0, i.wtime -
|
|
1967
|
-
endMs: a.wtime + a.wduration +
|
|
2037
|
+
startMs: Math.max(0, i.wtime - di),
|
|
2038
|
+
endMs: a.wtime + a.wduration + cr
|
|
1968
2039
|
});
|
|
1969
2040
|
}
|
|
1970
2041
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
1971
2042
|
}
|
|
1972
|
-
function
|
|
1973
|
-
const s =
|
|
2043
|
+
function pi(e, t, n, r = "neutral") {
|
|
2044
|
+
const s = Ge(r);
|
|
1974
2045
|
if (t.length === 0) return s;
|
|
1975
2046
|
if (n.length === 0 || e < n[0].wtime)
|
|
1976
|
-
return
|
|
1977
|
-
const i =
|
|
2047
|
+
return Ge(t[0]?.emotion, s);
|
|
2048
|
+
const i = hi(t, n);
|
|
1978
2049
|
let a = null;
|
|
1979
2050
|
for (const d of i)
|
|
1980
2051
|
e >= d.startMs && e <= d.endMs && (a = d);
|
|
1981
2052
|
if (a)
|
|
1982
|
-
return
|
|
2053
|
+
return Ge(a.sentence.emotion, s);
|
|
1983
2054
|
const o = n[n.length - 1], f = o.wtime + o.wduration;
|
|
1984
|
-
return e > f +
|
|
2055
|
+
return e > f + cr ? Ge(
|
|
1985
2056
|
t[t.length - 1]?.emotion,
|
|
1986
2057
|
s
|
|
1987
2058
|
) : s;
|
|
1988
2059
|
}
|
|
1989
|
-
function
|
|
2060
|
+
function an(e, t, n, r, s = rr) {
|
|
1990
2061
|
const i = new OffscreenCanvas(n, r), a = i.getContext("2d", { willReadFrequently: !0 });
|
|
1991
2062
|
a.drawImage(e, 0, 0, n, r);
|
|
1992
2063
|
const o = a.getImageData(0, 0, n, r), f = a.createImageData(n, r);
|
|
@@ -1995,45 +2066,45 @@ function sn(e, t, n, r, s = Jn) {
|
|
|
1995
2066
|
for (const c of t) {
|
|
1996
2067
|
u.clearRect(0, 0, n, r), u.drawImage(c, 0, 0, n, r);
|
|
1997
2068
|
const m = u.getImageData(0, 0, n, r);
|
|
1998
|
-
for (let
|
|
1999
|
-
const b = m.data[
|
|
2000
|
-
Math.max(b, h,
|
|
2069
|
+
for (let w = 0; w < f.data.length; w += 4) {
|
|
2070
|
+
const b = m.data[w], h = m.data[w + 1], I = m.data[w + 2];
|
|
2071
|
+
Math.max(b, h, I) > s && (f.data[w] = b, f.data[w + 1] = h, f.data[w + 2] = I, f.data[w + 3] = 255);
|
|
2001
2072
|
}
|
|
2002
2073
|
}
|
|
2003
2074
|
return a.putImageData(f, 0, 0), i;
|
|
2004
2075
|
}
|
|
2005
|
-
let Le = null,
|
|
2006
|
-
const
|
|
2007
|
-
function
|
|
2008
|
-
Le = null,
|
|
2076
|
+
let Le = null, Ye = null;
|
|
2077
|
+
const Et = /* @__PURE__ */ new Map();
|
|
2078
|
+
function wi() {
|
|
2079
|
+
Le = null, Ye = null, Et.clear();
|
|
2009
2080
|
}
|
|
2010
|
-
|
|
2011
|
-
function
|
|
2012
|
-
return e ??
|
|
2081
|
+
Xr(wi);
|
|
2082
|
+
function gi(e) {
|
|
2083
|
+
return e ?? Ye ?? void 0;
|
|
2013
2084
|
}
|
|
2014
|
-
function
|
|
2085
|
+
function on(e) {
|
|
2015
2086
|
return new Promise((t, n) => {
|
|
2016
2087
|
const r = new Image();
|
|
2017
2088
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
2018
2089
|
});
|
|
2019
2090
|
}
|
|
2020
|
-
async function
|
|
2021
|
-
return
|
|
2022
|
-
await
|
|
2023
|
-
) :
|
|
2091
|
+
async function yi(e) {
|
|
2092
|
+
return It() ? Vs(
|
|
2093
|
+
await Rt(vn(), e ?? "")
|
|
2094
|
+
) : on(vn());
|
|
2024
2095
|
}
|
|
2025
|
-
async function
|
|
2026
|
-
const s = n ? await
|
|
2096
|
+
async function Bn(e, t, n, r) {
|
|
2097
|
+
const s = n ? await Ns(e, r) : await fetch(e).then((d) => {
|
|
2027
2098
|
if (!d.ok) throw new Error(`Failed to load ${e}`);
|
|
2028
2099
|
return d.json();
|
|
2029
2100
|
}), i = s.sheets?.[0];
|
|
2030
2101
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
2031
|
-
const a = n ? await
|
|
2032
|
-
await
|
|
2033
|
-
|
|
2102
|
+
const a = n ? await Us(
|
|
2103
|
+
await Rt(
|
|
2104
|
+
zs(t, i.path, n),
|
|
2034
2105
|
r ?? ""
|
|
2035
2106
|
)
|
|
2036
|
-
) : await
|
|
2107
|
+
) : await on(`${t}/${i.path}`), o = /* @__PURE__ */ new Map();
|
|
2037
2108
|
for (const d of s.cells ?? [])
|
|
2038
2109
|
d.path && o.set(d.path, d);
|
|
2039
2110
|
const f = /* @__PURE__ */ new Map();
|
|
@@ -2042,29 +2113,29 @@ async function Dn(e, t, n, r) {
|
|
|
2042
2113
|
return { atlas: a, atlasMeta: s, cellByPath: o, sheetByIndex: f, diffBase: t };
|
|
2043
2114
|
}
|
|
2044
2115
|
async function qt(e) {
|
|
2045
|
-
const t =
|
|
2116
|
+
const t = gi(e), n = It();
|
|
2046
2117
|
if (n && !t)
|
|
2047
2118
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
2048
|
-
if (Le && (!n ||
|
|
2119
|
+
if (Le && (!n || Ye === (t ?? null))) {
|
|
2049
2120
|
const i = await Le;
|
|
2050
2121
|
return {
|
|
2051
|
-
...
|
|
2122
|
+
...Je(i),
|
|
2052
2123
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
2053
2124
|
};
|
|
2054
2125
|
}
|
|
2055
|
-
|
|
2056
|
-
const r =
|
|
2126
|
+
Ye = t ?? null, Et.clear();
|
|
2127
|
+
const r = Zr();
|
|
2057
2128
|
Le = (async () => {
|
|
2058
|
-
const i = await
|
|
2059
|
-
|
|
2129
|
+
const i = await yi(t), a = await Bn(
|
|
2130
|
+
es(),
|
|
2060
2131
|
r,
|
|
2061
2132
|
n,
|
|
2062
2133
|
t
|
|
2063
2134
|
);
|
|
2064
2135
|
let o = null;
|
|
2065
2136
|
try {
|
|
2066
|
-
o = await
|
|
2067
|
-
|
|
2137
|
+
o = await Bn(
|
|
2138
|
+
ts(),
|
|
2068
2139
|
r,
|
|
2069
2140
|
n,
|
|
2070
2141
|
t
|
|
@@ -2075,89 +2146,89 @@ async function qt(e) {
|
|
|
2075
2146
|
return { sil: i, viseme: a, expression: o };
|
|
2076
2147
|
})();
|
|
2077
2148
|
const s = await Le;
|
|
2078
|
-
return { ...
|
|
2149
|
+
return { ...Je(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
2079
2150
|
}
|
|
2080
|
-
async function
|
|
2151
|
+
async function cn(e) {
|
|
2081
2152
|
if (await qt(e), !Le) throw new Error("Assets not loaded");
|
|
2082
2153
|
return Le;
|
|
2083
2154
|
}
|
|
2084
|
-
function
|
|
2085
|
-
return
|
|
2155
|
+
function Je(e) {
|
|
2156
|
+
return Fs(
|
|
2086
2157
|
e.viseme.atlasMeta,
|
|
2087
2158
|
e.sil.naturalWidth,
|
|
2088
2159
|
e.sil.naturalHeight
|
|
2089
2160
|
);
|
|
2090
2161
|
}
|
|
2091
|
-
function
|
|
2162
|
+
function _i(e, t) {
|
|
2092
2163
|
const n = document.createElement("canvas");
|
|
2093
2164
|
return n.width = t.w, n.height = t.h, n.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), n;
|
|
2094
2165
|
}
|
|
2095
|
-
async function
|
|
2096
|
-
const r = `${t.diffBase}::${n}`, s =
|
|
2166
|
+
async function Tt(e, t, n) {
|
|
2167
|
+
const r = `${t.diffBase}::${n}`, s = Et.get(r);
|
|
2097
2168
|
if (s) return s;
|
|
2098
2169
|
const i = (async () => {
|
|
2099
2170
|
const a = t.cellByPath.get(n);
|
|
2100
2171
|
if (!a) throw new Error(`No atlas cell for path: ${n}`);
|
|
2101
|
-
const o =
|
|
2102
|
-
if (
|
|
2103
|
-
const c =
|
|
2172
|
+
const o = Ls(t.atlasMeta, a), f = Je(e);
|
|
2173
|
+
if (Os(a)) {
|
|
2174
|
+
const c = _i(t, a), m = document.createElement("canvas");
|
|
2104
2175
|
m.width = f.width, m.height = f.height;
|
|
2105
|
-
const
|
|
2106
|
-
return
|
|
2176
|
+
const w = m.getContext("2d");
|
|
2177
|
+
return w.fillStyle = "#000", w.fillRect(0, 0, f.width, f.height), w.drawImage(c, o.x, o.y), m;
|
|
2107
2178
|
}
|
|
2108
|
-
const d = `${t.diffBase}/${n}`, u = await
|
|
2179
|
+
const d = `${t.diffBase}/${n}`, u = await on(d);
|
|
2109
2180
|
if (u.naturalWidth === f.width && u.naturalHeight === f.height)
|
|
2110
2181
|
return u;
|
|
2111
2182
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
2112
2183
|
})();
|
|
2113
|
-
return
|
|
2184
|
+
return Et.set(r, i), i;
|
|
2114
2185
|
}
|
|
2115
|
-
async function
|
|
2186
|
+
async function Cn(e, t, n, r, s, i) {
|
|
2116
2187
|
if (s) {
|
|
2117
|
-
const { width:
|
|
2188
|
+
const { width: w, height: b } = s;
|
|
2118
2189
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
2119
2190
|
return;
|
|
2120
2191
|
const h = document.createElement("canvas");
|
|
2121
|
-
h.width =
|
|
2122
|
-
const
|
|
2123
|
-
if (
|
|
2124
|
-
(e.width !==
|
|
2192
|
+
h.width = w, h.height = b;
|
|
2193
|
+
const I = h.getContext("2d");
|
|
2194
|
+
if (I.clearRect(0, 0, w, b), I.drawImage(t, 0, 0, w, b), i && !i()) return;
|
|
2195
|
+
(e.width !== w || e.height !== b) && (e.width = w, e.height = b);
|
|
2125
2196
|
const E = e.getContext("2d");
|
|
2126
|
-
E.clearRect(0, 0,
|
|
2197
|
+
E.clearRect(0, 0, w, b), E.drawImage(h, 0, 0);
|
|
2127
2198
|
return;
|
|
2128
2199
|
}
|
|
2129
|
-
const a = await
|
|
2200
|
+
const a = await cn(), o = tn(a.viseme.atlasMeta), { width: f, height: d } = Je(a);
|
|
2130
2201
|
(e.width !== f || e.height !== d) && (e.width = f, e.height = d);
|
|
2131
2202
|
const u = [], c = e.getContext("2d");
|
|
2132
2203
|
if (c.clearRect(0, 0, f, d), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
2133
|
-
const
|
|
2134
|
-
c.drawImage(
|
|
2204
|
+
const w = a.sil;
|
|
2205
|
+
c.drawImage(w, 0, 0, f, d);
|
|
2135
2206
|
return;
|
|
2136
2207
|
}
|
|
2137
2208
|
if (u.length === 0) {
|
|
2138
2209
|
c.drawImage(t, 0, 0, f, d);
|
|
2139
2210
|
return;
|
|
2140
2211
|
}
|
|
2141
|
-
const m =
|
|
2212
|
+
const m = an(t, u, f, d, o);
|
|
2142
2213
|
c.drawImage(m, 0, 0);
|
|
2143
2214
|
}
|
|
2144
2215
|
async function Kt(e, t, n) {
|
|
2145
|
-
const r = await
|
|
2216
|
+
const r = await cn(Ye ?? void 0), s = tn(r.viseme.atlasMeta), { width: i, height: a } = Je(r);
|
|
2146
2217
|
(e.width !== i || e.height !== a) && (e.width = i, e.height = a);
|
|
2147
2218
|
const o = [];
|
|
2148
2219
|
if (t.mouthPath) {
|
|
2149
|
-
const u = new Set(r.viseme.cellByPath.keys()), c =
|
|
2150
|
-
c && o.push(await
|
|
2220
|
+
const u = new Set(r.viseme.cellByPath.keys()), c = sr(t.mouthPath, u) ?? (u.has(t.mouthPath) ? t.mouthPath : null);
|
|
2221
|
+
c && o.push(await Tt(r, r.viseme, c));
|
|
2151
2222
|
}
|
|
2152
2223
|
t.expressionPath && r.expression && o.push(
|
|
2153
|
-
await
|
|
2224
|
+
await Tt(r, r.expression, t.expressionPath)
|
|
2154
2225
|
);
|
|
2155
2226
|
const f = e.getContext("2d");
|
|
2156
2227
|
if (f.clearRect(0, 0, i, a), o.length === 0) {
|
|
2157
2228
|
f.drawImage(r.sil, 0, 0, i, a);
|
|
2158
2229
|
return;
|
|
2159
2230
|
}
|
|
2160
|
-
const d =
|
|
2231
|
+
const d = an(
|
|
2161
2232
|
r.sil,
|
|
2162
2233
|
o,
|
|
2163
2234
|
i,
|
|
@@ -2166,19 +2237,19 @@ async function Kt(e, t, n) {
|
|
|
2166
2237
|
);
|
|
2167
2238
|
f.drawImage(d, 0, 0);
|
|
2168
2239
|
}
|
|
2169
|
-
async function
|
|
2170
|
-
const n = await
|
|
2240
|
+
async function Si(e, t) {
|
|
2241
|
+
const n = await cn(Ye ?? void 0), r = tn(n.viseme.atlasMeta), { width: s, height: i } = Je(n), a = [];
|
|
2171
2242
|
if (e.mouthPath) {
|
|
2172
|
-
const u = new Set(n.viseme.cellByPath.keys()), c =
|
|
2173
|
-
c && a.push(await
|
|
2243
|
+
const u = new Set(n.viseme.cellByPath.keys()), c = sr(e.mouthPath, u) ?? (u.has(e.mouthPath) ? e.mouthPath : null);
|
|
2244
|
+
c && a.push(await Tt(n, n.viseme, c));
|
|
2174
2245
|
}
|
|
2175
2246
|
e.expressionPath && n.expression && a.push(
|
|
2176
|
-
await
|
|
2247
|
+
await Tt(n, n.expression, e.expressionPath)
|
|
2177
2248
|
);
|
|
2178
2249
|
const o = new OffscreenCanvas(s, i), f = o.getContext("2d");
|
|
2179
2250
|
if (a.length === 0)
|
|
2180
2251
|
return f.drawImage(n.sil, 0, 0, s, i), o.transferToImageBitmap();
|
|
2181
|
-
const d =
|
|
2252
|
+
const d = an(
|
|
2182
2253
|
n.sil,
|
|
2183
2254
|
a,
|
|
2184
2255
|
s,
|
|
@@ -2187,47 +2258,20 @@ async function ci(e, t) {
|
|
|
2187
2258
|
);
|
|
2188
2259
|
return f.drawImage(d, 0, 0), o.transferToImageBitmap();
|
|
2189
2260
|
}
|
|
2190
|
-
async function
|
|
2261
|
+
async function ki(e) {
|
|
2191
2262
|
await Kt(e, { mouthPath: null, expressionPath: null });
|
|
2192
2263
|
}
|
|
2193
|
-
|
|
2194
|
-
function
|
|
2195
|
-
|
|
2196
|
-
for (const n of e)
|
|
2197
|
-
t.has(n.vtime) || t.set(n.vtime, n);
|
|
2198
|
-
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
2199
|
-
}
|
|
2200
|
-
function di(e) {
|
|
2201
|
-
const t = fi(e), n = [];
|
|
2202
|
-
for (let r = 0; r < t.length - 1; r++) {
|
|
2203
|
-
const s = t[r].viseme, i = t[r + 1].viseme, a = t[r].vtime, o = t[r + 1].vtime;
|
|
2204
|
-
s === i || o <= a || n.push({ from: s, to: i, fromVtime: a, toVtime: o });
|
|
2205
|
-
}
|
|
2206
|
-
return n;
|
|
2207
|
-
}
|
|
2208
|
-
function mi(e, t) {
|
|
2209
|
-
let n = null;
|
|
2210
|
-
for (const r of e) {
|
|
2211
|
-
const { transEnd: s } = nr(r.fromVtime, r.toVtime);
|
|
2212
|
-
t >= r.fromVtime && t < s && (n = r);
|
|
2213
|
-
}
|
|
2214
|
-
return n;
|
|
2215
|
-
}
|
|
2216
|
-
function nr(e, t) {
|
|
2217
|
-
const n = Math.max(0, t - e), r = n > 0 ? Math.max(n, li) : 0, s = e, i = e + r;
|
|
2218
|
-
return { gapMs: n, effectiveGapMs: r, holdEnd: e, transStart: s, transEnd: i };
|
|
2219
|
-
}
|
|
2220
|
-
let rr = null;
|
|
2221
|
-
function xn(e) {
|
|
2222
|
-
rr = e;
|
|
2264
|
+
let ur = null;
|
|
2265
|
+
function Fn(e) {
|
|
2266
|
+
ur = e;
|
|
2223
2267
|
}
|
|
2224
2268
|
function Ne() {
|
|
2225
|
-
return
|
|
2269
|
+
return ur;
|
|
2226
2270
|
}
|
|
2227
|
-
function
|
|
2271
|
+
function bi(e) {
|
|
2228
2272
|
return `${e.from}→${e.to}@${e.fromVtime}`;
|
|
2229
2273
|
}
|
|
2230
|
-
function
|
|
2274
|
+
function Ln() {
|
|
2231
2275
|
return {
|
|
2232
2276
|
rafTicksSpeaking: 0,
|
|
2233
2277
|
rafTicksDeduped: 0,
|
|
@@ -2245,12 +2289,12 @@ function Cn() {
|
|
|
2245
2289
|
bufferPrefetched: 0
|
|
2246
2290
|
};
|
|
2247
2291
|
}
|
|
2248
|
-
function
|
|
2249
|
-
let e =
|
|
2292
|
+
function vi() {
|
|
2293
|
+
let e = Ln();
|
|
2250
2294
|
const t = /* @__PURE__ */ new Set(), n = /* @__PURE__ */ new Set(), r = /* @__PURE__ */ new Set();
|
|
2251
2295
|
let s = "", i = -1, a = "";
|
|
2252
2296
|
const o = () => {
|
|
2253
|
-
e =
|
|
2297
|
+
e = Ln(), t.clear(), n.clear(), r.clear(), s = "", i = -1, a = "";
|
|
2254
2298
|
}, f = (u) => {
|
|
2255
2299
|
t.add(u);
|
|
2256
2300
|
}, d = (u) => {
|
|
@@ -2274,7 +2318,7 @@ function pi() {
|
|
|
2274
2318
|
e.workerStale += 1;
|
|
2275
2319
|
},
|
|
2276
2320
|
onTransitionSample(u, c) {
|
|
2277
|
-
const m =
|
|
2321
|
+
const m = bi(u);
|
|
2278
2322
|
e.transitionFramesSampled += 1, m !== s && (s = m, i = -1, a !== m && (a = m, e.rifeFramesOmittedByGap += u.omittedByGap)), c && n.add(c), i >= 0 && u.frameIdx > i + 1 && (e.transitionFramesMissed += u.frameIdx - i - 1), i = u.frameIdx;
|
|
2279
2323
|
},
|
|
2280
2324
|
onBufferTick() {
|
|
@@ -2294,8 +2338,8 @@ function pi() {
|
|
|
2294
2338
|
onDrawDisplayed(u, c) {
|
|
2295
2339
|
if (e.drawsDisplayed += 1, u.transitionMeta) {
|
|
2296
2340
|
e.transitionFramesDisplayed += 1;
|
|
2297
|
-
const
|
|
2298
|
-
f(
|
|
2341
|
+
const w = u.transitionMeta;
|
|
2342
|
+
f(w.fromVtime), f(w.toVtime), d(u.mouthPath);
|
|
2299
2343
|
return;
|
|
2300
2344
|
}
|
|
2301
2345
|
if (u.label.includes("→")) {
|
|
@@ -2304,88 +2348,90 @@ function pi() {
|
|
|
2304
2348
|
}
|
|
2305
2349
|
const m = u.label.trim();
|
|
2306
2350
|
if (!(!m || m === "sil")) {
|
|
2307
|
-
for (const
|
|
2308
|
-
if (
|
|
2309
|
-
f(
|
|
2351
|
+
for (const w of c)
|
|
2352
|
+
if (w.viseme === m && u.elapsedMs >= w.vtime && u.elapsedMs < w.vtime + w.vduration) {
|
|
2353
|
+
f(w.vtime);
|
|
2310
2354
|
break;
|
|
2311
2355
|
}
|
|
2312
2356
|
}
|
|
2313
2357
|
},
|
|
2314
2358
|
snapshot(u, c) {
|
|
2315
|
-
let m = 0,
|
|
2359
|
+
let m = 0, w = 0;
|
|
2316
2360
|
for (const _ of u)
|
|
2317
2361
|
if (_.viseme !== "sil") {
|
|
2318
2362
|
if (_.vtime >= c) break;
|
|
2319
|
-
m += 1, t.has(_.vtime) && (
|
|
2363
|
+
m += 1, t.has(_.vtime) && (w += 1);
|
|
2320
2364
|
}
|
|
2321
|
-
const b = m > 0 ? Math.round(
|
|
2365
|
+
const b = m > 0 ? Math.round(w / m * 100) : 100, h = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), I = m - w, E = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
|
|
2322
2366
|
return {
|
|
2323
2367
|
...e,
|
|
2324
2368
|
bufferHitRate: E,
|
|
2325
2369
|
renderLoss: h,
|
|
2326
2370
|
visemeSlotsTotal: m,
|
|
2327
|
-
visemeSlotsCovered:
|
|
2371
|
+
visemeSlotsCovered: w,
|
|
2328
2372
|
visemeCoveragePct: b,
|
|
2329
2373
|
transitionFramesUniqueSampled: n.size,
|
|
2330
2374
|
transitionFramesUniquePainted: r.size,
|
|
2331
2375
|
drawsDeduped: e.rafTicksDeduped,
|
|
2332
2376
|
renderSkips: e.rafTicksDeduped + h,
|
|
2333
|
-
visemesShown:
|
|
2334
|
-
visemesSkipped:
|
|
2377
|
+
visemesShown: w,
|
|
2378
|
+
visemesSkipped: I,
|
|
2335
2379
|
rifeTransitionFramesSkipped: e.transitionFramesMissed
|
|
2336
2380
|
};
|
|
2337
2381
|
}
|
|
2338
2382
|
};
|
|
2339
2383
|
}
|
|
2340
|
-
const
|
|
2341
|
-
function
|
|
2342
|
-
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] ===
|
|
2384
|
+
const lr = zt, Ei = 200, Ti = 100, Ai = 600, fr = "__sil__";
|
|
2385
|
+
function Ii(e) {
|
|
2386
|
+
return e.lastDrawnKey ? e.lastDrawnKey.split("|")[0] === fr : !1;
|
|
2343
2387
|
}
|
|
2344
|
-
function
|
|
2388
|
+
function un() {
|
|
2345
2389
|
return { lastDrawnKey: "" };
|
|
2346
2390
|
}
|
|
2347
|
-
function
|
|
2391
|
+
function ke(e) {
|
|
2348
2392
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
2349
2393
|
}
|
|
2350
|
-
function
|
|
2394
|
+
function Mi(e, t) {
|
|
2351
2395
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
2352
2396
|
return t.transitionCache.transitions;
|
|
2353
|
-
const n =
|
|
2397
|
+
const n = gs(e);
|
|
2354
2398
|
return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
|
|
2355
2399
|
}
|
|
2356
|
-
function
|
|
2400
|
+
function Pi(e, t) {
|
|
2357
2401
|
let n = "sil";
|
|
2358
2402
|
for (const r of e)
|
|
2359
2403
|
r.viseme !== "sil" && (t != null && r.vtime > t || (n = r.viseme));
|
|
2360
2404
|
return n;
|
|
2361
2405
|
}
|
|
2362
|
-
function
|
|
2406
|
+
function Ri(e, t, n, r = 120) {
|
|
2363
2407
|
if (n !== "sil")
|
|
2364
2408
|
return n;
|
|
2365
|
-
const s =
|
|
2366
|
-
return s !== "sil" ? s :
|
|
2409
|
+
const s = Qn(e, t, r);
|
|
2410
|
+
return s !== "sil" ? s : Pi(e, t);
|
|
2367
2411
|
}
|
|
2368
|
-
function
|
|
2369
|
-
return e === "sil" ? !1 : t ?
|
|
2412
|
+
function Di(e, t) {
|
|
2413
|
+
return e === "sil" ? !1 : t ? qs(e, "sil", t) : nn(e, "sil").length > 0;
|
|
2370
2414
|
}
|
|
2371
|
-
function
|
|
2372
|
-
return
|
|
2415
|
+
function xi() {
|
|
2416
|
+
return lr + Ai;
|
|
2373
2417
|
}
|
|
2374
|
-
function
|
|
2375
|
-
return e ??
|
|
2418
|
+
function At(e) {
|
|
2419
|
+
return e ?? fr;
|
|
2376
2420
|
}
|
|
2377
|
-
function
|
|
2421
|
+
function ln(e, t, n, r, s = Ti) {
|
|
2378
2422
|
if (e.length === 0)
|
|
2379
2423
|
return { diffPath: null, label: "sil" };
|
|
2380
|
-
|
|
2424
|
+
if (t >= Fe(e))
|
|
2425
|
+
return { diffPath: null, label: "sil" };
|
|
2426
|
+
const i = Mi(e, r), a = ys(i, t);
|
|
2381
2427
|
if (a) {
|
|
2382
|
-
const f =
|
|
2428
|
+
const f = Yn(a.fromVtime, a.toVtime);
|
|
2383
2429
|
if (t >= f.transStart && t < f.transEnd) {
|
|
2384
|
-
let d =
|
|
2385
|
-
n && (d =
|
|
2386
|
-
const u =
|
|
2430
|
+
let d = nn(a.from, a.to);
|
|
2431
|
+
n && (d = ir(d, n));
|
|
2432
|
+
const u = Gs(d, f.effectiveGapMs);
|
|
2387
2433
|
if (u.length > 0) {
|
|
2388
|
-
const c =
|
|
2434
|
+
const c = js(
|
|
2389
2435
|
t,
|
|
2390
2436
|
f.transStart,
|
|
2391
2437
|
f.transEnd,
|
|
@@ -2406,48 +2452,48 @@ function un(e, t, n, r, s = gi) {
|
|
|
2406
2452
|
}
|
|
2407
2453
|
};
|
|
2408
2454
|
}
|
|
2409
|
-
return { diffPath:
|
|
2455
|
+
return { diffPath: vt(a.to), label: a.to };
|
|
2410
2456
|
}
|
|
2411
2457
|
}
|
|
2412
|
-
const o =
|
|
2413
|
-
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath:
|
|
2458
|
+
const o = Qn(e, t, s);
|
|
2459
|
+
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: vt(o), label: o };
|
|
2414
2460
|
}
|
|
2415
|
-
function
|
|
2416
|
-
const n = t ??
|
|
2417
|
-
return `${
|
|
2461
|
+
function fn(e, t) {
|
|
2462
|
+
const n = t ?? At(e.expressionPath);
|
|
2463
|
+
return `${At(e.mouthPath)}|${n}`;
|
|
2418
2464
|
}
|
|
2419
|
-
function
|
|
2420
|
-
const u =
|
|
2465
|
+
function Bi(e, t, n, r, s, i, a, o, f, d) {
|
|
2466
|
+
const u = ln(t, n, f, i), c = {
|
|
2421
2467
|
mouthPath: u.diffPath,
|
|
2422
2468
|
expressionPath: r
|
|
2423
|
-
}, m =
|
|
2424
|
-
if (u.transitionMeta &&
|
|
2425
|
-
|
|
2469
|
+
}, m = fn(c, s), w = Ne();
|
|
2470
|
+
if (u.transitionMeta && w?.onTransitionSample(u.transitionMeta, u.diffPath), m === i.lastDrawnKey) {
|
|
2471
|
+
w?.onDrawDeduped();
|
|
2426
2472
|
return;
|
|
2427
2473
|
}
|
|
2428
|
-
|
|
2474
|
+
w?.onDrawRequested(), o(u), i.lastDrawnKey = m, a(e, c, m, (b) => {
|
|
2429
2475
|
b === m && (i.lastDrawnKey = m);
|
|
2430
2476
|
});
|
|
2431
2477
|
}
|
|
2432
|
-
function
|
|
2433
|
-
const o = { mouthPath: null, expressionPath: t }, f = a != null ? `|idle@${Math.round(a * 1e3)}` : "", d =
|
|
2478
|
+
function On(e, t, n, r, s, i, a = null) {
|
|
2479
|
+
const o = { mouthPath: null, expressionPath: t }, f = a != null ? `|idle@${Math.round(a * 1e3)}` : "", d = fn(o, n) + f;
|
|
2434
2480
|
!(a != null) && d === r.lastDrawnKey || (i(
|
|
2435
2481
|
a != null ? "idle" : "sil"
|
|
2436
2482
|
), s(e, o, d, (c) => {
|
|
2437
2483
|
c === d && (r.lastDrawnKey = d);
|
|
2438
2484
|
}));
|
|
2439
2485
|
}
|
|
2440
|
-
function
|
|
2486
|
+
function dr(e, t, n, r, s = ut, i) {
|
|
2441
2487
|
if (n <= t || e.length === 0) return [];
|
|
2442
|
-
const a = i ??
|
|
2488
|
+
const a = i ?? un(), o = [];
|
|
2443
2489
|
let f = "";
|
|
2444
2490
|
for (let d = t; d < n; d += s) {
|
|
2445
|
-
const u =
|
|
2491
|
+
const u = ln(
|
|
2446
2492
|
e,
|
|
2447
2493
|
d,
|
|
2448
2494
|
r,
|
|
2449
2495
|
a
|
|
2450
|
-
), c =
|
|
2496
|
+
), c = At(u.diffPath);
|
|
2451
2497
|
c !== f && (f = c, o.push({
|
|
2452
2498
|
displayAtMs: d,
|
|
2453
2499
|
mouthPath: u.diffPath,
|
|
@@ -2457,8 +2503,8 @@ function ar(e, t, n, r, s = ft, i) {
|
|
|
2457
2503
|
}
|
|
2458
2504
|
return o;
|
|
2459
2505
|
}
|
|
2460
|
-
const
|
|
2461
|
-
function
|
|
2506
|
+
const Ci = 3;
|
|
2507
|
+
function mr(e) {
|
|
2462
2508
|
let t = 0;
|
|
2463
2509
|
const n = [];
|
|
2464
2510
|
let r = !1, s = !1;
|
|
@@ -2482,7 +2528,7 @@ function or(e) {
|
|
|
2482
2528
|
return {
|
|
2483
2529
|
enqueue(o, f, d) {
|
|
2484
2530
|
const u = n.findIndex((c) => c.drawKey === f);
|
|
2485
|
-
u >= 0 ? n[u] = { diffs: o, drawKey: f, onDisplayed: d } : (n.length >=
|
|
2531
|
+
u >= 0 ? n[u] = { diffs: o, drawKey: f, onDisplayed: d } : (n.length >= Ci && (n.shift(), Ne()?.onQueueSuperseded()), n.push({ diffs: o, drawKey: f, onDisplayed: d })), a();
|
|
2486
2532
|
},
|
|
2487
2533
|
reset() {
|
|
2488
2534
|
t += 1, n.length = 0;
|
|
@@ -2495,7 +2541,7 @@ function or(e) {
|
|
|
2495
2541
|
}
|
|
2496
2542
|
};
|
|
2497
2543
|
}
|
|
2498
|
-
function
|
|
2544
|
+
function Fi(e, t = 2) {
|
|
2499
2545
|
const n = [], r = /* @__PURE__ */ new Set();
|
|
2500
2546
|
let s = 0, i = !1, a = 0;
|
|
2501
2547
|
const o = (d, u) => `${d}|${u}`, f = async () => {
|
|
@@ -2537,7 +2583,7 @@ function Ii(e, t = 2) {
|
|
|
2537
2583
|
}
|
|
2538
2584
|
};
|
|
2539
2585
|
}
|
|
2540
|
-
function
|
|
2586
|
+
function Li() {
|
|
2541
2587
|
const e = /* @__PURE__ */ new Map(), t = (n) => {
|
|
2542
2588
|
n.bitmap.close();
|
|
2543
2589
|
};
|
|
@@ -2572,13 +2618,13 @@ function Mi() {
|
|
|
2572
2618
|
}
|
|
2573
2619
|
};
|
|
2574
2620
|
}
|
|
2575
|
-
function
|
|
2576
|
-
const a =
|
|
2621
|
+
function Oi(e, t, n, r, s, i) {
|
|
2622
|
+
const a = dr(
|
|
2577
2623
|
t,
|
|
2578
2624
|
n,
|
|
2579
2625
|
r,
|
|
2580
2626
|
s,
|
|
2581
|
-
|
|
2627
|
+
ut,
|
|
2582
2628
|
i
|
|
2583
2629
|
);
|
|
2584
2630
|
if (a.length === 0) return { ready: 0, total: 0 };
|
|
@@ -2587,10 +2633,10 @@ function Pi(e, t, n, r, s, i) {
|
|
|
2587
2633
|
e.has(f.displayAtMs, f.mouthKey) && (o += 1);
|
|
2588
2634
|
return { ready: o, total: a.length };
|
|
2589
2635
|
}
|
|
2590
|
-
function
|
|
2591
|
-
const t =
|
|
2636
|
+
function Ni(e) {
|
|
2637
|
+
const t = Li(), n = un(), r = /* @__PURE__ */ new Set();
|
|
2592
2638
|
let s = "", i = null;
|
|
2593
|
-
const a =
|
|
2639
|
+
const a = Fi(
|
|
2594
2640
|
async (c) => {
|
|
2595
2641
|
try {
|
|
2596
2642
|
if (!e.supportsBufferedPlayback) return;
|
|
@@ -2610,7 +2656,7 @@ function Di(e) {
|
|
|
2610
2656
|
r.delete(c.mouthKey);
|
|
2611
2657
|
}
|
|
2612
2658
|
},
|
|
2613
|
-
|
|
2659
|
+
Cr
|
|
2614
2660
|
), o = (c) => {
|
|
2615
2661
|
for (const m of c)
|
|
2616
2662
|
t.has(m.displayAtMs, m.mouthKey) || r.has(m.mouthKey) || a.isQueuedOrInflight(0, m.mouthKey) || (r.add(m.mouthKey), a.enqueue({
|
|
@@ -2622,23 +2668,23 @@ function Di(e) {
|
|
|
2622
2668
|
expressionPath: null
|
|
2623
2669
|
}
|
|
2624
2670
|
}));
|
|
2625
|
-
}, f = (c, m,
|
|
2671
|
+
}, f = (c, m, w, b = Ct) => {
|
|
2626
2672
|
if (!e.supportsBufferedPlayback) return;
|
|
2627
|
-
const h = Math.max(0, m -
|
|
2673
|
+
const h = Math.max(0, m - ut * 4), I = dr(
|
|
2628
2674
|
c,
|
|
2629
2675
|
h,
|
|
2630
2676
|
m + b,
|
|
2631
|
-
|
|
2632
|
-
|
|
2677
|
+
w,
|
|
2678
|
+
ut,
|
|
2633
2679
|
n
|
|
2634
2680
|
);
|
|
2635
|
-
o(
|
|
2681
|
+
o(I);
|
|
2636
2682
|
}, d = (c, m) => {
|
|
2637
2683
|
s = c, i = m;
|
|
2638
2684
|
}, u = (c, m) => !(s !== c || i !== m);
|
|
2639
2685
|
return {
|
|
2640
2686
|
reset() {
|
|
2641
|
-
t.reset(), a.reset(), r.clear(),
|
|
2687
|
+
t.reset(), a.reset(), r.clear(), ke(n), s = "", i = null, Ne()?.onBufferReset();
|
|
2642
2688
|
},
|
|
2643
2689
|
markExternallyDisplayed(c, m) {
|
|
2644
2690
|
d(c.split("|")[0] ?? c, m);
|
|
@@ -2648,12 +2694,12 @@ function Di(e) {
|
|
|
2648
2694
|
c.queue,
|
|
2649
2695
|
0,
|
|
2650
2696
|
c.availablePaths,
|
|
2651
|
-
Math.max(
|
|
2697
|
+
Math.max(Sn, Ct)
|
|
2652
2698
|
);
|
|
2653
2699
|
},
|
|
2654
|
-
isWarmupReady(c, m =
|
|
2700
|
+
isWarmupReady(c, m = Sn) {
|
|
2655
2701
|
if (!e.supportsBufferedPlayback) return !0;
|
|
2656
|
-
const { ready:
|
|
2702
|
+
const { ready: w, total: b } = Oi(
|
|
2657
2703
|
t,
|
|
2658
2704
|
c.queue,
|
|
2659
2705
|
0,
|
|
@@ -2661,7 +2707,7 @@ function Di(e) {
|
|
|
2661
2707
|
c.availablePaths,
|
|
2662
2708
|
n
|
|
2663
2709
|
);
|
|
2664
|
-
return b === 0 ? !1 :
|
|
2710
|
+
return b === 0 ? !1 : w / b >= Br;
|
|
2665
2711
|
},
|
|
2666
2712
|
getBufferedFrameCount: () => t.size(),
|
|
2667
2713
|
tick(c) {
|
|
@@ -2670,22 +2716,22 @@ function Di(e) {
|
|
|
2670
2716
|
c.queue,
|
|
2671
2717
|
c.elapsedMs,
|
|
2672
2718
|
c.availablePaths
|
|
2673
|
-
), t.pruneBefore(c.elapsedMs -
|
|
2674
|
-
const
|
|
2719
|
+
), t.pruneBefore(c.elapsedMs - Ct);
|
|
2720
|
+
const w = ln(
|
|
2675
2721
|
c.queue,
|
|
2676
2722
|
c.elapsedMs,
|
|
2677
2723
|
c.availablePaths,
|
|
2678
2724
|
n
|
|
2679
|
-
), b =
|
|
2680
|
-
{ mouthPath:
|
|
2725
|
+
), b = At(w.diffPath), h = fn(
|
|
2726
|
+
{ mouthPath: w.diffPath, expressionPath: c.expressionPath },
|
|
2681
2727
|
c.expressionDrawKey
|
|
2682
|
-
),
|
|
2728
|
+
), I = () => (d(b, c.expressionPath), m?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
|
|
2683
2729
|
if (u(b, c.expressionPath) || c.playbackState.lastDrawnKey === h)
|
|
2684
|
-
return
|
|
2730
|
+
return I();
|
|
2685
2731
|
const E = t.findForMouthKey(
|
|
2686
2732
|
b,
|
|
2687
2733
|
c.elapsedMs,
|
|
2688
|
-
|
|
2734
|
+
ut
|
|
2689
2735
|
);
|
|
2690
2736
|
return E && c.expressionPath != null ? (m?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : E ? (e.blitBitmap(c.canvas, E.bitmap), d(E.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = h, c.onStatus({
|
|
2691
2737
|
diffPath: E.mouthPath,
|
|
@@ -2694,9 +2740,9 @@ function Di(e) {
|
|
|
2694
2740
|
}
|
|
2695
2741
|
};
|
|
2696
2742
|
}
|
|
2697
|
-
const
|
|
2698
|
-
async function
|
|
2699
|
-
let t =
|
|
2743
|
+
const Nn = -1, kt = 1e5, Un = /* @__PURE__ */ new Map();
|
|
2744
|
+
async function Ui(e) {
|
|
2745
|
+
let t = Un.get(e);
|
|
2700
2746
|
if (!t) {
|
|
2701
2747
|
const n = await fetch(e);
|
|
2702
2748
|
if (!n.ok)
|
|
@@ -2704,11 +2750,11 @@ async function Ri(e) {
|
|
|
2704
2750
|
`Failed to fetch worker script (${n.status}): ${e}`
|
|
2705
2751
|
);
|
|
2706
2752
|
const r = await n.blob();
|
|
2707
|
-
t = URL.createObjectURL(r),
|
|
2753
|
+
t = URL.createObjectURL(r), Un.set(e, t);
|
|
2708
2754
|
}
|
|
2709
2755
|
return new Worker(t, { name: "visemeDiffPreview" });
|
|
2710
2756
|
}
|
|
2711
|
-
function
|
|
2757
|
+
function Vi() {
|
|
2712
2758
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
2713
2759
|
}
|
|
2714
2760
|
function Gt(e, t) {
|
|
@@ -2716,9 +2762,9 @@ function Gt(e, t) {
|
|
|
2716
2762
|
const n = e.getContext("2d");
|
|
2717
2763
|
n && n.drawImage(t, 0, 0);
|
|
2718
2764
|
}
|
|
2719
|
-
function
|
|
2765
|
+
function Vn(e, t) {
|
|
2720
2766
|
let n = 0, r = null;
|
|
2721
|
-
const s =
|
|
2767
|
+
const s = mr(async (i, a) => (await qt(), await Kt(e, i), s.isLatestSeq(a)));
|
|
2722
2768
|
return {
|
|
2723
2769
|
usesWorker: !1,
|
|
2724
2770
|
async loadAssets(i) {
|
|
@@ -2729,14 +2775,14 @@ function On(e, t) {
|
|
|
2729
2775
|
return r;
|
|
2730
2776
|
},
|
|
2731
2777
|
async renderSilOnly() {
|
|
2732
|
-
n += 1, s.reset(), await
|
|
2778
|
+
n += 1, s.reset(), await ki(e);
|
|
2733
2779
|
},
|
|
2734
2780
|
drawLiveFrame(i, a, o, f) {
|
|
2735
2781
|
s.enqueue(a, o, f);
|
|
2736
2782
|
},
|
|
2737
2783
|
async compositePrefetchFrame(i, a) {
|
|
2738
2784
|
try {
|
|
2739
|
-
return await
|
|
2785
|
+
return await Si(i);
|
|
2740
2786
|
} catch {
|
|
2741
2787
|
return null;
|
|
2742
2788
|
}
|
|
@@ -2749,7 +2795,7 @@ function On(e, t) {
|
|
|
2749
2795
|
n += 1;
|
|
2750
2796
|
const o = n;
|
|
2751
2797
|
t.onStatus?.(a), await Kt(i, {
|
|
2752
|
-
mouthPath:
|
|
2798
|
+
mouthPath: vt(a),
|
|
2753
2799
|
expressionPath: null
|
|
2754
2800
|
});
|
|
2755
2801
|
},
|
|
@@ -2758,14 +2804,14 @@ function On(e, t) {
|
|
|
2758
2804
|
}
|
|
2759
2805
|
};
|
|
2760
2806
|
}
|
|
2761
|
-
function
|
|
2807
|
+
function Wi(e, t, n) {
|
|
2762
2808
|
let r = null, s = 1, i = 0, a = !1, o = !1, f = null;
|
|
2763
2809
|
const d = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
|
|
2764
|
-
let c =
|
|
2765
|
-
const m =
|
|
2810
|
+
let c = kt;
|
|
2811
|
+
const m = mr(async (_, p, v) => (d.set(p, {
|
|
2766
2812
|
drawKey: v.drawKey,
|
|
2767
2813
|
onDisplayed: v.onDisplayed
|
|
2768
|
-
}), await
|
|
2814
|
+
}), await I(
|
|
2769
2815
|
{
|
|
2770
2816
|
type: "drawFrame",
|
|
2771
2817
|
diffPath: _.mouthPath,
|
|
@@ -2774,31 +2820,31 @@ function Ci(e, t, n) {
|
|
|
2774
2820
|
},
|
|
2775
2821
|
void 0,
|
|
2776
2822
|
!0
|
|
2777
|
-
), !1)),
|
|
2778
|
-
if (_ ===
|
|
2779
|
-
let
|
|
2780
|
-
for (const [
|
|
2781
|
-
|
|
2782
|
-
|
|
2823
|
+
), !1)), w = (_) => {
|
|
2824
|
+
if (_ === Nn) {
|
|
2825
|
+
let N = -1, F;
|
|
2826
|
+
for (const [j, R] of d)
|
|
2827
|
+
j >= N && (N = j, F = R);
|
|
2828
|
+
N >= 0 && d.delete(N), F?.onDisplayed?.(F.drawKey);
|
|
2783
2829
|
return;
|
|
2784
2830
|
}
|
|
2785
2831
|
const p = -_, v = d.get(p);
|
|
2786
2832
|
d.delete(p), v?.onDisplayed?.(v.drawKey);
|
|
2787
2833
|
}, b = /* @__PURE__ */ new Map(), h = (_, p) => {
|
|
2788
2834
|
o || !r || r.postMessage(_, []);
|
|
2789
|
-
},
|
|
2835
|
+
}, I = (_, p, v = !1) => {
|
|
2790
2836
|
if (o) return Promise.resolve();
|
|
2791
|
-
const
|
|
2792
|
-
return new Promise((F,
|
|
2793
|
-
b.set(
|
|
2794
|
-
resolve: (
|
|
2795
|
-
reject:
|
|
2837
|
+
const N = s++;
|
|
2838
|
+
return new Promise((F, j) => {
|
|
2839
|
+
b.set(N, {
|
|
2840
|
+
resolve: (R) => F(R),
|
|
2841
|
+
reject: j,
|
|
2796
2842
|
generation: typeof _.generation == "number" ? _.generation : void 0,
|
|
2797
2843
|
expectRenderDone: v
|
|
2798
|
-
}), h({ ..._, requestId:
|
|
2844
|
+
}), h({ ..._, requestId: N });
|
|
2799
2845
|
});
|
|
2800
2846
|
}, E = (async () => {
|
|
2801
|
-
r = await
|
|
2847
|
+
r = await Ui(n), r.onmessage = (_) => {
|
|
2802
2848
|
if (o) return;
|
|
2803
2849
|
const p = _.data;
|
|
2804
2850
|
if (p.type === "status") {
|
|
@@ -2806,28 +2852,28 @@ function Ci(e, t, n) {
|
|
|
2806
2852
|
return;
|
|
2807
2853
|
}
|
|
2808
2854
|
if (p.type === "frame") {
|
|
2809
|
-
if (p.generation <= -
|
|
2810
|
-
const F = -p.generation,
|
|
2811
|
-
u.delete(F),
|
|
2855
|
+
if (p.generation <= -kt) {
|
|
2856
|
+
const F = -p.generation, j = u.get(F);
|
|
2857
|
+
u.delete(F), j?.resolve(p.bitmap);
|
|
2812
2858
|
return;
|
|
2813
2859
|
}
|
|
2814
|
-
const
|
|
2815
|
-
if (!
|
|
2860
|
+
const N = p.generation < 0;
|
|
2861
|
+
if (!N && p.generation !== i) {
|
|
2816
2862
|
p.bitmap.close();
|
|
2817
2863
|
return;
|
|
2818
2864
|
}
|
|
2819
|
-
if (
|
|
2820
|
-
const
|
|
2821
|
-
if (!m.isLatestSeq(
|
|
2865
|
+
if (N && !(p.generation === Nn)) {
|
|
2866
|
+
const j = -p.generation;
|
|
2867
|
+
if (!m.isLatestSeq(j)) {
|
|
2822
2868
|
Ne()?.onWorkerStale(), p.bitmap.close();
|
|
2823
2869
|
return;
|
|
2824
2870
|
}
|
|
2825
2871
|
}
|
|
2826
|
-
if (
|
|
2872
|
+
if (N && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
2827
2873
|
Ne()?.onWorkerStale(), p.bitmap.close();
|
|
2828
2874
|
return;
|
|
2829
2875
|
}
|
|
2830
|
-
Gt(e, p.bitmap), p.bitmap.close(),
|
|
2876
|
+
Gt(e, p.bitmap), p.bitmap.close(), N && w(p.generation);
|
|
2831
2877
|
return;
|
|
2832
2878
|
}
|
|
2833
2879
|
const v = b.get(p.requestId);
|
|
@@ -2858,7 +2904,7 @@ function Ci(e, t, n) {
|
|
|
2858
2904
|
for (const [, v] of b)
|
|
2859
2905
|
v.reject(new Error(p));
|
|
2860
2906
|
b.clear();
|
|
2861
|
-
}, await
|
|
2907
|
+
}, await I({ type: "init" }), a = !0;
|
|
2862
2908
|
})();
|
|
2863
2909
|
return {
|
|
2864
2910
|
usesWorker: !0,
|
|
@@ -2866,10 +2912,10 @@ function Ci(e, t, n) {
|
|
|
2866
2912
|
if (o) return { width: 842, height: 1264 };
|
|
2867
2913
|
if (await E, o) return { width: 842, height: 1264 };
|
|
2868
2914
|
if (!a) throw new Error("Worker init failed");
|
|
2869
|
-
return await
|
|
2915
|
+
return await I({
|
|
2870
2916
|
type: "loadAssets",
|
|
2871
2917
|
keyHex: _,
|
|
2872
|
-
urls:
|
|
2918
|
+
urls: Jr(Ue())
|
|
2873
2919
|
}) ?? { width: 842, height: 1264 };
|
|
2874
2920
|
},
|
|
2875
2921
|
getVisemeAtlasPaths() {
|
|
@@ -2877,25 +2923,25 @@ function Ci(e, t, n) {
|
|
|
2877
2923
|
},
|
|
2878
2924
|
async renderSilOnly() {
|
|
2879
2925
|
if (o || (await E, o)) return;
|
|
2880
|
-
i += 1, m.reset(), d.clear(), u.forEach(({ resolve: p }) => p(null)), u.clear(), c =
|
|
2926
|
+
i += 1, m.reset(), d.clear(), u.forEach(({ resolve: p }) => p(null)), u.clear(), c = kt;
|
|
2881
2927
|
const _ = i;
|
|
2882
|
-
await
|
|
2928
|
+
await I({ type: "cancelLiveDraws" }), await I(
|
|
2883
2929
|
{ type: "renderSil", generation: _ },
|
|
2884
2930
|
void 0,
|
|
2885
2931
|
!0
|
|
2886
2932
|
);
|
|
2887
2933
|
},
|
|
2888
|
-
drawLiveFrame(_, p, v,
|
|
2934
|
+
drawLiveFrame(_, p, v, N) {
|
|
2889
2935
|
o || E.then(() => {
|
|
2890
|
-
o || m.enqueue(p, v,
|
|
2936
|
+
o || m.enqueue(p, v, N);
|
|
2891
2937
|
});
|
|
2892
2938
|
},
|
|
2893
2939
|
compositePrefetchFrame(_, p) {
|
|
2894
2940
|
return o ? Promise.resolve(null) : E.then(() => {
|
|
2895
2941
|
if (o) return null;
|
|
2896
2942
|
const v = ++c;
|
|
2897
|
-
return new Promise((
|
|
2898
|
-
u.set(v, { resolve:
|
|
2943
|
+
return new Promise((N) => {
|
|
2944
|
+
u.set(v, { resolve: N }), I(
|
|
2899
2945
|
{
|
|
2900
2946
|
type: "drawFrame",
|
|
2901
2947
|
diffPath: _.mouthPath,
|
|
@@ -2905,7 +2951,7 @@ function Ci(e, t, n) {
|
|
|
2905
2951
|
void 0,
|
|
2906
2952
|
!0
|
|
2907
2953
|
).catch(() => {
|
|
2908
|
-
u.delete(v),
|
|
2954
|
+
u.delete(v), N(null);
|
|
2909
2955
|
});
|
|
2910
2956
|
});
|
|
2911
2957
|
});
|
|
@@ -2917,12 +2963,12 @@ function Ci(e, t, n) {
|
|
|
2917
2963
|
async renderViseme(_, p, v = {}) {
|
|
2918
2964
|
if (o || (await E, o)) return;
|
|
2919
2965
|
i += 1, m.reset(), d.clear();
|
|
2920
|
-
const
|
|
2966
|
+
const N = i;
|
|
2921
2967
|
try {
|
|
2922
|
-
await
|
|
2968
|
+
await I({ type: "cancelLiveDraws" }), await I(
|
|
2923
2969
|
{
|
|
2924
2970
|
type: "renderViseme",
|
|
2925
|
-
generation:
|
|
2971
|
+
generation: N,
|
|
2926
2972
|
to: p,
|
|
2927
2973
|
from: v.from,
|
|
2928
2974
|
transitionDurationMs: v.transitionDurationMs,
|
|
@@ -2939,7 +2985,7 @@ function Ci(e, t, n) {
|
|
|
2939
2985
|
},
|
|
2940
2986
|
dispose() {
|
|
2941
2987
|
if (!o) {
|
|
2942
|
-
o = !0, i += 1, m.reset(), d.clear(), u.forEach(({ resolve: _ }) => _(null)), u.clear(), c =
|
|
2988
|
+
o = !0, i += 1, m.reset(), d.clear(), u.forEach(({ resolve: _ }) => _(null)), u.clear(), c = kt;
|
|
2943
2989
|
for (const [, _] of b)
|
|
2944
2990
|
_.resolve();
|
|
2945
2991
|
b.clear(), r?.terminate(), r = null;
|
|
@@ -2947,17 +2993,17 @@ function Ci(e, t, n) {
|
|
|
2947
2993
|
}
|
|
2948
2994
|
};
|
|
2949
2995
|
}
|
|
2950
|
-
function
|
|
2951
|
-
if (!
|
|
2952
|
-
return
|
|
2953
|
-
const n =
|
|
2996
|
+
function Hi(e, t = {}) {
|
|
2997
|
+
if (!Vi())
|
|
2998
|
+
return Vn(e, t);
|
|
2999
|
+
const n = Rr(t.workerScriptUrl);
|
|
2954
3000
|
try {
|
|
2955
|
-
return
|
|
3001
|
+
return Wi(e, t, n);
|
|
2956
3002
|
} catch {
|
|
2957
|
-
return
|
|
3003
|
+
return Vn(e, t);
|
|
2958
3004
|
}
|
|
2959
3005
|
}
|
|
2960
|
-
class
|
|
3006
|
+
class $i extends Error {
|
|
2961
3007
|
constructor(t, n) {
|
|
2962
3008
|
super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
2963
3009
|
}
|
|
@@ -2965,7 +3011,7 @@ class Fi extends Error {
|
|
|
2965
3011
|
function Nt(e, t, n) {
|
|
2966
3012
|
return new Promise((r, s) => {
|
|
2967
3013
|
const i = globalThis.setTimeout(() => {
|
|
2968
|
-
s(new
|
|
3014
|
+
s(new $i(n, t));
|
|
2969
3015
|
}, t);
|
|
2970
3016
|
e.then(
|
|
2971
3017
|
(a) => {
|
|
@@ -2977,15 +3023,15 @@ function Nt(e, t, n) {
|
|
|
2977
3023
|
);
|
|
2978
3024
|
});
|
|
2979
3025
|
}
|
|
2980
|
-
const
|
|
3026
|
+
const qi = {
|
|
2981
3027
|
position: "relative",
|
|
2982
3028
|
display: "inline-block",
|
|
2983
3029
|
lineHeight: 0
|
|
2984
|
-
},
|
|
3030
|
+
}, Ki = {
|
|
2985
3031
|
display: "block",
|
|
2986
3032
|
maxWidth: "100%",
|
|
2987
3033
|
height: "auto"
|
|
2988
|
-
},
|
|
3034
|
+
}, Gi = {
|
|
2989
3035
|
position: "absolute",
|
|
2990
3036
|
inset: 0,
|
|
2991
3037
|
display: "flex",
|
|
@@ -2997,603 +3043,614 @@ const Li = {
|
|
|
2997
3043
|
fontSize: "0.875rem",
|
|
2998
3044
|
textAlign: "center"
|
|
2999
3045
|
};
|
|
3000
|
-
function
|
|
3001
|
-
return
|
|
3046
|
+
function ot(e) {
|
|
3047
|
+
return Lr(e) ? er : Zn;
|
|
3002
3048
|
}
|
|
3003
|
-
function
|
|
3049
|
+
function Me(e, t) {
|
|
3004
3050
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
3005
3051
|
}
|
|
3006
|
-
const
|
|
3052
|
+
const na = _r(function({
|
|
3007
3053
|
id: t,
|
|
3008
3054
|
avatarId: n,
|
|
3009
3055
|
faceId: r,
|
|
3010
3056
|
assets: s,
|
|
3011
3057
|
authToken: i,
|
|
3012
3058
|
apiBase: a,
|
|
3013
|
-
ttsEngineId: o =
|
|
3059
|
+
ttsEngineId: o = je,
|
|
3014
3060
|
voiceId: f,
|
|
3015
|
-
speakingRate: d =
|
|
3061
|
+
speakingRate: d = Pt,
|
|
3016
3062
|
className: u,
|
|
3017
3063
|
style: c,
|
|
3018
3064
|
canvasStyle: m,
|
|
3019
|
-
onStatusChange:
|
|
3065
|
+
onStatusChange: w,
|
|
3020
3066
|
onDisplayStatus: b,
|
|
3021
3067
|
onError: h,
|
|
3022
|
-
onReady:
|
|
3068
|
+
onReady: I,
|
|
3023
3069
|
showErrorOverlay: E = !0,
|
|
3024
3070
|
onUserTranscript: _,
|
|
3025
3071
|
onBotOutput: p,
|
|
3026
3072
|
onRealtimeLipsyncDebug: v,
|
|
3027
|
-
onFrameRenderStats:
|
|
3073
|
+
onFrameRenderStats: N,
|
|
3028
3074
|
lipsyncBufferedPlayback: F = !0,
|
|
3029
|
-
lipsyncPlaybackWarmupMs:
|
|
3030
|
-
},
|
|
3031
|
-
const S =
|
|
3075
|
+
lipsyncPlaybackWarmupMs: j = 1500
|
|
3076
|
+
}, R) {
|
|
3077
|
+
const S = O(null), M = O(null), T = O(null), Z = O(F);
|
|
3078
|
+
Z.current = F;
|
|
3079
|
+
const D = O(0), X = O(un()), z = O(li()), se = O(0), ne = O(0), de = O(0), ue = O(null), y = O(null), A = O(!1), q = O(!1), x = O(!1), P = O("sil"), $ = O(0), C = O(!1), B = O(
|
|
3032
3080
|
null
|
|
3033
|
-
),
|
|
3034
|
-
|
|
3035
|
-
const
|
|
3036
|
-
return
|
|
3081
|
+
), Y = O(!1), [ee, pe] = at("idle"), [me, le] = at(null), [fe, Ve] = at(!1), [xe, We] = at(!1), [ft, dn] = at({ width: 842, height: 1264 }), l = O(i ?? null), k = a?.trim() || lt, V = O(null), K = O(null), ie = O(!1), Pe = O({ width: 842, height: 1264 }), ae = O(null), Re = O("sil"), ge = O(void 0), Ze = O(/* @__PURE__ */ new Map()), et = O(I), re = O(b), tt = O(h), dt = O(_), mt = O(p), be = O(v), nt = O(N), ve = O(vi());
|
|
3082
|
+
et.current = I, re.current = b, tt.current = h, dt.current = _, mt.current = p, be.current = v, nt.current = N, Ce(() => {
|
|
3083
|
+
const g = ve.current;
|
|
3084
|
+
return Fn(g), () => Fn(null);
|
|
3037
3085
|
}, []);
|
|
3038
|
-
const
|
|
3039
|
-
(
|
|
3040
|
-
const
|
|
3041
|
-
return { ttsEngineId:
|
|
3086
|
+
const oe = Se(
|
|
3087
|
+
(g) => {
|
|
3088
|
+
const L = g?.ttsEngineId ?? o ?? K.current?.ttsEngineId ?? je, U = g?.voiceId ?? f ?? K.current?.voiceId ?? ot(L);
|
|
3089
|
+
return { ttsEngineId: L, voiceId: U };
|
|
3042
3090
|
},
|
|
3043
3091
|
[o, f]
|
|
3044
|
-
),
|
|
3045
|
-
|
|
3046
|
-
}, []),
|
|
3047
|
-
(
|
|
3048
|
-
|
|
3049
|
-
},
|
|
3050
|
-
[
|
|
3051
|
-
),
|
|
3052
|
-
|
|
3053
|
-
onLipsyncDebug: (
|
|
3092
|
+
), ce = Se((g) => {
|
|
3093
|
+
le(g), tt.current?.(g);
|
|
3094
|
+
}, []), he = Se(
|
|
3095
|
+
(g) => {
|
|
3096
|
+
pe(g), w?.(g);
|
|
3097
|
+
},
|
|
3098
|
+
[w]
|
|
3099
|
+
), J = O(
|
|
3100
|
+
An(he, k, {
|
|
3101
|
+
onLipsyncDebug: (g) => be.current?.(g)
|
|
3054
3102
|
})
|
|
3055
|
-
),
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3103
|
+
), Q = O(null);
|
|
3104
|
+
Ce(() => (J.current = An(
|
|
3105
|
+
he,
|
|
3106
|
+
k,
|
|
3059
3107
|
{
|
|
3060
|
-
onLipsyncDebug: (
|
|
3108
|
+
onLipsyncDebug: (g) => be.current?.(g)
|
|
3061
3109
|
}
|
|
3062
|
-
), i &&
|
|
3063
|
-
|
|
3064
|
-
const
|
|
3065
|
-
|
|
3066
|
-
}), [
|
|
3067
|
-
const
|
|
3068
|
-
|
|
3110
|
+
), i && J.current.setDeveloperToken(i), J.current.setTtsEngineId(o), () => {
|
|
3111
|
+
J.current.stop();
|
|
3112
|
+
const g = Q.current;
|
|
3113
|
+
g && (g.disconnect(), Q.current = null);
|
|
3114
|
+
}), [he, i, o, k]);
|
|
3115
|
+
const ht = Se(() => (Q.current || (Q.current = Cs(
|
|
3116
|
+
he,
|
|
3069
3117
|
{
|
|
3070
3118
|
speakingRate: d,
|
|
3071
|
-
onUserTranscript: (
|
|
3072
|
-
onBotOutput: (
|
|
3073
|
-
onLipsyncDebug: (
|
|
3119
|
+
onUserTranscript: (g, L) => dt.current?.(g, L),
|
|
3120
|
+
onBotOutput: (g) => mt.current?.(g),
|
|
3121
|
+
onLipsyncDebug: (g) => be.current?.(g)
|
|
3074
3122
|
}
|
|
3075
|
-
),
|
|
3076
|
-
|
|
3077
|
-
}, []),
|
|
3078
|
-
|
|
3079
|
-
}, []),
|
|
3080
|
-
!
|
|
3081
|
-
if (
|
|
3082
|
-
|
|
3083
|
-
|
|
3123
|
+
), Q.current.setTtsEngineId(o)), Q.current), [he, d, o]), ye = Se(() => {
|
|
3124
|
+
ue.current != null && (clearTimeout(ue.current), ue.current = null);
|
|
3125
|
+
}, []), Te = Se(() => {
|
|
3126
|
+
y.current != null && (clearTimeout(y.current), y.current = null), x.current = !1;
|
|
3127
|
+
}, []), mn = Se(() => {
|
|
3128
|
+
!Y.current || !B.current || (Te(), x.current = !0, y.current = setTimeout(() => {
|
|
3129
|
+
if (y.current = null, Me(
|
|
3130
|
+
J.current,
|
|
3131
|
+
Q.current
|
|
3084
3132
|
).isSpeaking()) {
|
|
3085
|
-
|
|
3133
|
+
x.current = !1;
|
|
3086
3134
|
return;
|
|
3087
3135
|
}
|
|
3088
|
-
if (
|
|
3089
|
-
|
|
3136
|
+
if (A.current) {
|
|
3137
|
+
x.current = !1;
|
|
3090
3138
|
return;
|
|
3091
3139
|
}
|
|
3092
|
-
const
|
|
3093
|
-
if (!
|
|
3094
|
-
|
|
3140
|
+
const g = B.current;
|
|
3141
|
+
if (!g) {
|
|
3142
|
+
x.current = !1;
|
|
3095
3143
|
return;
|
|
3096
3144
|
}
|
|
3097
|
-
|
|
3098
|
-
const
|
|
3099
|
-
let
|
|
3145
|
+
g.restart(), g.setActive(!0);
|
|
3146
|
+
const L = g.getVideo();
|
|
3147
|
+
let U = !1;
|
|
3100
3148
|
const G = () => {
|
|
3101
|
-
|
|
3102
|
-
},
|
|
3149
|
+
U || (U = !0, L.removeEventListener("playing", W), x.current = !1);
|
|
3150
|
+
}, W = () => {
|
|
3103
3151
|
G();
|
|
3104
3152
|
};
|
|
3105
|
-
if (
|
|
3153
|
+
if (L.addEventListener("playing", W, { once: !0 }), L.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !L.paused) {
|
|
3106
3154
|
G();
|
|
3107
3155
|
return;
|
|
3108
3156
|
}
|
|
3109
3157
|
setTimeout(G, 300);
|
|
3110
|
-
},
|
|
3111
|
-
}, [
|
|
3112
|
-
if (
|
|
3113
|
-
|
|
3158
|
+
}, Ei));
|
|
3159
|
+
}, [Te]), He = Se(() => {
|
|
3160
|
+
if (ye(), re.current?.("sil"), A.current = !1, !Y.current || !B.current) {
|
|
3161
|
+
x.current = !1;
|
|
3114
3162
|
return;
|
|
3115
3163
|
}
|
|
3116
|
-
|
|
3117
|
-
}, [
|
|
3118
|
-
async (
|
|
3119
|
-
const
|
|
3120
|
-
|
|
3164
|
+
mn();
|
|
3165
|
+
}, [ye, mn]), Dt = Se(
|
|
3166
|
+
async (g) => {
|
|
3167
|
+
const L = ne.current, U = M.current, G = S.current, W = () => {
|
|
3168
|
+
g?.fallbackOnly || (A.current = !1);
|
|
3121
3169
|
};
|
|
3122
|
-
if (!
|
|
3123
|
-
|
|
3170
|
+
if (!U || !G || !fe) {
|
|
3171
|
+
W();
|
|
3124
3172
|
return;
|
|
3125
3173
|
}
|
|
3126
|
-
if (
|
|
3127
|
-
|
|
3128
|
-
|
|
3174
|
+
if (Me(
|
|
3175
|
+
J.current,
|
|
3176
|
+
Q.current
|
|
3129
3177
|
).isSpeaking()) {
|
|
3130
|
-
|
|
3178
|
+
W();
|
|
3131
3179
|
return;
|
|
3132
3180
|
}
|
|
3133
|
-
if (
|
|
3134
|
-
if (!
|
|
3135
|
-
|
|
3136
|
-
|
|
3181
|
+
if (g?.fallbackOnly) {
|
|
3182
|
+
if (!A.current || (ke(X.current), await U.renderSilOnly(), L !== ne.current) || Me(
|
|
3183
|
+
J.current,
|
|
3184
|
+
Q.current
|
|
3137
3185
|
).isSpeaking())
|
|
3138
3186
|
return;
|
|
3139
|
-
|
|
3187
|
+
He();
|
|
3140
3188
|
return;
|
|
3141
3189
|
}
|
|
3142
|
-
if (
|
|
3143
|
-
|
|
3190
|
+
if (Ii(X.current)) {
|
|
3191
|
+
ke(X.current), He();
|
|
3144
3192
|
return;
|
|
3145
3193
|
}
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3194
|
+
if (Z.current && U.supportsBufferedPlayback && !g?.fallbackOnly) {
|
|
3195
|
+
if (ke(X.current), T.current?.reset(), await U.renderSilOnly(), L !== ne.current || Me(
|
|
3196
|
+
J.current,
|
|
3197
|
+
Q.current
|
|
3198
|
+
).isSpeaking())
|
|
3199
|
+
return;
|
|
3200
|
+
He();
|
|
3201
|
+
return;
|
|
3202
|
+
}
|
|
3203
|
+
const _e = Ri(
|
|
3204
|
+
Me(
|
|
3205
|
+
J.current,
|
|
3206
|
+
Q.current
|
|
3150
3207
|
).getVisemeQueue(),
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
),
|
|
3154
|
-
|
|
3155
|
-
|
|
3208
|
+
$.current,
|
|
3209
|
+
P.current
|
|
3210
|
+
), pt = Di(
|
|
3211
|
+
_e,
|
|
3212
|
+
ae.current
|
|
3156
3213
|
);
|
|
3157
|
-
if (
|
|
3158
|
-
if (await
|
|
3159
|
-
|
|
3160
|
-
|
|
3214
|
+
if (ke(X.current), !pt) {
|
|
3215
|
+
if (await U.renderSilOnly(), L !== ne.current || Me(
|
|
3216
|
+
J.current,
|
|
3217
|
+
Q.current
|
|
3161
3218
|
).isSpeaking())
|
|
3162
3219
|
return;
|
|
3163
|
-
|
|
3220
|
+
He();
|
|
3164
3221
|
return;
|
|
3165
3222
|
}
|
|
3166
3223
|
try {
|
|
3167
|
-
await
|
|
3168
|
-
from:
|
|
3169
|
-
transitionDurationMs:
|
|
3224
|
+
await U.renderViseme(G, "sil", {
|
|
3225
|
+
from: _e,
|
|
3226
|
+
transitionDurationMs: lr
|
|
3170
3227
|
});
|
|
3171
|
-
} catch (
|
|
3172
|
-
if (
|
|
3173
|
-
throw
|
|
3228
|
+
} catch (De) {
|
|
3229
|
+
if (De?.name !== "AbortError")
|
|
3230
|
+
throw De;
|
|
3174
3231
|
}
|
|
3175
|
-
if (
|
|
3176
|
-
|
|
3232
|
+
if (L !== ne.current) {
|
|
3233
|
+
W();
|
|
3177
3234
|
return;
|
|
3178
3235
|
}
|
|
3179
|
-
if (
|
|
3180
|
-
|
|
3181
|
-
|
|
3236
|
+
if (Me(
|
|
3237
|
+
J.current,
|
|
3238
|
+
Q.current
|
|
3182
3239
|
).isSpeaking()) {
|
|
3183
|
-
|
|
3240
|
+
W();
|
|
3184
3241
|
return;
|
|
3185
3242
|
}
|
|
3186
|
-
|
|
3187
|
-
},
|
|
3188
|
-
[
|
|
3189
|
-
), rt =
|
|
3190
|
-
if (
|
|
3191
|
-
|
|
3192
|
-
const
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
}),
|
|
3196
|
-
|
|
3197
|
-
},
|
|
3198
|
-
}, [
|
|
3199
|
-
const
|
|
3200
|
-
if (
|
|
3201
|
-
return
|
|
3202
|
-
const
|
|
3203
|
-
|
|
3204
|
-
const
|
|
3205
|
-
return
|
|
3206
|
-
key:
|
|
3207
|
-
expiresAt:
|
|
3208
|
-
},
|
|
3209
|
-
}, [
|
|
3210
|
-
|
|
3211
|
-
i && (
|
|
3212
|
-
}, [i]),
|
|
3213
|
-
|
|
3214
|
-
}, [o]),
|
|
3215
|
-
const
|
|
3216
|
-
|
|
3243
|
+
He();
|
|
3244
|
+
},
|
|
3245
|
+
[fe, He]
|
|
3246
|
+
), rt = Se(() => {
|
|
3247
|
+
if (q.current || A.current) return;
|
|
3248
|
+
q.current = !0, A.current = !0, ye();
|
|
3249
|
+
const g = ne.current;
|
|
3250
|
+
Dt().finally(() => {
|
|
3251
|
+
q.current = !1;
|
|
3252
|
+
}), ue.current = setTimeout(() => {
|
|
3253
|
+
ue.current = null, g === ne.current && Dt({ fallbackOnly: !0 });
|
|
3254
|
+
}, xi());
|
|
3255
|
+
}, [ye, Dt]), hn = Se(async () => {
|
|
3256
|
+
const g = Math.floor(Date.now() / 1e3);
|
|
3257
|
+
if (V.current && g < V.current.expiresAt - 60)
|
|
3258
|
+
return V.current.key;
|
|
3259
|
+
const L = l.current ?? await Ft();
|
|
3260
|
+
l.current = L, J.current.setDeveloperToken(L);
|
|
3261
|
+
const U = await qr(L, k);
|
|
3262
|
+
return V.current = {
|
|
3263
|
+
key: U.value,
|
|
3264
|
+
expiresAt: U.expiresAt
|
|
3265
|
+
}, U.value;
|
|
3266
|
+
}, [k]);
|
|
3267
|
+
Ce(() => {
|
|
3268
|
+
i && (l.current = i, J.current.setDeveloperToken(i));
|
|
3269
|
+
}, [i]), Ce(() => {
|
|
3270
|
+
J.current.setTtsEngineId(o), Q.current?.setTtsEngineId(o), K.current && (K.current.ttsEngineId = o);
|
|
3271
|
+
}, [o]), Ce(() => {
|
|
3272
|
+
const g = f ?? ot(o);
|
|
3273
|
+
K.current && (K.current.voiceId = g);
|
|
3217
3274
|
}, [f, o]);
|
|
3218
|
-
const Be =
|
|
3219
|
-
() =>
|
|
3275
|
+
const Be = _n(
|
|
3276
|
+
() => zr(n, r),
|
|
3220
3277
|
[n, r]
|
|
3221
|
-
),
|
|
3222
|
-
return
|
|
3278
|
+
), hr = _n(() => s ? JSON.stringify(s) : Be ? `face:${Be}` : `id:${t ?? ""}`, [s, Be, t]);
|
|
3279
|
+
return Ce(() => {
|
|
3223
3280
|
if (!t && !s && !Be) {
|
|
3224
|
-
|
|
3281
|
+
ce("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
3225
3282
|
return;
|
|
3226
3283
|
}
|
|
3227
|
-
let
|
|
3228
|
-
|
|
3229
|
-
const
|
|
3230
|
-
if (!
|
|
3231
|
-
let
|
|
3284
|
+
let g = !1;
|
|
3285
|
+
ie.current = !1, Ve(!1), We(!1), le(null), K.current = null, B.current = null, Y.current = !1;
|
|
3286
|
+
const L = S.current;
|
|
3287
|
+
if (!L) return;
|
|
3288
|
+
let U = null;
|
|
3232
3289
|
return (async () => {
|
|
3233
3290
|
try {
|
|
3234
|
-
let G,
|
|
3291
|
+
let G, W, we, _e;
|
|
3235
3292
|
if (s)
|
|
3236
|
-
G = s,
|
|
3293
|
+
G = s, W = o, we = f ?? ot(W);
|
|
3237
3294
|
else if (Be)
|
|
3238
|
-
|
|
3295
|
+
re.current?.("loadFace"), G = bn(Be), W = o, we = f ?? ot(W);
|
|
3239
3296
|
else {
|
|
3240
|
-
|
|
3241
|
-
const
|
|
3242
|
-
|
|
3297
|
+
re.current?.("getAiTwin");
|
|
3298
|
+
const H = await Nt(
|
|
3299
|
+
Nr(t),
|
|
3243
3300
|
3e4,
|
|
3244
3301
|
"getAiTwin"
|
|
3245
3302
|
);
|
|
3246
|
-
if (
|
|
3247
|
-
if (
|
|
3303
|
+
if (g) return;
|
|
3304
|
+
if (!H.faceId?.trim())
|
|
3248
3305
|
throw new Error("getAiTwin returned no faceId");
|
|
3249
|
-
|
|
3306
|
+
W = H.ttsEngineId, we = f ?? H.voiceId ?? ot(W), _e = H.knowledgeContextId?.trim() || void 0, G = bn(H.faceId);
|
|
3250
3307
|
}
|
|
3251
|
-
|
|
3252
|
-
onStatus: (
|
|
3253
|
-
|
|
3308
|
+
K.current = { ttsEngineId: W, voiceId: we, personaId: _e }, Yr(G), B.current = fi(), U = Hi(L, {
|
|
3309
|
+
onStatus: (H) => {
|
|
3310
|
+
g || re.current?.(H);
|
|
3254
3311
|
},
|
|
3255
|
-
onError: (
|
|
3256
|
-
|
|
3312
|
+
onError: (H) => {
|
|
3313
|
+
g || ce(H);
|
|
3257
3314
|
},
|
|
3258
|
-
shouldAcceptLiveFrame: () =>
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
).isSpeaking() && !
|
|
3262
|
-
}),
|
|
3263
|
-
const te = () =>
|
|
3264
|
-
|
|
3265
|
-
})(!0),
|
|
3266
|
-
const
|
|
3267
|
-
if (
|
|
3268
|
-
|
|
3269
|
-
const
|
|
3270
|
-
if (
|
|
3271
|
-
|
|
3272
|
-
const
|
|
3273
|
-
|
|
3315
|
+
shouldAcceptLiveFrame: () => Me(
|
|
3316
|
+
J.current,
|
|
3317
|
+
Q.current
|
|
3318
|
+
).isSpeaking() && !A.current
|
|
3319
|
+
}), M.current = U, T.current = Ni(U), ((H) => {
|
|
3320
|
+
const te = () => H && F && (M.current?.supportsBufferedPlayback ?? !1) && j > 0;
|
|
3321
|
+
J.current.setLipsyncWarmupHold(H, te), Q.current?.setLipsyncWarmupHold(H, te);
|
|
3322
|
+
})(!0), re.current?.("auth");
|
|
3323
|
+
const De = l.current ?? i ?? await Nt(Ft(), 3e4, "getAuthToken");
|
|
3324
|
+
if (g) return;
|
|
3325
|
+
l.current = De, J.current.setDeveloperToken(De), J.current.setTtsEngineId(W);
|
|
3326
|
+
const st = It() ? await hn() : void 0;
|
|
3327
|
+
if (g) return;
|
|
3328
|
+
re.current?.("loadAssets");
|
|
3329
|
+
const $e = await Nt(
|
|
3330
|
+
U.loadAssets(st),
|
|
3274
3331
|
18e4,
|
|
3275
3332
|
"load face assets"
|
|
3276
3333
|
);
|
|
3277
|
-
if (!
|
|
3278
|
-
|
|
3279
|
-
|
|
3334
|
+
if (!g && $e.width > 0 && $e.height > 0 && (Pe.current = $e, dn($e)), g) return;
|
|
3335
|
+
ae.current = U.getVisemeAtlasPaths(), ie.current = !0, Ve(!0), et.current?.(), U.renderSilOnly().then(() => {
|
|
3336
|
+
g || re.current?.("sil");
|
|
3280
3337
|
}), (async () => {
|
|
3281
3338
|
try {
|
|
3282
|
-
const
|
|
3283
|
-
if (await
|
|
3284
|
-
|
|
3285
|
-
const te =
|
|
3286
|
-
await
|
|
3287
|
-
|
|
3339
|
+
const H = await Hs(st);
|
|
3340
|
+
if (await B.current.load(H), g) return;
|
|
3341
|
+
Y.current = !0, We(!0), ke(X.current), B.current.setActive(!0);
|
|
3342
|
+
const te = B.current.getVideo();
|
|
3343
|
+
await Cn(
|
|
3344
|
+
L,
|
|
3288
3345
|
te,
|
|
3289
3346
|
null,
|
|
3290
3347
|
void 0,
|
|
3291
|
-
|
|
3292
|
-
),
|
|
3293
|
-
} catch (
|
|
3294
|
-
if (
|
|
3295
|
-
|
|
3348
|
+
Pe.current
|
|
3349
|
+
), g || re.current?.("idle");
|
|
3350
|
+
} catch (H) {
|
|
3351
|
+
if (g) return;
|
|
3352
|
+
Y.current = !1, We(!1), console.warn("[AiTwin] Idle video unavailable:", H);
|
|
3296
3353
|
}
|
|
3297
3354
|
})();
|
|
3298
3355
|
} catch (G) {
|
|
3299
|
-
if (
|
|
3356
|
+
if (g) return;
|
|
3300
3357
|
if (G instanceof Ut) {
|
|
3301
|
-
|
|
3358
|
+
ce(G.message);
|
|
3302
3359
|
return;
|
|
3303
3360
|
}
|
|
3304
|
-
|
|
3361
|
+
ce(G instanceof Error ? G.message : "Failed to load AI twin");
|
|
3305
3362
|
}
|
|
3306
3363
|
})(), () => {
|
|
3307
|
-
|
|
3364
|
+
g = !0, B.current?.dispose(), U?.dispose(), M.current = null;
|
|
3308
3365
|
};
|
|
3309
|
-
}, [
|
|
3310
|
-
const
|
|
3311
|
-
const
|
|
3312
|
-
|
|
3313
|
-
|
|
3366
|
+
}, [hr, s, Be, t, o, f, i, hn, ce]), Ce(() => {
|
|
3367
|
+
const g = { current: !1 }, L = () => {
|
|
3368
|
+
const U = S.current, G = M.current, W = Me(
|
|
3369
|
+
J.current,
|
|
3370
|
+
Q.current
|
|
3314
3371
|
);
|
|
3315
|
-
if (!
|
|
3316
|
-
|
|
3372
|
+
if (!U || !G || !fe) {
|
|
3373
|
+
se.current = requestAnimationFrame(L);
|
|
3317
3374
|
return;
|
|
3318
3375
|
}
|
|
3319
|
-
const
|
|
3320
|
-
|
|
3321
|
-
const
|
|
3322
|
-
if (
|
|
3323
|
-
|
|
3324
|
-
const
|
|
3325
|
-
|
|
3326
|
-
const te =
|
|
3327
|
-
queue:
|
|
3376
|
+
const we = W.isSpeaking(), _e = W.isWarmingUp(), pt = we && !C.current, De = C.current && !we;
|
|
3377
|
+
pt && (ye(), Te(), A.current = !1, q.current = !1, ke(X.current), (T.current?.getBufferedFrameCount() ?? 0) === 0 && T.current?.reset(), ve.current.reset(), ge.current = void 0, de.current = 0, P.current = "sil", $.current = 0, B.current?.setActive(!1)), De && (z.current.reset(), B.current?.setActive(!1), rt());
|
|
3378
|
+
const st = De || A.current || x.current, $e = F && G.supportsBufferedPlayback;
|
|
3379
|
+
if (_e && $e && T.current) {
|
|
3380
|
+
Y.current && B.current?.setActive(!1);
|
|
3381
|
+
const H = W.getVisemeQueue();
|
|
3382
|
+
H.length > 0 && D.current === 0 && (D.current = performance.now()), z.current.advance(performance.now());
|
|
3383
|
+
const te = z.current.getExpressionPath(), Ee = z.current.getDrawKey(), Ae = {
|
|
3384
|
+
queue: H,
|
|
3328
3385
|
elapsedMs: 0,
|
|
3329
3386
|
expressionPath: te,
|
|
3330
|
-
expressionDrawKey:
|
|
3331
|
-
availablePaths:
|
|
3387
|
+
expressionDrawKey: Ee,
|
|
3388
|
+
availablePaths: ae.current
|
|
3332
3389
|
};
|
|
3333
|
-
T.current.warmupTick(
|
|
3334
|
-
const
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
),
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
), (
|
|
3390
|
+
T.current.warmupTick(Ae);
|
|
3391
|
+
const Ie = T.current.isWarmupReady(
|
|
3392
|
+
Ae,
|
|
3393
|
+
j
|
|
3394
|
+
), qe = D.current > 0 && performance.now() - D.current > xr;
|
|
3395
|
+
re.current?.(
|
|
3396
|
+
Ie ? "buffer ready" : "buffering lipsync…"
|
|
3397
|
+
), (Ie || qe) && (D.current = 0, W.releaseWarmupHold()), C.current = W.isSpeaking(), se.current = requestAnimationFrame(L);
|
|
3341
3398
|
return;
|
|
3342
3399
|
}
|
|
3343
|
-
if (
|
|
3344
|
-
|
|
3345
|
-
const
|
|
3346
|
-
|
|
3347
|
-
const
|
|
3348
|
-
|
|
3349
|
-
const
|
|
3400
|
+
if (we) {
|
|
3401
|
+
Y.current && B.current?.setActive(!1);
|
|
3402
|
+
const H = W.getVisemeQueue(), te = W.getPlaybackElapsedMs();
|
|
3403
|
+
Es(H, te), $.current = te;
|
|
3404
|
+
const Ee = H.length > 0 ? Mt(H, te) : "sil";
|
|
3405
|
+
Ee !== "sil" && (P.current = Ee);
|
|
3406
|
+
const Ae = pi(
|
|
3350
3407
|
te,
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3408
|
+
W.getSentenceEmotions(),
|
|
3409
|
+
W.getWordQueue(),
|
|
3410
|
+
W.getStreamMood()
|
|
3354
3411
|
);
|
|
3355
|
-
|
|
3356
|
-
|
|
3412
|
+
z.current.setTargetEmotion(Ae), z.current.setTargetEyebrow(
|
|
3413
|
+
ui(
|
|
3357
3414
|
te,
|
|
3358
|
-
|
|
3359
|
-
|
|
3415
|
+
W.getWordQueue(),
|
|
3416
|
+
sn(Ae)
|
|
3360
3417
|
)
|
|
3361
|
-
),
|
|
3362
|
-
const
|
|
3363
|
-
const
|
|
3364
|
-
label:
|
|
3418
|
+
), z.current.advance(performance.now());
|
|
3419
|
+
const Ie = z.current.getExpressionPath(), qe = z.current.getDrawKey(), pr = (Ke, xt, it, Bt) => {
|
|
3420
|
+
const gn = {
|
|
3421
|
+
label: Re.current,
|
|
3365
3422
|
elapsedMs: te,
|
|
3366
3423
|
mouthPath: xt.mouthPath,
|
|
3367
|
-
transitionMeta:
|
|
3424
|
+
transitionMeta: ge.current
|
|
3368
3425
|
};
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
), G.drawLiveFrame(
|
|
3373
|
-
const
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3426
|
+
Ze.current.set(it, gn), T.current?.markExternallyDisplayed(
|
|
3427
|
+
it,
|
|
3428
|
+
Ie
|
|
3429
|
+
), G.drawLiveFrame(Ke, xt, it, (wt) => {
|
|
3430
|
+
const gr = Ze.current.get(wt) ?? gn;
|
|
3431
|
+
Ze.current.delete(wt), ve.current.onDrawDisplayed(
|
|
3432
|
+
gr,
|
|
3433
|
+
H
|
|
3377
3434
|
), T.current?.markExternallyDisplayed(
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
),
|
|
3435
|
+
wt,
|
|
3436
|
+
Ie
|
|
3437
|
+
), Bt?.(wt);
|
|
3381
3438
|
});
|
|
3382
|
-
},
|
|
3383
|
-
|
|
3384
|
-
},
|
|
3385
|
-
let
|
|
3386
|
-
|
|
3387
|
-
canvas:
|
|
3388
|
-
queue:
|
|
3439
|
+
}, pn = (Ke) => {
|
|
3440
|
+
Re.current = Ke.label, ge.current = Ke.transitionMeta, re.current?.(Ke.label);
|
|
3441
|
+
}, wr = F && G.supportsBufferedPlayback;
|
|
3442
|
+
let wn = !1;
|
|
3443
|
+
wr && T.current && (wn = T.current.tick({
|
|
3444
|
+
canvas: U,
|
|
3445
|
+
queue: H,
|
|
3389
3446
|
elapsedMs: te,
|
|
3390
|
-
expressionPath:
|
|
3391
|
-
expressionDrawKey:
|
|
3392
|
-
playbackState:
|
|
3393
|
-
availablePaths:
|
|
3394
|
-
onStatus:
|
|
3395
|
-
onDisplayed: (xt,
|
|
3396
|
-
|
|
3447
|
+
expressionPath: Ie,
|
|
3448
|
+
expressionDrawKey: qe,
|
|
3449
|
+
playbackState: X.current,
|
|
3450
|
+
availablePaths: ae.current,
|
|
3451
|
+
onStatus: pn,
|
|
3452
|
+
onDisplayed: (xt, it, Bt) => {
|
|
3453
|
+
ve.current.onDrawDisplayed(
|
|
3397
3454
|
{
|
|
3398
|
-
label:
|
|
3455
|
+
label: Bt,
|
|
3399
3456
|
elapsedMs: te,
|
|
3400
|
-
mouthPath:
|
|
3401
|
-
transitionMeta:
|
|
3457
|
+
mouthPath: it,
|
|
3458
|
+
transitionMeta: ge.current
|
|
3402
3459
|
},
|
|
3403
|
-
|
|
3460
|
+
H
|
|
3404
3461
|
);
|
|
3405
3462
|
}
|
|
3406
|
-
}).usedBuffer),
|
|
3407
|
-
|
|
3408
|
-
|
|
3463
|
+
}).usedBuffer), wn || Bi(
|
|
3464
|
+
U,
|
|
3465
|
+
H,
|
|
3409
3466
|
te,
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
),
|
|
3417
|
-
|
|
3467
|
+
Ie,
|
|
3468
|
+
qe,
|
|
3469
|
+
X.current,
|
|
3470
|
+
pr,
|
|
3471
|
+
pn,
|
|
3472
|
+
ae.current
|
|
3473
|
+
), ve.current.onRafTickSpeaking(), nt.current?.(
|
|
3474
|
+
ve.current.snapshot(H, te)
|
|
3418
3475
|
);
|
|
3419
|
-
} else if (!
|
|
3420
|
-
const
|
|
3421
|
-
te.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (
|
|
3422
|
-
|
|
3476
|
+
} else if (!st && Y.current && B.current) {
|
|
3477
|
+
const H = B.current, te = H.getVideo();
|
|
3478
|
+
te.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (H.setActive(!0), g.current || (g.current = !0, Cn(
|
|
3479
|
+
U,
|
|
3423
3480
|
te,
|
|
3424
3481
|
null,
|
|
3425
3482
|
void 0,
|
|
3426
|
-
|
|
3427
|
-
() => !
|
|
3428
|
-
).then(() =>
|
|
3429
|
-
|
|
3430
|
-
}))) :
|
|
3431
|
-
|
|
3483
|
+
Pe.current,
|
|
3484
|
+
() => !W.isSpeaking() && !A.current && !x.current
|
|
3485
|
+
).then(() => re.current?.("idle")).finally(() => {
|
|
3486
|
+
g.current = !1;
|
|
3487
|
+
}))) : On(
|
|
3488
|
+
U,
|
|
3432
3489
|
null,
|
|
3433
3490
|
"__sil__",
|
|
3434
|
-
|
|
3435
|
-
(
|
|
3436
|
-
(
|
|
3491
|
+
X.current,
|
|
3492
|
+
(Ee, Ae, Ie, qe) => G.drawLiveFrame(Ee, Ae, Ie, qe),
|
|
3493
|
+
(Ee) => re.current?.(Ee)
|
|
3437
3494
|
);
|
|
3438
|
-
} else
|
|
3439
|
-
|
|
3495
|
+
} else st || On(
|
|
3496
|
+
U,
|
|
3440
3497
|
null,
|
|
3441
3498
|
"__sil__",
|
|
3442
|
-
|
|
3443
|
-
(
|
|
3444
|
-
(
|
|
3499
|
+
X.current,
|
|
3500
|
+
(H, te, Ee, Ae) => G.drawLiveFrame(H, te, Ee, Ae),
|
|
3501
|
+
(H) => re.current?.(H)
|
|
3445
3502
|
);
|
|
3446
|
-
|
|
3503
|
+
C.current = we, se.current = requestAnimationFrame(L);
|
|
3447
3504
|
};
|
|
3448
|
-
return
|
|
3449
|
-
cancelAnimationFrame(
|
|
3505
|
+
return se.current = requestAnimationFrame(L), () => {
|
|
3506
|
+
cancelAnimationFrame(se.current), ye(), Te(), J.current.stop(), Q.current?.stop();
|
|
3450
3507
|
};
|
|
3451
3508
|
}, [
|
|
3452
|
-
|
|
3453
|
-
|
|
3509
|
+
fe,
|
|
3510
|
+
xe,
|
|
3454
3511
|
rt,
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
]),
|
|
3458
|
-
|
|
3512
|
+
ye,
|
|
3513
|
+
Te
|
|
3514
|
+
]), Sr(
|
|
3515
|
+
R,
|
|
3459
3516
|
() => ({
|
|
3460
|
-
speakText: async (
|
|
3461
|
-
const
|
|
3462
|
-
if (!
|
|
3463
|
-
const G =
|
|
3464
|
-
if (!G || !
|
|
3517
|
+
speakText: async (g, L) => {
|
|
3518
|
+
const U = g.trim();
|
|
3519
|
+
if (!U) return;
|
|
3520
|
+
const G = M.current;
|
|
3521
|
+
if (!G || !ie.current && !fe)
|
|
3465
3522
|
throw new Error("AI twin is not ready");
|
|
3466
|
-
const { ttsEngineId:
|
|
3467
|
-
|
|
3523
|
+
const { ttsEngineId: W, voiceId: we } = oe(L);
|
|
3524
|
+
le(null), ne.current += 1, ye(), Te(), A.current = !1, q.current = !1, P.current = "sil", $.current = 0, ke(X.current), z.current.reset(), C.current = !1;
|
|
3468
3525
|
try {
|
|
3469
|
-
|
|
3470
|
-
voiceId:
|
|
3471
|
-
speakingRate:
|
|
3472
|
-
ttsEngineId:
|
|
3526
|
+
Y.current ? (B.current?.setActive(!1), B.current?.restart(), ke(X.current)) : await G.renderSilOnly(), await J.current.speak(U, {
|
|
3527
|
+
voiceId: we,
|
|
3528
|
+
speakingRate: L?.speakingRate ?? d,
|
|
3529
|
+
ttsEngineId: W
|
|
3473
3530
|
});
|
|
3474
|
-
} catch (
|
|
3475
|
-
throw
|
|
3531
|
+
} catch (_e) {
|
|
3532
|
+
throw ce(_e instanceof Error ? _e.message : "TTS failed"), _e;
|
|
3476
3533
|
}
|
|
3477
3534
|
},
|
|
3478
3535
|
stop: () => {
|
|
3479
|
-
|
|
3536
|
+
ne.current += 1, ye(), Te(), A.current = !1, q.current = !1, J.current.stop(), Q.current?.stop(), ke(X.current), T.current?.reset(), D.current = 0, C.current = !1, rt();
|
|
3480
3537
|
},
|
|
3481
|
-
setTtsEngineId: (
|
|
3482
|
-
|
|
3538
|
+
setTtsEngineId: (g) => {
|
|
3539
|
+
J.current.setTtsEngineId(g), Q.current?.setTtsEngineId(g), K.current && (K.current.ttsEngineId = g);
|
|
3483
3540
|
},
|
|
3484
|
-
renderViseme: async (
|
|
3485
|
-
const
|
|
3486
|
-
if (!
|
|
3541
|
+
renderViseme: async (g, L) => {
|
|
3542
|
+
const U = M.current, G = S.current;
|
|
3543
|
+
if (!U || !G || !ie.current)
|
|
3487
3544
|
throw new Error("AI twin is not ready");
|
|
3488
|
-
await
|
|
3489
|
-
from:
|
|
3490
|
-
transitionDurationMs:
|
|
3491
|
-
gapMs:
|
|
3492
|
-
onStatus: (
|
|
3545
|
+
await U.renderViseme(G, g, {
|
|
3546
|
+
from: L?.from,
|
|
3547
|
+
transitionDurationMs: L?.transitionDurationMs,
|
|
3548
|
+
gapMs: L?.gapMs,
|
|
3549
|
+
onStatus: (W) => re.current?.(W)
|
|
3493
3550
|
});
|
|
3494
3551
|
},
|
|
3495
|
-
isReady: () =>
|
|
3496
|
-
getStatus: () =>
|
|
3497
|
-
connect: async (
|
|
3498
|
-
|
|
3552
|
+
isReady: () => ie.current,
|
|
3553
|
+
getStatus: () => ee,
|
|
3554
|
+
connect: async (g = {}) => {
|
|
3555
|
+
le(null);
|
|
3499
3556
|
try {
|
|
3500
|
-
let
|
|
3501
|
-
|
|
3502
|
-
const
|
|
3503
|
-
await
|
|
3504
|
-
...
|
|
3505
|
-
apiBase:
|
|
3506
|
-
authToken:
|
|
3507
|
-
voiceId:
|
|
3557
|
+
let L = g.authToken?.trim();
|
|
3558
|
+
L || (L = l.current ?? i ?? await Ft(), l.current = L);
|
|
3559
|
+
const U = g.voiceId?.trim() ?? f ?? K.current?.voiceId, G = g.personaId?.trim() ?? K.current?.personaId, W = ht();
|
|
3560
|
+
await W.unlockAudio(), await W.connect({
|
|
3561
|
+
...g,
|
|
3562
|
+
apiBase: g.apiBase?.trim() || k,
|
|
3563
|
+
authToken: L,
|
|
3564
|
+
voiceId: U,
|
|
3508
3565
|
personaId: G,
|
|
3509
|
-
speakingRate:
|
|
3566
|
+
speakingRate: g.speakingRate ?? d
|
|
3510
3567
|
});
|
|
3511
|
-
} catch (
|
|
3512
|
-
throw
|
|
3513
|
-
|
|
3514
|
-
),
|
|
3568
|
+
} catch (L) {
|
|
3569
|
+
throw ce(
|
|
3570
|
+
L instanceof Error ? L.message : "Voice connect failed"
|
|
3571
|
+
), L;
|
|
3515
3572
|
}
|
|
3516
3573
|
},
|
|
3517
3574
|
disconnect: async () => {
|
|
3518
|
-
const
|
|
3519
|
-
|
|
3575
|
+
const g = Q.current;
|
|
3576
|
+
g && (ne.current += 1, ye(), Te(), A.current = !1, q.current = !1, ke(X.current), T.current?.reset(), D.current = 0, C.current = !1, await g.disconnect(), rt());
|
|
3520
3577
|
},
|
|
3521
|
-
isConnected: () =>
|
|
3522
|
-
getVoiceStream: () =>
|
|
3578
|
+
isConnected: () => Q.current?.isConnected() ?? !1,
|
|
3579
|
+
getVoiceStream: () => Q.current?.getVoiceStream() ?? J.current?.getVoiceStream() ?? null
|
|
3523
3580
|
}),
|
|
3524
3581
|
[
|
|
3525
|
-
|
|
3582
|
+
fe,
|
|
3526
3583
|
d,
|
|
3527
3584
|
i,
|
|
3528
3585
|
f,
|
|
3529
|
-
|
|
3530
|
-
|
|
3586
|
+
ye,
|
|
3587
|
+
Te,
|
|
3531
3588
|
rt,
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3589
|
+
ce,
|
|
3590
|
+
oe,
|
|
3591
|
+
ht,
|
|
3592
|
+
ee
|
|
3536
3593
|
]
|
|
3537
|
-
), /* @__PURE__ */
|
|
3538
|
-
/* @__PURE__ */
|
|
3594
|
+
), /* @__PURE__ */ yr("div", { className: u, style: { ...qi, ...c }, children: [
|
|
3595
|
+
/* @__PURE__ */ yn(
|
|
3539
3596
|
"canvas",
|
|
3540
3597
|
{
|
|
3541
3598
|
ref: S,
|
|
3542
|
-
width:
|
|
3543
|
-
height:
|
|
3544
|
-
style: { ...
|
|
3599
|
+
width: ft.width,
|
|
3600
|
+
height: ft.height,
|
|
3601
|
+
style: { ...Ki, ...m },
|
|
3545
3602
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
3546
3603
|
}
|
|
3547
3604
|
),
|
|
3548
|
-
E &&
|
|
3605
|
+
E && me ? /* @__PURE__ */ yn("div", { style: Gi, children: me }) : null
|
|
3549
3606
|
] });
|
|
3550
|
-
}),
|
|
3551
|
-
function
|
|
3607
|
+
}), ji = "thumbnail.webp";
|
|
3608
|
+
function ra(e, t = jt) {
|
|
3552
3609
|
const n = e.trim();
|
|
3553
3610
|
if (!n)
|
|
3554
3611
|
throw new Error("faceId is required");
|
|
3555
|
-
return `${t.replace(/\/$/, "")}/${n}/${
|
|
3612
|
+
return `${t.replace(/\/$/, "")}/${n}/${ji}`;
|
|
3556
3613
|
}
|
|
3557
|
-
const
|
|
3558
|
-
function
|
|
3614
|
+
const zi = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".webp"]);
|
|
3615
|
+
function Yi(e = ".png") {
|
|
3559
3616
|
const t = e.toLowerCase();
|
|
3560
|
-
return
|
|
3617
|
+
return zi.has(t) ? `source${t}` : "source.png";
|
|
3561
3618
|
}
|
|
3562
|
-
function
|
|
3619
|
+
function sa(e, t = jt, n = ".png") {
|
|
3563
3620
|
const r = e.trim();
|
|
3564
3621
|
if (!r)
|
|
3565
3622
|
throw new Error("faceId is required");
|
|
3566
|
-
return `${t.replace(/\/$/, "")}/${r}/${
|
|
3623
|
+
return `${t.replace(/\/$/, "")}/${r}/${Yi(n)}`;
|
|
3567
3624
|
}
|
|
3568
3625
|
export {
|
|
3569
|
-
|
|
3570
|
-
|
|
3626
|
+
ji as AI_TWIN_THUMBNAIL_FILENAME,
|
|
3627
|
+
na as AiTwin,
|
|
3571
3628
|
Ut as AiTwinNotFoundError,
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3590
|
-
|
|
3629
|
+
je as DEFAULT_TTS_ENGINE_ID,
|
|
3630
|
+
tr as MIC_SAMPLE_RATE,
|
|
3631
|
+
ns as OCULUS_VISEME_IDS,
|
|
3632
|
+
nr as PLAYBACK_SAMPLE_RATE,
|
|
3633
|
+
Zt as SPEAKING_RATE_MAX,
|
|
3634
|
+
Qt as SPEAKING_RATE_MIN,
|
|
3635
|
+
Xe as TTS_ENGINE_CARTESIA,
|
|
3636
|
+
Hn as TTS_ENGINE_GOOGLE,
|
|
3637
|
+
Yt as TTS_ENGINE_INWORLD,
|
|
3638
|
+
ta as VISEME_IDS,
|
|
3639
|
+
er as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
3640
|
+
Pt as VISEME_TEST_SPEAKING_RATE,
|
|
3641
|
+
Zn as VISEME_TEST_VOICE_ID,
|
|
3642
|
+
Yi as aiTwinSourceFilename,
|
|
3643
|
+
Ds as buildVoiceWebSocketUrl,
|
|
3644
|
+
An as createAvatarTtsLipsyncController,
|
|
3645
|
+
Cs as createRealtimeVoiceLipsyncController,
|
|
3646
|
+
bn as faceAssetUrls,
|
|
3647
|
+
Nr as fetchAiTwin,
|
|
3591
3648
|
Ft as fetchDevAuthToken,
|
|
3592
|
-
|
|
3593
|
-
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3649
|
+
sa as getAiTwinSourceUrl,
|
|
3650
|
+
ra as getAiTwinThumbnailUrl,
|
|
3651
|
+
ss as normalizeOculusViseme,
|
|
3652
|
+
zr as resolveDirectFaceId,
|
|
3653
|
+
Mt as resolveVisemeAtTime,
|
|
3654
|
+
ea as resolveWordAtTime,
|
|
3655
|
+
Yr as setActiveTwinAssets
|
|
3599
3656
|
};
|