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