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