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