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