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