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