@streamoji/aitwin 0.2.3 → 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.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
|
|
170
|
-
}
|
|
171
|
-
function Qn(e) {
|
|
172
|
-
return st.add(e), () => st.delete(e);
|
|
169
|
+
return it;
|
|
173
170
|
}
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
return Ie(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
171
|
+
function Xn(e) {
|
|
172
|
+
return ot.add(e), () => ot.delete(e);
|
|
177
173
|
}
|
|
178
|
-
function
|
|
179
|
-
const e =
|
|
180
|
-
return
|
|
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,36 +295,36 @@ 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, "/");
|
|
@@ -334,7 +334,7 @@ function wr(e) {
|
|
|
334
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,14 +345,14 @@ 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 =
|
|
354
|
+
async function yr(e, t) {
|
|
355
|
+
const n = pr(t);
|
|
356
356
|
if (_r(n)) {
|
|
357
357
|
const r = n.buffer.slice(
|
|
358
358
|
n.byteOffset,
|
|
@@ -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,103 +369,103 @@ 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,
|
|
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
|
-
for (const
|
|
393
|
+
for (const g of r)
|
|
394
394
|
try {
|
|
395
|
-
|
|
395
|
+
g.stop();
|
|
396
396
|
} catch {
|
|
397
397
|
}
|
|
398
398
|
r.length = 0;
|
|
399
|
-
},
|
|
400
|
-
for (const
|
|
401
|
-
|
|
399
|
+
}, S = () => {
|
|
400
|
+
for (const g of r)
|
|
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
|
|
420
|
-
|
|
421
|
-
word:
|
|
422
|
-
wtime:
|
|
423
|
-
wduration:
|
|
424
|
-
queueIndex:
|
|
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
|
+
g.push({
|
|
421
|
+
word: O,
|
|
422
|
+
wtime: _ + W,
|
|
423
|
+
wduration: G,
|
|
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 && (
|
|
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
|
-
|
|
446
|
-
viseme:
|
|
445
|
+
g.push({
|
|
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
|
-
|
|
454
|
-
|
|
455
|
-
|
|
452
|
+
}, z = (g, M, b, D, A, P, O) => {
|
|
453
|
+
N(M, D, A, P), $(
|
|
454
|
+
g,
|
|
455
|
+
M,
|
|
456
456
|
b,
|
|
457
457
|
A,
|
|
458
458
|
P,
|
|
459
|
-
|
|
459
|
+
O
|
|
460
460
|
);
|
|
461
|
-
}, y = async (
|
|
461
|
+
}, y = async (g, M, b, D, A, P, O) => {
|
|
462
462
|
if (p || !b?.trim()) {
|
|
463
|
-
(D.length > 0 || A.length > 0) && !a &&
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
(D.length > 0 || A.length > 0) && !a && z(
|
|
464
|
+
g,
|
|
465
|
+
M,
|
|
466
466
|
D,
|
|
467
467
|
A,
|
|
468
|
-
|
|
468
|
+
_,
|
|
469
469
|
P,
|
|
470
470
|
u
|
|
471
471
|
);
|
|
@@ -482,88 +482,88 @@ 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
|
-
|
|
511
|
-
|
|
512
|
-
|
|
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
|
+
g,
|
|
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
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
523
|
+
const W = n.shift();
|
|
524
|
+
W ? await y(
|
|
525
|
+
g,
|
|
526
|
+
M,
|
|
527
|
+
W.audio,
|
|
528
|
+
W.visemes,
|
|
529
|
+
W.words,
|
|
530
|
+
W.isNewSegment,
|
|
531
|
+
O
|
|
532
532
|
) : R();
|
|
533
533
|
}
|
|
534
534
|
};
|
|
535
535
|
return {
|
|
536
|
-
setStreamTtsEngineId: (
|
|
537
|
-
u =
|
|
536
|
+
setStreamTtsEngineId: (g) => {
|
|
537
|
+
u = g;
|
|
538
538
|
},
|
|
539
|
-
setPlaybackSpeed: (
|
|
540
|
-
k = Math.max(0.1, Math.min(1,
|
|
539
|
+
setPlaybackSpeed: (g) => {
|
|
540
|
+
k = Math.max(0.1, Math.min(1, g)), S();
|
|
541
541
|
},
|
|
542
542
|
getPlaybackSpeed: () => k,
|
|
543
|
-
resetForNewStream: (
|
|
544
|
-
p = !1, f = !1, u =
|
|
543
|
+
resetForNewStream: (g) => {
|
|
544
|
+
p = !1, f = !1, u = g;
|
|
545
545
|
},
|
|
546
546
|
/** Call from a user gesture before bot audio (connect / unlock). */
|
|
547
547
|
primeAudioContext: async () => {
|
|
548
|
-
const
|
|
549
|
-
s || (s = new
|
|
548
|
+
const g = window.AudioContext || window.webkitAudioContext;
|
|
549
|
+
s || (s = new g()), s.state === "suspended" && await s.resume();
|
|
550
550
|
},
|
|
551
551
|
stop: () => {
|
|
552
|
-
p = !0, d(), I(), n.length = 0, i = !1, o = !1, a = !1, f = !1,
|
|
552
|
+
p = !0, d(), I(), n.length = 0, i = !1, o = !1, a = !1, f = !1, _ = 0, m = 0, w = 0, l = 0;
|
|
553
553
|
},
|
|
554
|
-
markStreamComplete: (
|
|
555
|
-
if (f = !0, !a &&
|
|
556
|
-
|
|
554
|
+
markStreamComplete: (g) => {
|
|
555
|
+
if (f = !0, !a && g.length > 0) {
|
|
556
|
+
q(g);
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
559
|
R();
|
|
560
560
|
},
|
|
561
561
|
playAudioChunk: y,
|
|
562
|
-
queueTimingsOnly: (
|
|
563
|
-
let P =
|
|
564
|
-
A &&
|
|
565
|
-
|
|
566
|
-
|
|
562
|
+
queueTimingsOnly: (g, M, b, D, A) => {
|
|
563
|
+
let P = _;
|
|
564
|
+
A && g.length > 0 && (P = Bt(g)), z(
|
|
565
|
+
g,
|
|
566
|
+
M,
|
|
567
567
|
b,
|
|
568
568
|
D,
|
|
569
569
|
P,
|
|
@@ -586,31 +586,42 @@ 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
|
};
|
|
615
626
|
return {
|
|
616
627
|
setDeveloperToken: (k) => {
|
|
@@ -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 ??
|
|
629
|
-
|
|
630
|
-
const I = u?.voiceId ??
|
|
631
|
-
|
|
632
|
-
Math.min(
|
|
633
|
-
),
|
|
639
|
+
const d = u?.ttsEngineId ?? f ?? Ie;
|
|
640
|
+
_.resetForNewStream(d), _.setStreamTtsEngineId(d);
|
|
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
|
|
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 ?? [],
|
|
660
|
-
D ? await
|
|
670
|
+
const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], O = b.data.is_new_segment ?? !1;
|
|
671
|
+
D ? await _.playAudioChunk(
|
|
661
672
|
r,
|
|
662
673
|
s,
|
|
663
674
|
D,
|
|
664
675
|
A,
|
|
665
676
|
P,
|
|
666
|
-
|
|
667
|
-
) : (A.length > 0 || P.length > 0) &&
|
|
677
|
+
O
|
|
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
|
-
for (const A of D) await
|
|
708
|
-
if (
|
|
709
|
-
T.trim() && await
|
|
718
|
+
for (const A of D) await g(A);
|
|
719
|
+
if (M) {
|
|
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,
|
|
@@ -719,17 +730,17 @@ function Pt(e, t = be) {
|
|
|
719
730
|
getWordQueue: () => s,
|
|
720
731
|
getSentenceEmotions: () => i,
|
|
721
732
|
getStreamMood: () => o,
|
|
722
|
-
getPlaybackElapsedMs: () =>
|
|
723
|
-
isSpeaking: () =>
|
|
733
|
+
getPlaybackElapsedMs: () => _.getPlaybackElapsedMs(),
|
|
734
|
+
isSpeaking: () => _.isSpeaking(),
|
|
724
735
|
setPlaybackSpeed: (k) => {
|
|
725
|
-
|
|
736
|
+
_.setPlaybackSpeed(k);
|
|
726
737
|
},
|
|
727
|
-
getPlaybackSpeed: () =>
|
|
738
|
+
getPlaybackSpeed: () => _.getPlaybackSpeed(),
|
|
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
|
-
},
|
|
838
|
-
R.stop(), T(), y("reset"),
|
|
839
|
-
},
|
|
840
|
-
|
|
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
|
-
...
|
|
848
|
+
}, g = () => {
|
|
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
|
|
940
|
-
mediaManager:
|
|
941
|
-
recorderSampleRate:
|
|
942
|
-
playerSampleRate:
|
|
949
|
+
}, G = () => w || (_ = new vr(), w = new Tn({
|
|
950
|
+
transport: new An({
|
|
951
|
+
mediaManager: _,
|
|
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
|
-
|
|
1005
|
+
g(), await w.sendText(B);
|
|
995
1006
|
}
|
|
996
1007
|
},
|
|
997
1008
|
stop: () => {
|
|
998
|
-
|
|
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,13 +1140,11 @@ const qs = [
|
|
|
1129
1140
|
"RR",
|
|
1130
1141
|
"kk",
|
|
1131
1142
|
"nn"
|
|
1132
|
-
],
|
|
1133
|
-
"t01_0.
|
|
1134
|
-
"t02_0.
|
|
1135
|
-
"t03_0.
|
|
1136
|
-
|
|
1137
|
-
"t05_0.83"
|
|
1138
|
-
], Or = it.length, Lt = /* @__PURE__ */ new Set([
|
|
1143
|
+
], at = [
|
|
1144
|
+
"t01_0.25",
|
|
1145
|
+
"t02_0.50",
|
|
1146
|
+
"t03_0.75"
|
|
1147
|
+
], Ur = at.length, Ft = /* @__PURE__ */ new Set([
|
|
1139
1148
|
"aa__kk",
|
|
1140
1149
|
"aa__nn",
|
|
1141
1150
|
"aa__sil",
|
|
@@ -1242,75 +1251,75 @@ const qs = [
|
|
|
1242
1251
|
"U__nn",
|
|
1243
1252
|
"U__sil"
|
|
1244
1253
|
]);
|
|
1245
|
-
function
|
|
1254
|
+
function Ut(e, t) {
|
|
1246
1255
|
return `${e}__${t}`;
|
|
1247
1256
|
}
|
|
1248
|
-
function
|
|
1257
|
+
function Nt(e, t) {
|
|
1249
1258
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1250
1259
|
}
|
|
1251
|
-
function
|
|
1260
|
+
function qe(e) {
|
|
1252
1261
|
return `${e}_minus_sil.png`;
|
|
1253
1262
|
}
|
|
1254
|
-
function
|
|
1263
|
+
function Nr(e, t) {
|
|
1255
1264
|
if (t.has(e)) return e;
|
|
1256
1265
|
const n = /^pairs\/([^/]+)\//.exec(e);
|
|
1257
1266
|
if (!n) return null;
|
|
1258
1267
|
const r = n[1].split("__")[1];
|
|
1259
1268
|
if (!r || r === "sil") return null;
|
|
1260
|
-
const s =
|
|
1269
|
+
const s = qe(r);
|
|
1261
1270
|
return t.has(s) ? s : null;
|
|
1262
1271
|
}
|
|
1263
|
-
function
|
|
1272
|
+
function un(e, t) {
|
|
1264
1273
|
return e.filter((n) => t.has(n));
|
|
1265
1274
|
}
|
|
1266
|
-
function
|
|
1267
|
-
const r =
|
|
1268
|
-
return
|
|
1275
|
+
function Vr(e, t, n) {
|
|
1276
|
+
const r = wt(e, t);
|
|
1277
|
+
return un(r, n).length > 0;
|
|
1269
1278
|
}
|
|
1270
|
-
function
|
|
1279
|
+
function wt(e, t) {
|
|
1271
1280
|
if (e === t) return [];
|
|
1272
|
-
const n = [], r =
|
|
1273
|
-
if (
|
|
1274
|
-
for (const i of
|
|
1275
|
-
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));
|
|
1276
1285
|
return n;
|
|
1277
1286
|
}
|
|
1278
|
-
const s =
|
|
1279
|
-
if (
|
|
1280
|
-
for (let i =
|
|
1281
|
-
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]));
|
|
1282
1291
|
return n;
|
|
1283
1292
|
}
|
|
1284
1293
|
return [];
|
|
1285
1294
|
}
|
|
1286
|
-
function
|
|
1287
|
-
return e < 16 ? [] : e < 35 ? [
|
|
1295
|
+
function $r(e) {
|
|
1296
|
+
return e < 16 ? [] : e < 35 ? [1] : e < 51 ? [0, 2] : [0, 1, 2];
|
|
1288
1297
|
}
|
|
1289
|
-
function
|
|
1290
|
-
return
|
|
1298
|
+
function Wr(e, t) {
|
|
1299
|
+
return $r(t).map((r) => e[r]).filter((r) => r != null);
|
|
1291
1300
|
}
|
|
1292
|
-
function
|
|
1301
|
+
function Hr(e, t, n, r) {
|
|
1293
1302
|
if (r <= 0) return 0;
|
|
1294
1303
|
const i = Math.max(1, n - t) / r, o = e - t, a = Math.floor(o / i);
|
|
1295
1304
|
return Math.min(r - 1, Math.max(0, a));
|
|
1296
1305
|
}
|
|
1297
|
-
function
|
|
1306
|
+
function qr(e, t, n) {
|
|
1298
1307
|
if (!n) return `${e}/${t}`;
|
|
1299
1308
|
const r = t.split("/").pop() ?? t, s = r.includes(".") ? r.slice(0, r.lastIndexOf(".")) : r;
|
|
1300
1309
|
return `${e}/${s}.bin`;
|
|
1301
1310
|
}
|
|
1302
|
-
const
|
|
1311
|
+
const Kr = [0.32, 0.24, 0.16, 0.08, 0], jr = Kr.map(
|
|
1303
1312
|
(e) => `eyes_${e.toFixed(2)}`
|
|
1304
|
-
),
|
|
1313
|
+
), Gr = [
|
|
1305
1314
|
"eyes_0.32",
|
|
1306
1315
|
"eyes_0.16",
|
|
1307
1316
|
"eyes_0.00"
|
|
1308
|
-
],
|
|
1317
|
+
], zr = [
|
|
1309
1318
|
"eyes_0.32",
|
|
1310
1319
|
"eyes_0.16",
|
|
1311
1320
|
"eyes_0.08",
|
|
1312
1321
|
"eyes_0.00"
|
|
1313
|
-
],
|
|
1322
|
+
], Vt = 2, Yr = -30, ct = 20, Jr = {
|
|
1314
1323
|
fear: -30,
|
|
1315
1324
|
anger: -20,
|
|
1316
1325
|
sad: -10,
|
|
@@ -1319,24 +1328,24 @@ const Wr = [0.32, 0.24, 0.16, 0.08, 0], qr = Wr.map(
|
|
|
1319
1328
|
happy: 0,
|
|
1320
1329
|
disgust: 20
|
|
1321
1330
|
};
|
|
1322
|
-
function
|
|
1331
|
+
function gt(e) {
|
|
1323
1332
|
return `brow_${e}`;
|
|
1324
1333
|
}
|
|
1325
|
-
function
|
|
1326
|
-
return
|
|
1334
|
+
function _t(e) {
|
|
1335
|
+
return Jr[e];
|
|
1327
1336
|
}
|
|
1328
|
-
function
|
|
1329
|
-
return Math.max(
|
|
1337
|
+
function Ee(e) {
|
|
1338
|
+
return Math.max(Yr, Math.min(ct, e));
|
|
1330
1339
|
}
|
|
1331
|
-
function
|
|
1340
|
+
function Qr(e, t) {
|
|
1332
1341
|
if (e === t) return [];
|
|
1333
|
-
const n = e < t ?
|
|
1342
|
+
const n = e < t ? Vt : -Vt, r = [];
|
|
1334
1343
|
let s = e;
|
|
1335
1344
|
for (; s !== t; )
|
|
1336
1345
|
s += n, r.push(s);
|
|
1337
1346
|
return r;
|
|
1338
1347
|
}
|
|
1339
|
-
const
|
|
1348
|
+
const Xr = {
|
|
1340
1349
|
fear: "fear",
|
|
1341
1350
|
afraid: "fear",
|
|
1342
1351
|
anxiety: "fear",
|
|
@@ -1359,63 +1368,63 @@ const Jr = {
|
|
|
1359
1368
|
disgust: "disgust",
|
|
1360
1369
|
disgusted: "disgust"
|
|
1361
1370
|
};
|
|
1362
|
-
function
|
|
1371
|
+
function Te(e, t = "neutral") {
|
|
1363
1372
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1364
|
-
return n ?
|
|
1365
|
-
}
|
|
1366
|
-
function un(e) {
|
|
1367
|
-
return e === 0 ? null : dt(mt(e), "eyes_standard");
|
|
1373
|
+
return n ? Xr[n] ?? t : t;
|
|
1368
1374
|
}
|
|
1369
1375
|
function ln(e) {
|
|
1370
|
-
return
|
|
1376
|
+
return e === 0 ? null : mt(gt(e), "eyes_standard");
|
|
1371
1377
|
}
|
|
1372
|
-
function
|
|
1373
|
-
|
|
1374
|
-
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));
|
|
1375
1380
|
}
|
|
1376
|
-
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) {
|
|
1377
1386
|
const n = [];
|
|
1378
1387
|
for (const r of t)
|
|
1379
|
-
n.push(
|
|
1388
|
+
n.push($t(e, r));
|
|
1380
1389
|
for (let r = t.length - 2; r >= 0; r--)
|
|
1381
|
-
n.push(
|
|
1382
|
-
return n.push(
|
|
1390
|
+
n.push($t(e, t[r]));
|
|
1391
|
+
return n.push(fn(e)), n;
|
|
1383
1392
|
}
|
|
1384
|
-
function
|
|
1385
|
-
return e === 0 ? null :
|
|
1386
|
-
}
|
|
1387
|
-
function Zr(e, t) {
|
|
1388
|
-
return Yr(e, t).map(Xr).filter((n) => n != null);
|
|
1393
|
+
function es(e) {
|
|
1394
|
+
return e === 0 ? null : mt(gt(e), "eyes_standard");
|
|
1389
1395
|
}
|
|
1390
|
-
const es = 6;
|
|
1391
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) {
|
|
1392
1401
|
for (const n of e)
|
|
1393
1402
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
1394
1403
|
return n;
|
|
1395
1404
|
return null;
|
|
1396
1405
|
}
|
|
1397
|
-
function
|
|
1398
|
-
const t =
|
|
1399
|
-
return t >=
|
|
1406
|
+
function ss(e) {
|
|
1407
|
+
const t = Ee(e);
|
|
1408
|
+
return t >= ct ? ct : Ee(t + ns);
|
|
1400
1409
|
}
|
|
1401
|
-
function
|
|
1402
|
-
const r =
|
|
1403
|
-
return
|
|
1410
|
+
function is(e, t, n) {
|
|
1411
|
+
const r = Ee(n);
|
|
1412
|
+
return rs(t, e)?.emphasis ? ss(r) : r;
|
|
1404
1413
|
}
|
|
1405
|
-
function
|
|
1414
|
+
function Wt(e) {
|
|
1406
1415
|
if (!e) return 0;
|
|
1407
1416
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1408
1417
|
if (!t?.[1]) return null;
|
|
1409
1418
|
const n = Number.parseInt(t[1], 10);
|
|
1410
|
-
return Number.isFinite(n) ?
|
|
1419
|
+
return Number.isFinite(n) ? Ee(n) : null;
|
|
1411
1420
|
}
|
|
1412
|
-
function
|
|
1421
|
+
function Le(e, t) {
|
|
1413
1422
|
return e + Math.random() * (t - e);
|
|
1414
1423
|
}
|
|
1415
1424
|
function We() {
|
|
1416
|
-
return
|
|
1425
|
+
return Le(14, 32);
|
|
1417
1426
|
}
|
|
1418
|
-
function
|
|
1427
|
+
function os(e = {}) {
|
|
1419
1428
|
const {
|
|
1420
1429
|
initialDelayMs: t = 800 + Math.random() * 1200,
|
|
1421
1430
|
intervalMinMs: n = 2200,
|
|
@@ -1427,29 +1436,29 @@ function ss(e = {}) {
|
|
|
1427
1436
|
postEmotionChangeDelayMs: f = 380,
|
|
1428
1437
|
minDwellMs: l = 550
|
|
1429
1438
|
} = e;
|
|
1430
|
-
let w = "neutral",
|
|
1439
|
+
let w = "neutral", _ = "neutral", m = 0, v = 0, k = 0, u = {
|
|
1431
1440
|
kind: "idle",
|
|
1432
1441
|
nextBlinkAt: performance.now() + t
|
|
1433
1442
|
}, p = null, d = "__eyes_open__|neutral|brow:0";
|
|
1434
1443
|
function I(y = w) {
|
|
1435
|
-
d = `${p ?? "__eyes_open__"}|${y}|brow:${
|
|
1444
|
+
d = `${p ?? "__eyes_open__"}|${y}|brow:${v}`;
|
|
1436
1445
|
}
|
|
1437
|
-
function
|
|
1446
|
+
function S(y, T = w) {
|
|
1438
1447
|
p = y;
|
|
1439
|
-
const
|
|
1440
|
-
|
|
1448
|
+
const g = Wt(y);
|
|
1449
|
+
g != null ? v = g : y == null && (v = 0), I(T);
|
|
1441
1450
|
}
|
|
1442
1451
|
function R(y) {
|
|
1443
|
-
return
|
|
1452
|
+
return ln(y);
|
|
1444
1453
|
}
|
|
1445
|
-
function
|
|
1446
|
-
const
|
|
1447
|
-
if (m = b,
|
|
1448
|
-
|
|
1454
|
+
function q(y, T, g) {
|
|
1455
|
+
const M = Ee(T), b = Ee(g);
|
|
1456
|
+
if (m = b, M === b) {
|
|
1457
|
+
S(R(b));
|
|
1449
1458
|
return;
|
|
1450
1459
|
}
|
|
1451
1460
|
const D = [
|
|
1452
|
-
...
|
|
1461
|
+
...ts(M, b),
|
|
1453
1462
|
R(b)
|
|
1454
1463
|
];
|
|
1455
1464
|
u = {
|
|
@@ -1458,99 +1467,99 @@ function ss(e = {}) {
|
|
|
1458
1467
|
index: 0,
|
|
1459
1468
|
holdUntil: y + We(),
|
|
1460
1469
|
targetBrow: b
|
|
1461
|
-
},
|
|
1470
|
+
}, S(D[0] ?? null);
|
|
1462
1471
|
}
|
|
1463
|
-
function
|
|
1472
|
+
function N(y, T) {
|
|
1464
1473
|
u = {
|
|
1465
1474
|
kind: "idle",
|
|
1466
|
-
nextBlinkAt: y +
|
|
1467
|
-
},
|
|
1475
|
+
nextBlinkAt: y + Le(n, r)
|
|
1476
|
+
}, _ = T, S(R(m), T);
|
|
1468
1477
|
}
|
|
1469
|
-
function
|
|
1470
|
-
const
|
|
1478
|
+
function $(y, T, g) {
|
|
1479
|
+
const M = g ? Gr : Math.random() < a ? jr : zr;
|
|
1471
1480
|
u = {
|
|
1472
1481
|
kind: "playing",
|
|
1473
|
-
paths:
|
|
1482
|
+
paths: Zr(T, M),
|
|
1474
1483
|
index: 0,
|
|
1475
1484
|
holdUntil: y + We(),
|
|
1476
1485
|
after: "idle",
|
|
1477
1486
|
blinkEmotion: T
|
|
1478
|
-
},
|
|
1487
|
+
}, _ = T, S(u.paths[0] ?? null, T);
|
|
1479
1488
|
}
|
|
1480
|
-
function
|
|
1489
|
+
function z(y) {
|
|
1481
1490
|
if (u.kind === "browBlend") {
|
|
1482
1491
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1483
1492
|
u.index += 1, u.holdUntil = y + We();
|
|
1484
1493
|
const T = u.paths[u.index] ?? null;
|
|
1485
|
-
|
|
1494
|
+
S(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (v = u.targetBrow, m = u.targetBrow, S(R(u.targetBrow)), u = {
|
|
1486
1495
|
kind: "idle",
|
|
1487
1496
|
nextBlinkAt: y + f
|
|
1488
1497
|
});
|
|
1489
1498
|
return;
|
|
1490
1499
|
}
|
|
1491
1500
|
if (u.kind === "idle") {
|
|
1492
|
-
|
|
1501
|
+
S(R(m), _), y >= u.nextBlinkAt && $(y, _, !1);
|
|
1493
1502
|
return;
|
|
1494
1503
|
}
|
|
1495
1504
|
if (u.kind === "doublePause") {
|
|
1496
|
-
|
|
1505
|
+
S(R(m), u.blinkEmotion), y >= u.resumeAt && $(y, u.blinkEmotion, !0);
|
|
1497
1506
|
return;
|
|
1498
1507
|
}
|
|
1499
1508
|
if (u.kind === "playing") {
|
|
1500
1509
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1501
1510
|
u.index += 1, u.holdUntil = y + We();
|
|
1502
|
-
if (
|
|
1511
|
+
if (S(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
|
|
1503
1512
|
if (u.after === "resumeIdle") {
|
|
1504
|
-
|
|
1513
|
+
N(y + f, w);
|
|
1505
1514
|
return;
|
|
1506
1515
|
}
|
|
1507
1516
|
if (u.after === "doublePause") {
|
|
1508
1517
|
u = {
|
|
1509
1518
|
kind: "doublePause",
|
|
1510
|
-
resumeAt: y +
|
|
1519
|
+
resumeAt: y + Le(i, o),
|
|
1511
1520
|
blinkEmotion: u.blinkEmotion
|
|
1512
|
-
},
|
|
1521
|
+
}, S(R(m), u.blinkEmotion);
|
|
1513
1522
|
return;
|
|
1514
1523
|
}
|
|
1515
1524
|
if (u.after === "idle" && Math.random() < s) {
|
|
1516
1525
|
u = {
|
|
1517
1526
|
kind: "doublePause",
|
|
1518
|
-
resumeAt: y +
|
|
1527
|
+
resumeAt: y + Le(i, o),
|
|
1519
1528
|
blinkEmotion: u.blinkEmotion
|
|
1520
|
-
},
|
|
1529
|
+
}, S(R(m), u.blinkEmotion);
|
|
1521
1530
|
return;
|
|
1522
1531
|
}
|
|
1523
|
-
|
|
1532
|
+
N(y, u.blinkEmotion);
|
|
1524
1533
|
}
|
|
1525
1534
|
}
|
|
1526
1535
|
}
|
|
1527
1536
|
return {
|
|
1528
|
-
advance:
|
|
1537
|
+
advance: z,
|
|
1529
1538
|
setTargetEmotion(y) {
|
|
1530
|
-
const T =
|
|
1539
|
+
const T = Te(y, w);
|
|
1531
1540
|
if (T === w) return;
|
|
1532
|
-
const
|
|
1533
|
-
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") &&
|
|
1541
|
+
const g = performance.now();
|
|
1542
|
+
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && g - k < l || (w = T, _ = T, k = g);
|
|
1534
1543
|
},
|
|
1535
1544
|
setTargetEyebrow(y) {
|
|
1536
|
-
const T =
|
|
1545
|
+
const T = Ee(y);
|
|
1537
1546
|
if (T === m && u.kind !== "browBlend") return;
|
|
1538
|
-
const
|
|
1539
|
-
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));
|
|
1540
1549
|
},
|
|
1541
1550
|
getTargetEmotion: () => w,
|
|
1542
1551
|
getTargetEyebrow: () => m,
|
|
1543
1552
|
getExpressionPath: () => p,
|
|
1544
1553
|
getDrawKey: () => d,
|
|
1545
1554
|
reset() {
|
|
1546
|
-
w = "neutral",
|
|
1547
|
-
performance.now() +
|
|
1555
|
+
w = "neutral", _ = "neutral", m = 0, v = 0, k = 0, N(
|
|
1556
|
+
performance.now() + Le(n, r),
|
|
1548
1557
|
"neutral"
|
|
1549
1558
|
);
|
|
1550
1559
|
}
|
|
1551
1560
|
};
|
|
1552
1561
|
}
|
|
1553
|
-
function
|
|
1562
|
+
function as() {
|
|
1554
1563
|
const e = document.createElement("video");
|
|
1555
1564
|
e.muted = !0, e.playsInline = !0, e.preload = "auto", e.setAttribute("playsinline", ""), e.loop = !0;
|
|
1556
1565
|
let t = !1, n = null, r = "";
|
|
@@ -1593,17 +1602,17 @@ function is() {
|
|
|
1593
1602
|
}
|
|
1594
1603
|
};
|
|
1595
1604
|
}
|
|
1596
|
-
const
|
|
1597
|
-
function
|
|
1605
|
+
const cs = 50, dn = 400;
|
|
1606
|
+
function us(e, t, n) {
|
|
1598
1607
|
return e.filter((r) => {
|
|
1599
1608
|
const s = r.queueIndex ?? -1;
|
|
1600
1609
|
return s >= t && s <= n;
|
|
1601
1610
|
});
|
|
1602
1611
|
}
|
|
1603
|
-
function
|
|
1612
|
+
function ls(e, t) {
|
|
1604
1613
|
const n = [];
|
|
1605
1614
|
for (const r of e) {
|
|
1606
|
-
const s =
|
|
1615
|
+
const s = us(
|
|
1607
1616
|
t,
|
|
1608
1617
|
r.start_word,
|
|
1609
1618
|
r.end_word
|
|
@@ -1612,77 +1621,77 @@ function cs(e, t) {
|
|
|
1612
1621
|
const i = s[0], o = s[s.length - 1];
|
|
1613
1622
|
n.push({
|
|
1614
1623
|
sentence: r,
|
|
1615
|
-
startMs: Math.max(0, i.wtime -
|
|
1616
|
-
endMs: o.wtime + o.wduration +
|
|
1624
|
+
startMs: Math.max(0, i.wtime - cs),
|
|
1625
|
+
endMs: o.wtime + o.wduration + dn
|
|
1617
1626
|
});
|
|
1618
1627
|
}
|
|
1619
1628
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
1620
1629
|
}
|
|
1621
|
-
function
|
|
1622
|
-
const s =
|
|
1630
|
+
function fs(e, t, n, r = "neutral") {
|
|
1631
|
+
const s = Te(r);
|
|
1623
1632
|
if (t.length === 0) return s;
|
|
1624
1633
|
if (n.length === 0 || e < n[0].wtime)
|
|
1625
|
-
return
|
|
1626
|
-
const i =
|
|
1634
|
+
return Te(t[0]?.emotion, s);
|
|
1635
|
+
const i = ls(t, n);
|
|
1627
1636
|
let o = null;
|
|
1628
1637
|
for (const l of i)
|
|
1629
1638
|
e >= l.startMs && e <= l.endMs && (o = l);
|
|
1630
1639
|
if (o)
|
|
1631
|
-
return
|
|
1640
|
+
return Te(o.sentence.emotion, s);
|
|
1632
1641
|
const a = n[n.length - 1], f = a.wtime + a.wduration;
|
|
1633
|
-
return e > f +
|
|
1642
|
+
return e > f + dn ? Te(
|
|
1634
1643
|
t[t.length - 1]?.emotion,
|
|
1635
1644
|
s
|
|
1636
1645
|
) : s;
|
|
1637
1646
|
}
|
|
1638
|
-
function
|
|
1647
|
+
function hn(e, t, n, r, s = an) {
|
|
1639
1648
|
const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
|
|
1640
1649
|
o.drawImage(e, 0, 0, n, r);
|
|
1641
1650
|
const a = o.getImageData(0, 0, n, r), f = o.createImageData(n, r);
|
|
1642
1651
|
f.data.set(a.data);
|
|
1643
1652
|
const w = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
|
|
1644
|
-
for (const
|
|
1645
|
-
w.clearRect(0, 0, n, r), w.drawImage(
|
|
1653
|
+
for (const _ of t) {
|
|
1654
|
+
w.clearRect(0, 0, n, r), w.drawImage(_, 0, 0, n, r);
|
|
1646
1655
|
const m = w.getImageData(0, 0, n, r);
|
|
1647
|
-
for (let
|
|
1648
|
-
const k = m.data[
|
|
1649
|
-
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);
|
|
1650
1659
|
}
|
|
1651
1660
|
}
|
|
1652
1661
|
return o.putImageData(f, 0, 0), i;
|
|
1653
1662
|
}
|
|
1654
|
-
let
|
|
1655
|
-
const
|
|
1656
|
-
function
|
|
1657
|
-
|
|
1663
|
+
let ye = null, Oe = null;
|
|
1664
|
+
const Ke = /* @__PURE__ */ new Map();
|
|
1665
|
+
function ds() {
|
|
1666
|
+
ye = null, Oe = null, Ke.clear();
|
|
1658
1667
|
}
|
|
1659
|
-
|
|
1660
|
-
function
|
|
1661
|
-
return e ??
|
|
1668
|
+
Xn(ds);
|
|
1669
|
+
function hs(e) {
|
|
1670
|
+
return e ?? Oe ?? void 0;
|
|
1662
1671
|
}
|
|
1663
|
-
function
|
|
1672
|
+
function pt(e) {
|
|
1664
1673
|
return new Promise((t, n) => {
|
|
1665
1674
|
const r = new Image();
|
|
1666
1675
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
1667
1676
|
});
|
|
1668
1677
|
}
|
|
1669
|
-
async function
|
|
1670
|
-
return
|
|
1671
|
-
await Ye(
|
|
1672
|
-
) :
|
|
1678
|
+
async function ms(e) {
|
|
1679
|
+
return je() ? Lr(
|
|
1680
|
+
await Ye(xt(), e ?? "")
|
|
1681
|
+
) : pt(xt());
|
|
1673
1682
|
}
|
|
1674
|
-
async function
|
|
1675
|
-
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) => {
|
|
1676
1685
|
if (!l.ok) throw new Error(`Failed to load ${e}`);
|
|
1677
1686
|
return l.json();
|
|
1678
1687
|
}), i = s.sheets?.[0];
|
|
1679
1688
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
1680
|
-
const o = n ? await
|
|
1689
|
+
const o = n ? await Br(
|
|
1681
1690
|
await Ye(
|
|
1682
|
-
|
|
1691
|
+
qr(t, i.path, n),
|
|
1683
1692
|
r ?? ""
|
|
1684
1693
|
)
|
|
1685
|
-
) : await
|
|
1694
|
+
) : await pt(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
|
|
1686
1695
|
for (const l of s.cells ?? [])
|
|
1687
1696
|
l.path && a.set(l.path, l);
|
|
1688
1697
|
const f = /* @__PURE__ */ new Map();
|
|
@@ -1690,30 +1699,30 @@ async function $t(e, t, n, r) {
|
|
|
1690
1699
|
f.set(l.index, l);
|
|
1691
1700
|
return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: f, diffBase: t };
|
|
1692
1701
|
}
|
|
1693
|
-
async function
|
|
1694
|
-
const t =
|
|
1702
|
+
async function ut(e) {
|
|
1703
|
+
const t = hs(e), n = je();
|
|
1695
1704
|
if (n && !t)
|
|
1696
1705
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
1697
|
-
if (
|
|
1698
|
-
const i = await
|
|
1706
|
+
if (ye && (!n || Oe === (t ?? null))) {
|
|
1707
|
+
const i = await ye;
|
|
1699
1708
|
return {
|
|
1700
|
-
...
|
|
1709
|
+
...Fe(i),
|
|
1701
1710
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
1702
1711
|
};
|
|
1703
1712
|
}
|
|
1704
|
-
|
|
1705
|
-
const r =
|
|
1706
|
-
|
|
1707
|
-
const i = await
|
|
1708
|
-
|
|
1713
|
+
Oe = t ?? null, Ke.clear();
|
|
1714
|
+
const r = er();
|
|
1715
|
+
ye = (async () => {
|
|
1716
|
+
const i = await ms(t), o = await Ht(
|
|
1717
|
+
tr(),
|
|
1709
1718
|
r,
|
|
1710
1719
|
n,
|
|
1711
1720
|
t
|
|
1712
1721
|
);
|
|
1713
1722
|
let a = null;
|
|
1714
1723
|
try {
|
|
1715
|
-
a = await
|
|
1716
|
-
|
|
1724
|
+
a = await Ht(
|
|
1725
|
+
nr(),
|
|
1717
1726
|
r,
|
|
1718
1727
|
n,
|
|
1719
1728
|
t
|
|
@@ -1723,90 +1732,90 @@ async function at(e) {
|
|
|
1723
1732
|
}
|
|
1724
1733
|
return { sil: i, viseme: o, expression: a };
|
|
1725
1734
|
})();
|
|
1726
|
-
const s = await
|
|
1727
|
-
return { ...
|
|
1735
|
+
const s = await ye;
|
|
1736
|
+
return { ...Fe(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
1728
1737
|
}
|
|
1729
|
-
async function
|
|
1730
|
-
if (await
|
|
1731
|
-
return
|
|
1738
|
+
async function mn(e) {
|
|
1739
|
+
if (await ut(e), !ye) throw new Error("Assets not loaded");
|
|
1740
|
+
return ye;
|
|
1732
1741
|
}
|
|
1733
|
-
function
|
|
1734
|
-
return
|
|
1742
|
+
function Fe(e) {
|
|
1743
|
+
return Cr(
|
|
1735
1744
|
e.viseme.atlasMeta,
|
|
1736
1745
|
e.sil.naturalWidth,
|
|
1737
1746
|
e.sil.naturalHeight
|
|
1738
1747
|
);
|
|
1739
1748
|
}
|
|
1740
|
-
function
|
|
1749
|
+
function ws(e, t) {
|
|
1741
1750
|
const n = document.createElement("canvas");
|
|
1742
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;
|
|
1743
1752
|
}
|
|
1744
|
-
async function
|
|
1745
|
-
const r = `${t.diffBase}::${n}`, s =
|
|
1753
|
+
async function qt(e, t, n) {
|
|
1754
|
+
const r = `${t.diffBase}::${n}`, s = Ke.get(r);
|
|
1746
1755
|
if (s) return s;
|
|
1747
1756
|
const i = (async () => {
|
|
1748
1757
|
const o = t.cellByPath.get(n);
|
|
1749
1758
|
if (!o) throw new Error(`No atlas cell for path: ${n}`);
|
|
1750
|
-
const a =
|
|
1751
|
-
if (
|
|
1752
|
-
const
|
|
1759
|
+
const a = Mr(t.atlasMeta, o), f = Fe(e);
|
|
1760
|
+
if (xr(o)) {
|
|
1761
|
+
const _ = ws(t, o), m = document.createElement("canvas");
|
|
1753
1762
|
m.width = f.width, m.height = f.height;
|
|
1754
|
-
const
|
|
1755
|
-
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;
|
|
1756
1765
|
}
|
|
1757
|
-
const l = `${t.diffBase}/${n}`, w = await
|
|
1766
|
+
const l = `${t.diffBase}/${n}`, w = await pt(l);
|
|
1758
1767
|
if (w.naturalWidth === f.width && w.naturalHeight === f.height)
|
|
1759
1768
|
return w;
|
|
1760
1769
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
1761
1770
|
})();
|
|
1762
|
-
return
|
|
1771
|
+
return Ke.set(r, i), i;
|
|
1763
1772
|
}
|
|
1764
|
-
async function
|
|
1773
|
+
async function Kt(e, t, n, r, s, i) {
|
|
1765
1774
|
if (s) {
|
|
1766
|
-
const { width:
|
|
1775
|
+
const { width: v, height: k } = s;
|
|
1767
1776
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
1768
1777
|
return;
|
|
1769
1778
|
const u = document.createElement("canvas");
|
|
1770
|
-
u.width =
|
|
1779
|
+
u.width = v, u.height = k;
|
|
1771
1780
|
const p = u.getContext("2d");
|
|
1772
|
-
if (p.clearRect(0, 0,
|
|
1773
|
-
(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);
|
|
1774
1783
|
const d = e.getContext("2d");
|
|
1775
|
-
d.clearRect(0, 0,
|
|
1784
|
+
d.clearRect(0, 0, v, k), d.drawImage(u, 0, 0);
|
|
1776
1785
|
return;
|
|
1777
1786
|
}
|
|
1778
|
-
const o = await
|
|
1787
|
+
const o = await mn(), a = cn(o.viseme.atlasMeta), { width: f, height: l } = Fe(o);
|
|
1779
1788
|
(e.width !== f || e.height !== l) && (e.width = f, e.height = l);
|
|
1780
|
-
const w = [],
|
|
1781
|
-
if (
|
|
1782
|
-
const
|
|
1783
|
-
|
|
1789
|
+
const w = [], _ = e.getContext("2d");
|
|
1790
|
+
if (_.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
1791
|
+
const v = o.sil;
|
|
1792
|
+
_.drawImage(v, 0, 0, f, l);
|
|
1784
1793
|
return;
|
|
1785
1794
|
}
|
|
1786
1795
|
if (w.length === 0) {
|
|
1787
|
-
|
|
1796
|
+
_.drawImage(t, 0, 0, f, l);
|
|
1788
1797
|
return;
|
|
1789
1798
|
}
|
|
1790
|
-
const m =
|
|
1791
|
-
|
|
1799
|
+
const m = hn(t, w, f, l, a);
|
|
1800
|
+
_.drawImage(m, 0, 0);
|
|
1792
1801
|
}
|
|
1793
|
-
async function
|
|
1794
|
-
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);
|
|
1795
1804
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
1796
1805
|
const a = [];
|
|
1797
1806
|
if (t.mouthPath) {
|
|
1798
|
-
const w = new Set(r.viseme.cellByPath.keys()),
|
|
1799
|
-
|
|
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, _));
|
|
1800
1809
|
}
|
|
1801
1810
|
t.expressionPath && r.expression && a.push(
|
|
1802
|
-
await
|
|
1811
|
+
await qt(r, r.expression, t.expressionPath)
|
|
1803
1812
|
);
|
|
1804
1813
|
const f = e.getContext("2d");
|
|
1805
1814
|
if (f.clearRect(0, 0, i, o), a.length === 0) {
|
|
1806
1815
|
f.drawImage(r.sil, 0, 0, i, o);
|
|
1807
1816
|
return;
|
|
1808
1817
|
}
|
|
1809
|
-
const l =
|
|
1818
|
+
const l = hn(
|
|
1810
1819
|
r.sil,
|
|
1811
1820
|
a,
|
|
1812
1821
|
i,
|
|
@@ -1815,104 +1824,110 @@ async function ct(e, t, n) {
|
|
|
1815
1824
|
);
|
|
1816
1825
|
f.drawImage(l, 0, 0);
|
|
1817
1826
|
}
|
|
1818
|
-
async function
|
|
1819
|
-
await
|
|
1827
|
+
async function gs(e) {
|
|
1828
|
+
await lt(e, { mouthPath: null, expressionPath: null });
|
|
1820
1829
|
}
|
|
1821
|
-
function
|
|
1830
|
+
function _s(e) {
|
|
1822
1831
|
const t = /* @__PURE__ */ new Map();
|
|
1823
1832
|
for (const n of e)
|
|
1824
1833
|
t.has(n.vtime) || t.set(n.vtime, n);
|
|
1825
1834
|
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
1826
1835
|
}
|
|
1827
|
-
function
|
|
1828
|
-
const t =
|
|
1836
|
+
function ps(e) {
|
|
1837
|
+
const t = _s(e), n = [];
|
|
1829
1838
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1830
1839
|
const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
|
|
1831
1840
|
s === i || a <= o || n.push({ from: s, to: i, fromVtime: o, toVtime: a });
|
|
1832
1841
|
}
|
|
1833
1842
|
return n;
|
|
1834
1843
|
}
|
|
1835
|
-
function
|
|
1844
|
+
function ys(e, t) {
|
|
1836
1845
|
let n = null;
|
|
1837
1846
|
for (const r of e)
|
|
1838
1847
|
t >= r.fromVtime && t < r.toVtime && (n = r);
|
|
1839
1848
|
return n;
|
|
1840
1849
|
}
|
|
1841
|
-
function
|
|
1850
|
+
function Es(e, t) {
|
|
1842
1851
|
return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
|
|
1843
1852
|
}
|
|
1844
|
-
const
|
|
1845
|
-
function
|
|
1853
|
+
const wn = 400, Ss = 200, ks = 600, vs = "__sil__";
|
|
1854
|
+
function bs() {
|
|
1846
1855
|
return { lastDrawnKey: "" };
|
|
1847
1856
|
}
|
|
1848
|
-
function
|
|
1857
|
+
function we(e) {
|
|
1849
1858
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
1850
1859
|
}
|
|
1851
|
-
function
|
|
1860
|
+
function Ts(e, t) {
|
|
1852
1861
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
1853
1862
|
return t.transitionCache.transitions;
|
|
1854
|
-
const n =
|
|
1863
|
+
const n = ps(e);
|
|
1855
1864
|
return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
|
|
1856
1865
|
}
|
|
1857
|
-
function
|
|
1858
|
-
let
|
|
1859
|
-
for (const
|
|
1860
|
-
|
|
1861
|
-
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;
|
|
1862
1871
|
}
|
|
1863
|
-
function
|
|
1864
|
-
|
|
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);
|
|
1865
1877
|
}
|
|
1866
|
-
function
|
|
1867
|
-
return
|
|
1878
|
+
function Rs(e, t) {
|
|
1879
|
+
return e === "sil" ? !1 : t ? Vr(e, "sil", t) : wt(e, "sil").length > 0;
|
|
1868
1880
|
}
|
|
1869
|
-
function
|
|
1870
|
-
return
|
|
1881
|
+
function Ds() {
|
|
1882
|
+
return wn + ks;
|
|
1871
1883
|
}
|
|
1872
|
-
function
|
|
1884
|
+
function jt(e) {
|
|
1885
|
+
return e ?? vs;
|
|
1886
|
+
}
|
|
1887
|
+
function Cs(e, t, n, r) {
|
|
1873
1888
|
if (e.length === 0)
|
|
1874
1889
|
return { diffPath: null, label: "sil" };
|
|
1875
|
-
const s =
|
|
1890
|
+
const s = Ts(e, r), i = ys(s, t);
|
|
1876
1891
|
if (i) {
|
|
1877
|
-
const a = i.toVtime - i.fromVtime, f =
|
|
1892
|
+
const a = i.toVtime - i.fromVtime, f = Es(i.fromVtime, i.toVtime);
|
|
1878
1893
|
if (t >= f.transStart && t < i.toVtime) {
|
|
1879
|
-
let l =
|
|
1880
|
-
n && (l =
|
|
1881
|
-
const w =
|
|
1894
|
+
let l = wt(i.from, i.to);
|
|
1895
|
+
n && (l = un(l, n));
|
|
1896
|
+
const w = Wr(l, a);
|
|
1882
1897
|
if (w.length > 0) {
|
|
1883
|
-
const
|
|
1898
|
+
const _ = Hr(
|
|
1884
1899
|
t,
|
|
1885
1900
|
f.transStart,
|
|
1886
1901
|
i.toVtime,
|
|
1887
1902
|
w.length
|
|
1888
1903
|
);
|
|
1889
|
-
return { diffPath: w[
|
|
1904
|
+
return { diffPath: w[_] ?? w[w.length - 1], label: `${i.from}→${i.to}` };
|
|
1890
1905
|
}
|
|
1891
|
-
return { diffPath:
|
|
1906
|
+
return { diffPath: qe(i.to), label: i.to };
|
|
1892
1907
|
}
|
|
1893
1908
|
}
|
|
1894
|
-
const o =
|
|
1895
|
-
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 };
|
|
1896
1911
|
}
|
|
1897
|
-
function
|
|
1898
|
-
const n = t ??
|
|
1899
|
-
return `${
|
|
1912
|
+
function gn(e, t) {
|
|
1913
|
+
const n = t ?? jt(e.expressionPath);
|
|
1914
|
+
return `${jt(e.mouthPath)}|${n}`;
|
|
1900
1915
|
}
|
|
1901
|
-
function
|
|
1902
|
-
const w =
|
|
1916
|
+
function Ms(e, t, n, r, s, i, o, a, f, l) {
|
|
1917
|
+
const w = Cs(t, n, f, i), _ = {
|
|
1903
1918
|
mouthPath: w.diffPath,
|
|
1904
1919
|
expressionPath: r
|
|
1905
|
-
}, m =
|
|
1906
|
-
m !== i.lastDrawnKey && (a(w.label), o(e,
|
|
1907
|
-
|
|
1920
|
+
}, m = gn(_, s);
|
|
1921
|
+
m !== i.lastDrawnKey && (a(w.label), o(e, _, m, (v) => {
|
|
1922
|
+
v === m && (i.lastDrawnKey = m);
|
|
1908
1923
|
}));
|
|
1909
1924
|
}
|
|
1910
|
-
function
|
|
1911
|
-
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;
|
|
1912
1927
|
!(o != null) && l === r.lastDrawnKey || (i(
|
|
1913
1928
|
o != null ? "idle" : "sil"
|
|
1914
|
-
), s(e, a, l, (
|
|
1915
|
-
|
|
1929
|
+
), s(e, a, l, (_) => {
|
|
1930
|
+
_ === l && (r.lastDrawnKey = l);
|
|
1916
1931
|
}));
|
|
1917
1932
|
}
|
|
1918
1933
|
function _n(e) {
|
|
@@ -1951,9 +1966,9 @@ function _n(e) {
|
|
|
1951
1966
|
}
|
|
1952
1967
|
};
|
|
1953
1968
|
}
|
|
1954
|
-
const
|
|
1955
|
-
async function
|
|
1956
|
-
let t =
|
|
1969
|
+
const zt = -1, Yt = /* @__PURE__ */ new Map();
|
|
1970
|
+
async function xs(e) {
|
|
1971
|
+
let t = Yt.get(e);
|
|
1957
1972
|
if (!t) {
|
|
1958
1973
|
const n = await fetch(e);
|
|
1959
1974
|
if (!n.ok)
|
|
@@ -1961,32 +1976,32 @@ async function Ds(e) {
|
|
|
1961
1976
|
`Failed to fetch worker script (${n.status}): ${e}`
|
|
1962
1977
|
);
|
|
1963
1978
|
const r = await n.blob();
|
|
1964
|
-
t = URL.createObjectURL(r),
|
|
1979
|
+
t = URL.createObjectURL(r), Yt.set(e, t);
|
|
1965
1980
|
}
|
|
1966
1981
|
return new Worker(t, { name: "visemeDiffPreview" });
|
|
1967
1982
|
}
|
|
1968
|
-
function
|
|
1983
|
+
function Ps() {
|
|
1969
1984
|
return typeof Worker < "u" && typeof OffscreenCanvas < "u";
|
|
1970
1985
|
}
|
|
1971
|
-
function
|
|
1986
|
+
function Bs(e, t) {
|
|
1972
1987
|
(e.width !== t.width || e.height !== t.height) && (e.width = t.width, e.height = t.height);
|
|
1973
1988
|
const n = e.getContext("2d");
|
|
1974
1989
|
n && n.drawImage(t, 0, 0);
|
|
1975
1990
|
}
|
|
1976
|
-
function
|
|
1991
|
+
function Jt(e, t) {
|
|
1977
1992
|
let n = 0, r = null;
|
|
1978
|
-
const s = _n(async (i, o) => (await
|
|
1993
|
+
const s = _n(async (i, o) => (await ut(), await lt(e, i), s.isLatestSeq(o)));
|
|
1979
1994
|
return {
|
|
1980
1995
|
usesWorker: !1,
|
|
1981
1996
|
async loadAssets(i) {
|
|
1982
|
-
const o = await
|
|
1997
|
+
const o = await ut(i);
|
|
1983
1998
|
return r = o.visemePaths ? new Set(o.visemePaths) : null, o;
|
|
1984
1999
|
},
|
|
1985
2000
|
getVisemeAtlasPaths() {
|
|
1986
2001
|
return r;
|
|
1987
2002
|
},
|
|
1988
2003
|
async renderSilOnly() {
|
|
1989
|
-
n += 1, s.reset(), await
|
|
2004
|
+
n += 1, s.reset(), await gs(e);
|
|
1990
2005
|
},
|
|
1991
2006
|
drawLiveFrame(i, o, a, f) {
|
|
1992
2007
|
s.enqueue(o, a, f);
|
|
@@ -1994,8 +2009,8 @@ function zt(e, t) {
|
|
|
1994
2009
|
async renderViseme(i, o) {
|
|
1995
2010
|
n += 1;
|
|
1996
2011
|
const a = n;
|
|
1997
|
-
t.onStatus?.(o), await
|
|
1998
|
-
mouthPath:
|
|
2012
|
+
t.onStatus?.(o), await lt(i, {
|
|
2013
|
+
mouthPath: qe(o),
|
|
1999
2014
|
expressionPath: null
|
|
2000
2015
|
});
|
|
2001
2016
|
},
|
|
@@ -2004,7 +2019,7 @@ function zt(e, t) {
|
|
|
2004
2019
|
}
|
|
2005
2020
|
};
|
|
2006
2021
|
}
|
|
2007
|
-
function
|
|
2022
|
+
function Ls(e, t, n) {
|
|
2008
2023
|
let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
|
|
2009
2024
|
const l = /* @__PURE__ */ new Map(), w = _n(async (p, d, I) => (l.set(d, {
|
|
2010
2025
|
drawKey: I.drawKey,
|
|
@@ -2018,31 +2033,31 @@ function Cs(e, t, n) {
|
|
|
2018
2033
|
},
|
|
2019
2034
|
void 0,
|
|
2020
2035
|
!0
|
|
2021
|
-
), !1)),
|
|
2022
|
-
if (p ===
|
|
2023
|
-
let
|
|
2024
|
-
for (const [
|
|
2025
|
-
|
|
2026
|
-
|
|
2036
|
+
), !1)), _ = (p) => {
|
|
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);
|
|
2027
2042
|
return;
|
|
2028
2043
|
}
|
|
2029
2044
|
const d = -p, I = l.get(d);
|
|
2030
2045
|
l.delete(d), I?.onDisplayed?.(I.drawKey);
|
|
2031
|
-
}, m = /* @__PURE__ */ new Map(),
|
|
2046
|
+
}, m = /* @__PURE__ */ new Map(), v = (p, d) => {
|
|
2032
2047
|
a || !r || r.postMessage(p, []);
|
|
2033
2048
|
}, k = (p, d, I = !1) => {
|
|
2034
2049
|
if (a) return Promise.resolve();
|
|
2035
|
-
const
|
|
2036
|
-
return new Promise((R,
|
|
2037
|
-
m.set(
|
|
2038
|
-
resolve: (
|
|
2039
|
-
reject:
|
|
2050
|
+
const S = s++;
|
|
2051
|
+
return new Promise((R, q) => {
|
|
2052
|
+
m.set(S, {
|
|
2053
|
+
resolve: (N) => R(N),
|
|
2054
|
+
reject: q,
|
|
2040
2055
|
generation: typeof p.generation == "number" ? p.generation : void 0,
|
|
2041
2056
|
expectRenderDone: I
|
|
2042
|
-
}),
|
|
2057
|
+
}), v({ ...p, requestId: S });
|
|
2043
2058
|
});
|
|
2044
2059
|
}, u = (async () => {
|
|
2045
|
-
r = await
|
|
2060
|
+
r = await xs(n), r.onmessage = (p) => {
|
|
2046
2061
|
if (a) return;
|
|
2047
2062
|
const d = p.data;
|
|
2048
2063
|
if (d.type === "status") {
|
|
@@ -2050,23 +2065,23 @@ function Cs(e, t, n) {
|
|
|
2050
2065
|
return;
|
|
2051
2066
|
}
|
|
2052
2067
|
if (d.type === "frame") {
|
|
2053
|
-
const
|
|
2054
|
-
if (!
|
|
2068
|
+
const S = d.generation < 0;
|
|
2069
|
+
if (!S && d.generation !== i) {
|
|
2055
2070
|
d.bitmap.close();
|
|
2056
2071
|
return;
|
|
2057
2072
|
}
|
|
2058
|
-
if (
|
|
2059
|
-
const
|
|
2060
|
-
if (!w.isLatestSeq(
|
|
2073
|
+
if (S && !(d.generation === zt)) {
|
|
2074
|
+
const q = -d.generation;
|
|
2075
|
+
if (!w.isLatestSeq(q)) {
|
|
2061
2076
|
d.bitmap.close();
|
|
2062
2077
|
return;
|
|
2063
2078
|
}
|
|
2064
2079
|
}
|
|
2065
|
-
if (
|
|
2080
|
+
if (S && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
2066
2081
|
d.bitmap.close();
|
|
2067
2082
|
return;
|
|
2068
2083
|
}
|
|
2069
|
-
|
|
2084
|
+
Bs(e, d.bitmap), d.bitmap.close(), S && _(d.generation);
|
|
2070
2085
|
return;
|
|
2071
2086
|
}
|
|
2072
2087
|
const I = m.get(d.requestId);
|
|
@@ -2108,7 +2123,7 @@ function Cs(e, t, n) {
|
|
|
2108
2123
|
return await k({
|
|
2109
2124
|
type: "loadAssets",
|
|
2110
2125
|
keyHex: p,
|
|
2111
|
-
urls:
|
|
2126
|
+
urls: Qn(Se())
|
|
2112
2127
|
}) ?? { width: 842, height: 1264 };
|
|
2113
2128
|
},
|
|
2114
2129
|
getVisemeAtlasPaths() {
|
|
@@ -2124,20 +2139,20 @@ function Cs(e, t, n) {
|
|
|
2124
2139
|
!0
|
|
2125
2140
|
);
|
|
2126
2141
|
},
|
|
2127
|
-
drawLiveFrame(p, d, I,
|
|
2142
|
+
drawLiveFrame(p, d, I, S) {
|
|
2128
2143
|
a || u.then(() => {
|
|
2129
|
-
a || w.enqueue(d, I,
|
|
2144
|
+
a || w.enqueue(d, I, S);
|
|
2130
2145
|
});
|
|
2131
2146
|
},
|
|
2132
2147
|
async renderViseme(p, d, I = {}) {
|
|
2133
2148
|
if (a || (await u, a)) return;
|
|
2134
2149
|
i += 1, w.reset(), l.clear();
|
|
2135
|
-
const
|
|
2150
|
+
const S = i;
|
|
2136
2151
|
try {
|
|
2137
2152
|
await k({ type: "cancelLiveDraws" }), await k(
|
|
2138
2153
|
{
|
|
2139
2154
|
type: "renderViseme",
|
|
2140
|
-
generation:
|
|
2155
|
+
generation: S,
|
|
2141
2156
|
to: d,
|
|
2142
2157
|
from: I.from,
|
|
2143
2158
|
transitionDurationMs: I.transitionDurationMs,
|
|
@@ -2162,25 +2177,25 @@ function Cs(e, t, n) {
|
|
|
2162
2177
|
}
|
|
2163
2178
|
};
|
|
2164
2179
|
}
|
|
2165
|
-
function
|
|
2166
|
-
if (!
|
|
2167
|
-
return
|
|
2168
|
-
const n =
|
|
2180
|
+
function Os(e, t = {}) {
|
|
2181
|
+
if (!Ps())
|
|
2182
|
+
return Jt(e, t);
|
|
2183
|
+
const n = Pn(t.workerScriptUrl);
|
|
2169
2184
|
try {
|
|
2170
|
-
return
|
|
2185
|
+
return Ls(e, t, n);
|
|
2171
2186
|
} catch {
|
|
2172
|
-
return
|
|
2187
|
+
return Jt(e, t);
|
|
2173
2188
|
}
|
|
2174
2189
|
}
|
|
2175
|
-
class
|
|
2190
|
+
class Fs extends Error {
|
|
2176
2191
|
constructor(t, n) {
|
|
2177
2192
|
super(`${t} timed out after ${Math.round(n / 1e3)}s`), this.name = "LoadTimeoutError";
|
|
2178
2193
|
}
|
|
2179
2194
|
}
|
|
2180
|
-
function
|
|
2195
|
+
function rt(e, t, n) {
|
|
2181
2196
|
return new Promise((r, s) => {
|
|
2182
2197
|
const i = globalThis.setTimeout(() => {
|
|
2183
|
-
s(new
|
|
2198
|
+
s(new Fs(n, t));
|
|
2184
2199
|
}, t);
|
|
2185
2200
|
e.then(
|
|
2186
2201
|
(o) => {
|
|
@@ -2192,15 +2207,15 @@ function tt(e, t, n) {
|
|
|
2192
2207
|
);
|
|
2193
2208
|
});
|
|
2194
2209
|
}
|
|
2195
|
-
const
|
|
2210
|
+
const Us = {
|
|
2196
2211
|
position: "relative",
|
|
2197
2212
|
display: "inline-block",
|
|
2198
2213
|
lineHeight: 0
|
|
2199
|
-
},
|
|
2214
|
+
}, Ns = {
|
|
2200
2215
|
display: "block",
|
|
2201
2216
|
maxWidth: "100%",
|
|
2202
2217
|
height: "auto"
|
|
2203
|
-
},
|
|
2218
|
+
}, Vs = {
|
|
2204
2219
|
position: "absolute",
|
|
2205
2220
|
inset: 0,
|
|
2206
2221
|
display: "flex",
|
|
@@ -2212,78 +2227,78 @@ const Ls = {
|
|
|
2212
2227
|
fontSize: "0.875rem",
|
|
2213
2228
|
textAlign: "center"
|
|
2214
2229
|
};
|
|
2215
|
-
function
|
|
2216
|
-
return
|
|
2230
|
+
function Be(e) {
|
|
2231
|
+
return Fn(e) ? kr : rn;
|
|
2217
2232
|
}
|
|
2218
|
-
function
|
|
2233
|
+
function ge(e, t) {
|
|
2219
2234
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
2220
2235
|
}
|
|
2221
|
-
const
|
|
2236
|
+
const Js = vn(function({
|
|
2222
2237
|
id: t,
|
|
2223
2238
|
avatarId: n,
|
|
2224
2239
|
faceId: r,
|
|
2225
2240
|
assets: s,
|
|
2226
2241
|
authToken: i,
|
|
2227
|
-
ttsEngineId: o =
|
|
2242
|
+
ttsEngineId: o = Ie,
|
|
2228
2243
|
voiceId: a,
|
|
2229
|
-
speakingRate: f =
|
|
2244
|
+
speakingRate: f = ht,
|
|
2230
2245
|
className: l,
|
|
2231
2246
|
style: w,
|
|
2232
|
-
canvasStyle:
|
|
2247
|
+
canvasStyle: _,
|
|
2233
2248
|
onStatusChange: m,
|
|
2234
|
-
onDisplayStatus:
|
|
2249
|
+
onDisplayStatus: v,
|
|
2235
2250
|
onError: k,
|
|
2236
2251
|
onReady: u,
|
|
2237
2252
|
showErrorOverlay: p = !0,
|
|
2238
2253
|
onUserTranscript: d,
|
|
2239
2254
|
onBotOutput: I,
|
|
2240
|
-
onRealtimeLipsyncDebug:
|
|
2255
|
+
onRealtimeLipsyncDebug: S
|
|
2241
2256
|
}, R) {
|
|
2242
|
-
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(
|
|
2243
2258
|
null
|
|
2244
|
-
),
|
|
2245
|
-
|
|
2246
|
-
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(
|
|
2247
2262
|
(h) => {
|
|
2248
|
-
const
|
|
2249
|
-
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 };
|
|
2250
2265
|
},
|
|
2251
2266
|
[o, a]
|
|
2252
|
-
),
|
|
2253
|
-
|
|
2267
|
+
), de = oe((h) => {
|
|
2268
|
+
c(h), Et.current?.(h);
|
|
2254
2269
|
}, []), Me = oe(
|
|
2255
2270
|
(h) => {
|
|
2256
|
-
|
|
2271
|
+
fe(h), m?.(h);
|
|
2257
2272
|
},
|
|
2258
2273
|
[m]
|
|
2259
|
-
),
|
|
2260
|
-
|
|
2261
|
-
),
|
|
2262
|
-
|
|
2274
|
+
), K = L(
|
|
2275
|
+
Lt(Me, Ae)
|
|
2276
|
+
), j = L(null);
|
|
2277
|
+
be(() => (K.current = Lt(
|
|
2263
2278
|
Me,
|
|
2264
|
-
|
|
2265
|
-
), i &&
|
|
2266
|
-
|
|
2267
|
-
const h =
|
|
2268
|
-
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);
|
|
2269
2284
|
}), [Me, i, o]);
|
|
2270
|
-
const
|
|
2285
|
+
const Tt = oe(() => (j.current || (j.current = Dr(
|
|
2271
2286
|
Me,
|
|
2272
2287
|
{
|
|
2273
2288
|
speakingRate: f,
|
|
2274
|
-
onUserTranscript: (h,
|
|
2275
|
-
onBotOutput: (h) =>
|
|
2276
|
-
onLipsyncDebug: (h) =>
|
|
2289
|
+
onUserTranscript: (h, C) => St.current?.(h, C),
|
|
2290
|
+
onBotOutput: (h) => kt.current?.(h),
|
|
2291
|
+
onLipsyncDebug: (h) => vt.current?.(h)
|
|
2277
2292
|
}
|
|
2278
|
-
),
|
|
2279
|
-
|
|
2280
|
-
}, []),
|
|
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(() => {
|
|
2281
2296
|
b.current != null && (clearTimeout(b.current), b.current = null), P.current = !1;
|
|
2282
|
-
}, []),
|
|
2283
|
-
!
|
|
2284
|
-
if (b.current = null,
|
|
2285
|
-
|
|
2286
|
-
|
|
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
|
|
2287
2302
|
).isSpeaking()) {
|
|
2288
2303
|
P.current = !1;
|
|
2289
2304
|
return;
|
|
@@ -2292,418 +2307,435 @@ const Ks = Sn(function({
|
|
|
2292
2307
|
P.current = !1;
|
|
2293
2308
|
return;
|
|
2294
2309
|
}
|
|
2295
|
-
const h =
|
|
2310
|
+
const h = H.current;
|
|
2296
2311
|
if (!h) {
|
|
2297
2312
|
P.current = !1;
|
|
2298
2313
|
return;
|
|
2299
2314
|
}
|
|
2300
2315
|
h.restart(), h.setActive(!0);
|
|
2301
|
-
const
|
|
2302
|
-
let
|
|
2303
|
-
const
|
|
2304
|
-
|
|
2305
|
-
},
|
|
2306
|
-
|
|
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();
|
|
2307
2322
|
};
|
|
2308
|
-
if (
|
|
2309
|
-
|
|
2323
|
+
if (C.addEventListener("playing", U, { once: !0 }), C.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !C.paused) {
|
|
2324
|
+
F();
|
|
2310
2325
|
return;
|
|
2311
2326
|
}
|
|
2312
|
-
setTimeout(
|
|
2313
|
-
},
|
|
2314
|
-
}, [
|
|
2315
|
-
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) {
|
|
2316
2331
|
P.current = !1;
|
|
2317
2332
|
return;
|
|
2318
2333
|
}
|
|
2319
|
-
|
|
2320
|
-
}, [ie,
|
|
2334
|
+
At();
|
|
2335
|
+
}, [ie, At]), Xe = oe(
|
|
2321
2336
|
async (h) => {
|
|
2322
|
-
const
|
|
2337
|
+
const C = T.current, x = N.current, F = q.current, U = () => {
|
|
2323
2338
|
h?.fallbackOnly || (D.current = !1);
|
|
2324
2339
|
};
|
|
2325
|
-
if (!
|
|
2326
|
-
|
|
2340
|
+
if (!x || !F || !E) {
|
|
2341
|
+
U();
|
|
2327
2342
|
return;
|
|
2328
2343
|
}
|
|
2329
|
-
if (
|
|
2330
|
-
|
|
2331
|
-
|
|
2344
|
+
if (ge(
|
|
2345
|
+
K.current,
|
|
2346
|
+
j.current
|
|
2332
2347
|
).isSpeaking()) {
|
|
2333
|
-
|
|
2348
|
+
U();
|
|
2334
2349
|
return;
|
|
2335
2350
|
}
|
|
2336
2351
|
if (h?.fallbackOnly) {
|
|
2337
|
-
if (!D.current || (
|
|
2338
|
-
|
|
2339
|
-
|
|
2352
|
+
if (!D.current || (we($.current), await x.renderSilOnly(), C !== T.current) || ge(
|
|
2353
|
+
K.current,
|
|
2354
|
+
j.current
|
|
2340
2355
|
).isSpeaking())
|
|
2341
2356
|
return;
|
|
2342
|
-
|
|
2357
|
+
Ue();
|
|
2343
2358
|
return;
|
|
2344
2359
|
}
|
|
2345
|
-
const
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
).getVisemeQueue()
|
|
2350
|
-
|
|
2351
|
-
|
|
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,
|
|
2352
2369
|
Qe.current
|
|
2353
2370
|
);
|
|
2354
|
-
if (
|
|
2355
|
-
if (await
|
|
2356
|
-
|
|
2357
|
-
|
|
2371
|
+
if (we($.current), !ae) {
|
|
2372
|
+
if (await x.renderSilOnly(), C !== T.current || ge(
|
|
2373
|
+
K.current,
|
|
2374
|
+
j.current
|
|
2358
2375
|
).isSpeaking())
|
|
2359
2376
|
return;
|
|
2360
|
-
|
|
2377
|
+
Ue();
|
|
2361
2378
|
return;
|
|
2362
2379
|
}
|
|
2363
2380
|
try {
|
|
2364
|
-
await
|
|
2365
|
-
from:
|
|
2366
|
-
transitionDurationMs:
|
|
2381
|
+
await x.renderViseme(F, "sil", {
|
|
2382
|
+
from: Z,
|
|
2383
|
+
transitionDurationMs: wn
|
|
2367
2384
|
});
|
|
2368
|
-
} catch (
|
|
2369
|
-
if (
|
|
2370
|
-
throw
|
|
2385
|
+
} catch (he) {
|
|
2386
|
+
if (he?.name !== "AbortError")
|
|
2387
|
+
throw he;
|
|
2371
2388
|
}
|
|
2372
|
-
if (
|
|
2373
|
-
|
|
2389
|
+
if (C !== T.current) {
|
|
2390
|
+
U();
|
|
2374
2391
|
return;
|
|
2375
2392
|
}
|
|
2376
|
-
if (
|
|
2377
|
-
|
|
2378
|
-
|
|
2393
|
+
if (ge(
|
|
2394
|
+
K.current,
|
|
2395
|
+
j.current
|
|
2379
2396
|
).isSpeaking()) {
|
|
2380
|
-
|
|
2397
|
+
U();
|
|
2381
2398
|
return;
|
|
2382
2399
|
}
|
|
2383
|
-
|
|
2400
|
+
Ue();
|
|
2384
2401
|
},
|
|
2385
|
-
[
|
|
2402
|
+
[E, Ue]
|
|
2386
2403
|
), xe = oe(() => {
|
|
2387
2404
|
if (A.current || D.current) return;
|
|
2388
2405
|
A.current = !0, D.current = !0, ie();
|
|
2389
2406
|
const h = T.current;
|
|
2390
2407
|
Xe().finally(() => {
|
|
2391
2408
|
A.current = !1;
|
|
2392
|
-
}),
|
|
2393
|
-
|
|
2394
|
-
},
|
|
2395
|
-
}, [ie, Xe]),
|
|
2409
|
+
}), M.current = setTimeout(() => {
|
|
2410
|
+
M.current = null, h === T.current && Xe({ fallbackOnly: !0 });
|
|
2411
|
+
}, Ds());
|
|
2412
|
+
}, [ie, Xe]), It = oe(async () => {
|
|
2396
2413
|
const h = Math.floor(Date.now() / 1e3);
|
|
2397
|
-
if (
|
|
2398
|
-
return
|
|
2399
|
-
const
|
|
2400
|
-
|
|
2401
|
-
const
|
|
2402
|
-
return
|
|
2403
|
-
key:
|
|
2404
|
-
expiresAt:
|
|
2405
|
-
},
|
|
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;
|
|
2406
2423
|
}, []);
|
|
2407
|
-
|
|
2408
|
-
i && (
|
|
2409
|
-
}, [i]),
|
|
2410
|
-
|
|
2411
|
-
}, [o]),
|
|
2412
|
-
const h = a ??
|
|
2413
|
-
|
|
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);
|
|
2414
2431
|
}, [a, o]);
|
|
2415
|
-
const _e =
|
|
2416
|
-
() =>
|
|
2432
|
+
const _e = Dt(
|
|
2433
|
+
() => Yn(n, r),
|
|
2417
2434
|
[n, r]
|
|
2418
|
-
),
|
|
2419
|
-
return
|
|
2435
|
+
), pn = Dt(() => s ? JSON.stringify(s) : _e ? `face:${_e}` : `id:${t ?? ""}`, [s, _e, t]);
|
|
2436
|
+
return be(() => {
|
|
2420
2437
|
if (!t && !s && !_e) {
|
|
2421
|
-
|
|
2438
|
+
de("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
2422
2439
|
return;
|
|
2423
2440
|
}
|
|
2424
2441
|
let h = !1;
|
|
2425
|
-
|
|
2426
|
-
const
|
|
2427
|
-
if (!
|
|
2428
|
-
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;
|
|
2429
2446
|
return (async () => {
|
|
2430
2447
|
try {
|
|
2431
|
-
let
|
|
2448
|
+
let F, U, Z;
|
|
2432
2449
|
if (s)
|
|
2433
|
-
|
|
2450
|
+
F = s, U = o, Z = a ?? Be(U);
|
|
2434
2451
|
else if (_e)
|
|
2435
|
-
|
|
2452
|
+
X.current?.("loadFace"), F = Mt(_e), U = o, Z = a ?? Be(U);
|
|
2436
2453
|
else {
|
|
2437
|
-
|
|
2438
|
-
const
|
|
2439
|
-
|
|
2454
|
+
X.current?.("getAiTwin");
|
|
2455
|
+
const V = await rt(
|
|
2456
|
+
Nn(t),
|
|
2440
2457
|
3e4,
|
|
2441
2458
|
"getAiTwin"
|
|
2442
2459
|
);
|
|
2443
2460
|
if (h) return;
|
|
2444
|
-
if (!
|
|
2461
|
+
if (!V.faceId?.trim())
|
|
2445
2462
|
throw new Error("getAiTwin returned no faceId");
|
|
2446
|
-
|
|
2463
|
+
U = V.ttsEngineId, Z = a ?? V.voiceId ?? Be(U), F = Mt(V.faceId);
|
|
2447
2464
|
}
|
|
2448
|
-
|
|
2449
|
-
onStatus: (
|
|
2450
|
-
h ||
|
|
2465
|
+
se.current = { ttsEngineId: U, voiceId: Z }, Jn(F), H.current = as(), x = Os(C, {
|
|
2466
|
+
onStatus: (V) => {
|
|
2467
|
+
h || X.current?.(V);
|
|
2451
2468
|
},
|
|
2452
|
-
onError: (
|
|
2453
|
-
h ||
|
|
2469
|
+
onError: (V) => {
|
|
2470
|
+
h || de(V);
|
|
2454
2471
|
},
|
|
2455
|
-
shouldAcceptLiveFrame: () =>
|
|
2456
|
-
|
|
2457
|
-
|
|
2472
|
+
shouldAcceptLiveFrame: () => ge(
|
|
2473
|
+
K.current,
|
|
2474
|
+
j.current
|
|
2458
2475
|
).isSpeaking() && !D.current
|
|
2459
|
-
}),
|
|
2460
|
-
const ae =
|
|
2476
|
+
}), N.current = x, X.current?.("auth");
|
|
2477
|
+
const ae = ce.current ?? i ?? await rt(nt(), 3e4, "getAuthToken");
|
|
2461
2478
|
if (h) return;
|
|
2462
|
-
|
|
2463
|
-
const
|
|
2479
|
+
ce.current = ae, K.current.setDeveloperToken(ae), K.current.setTtsEngineId(U);
|
|
2480
|
+
const he = je() ? await It() : void 0;
|
|
2464
2481
|
if (h) return;
|
|
2465
|
-
|
|
2466
|
-
const
|
|
2467
|
-
|
|
2482
|
+
X.current?.("loadAssets");
|
|
2483
|
+
const pe = await rt(
|
|
2484
|
+
x.loadAssets(he),
|
|
2468
2485
|
18e4,
|
|
2469
2486
|
"load face assets"
|
|
2470
2487
|
);
|
|
2471
|
-
if (!h &&
|
|
2472
|
-
Qe.current =
|
|
2473
|
-
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");
|
|
2474
2491
|
}), (async () => {
|
|
2475
2492
|
try {
|
|
2476
|
-
const
|
|
2477
|
-
if (await
|
|
2478
|
-
|
|
2479
|
-
const
|
|
2480
|
-
await
|
|
2481
|
-
|
|
2482
|
-
|
|
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,
|
|
2483
2500
|
null,
|
|
2484
2501
|
void 0,
|
|
2485
2502
|
Je.current
|
|
2486
|
-
), h ||
|
|
2487
|
-
} catch (
|
|
2503
|
+
), h || X.current?.("idle");
|
|
2504
|
+
} catch (V) {
|
|
2488
2505
|
if (h) return;
|
|
2489
|
-
|
|
2506
|
+
Y.current = !1, te(!1), console.warn("[AiTwin] Idle video unavailable:", V);
|
|
2490
2507
|
}
|
|
2491
2508
|
})();
|
|
2492
|
-
} catch (
|
|
2509
|
+
} catch (F) {
|
|
2493
2510
|
if (h) return;
|
|
2494
|
-
if (
|
|
2495
|
-
|
|
2511
|
+
if (F instanceof st) {
|
|
2512
|
+
de(F.message);
|
|
2496
2513
|
return;
|
|
2497
2514
|
}
|
|
2498
|
-
|
|
2515
|
+
de(F instanceof Error ? F.message : "Failed to load AI twin");
|
|
2499
2516
|
}
|
|
2500
2517
|
})(), () => {
|
|
2501
|
-
h = !0,
|
|
2518
|
+
h = !0, H.current?.dispose(), x?.dispose(), N.current = null;
|
|
2502
2519
|
};
|
|
2503
|
-
}, [
|
|
2504
|
-
const h = { current: !1 },
|
|
2505
|
-
const
|
|
2506
|
-
|
|
2507
|
-
|
|
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
|
|
2508
2525
|
);
|
|
2509
|
-
if (!
|
|
2510
|
-
y.current = requestAnimationFrame(
|
|
2526
|
+
if (!x || !F || !E) {
|
|
2527
|
+
y.current = requestAnimationFrame(C);
|
|
2511
2528
|
return;
|
|
2512
2529
|
}
|
|
2513
|
-
const
|
|
2514
|
-
ae && (ie(),
|
|
2515
|
-
const
|
|
2516
|
-
if (
|
|
2517
|
-
|
|
2518
|
-
const
|
|
2519
|
-
|
|
2520
|
-
const
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
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()
|
|
2525
2544
|
);
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2545
|
+
z.current.setTargetEmotion(ve), z.current.setTargetEyebrow(
|
|
2546
|
+
is(
|
|
2547
|
+
ne,
|
|
2548
|
+
U.getWordQueue(),
|
|
2549
|
+
_t(ve)
|
|
2531
2550
|
)
|
|
2532
|
-
),
|
|
2533
|
-
const
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
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,
|
|
2539
2557
|
Ze,
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
(
|
|
2558
|
+
et,
|
|
2559
|
+
$.current,
|
|
2560
|
+
(tt, yn, En, Sn) => F.drawLiveFrame(tt, yn, En, Sn),
|
|
2561
|
+
(tt) => X.current?.(tt),
|
|
2543
2562
|
Qe.current
|
|
2544
2563
|
);
|
|
2545
|
-
} else if (!
|
|
2546
|
-
const
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
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,
|
|
2550
2569
|
null,
|
|
2551
2570
|
void 0,
|
|
2552
2571
|
Je.current,
|
|
2553
|
-
() => !
|
|
2554
|
-
).then(() =>
|
|
2572
|
+
() => !U.isSpeaking() && !D.current && !P.current
|
|
2573
|
+
).then(() => X.current?.("idle")).finally(() => {
|
|
2555
2574
|
h.current = !1;
|
|
2556
|
-
}))) :
|
|
2557
|
-
|
|
2575
|
+
}))) : Gt(
|
|
2576
|
+
x,
|
|
2558
2577
|
null,
|
|
2559
2578
|
"__sil__",
|
|
2560
|
-
|
|
2561
|
-
(
|
|
2562
|
-
(
|
|
2579
|
+
$.current,
|
|
2580
|
+
(me, ve, Ze, et) => F.drawLiveFrame(me, ve, Ze, et),
|
|
2581
|
+
(me) => X.current?.(me)
|
|
2563
2582
|
);
|
|
2564
|
-
} else
|
|
2565
|
-
|
|
2583
|
+
} else pe || Gt(
|
|
2584
|
+
x,
|
|
2566
2585
|
null,
|
|
2567
2586
|
"__sil__",
|
|
2568
|
-
|
|
2569
|
-
(
|
|
2570
|
-
(
|
|
2587
|
+
$.current,
|
|
2588
|
+
(V, ne, me, ve) => F.drawLiveFrame(V, ne, me, ve),
|
|
2589
|
+
(V) => X.current?.(V)
|
|
2571
2590
|
);
|
|
2572
|
-
|
|
2591
|
+
G.current = Z, y.current = requestAnimationFrame(C);
|
|
2573
2592
|
};
|
|
2574
|
-
return y.current = requestAnimationFrame(
|
|
2575
|
-
cancelAnimationFrame(y.current), ie(),
|
|
2593
|
+
return y.current = requestAnimationFrame(C), () => {
|
|
2594
|
+
cancelAnimationFrame(y.current), ie(), le(), K.current.stop(), j.current?.stop();
|
|
2576
2595
|
};
|
|
2577
2596
|
}, [
|
|
2578
|
-
|
|
2579
|
-
|
|
2597
|
+
E,
|
|
2598
|
+
Q,
|
|
2580
2599
|
xe,
|
|
2581
2600
|
ie,
|
|
2582
|
-
|
|
2583
|
-
]),
|
|
2601
|
+
le
|
|
2602
|
+
]), bn(
|
|
2584
2603
|
R,
|
|
2585
2604
|
() => ({
|
|
2586
|
-
speakText: async (h,
|
|
2587
|
-
const
|
|
2588
|
-
if (!
|
|
2589
|
-
const
|
|
2590
|
-
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)
|
|
2591
2610
|
throw new Error("AI twin is not ready");
|
|
2592
|
-
const { ttsEngineId:
|
|
2593
|
-
|
|
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;
|
|
2594
2613
|
try {
|
|
2595
|
-
|
|
2596
|
-
voiceId:
|
|
2597
|
-
speakingRate:
|
|
2598
|
-
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
|
|
2599
2618
|
});
|
|
2600
2619
|
} catch (ae) {
|
|
2601
|
-
throw
|
|
2620
|
+
throw de(ae instanceof Error ? ae.message : "TTS failed"), ae;
|
|
2602
2621
|
}
|
|
2603
2622
|
},
|
|
2604
2623
|
stop: () => {
|
|
2605
|
-
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();
|
|
2606
2625
|
},
|
|
2607
2626
|
setTtsEngineId: (h) => {
|
|
2608
|
-
|
|
2627
|
+
K.current.setTtsEngineId(h), j.current?.setTtsEngineId(h), se.current && (se.current.ttsEngineId = h);
|
|
2609
2628
|
},
|
|
2610
|
-
renderViseme: async (h,
|
|
2611
|
-
const
|
|
2612
|
-
if (!
|
|
2629
|
+
renderViseme: async (h, C) => {
|
|
2630
|
+
const x = N.current, F = q.current;
|
|
2631
|
+
if (!x || !F || !Ce.current)
|
|
2613
2632
|
throw new Error("AI twin is not ready");
|
|
2614
|
-
await
|
|
2615
|
-
from:
|
|
2616
|
-
transitionDurationMs:
|
|
2617
|
-
gapMs:
|
|
2618
|
-
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)
|
|
2619
2638
|
});
|
|
2620
2639
|
},
|
|
2621
|
-
isReady: () =>
|
|
2622
|
-
getStatus: () =>
|
|
2640
|
+
isReady: () => Ce.current,
|
|
2641
|
+
getStatus: () => J,
|
|
2623
2642
|
connect: async (h = {}) => {
|
|
2624
|
-
|
|
2643
|
+
c(null);
|
|
2625
2644
|
try {
|
|
2626
|
-
let
|
|
2627
|
-
|
|
2628
|
-
const
|
|
2629
|
-
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({
|
|
2630
2649
|
...h,
|
|
2631
|
-
authToken:
|
|
2632
|
-
voiceId:
|
|
2650
|
+
authToken: C,
|
|
2651
|
+
voiceId: x,
|
|
2633
2652
|
speakingRate: h.speakingRate ?? f
|
|
2634
2653
|
});
|
|
2635
|
-
} catch (
|
|
2636
|
-
throw
|
|
2637
|
-
|
|
2638
|
-
),
|
|
2654
|
+
} catch (C) {
|
|
2655
|
+
throw de(
|
|
2656
|
+
C instanceof Error ? C.message : "Voice connect failed"
|
|
2657
|
+
), C;
|
|
2639
2658
|
}
|
|
2640
2659
|
},
|
|
2641
2660
|
disconnect: async () => {
|
|
2642
|
-
const h =
|
|
2643
|
-
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());
|
|
2644
2663
|
},
|
|
2645
|
-
isConnected: () =>
|
|
2664
|
+
isConnected: () => j.current?.isConnected() ?? !1
|
|
2646
2665
|
}),
|
|
2647
2666
|
[
|
|
2648
|
-
|
|
2667
|
+
E,
|
|
2649
2668
|
f,
|
|
2650
2669
|
i,
|
|
2651
2670
|
a,
|
|
2652
2671
|
ie,
|
|
2653
|
-
|
|
2672
|
+
le,
|
|
2654
2673
|
xe,
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2674
|
+
de,
|
|
2675
|
+
bt,
|
|
2676
|
+
Tt,
|
|
2677
|
+
J
|
|
2659
2678
|
]
|
|
2660
|
-
), /* @__PURE__ */ kn("div", { className: l, style: { ...
|
|
2661
|
-
/* @__PURE__ */
|
|
2679
|
+
), /* @__PURE__ */ kn("div", { className: l, style: { ...Us, ...w }, children: [
|
|
2680
|
+
/* @__PURE__ */ Rt(
|
|
2662
2681
|
"canvas",
|
|
2663
2682
|
{
|
|
2664
|
-
ref:
|
|
2665
|
-
width:
|
|
2666
|
-
height:
|
|
2667
|
-
style: { ...
|
|
2683
|
+
ref: q,
|
|
2684
|
+
width: ke.width,
|
|
2685
|
+
height: ke.height,
|
|
2686
|
+
style: { ...Ns, ..._ },
|
|
2668
2687
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
2669
2688
|
}
|
|
2670
2689
|
),
|
|
2671
|
-
p &&
|
|
2690
|
+
p && ee ? /* @__PURE__ */ Rt("div", { style: Vs, children: ee }) : null
|
|
2672
2691
|
] });
|
|
2673
|
-
}),
|
|
2674
|
-
function
|
|
2692
|
+
}), $s = "thumbnail.webp";
|
|
2693
|
+
function Qs(e, t = ft) {
|
|
2675
2694
|
const n = e.trim();
|
|
2676
2695
|
if (!n)
|
|
2677
2696
|
throw new Error("faceId is required");
|
|
2678
|
-
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)}`;
|
|
2679
2709
|
}
|
|
2680
2710
|
export {
|
|
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
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
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
|
|
2709
2741
|
};
|