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