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