@streamoji/aitwin 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aitwin.cjs +4 -4
- package/dist/aitwin.js +1054 -1051
- package/package.json +4 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { jsxs as Wn, jsx as Ir } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as Hn, useRef as H, useState as
|
|
2
|
+
import { forwardRef as Hn, useRef as H, useState as Ze, useEffect as He, useCallback as xe, useMemo as Mr, useImperativeHandle as $n } from "react";
|
|
3
3
|
import { PipecatClient as qn } from "@pipecat-ai/client-js";
|
|
4
4
|
import { WebSocketTransport as Kn, DailyMediaManager as Gn, ProtobufFrameSerializer as zn } from "@pipecat-ai/websocket-transport";
|
|
5
|
-
import { Filter as jn, GlProgram as Yn, Application as Xn, RendererType as Jn, Sprite as
|
|
5
|
+
import { Filter as jn, GlProgram as Yn, Application as Xn, RendererType as Jn, Sprite as xt, Texture as ge, VideoSource as Qn, Rectangle as Zn } from "pixi.js";
|
|
6
6
|
const es = "https://aitwin.bubu.social", nn = {
|
|
7
7
|
publicBase: es
|
|
8
|
-
}, ts = "0.4.
|
|
8
|
+
}, ts = "0.4.6", rs = {
|
|
9
9
|
version: ts
|
|
10
|
-
}, ns = {},
|
|
10
|
+
}, ns = {}, St = "https://ai.aitwin.me", ar = `${nn.publicBase}/custom-faces`, ss = `${nn.publicBase}/aitwin-workers/v${rs.version}/visemeDiffPreview.worker.js`;
|
|
11
11
|
function is(e) {
|
|
12
12
|
if (e) return e;
|
|
13
13
|
const t = typeof import.meta < "u" ? ns?.VITE_AITWIN_WORKER_URL : void 0;
|
|
14
14
|
return t?.trim() ? t.trim() : ss;
|
|
15
15
|
}
|
|
16
|
-
const as = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", zt = 3e3,
|
|
16
|
+
const as = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", zt = 3e3, _t = 16, Rr = 3e3, os = 4e3, cs = 0.85, us = 8, or = 400, sn = "eng_a7f2b9c1", cr = "eng_d4e8f3a2", it = "eng_c9b1e6d4", tt = it, an = /* @__PURE__ */ new Set([
|
|
17
17
|
cr,
|
|
18
|
-
|
|
18
|
+
it
|
|
19
19
|
]), on = {
|
|
20
20
|
[sn]: "oculus_direct",
|
|
21
|
-
[
|
|
21
|
+
[it]: "oculus_direct",
|
|
22
22
|
[cr]: "inworld_word"
|
|
23
23
|
}, Dr = {
|
|
24
24
|
google: sn,
|
|
25
25
|
inworld: cr,
|
|
26
|
-
cartesia:
|
|
26
|
+
cartesia: it
|
|
27
27
|
};
|
|
28
28
|
function ls(e) {
|
|
29
29
|
return on[e];
|
|
30
30
|
}
|
|
31
31
|
function fs(e) {
|
|
32
|
-
return e ===
|
|
32
|
+
return e === it;
|
|
33
33
|
}
|
|
34
34
|
function ds(e) {
|
|
35
35
|
if (e.ttsEngineId && e.ttsEngineId in on)
|
|
36
36
|
return e.ttsEngineId;
|
|
37
37
|
const t = e.tts?.toLowerCase();
|
|
38
|
-
return t && t in Dr ? Dr[t] :
|
|
38
|
+
return t && t in Dr ? Dr[t] : tt;
|
|
39
39
|
}
|
|
40
40
|
class Qt extends Error {
|
|
41
41
|
constructor(t = "AI twin not found") {
|
|
@@ -81,7 +81,7 @@ async function jt() {
|
|
|
81
81
|
throw new Error("getAuthToken returned no token");
|
|
82
82
|
return r;
|
|
83
83
|
}
|
|
84
|
-
async function _s(e, t =
|
|
84
|
+
async function _s(e, t = St) {
|
|
85
85
|
const r = await fetch(`${t.replace(/\/$/, "")}/api/session-value`, {
|
|
86
86
|
headers: { Authorization: `Bearer ${e}` }
|
|
87
87
|
});
|
|
@@ -99,7 +99,7 @@ function vs(e) {
|
|
|
99
99
|
r[n / 2] = Number.parseInt(t.slice(n, n + 2), 16);
|
|
100
100
|
return r;
|
|
101
101
|
}
|
|
102
|
-
function
|
|
102
|
+
function It(e) {
|
|
103
103
|
return Uint8Array.from(e);
|
|
104
104
|
}
|
|
105
105
|
function Ss(e, t) {
|
|
@@ -110,7 +110,7 @@ async function bs(e, t) {
|
|
|
110
110
|
if (!t) throw new Error("Asset key is required for encrypted assets");
|
|
111
111
|
if (e.byteLength < 28)
|
|
112
112
|
throw new Error("Encrypted payload too small");
|
|
113
|
-
const r = new Uint8Array(e), n =
|
|
113
|
+
const r = new Uint8Array(e), n = It(r.subarray(0, 12)), s = It(r.subarray(12, 28)), i = It(r.subarray(28)), o = It(Ss(i, s)), a = await crypto.subtle.importKey(
|
|
114
114
|
"raw",
|
|
115
115
|
vs(t),
|
|
116
116
|
{ name: "AES-GCM" },
|
|
@@ -125,18 +125,18 @@ async function bs(e, t) {
|
|
|
125
125
|
}
|
|
126
126
|
let Zt = null;
|
|
127
127
|
const er = /* @__PURE__ */ new Set();
|
|
128
|
-
function
|
|
128
|
+
function Mt(e) {
|
|
129
129
|
return e.includes("/custom-faces/");
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function Ct(e) {
|
|
132
132
|
const t = e.binBase.trim().replace(/\/$/, ""), r = e.twinBase.trim().replace(/\/$/, "");
|
|
133
|
-
if (!(e.encrypted ||
|
|
133
|
+
if (!(e.encrypted || Mt(t) || Mt(r)))
|
|
134
134
|
return { twinBase: r, binBase: t, encrypted: !1 };
|
|
135
|
-
const s =
|
|
135
|
+
const s = Mt(t) ? t : Mt(r) ? r : t;
|
|
136
136
|
return { twinBase: s, binBase: s, encrypted: !0 };
|
|
137
137
|
}
|
|
138
|
-
function
|
|
139
|
-
return
|
|
138
|
+
function Ge(e) {
|
|
139
|
+
return Ct(e).encrypted;
|
|
140
140
|
}
|
|
141
141
|
function Br(e, t = ar) {
|
|
142
142
|
const r = `${t.replace(/\/$/, "")}/${e}`;
|
|
@@ -146,12 +146,12 @@ function ks(e, t) {
|
|
|
146
146
|
return (e ?? t)?.trim() || void 0;
|
|
147
147
|
}
|
|
148
148
|
function Ts(e) {
|
|
149
|
-
Zt =
|
|
149
|
+
Zt = Ct(e);
|
|
150
150
|
for (const t of er) t();
|
|
151
151
|
}
|
|
152
152
|
function Es(e, t) {
|
|
153
153
|
const r = typeof globalThis.location < "u" ? globalThis.location.href : void 0;
|
|
154
|
-
if (!r) return
|
|
154
|
+
if (!r) return Ct(e);
|
|
155
155
|
const n = (s) => {
|
|
156
156
|
try {
|
|
157
157
|
return new URL(s, r).href.replace(/\/$/, "");
|
|
@@ -159,13 +159,13 @@ function Es(e, t) {
|
|
|
159
159
|
return s;
|
|
160
160
|
}
|
|
161
161
|
};
|
|
162
|
-
return
|
|
162
|
+
return Ct({
|
|
163
163
|
twinBase: n(e.twinBase),
|
|
164
164
|
binBase: n(e.binBase),
|
|
165
165
|
encrypted: e.encrypted
|
|
166
166
|
});
|
|
167
167
|
}
|
|
168
|
-
function
|
|
168
|
+
function ze() {
|
|
169
169
|
if (!Zt)
|
|
170
170
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
171
171
|
return Zt;
|
|
@@ -173,28 +173,28 @@ function je() {
|
|
|
173
173
|
function cn(e) {
|
|
174
174
|
return er.add(e), () => er.delete(e);
|
|
175
175
|
}
|
|
176
|
-
function
|
|
177
|
-
const e =
|
|
178
|
-
return
|
|
176
|
+
function Ft() {
|
|
177
|
+
const e = ze();
|
|
178
|
+
return Ge(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
179
179
|
}
|
|
180
180
|
function As() {
|
|
181
|
-
const e =
|
|
182
|
-
return
|
|
181
|
+
const e = ze();
|
|
182
|
+
return Ge(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
183
183
|
}
|
|
184
184
|
function un() {
|
|
185
|
-
const e =
|
|
186
|
-
return
|
|
185
|
+
const e = ze();
|
|
186
|
+
return Ge(e) ? e.binBase : e.twinBase;
|
|
187
187
|
}
|
|
188
|
-
function
|
|
189
|
-
return ze(
|
|
188
|
+
function bt() {
|
|
189
|
+
return Ge(ze());
|
|
190
190
|
}
|
|
191
191
|
function ln() {
|
|
192
|
-
const e =
|
|
193
|
-
return
|
|
192
|
+
const e = ze();
|
|
193
|
+
return Ge(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
194
194
|
}
|
|
195
195
|
function fn() {
|
|
196
|
-
const e =
|
|
197
|
-
return
|
|
196
|
+
const e = ze();
|
|
197
|
+
return Ge(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
198
198
|
}
|
|
199
199
|
function dn(e) {
|
|
200
200
|
const t = e.split(/\r?\n/);
|
|
@@ -259,16 +259,16 @@ function Ds(e, t) {
|
|
|
259
259
|
const s = Math.max(0, Math.min(1, (t - e.wtime) / n));
|
|
260
260
|
return Math.min(r - 1, Math.floor(s * r));
|
|
261
261
|
}
|
|
262
|
-
function
|
|
262
|
+
function rt(e, t) {
|
|
263
263
|
const r = Math.max(0, Math.min(e.length - 1, t));
|
|
264
264
|
return e[r] ?? "";
|
|
265
265
|
}
|
|
266
266
|
function ur(e, t) {
|
|
267
267
|
const r = e.toLowerCase().replace(/[^a-z']/g, "");
|
|
268
|
-
return !r ||
|
|
268
|
+
return !r || rt(r, t) !== "w" || t > 0 && rt(r, t - 1) === "q" ? !1 : t === 0 && /^w[aeiouy]/.test(r);
|
|
269
269
|
}
|
|
270
270
|
function Bs(e, t) {
|
|
271
|
-
const r = e.toLowerCase(), n =
|
|
271
|
+
const r = e.toLowerCase(), n = rt(r, t), s = r.slice(Math.max(0, t - 1), t + 2);
|
|
272
272
|
return n === "i" || n === "y" ? "I" : s.includes("ee") || n === "e" || r.includes("ea") ? "E" : "aa";
|
|
273
273
|
}
|
|
274
274
|
function Cs(e, t) {
|
|
@@ -278,7 +278,7 @@ function Cs(e, t) {
|
|
|
278
278
|
);
|
|
279
279
|
if (/oo|ou|uw/.test(n)) return "U";
|
|
280
280
|
if (ur(r, t)) return "FF";
|
|
281
|
-
const s =
|
|
281
|
+
const s = rt(r, t);
|
|
282
282
|
return s === "u" || s === "w" ? "U" : "O";
|
|
283
283
|
}
|
|
284
284
|
function Fs(e, t) {
|
|
@@ -290,9 +290,9 @@ function Fs(e, t) {
|
|
|
290
290
|
Math.max(0, t - 1),
|
|
291
291
|
Math.min(r.length, t + 3)
|
|
292
292
|
);
|
|
293
|
-
return /wo|wh/.test(s) ||
|
|
293
|
+
return /wo|wh/.test(s) || rt(r, t) === "o" ? "O" : "U";
|
|
294
294
|
}
|
|
295
|
-
const
|
|
295
|
+
const Rt = {
|
|
296
296
|
d: "DD",
|
|
297
297
|
t: "DD",
|
|
298
298
|
n: "DD",
|
|
@@ -305,11 +305,11 @@ const Dt = {
|
|
|
305
305
|
j: "CH"
|
|
306
306
|
};
|
|
307
307
|
function Ls(e, t) {
|
|
308
|
-
const r = e.toLowerCase(), n =
|
|
309
|
-
if (
|
|
308
|
+
const r = e.toLowerCase(), n = rt(r, t);
|
|
309
|
+
if (Rt[n]) return Rt[n];
|
|
310
310
|
for (let s = 0; s < r.length; s++) {
|
|
311
311
|
const i = r[s];
|
|
312
|
-
if (
|
|
312
|
+
if (Rt[i]) return Rt[i];
|
|
313
313
|
}
|
|
314
314
|
return "DD";
|
|
315
315
|
}
|
|
@@ -351,7 +351,7 @@ function hn(e) {
|
|
|
351
351
|
function Us(e) {
|
|
352
352
|
return pn(e).find((r) => r.viseme !== "sil") ?? null;
|
|
353
353
|
}
|
|
354
|
-
function
|
|
354
|
+
function $e(e) {
|
|
355
355
|
const t = mn(e);
|
|
356
356
|
return hn(e) ? t + or : t;
|
|
357
357
|
}
|
|
@@ -480,7 +480,7 @@ function zs(e, t) {
|
|
|
480
480
|
}
|
|
481
481
|
function yn(e, t) {
|
|
482
482
|
const r = [], n = [];
|
|
483
|
-
let s = null, i = !1, o = !1, a = !1, u = !1, l = 0, f = 0, c = 0, d = null, g = 1, S = t,
|
|
483
|
+
let s = null, i = !1, o = !1, a = !1, u = !1, l = 0, f = 0, c = 0, d = null, g = 1, S = t, h = !1, M = null, _ = 0, D = !1, w = !1, b = 0, L = null, B = null, G = null;
|
|
484
484
|
const C = () => ({
|
|
485
485
|
visemes: [],
|
|
486
486
|
words: [],
|
|
@@ -489,131 +489,131 @@ function yn(e, t) {
|
|
|
489
489
|
w = !1, b = 0;
|
|
490
490
|
}, P = () => {
|
|
491
491
|
d != null && (clearTimeout(d), d = null);
|
|
492
|
-
},
|
|
493
|
-
for (const
|
|
492
|
+
}, N = () => {
|
|
493
|
+
for (const m of n) {
|
|
494
494
|
try {
|
|
495
|
-
|
|
495
|
+
m.onended = null, m.stop(0);
|
|
496
496
|
} catch {
|
|
497
497
|
}
|
|
498
498
|
try {
|
|
499
|
-
|
|
499
|
+
m.disconnect();
|
|
500
500
|
} catch {
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
503
|
n.length = 0;
|
|
504
|
-
},
|
|
505
|
-
for (const
|
|
506
|
-
|
|
507
|
-
},
|
|
508
|
-
if (!(
|
|
504
|
+
}, I = () => {
|
|
505
|
+
for (const m of n)
|
|
506
|
+
m.playbackRate.value = g;
|
|
507
|
+
}, te = () => {
|
|
508
|
+
if (!(h || !u || i || w || n.length > 0 || r.length > 0)) {
|
|
509
509
|
if (a && s && f > 0) {
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
510
|
+
const m = (s.currentTime - f) * 1e3;
|
|
511
|
+
if (m < _) {
|
|
512
512
|
P();
|
|
513
|
-
const
|
|
513
|
+
const T = g > 0 ? (_ - m) / g : _ - m;
|
|
514
514
|
d = setTimeout(() => {
|
|
515
|
-
|
|
516
|
-
}, Math.max(0,
|
|
515
|
+
h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
|
|
516
|
+
}, Math.max(0, T));
|
|
517
517
|
return;
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
o = !1, P(), e.onSpeakingDone(), e.onNotify();
|
|
521
521
|
}
|
|
522
|
-
},
|
|
523
|
-
const
|
|
524
|
-
if (
|
|
522
|
+
}, V = (m) => {
|
|
523
|
+
const T = $e(m);
|
|
524
|
+
if (T <= 0) {
|
|
525
525
|
e.onSpeakingDone(), e.onNotify();
|
|
526
526
|
return;
|
|
527
527
|
}
|
|
528
528
|
o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), P();
|
|
529
|
-
const
|
|
529
|
+
const R = g > 0 ? T / g : T;
|
|
530
530
|
d = setTimeout(() => {
|
|
531
|
-
|
|
532
|
-
},
|
|
533
|
-
},
|
|
534
|
-
|
|
531
|
+
h || (o = !1, d = null, e.onSpeakingDone(), e.onNotify());
|
|
532
|
+
}, R);
|
|
533
|
+
}, J = (m, T, R, F) => {
|
|
534
|
+
T.length !== 0 && (c = R, T.forEach((A) => {
|
|
535
535
|
const Y = String(A.word ?? "").trim();
|
|
536
536
|
if (!Y) return;
|
|
537
537
|
const Q = 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;
|
|
538
|
-
|
|
538
|
+
m.push({
|
|
539
539
|
word: Y,
|
|
540
540
|
wtime: c + Q,
|
|
541
541
|
wduration: Z,
|
|
542
|
-
queueIndex:
|
|
542
|
+
queueIndex: m.length,
|
|
543
543
|
gesture: A.gesture ?? null,
|
|
544
544
|
emphasis: A.emphasis === !0
|
|
545
545
|
});
|
|
546
546
|
}));
|
|
547
|
-
},
|
|
548
|
-
|
|
547
|
+
}, j = (m, T, R, F, A, $) => {
|
|
548
|
+
R.length !== 0 && (c = F, R.forEach((Y) => {
|
|
549
549
|
const Q = String(Y.symbol ?? Y.viseme ?? "").trim();
|
|
550
550
|
if (!Q) return;
|
|
551
|
-
const Z = Math.round((Y.start ?? 0) * 1e3),
|
|
552
|
-
let
|
|
553
|
-
ls($) === "oculus_direct" ? (
|
|
551
|
+
const Z = Math.round((Y.start ?? 0) * 1e3), be = Math.max(1, Math.round((Y.duration ?? 0) * 1e3)), ke = c + Z, Be = zs(T, ke), ot = Be ? Ds(Be, ke) : 0;
|
|
552
|
+
let Me;
|
|
553
|
+
ls($) === "oculus_direct" ? (Me = Is(Q), Me === "U" && Be && ur(Be.word, ot) && (Me = "FF")) : Me = Os(
|
|
554
554
|
Q,
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
),
|
|
558
|
-
viseme:
|
|
555
|
+
Be?.word ?? "",
|
|
556
|
+
ot
|
|
557
|
+
), m.push({
|
|
558
|
+
viseme: Me,
|
|
559
559
|
weight: 1,
|
|
560
|
-
vtime:
|
|
561
|
-
vduration:
|
|
560
|
+
vtime: ke,
|
|
561
|
+
vduration: be
|
|
562
562
|
});
|
|
563
563
|
}), e.onNotify());
|
|
564
|
-
},
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
564
|
+
}, X = (m, T, R, F, A, $, Y) => {
|
|
565
|
+
J(T, F, A), j(
|
|
566
|
+
m,
|
|
567
|
+
T,
|
|
568
|
+
R,
|
|
569
569
|
A,
|
|
570
570
|
$,
|
|
571
571
|
Y
|
|
572
572
|
);
|
|
573
|
-
},
|
|
574
|
-
G ===
|
|
575
|
-
},
|
|
576
|
-
const
|
|
577
|
-
return s || (s = new
|
|
578
|
-
},
|
|
573
|
+
}, pe = (m, T, R) => {
|
|
574
|
+
G === m && m.visemes === T || (T.length = 0, R.length = 0, m.visemes = T, m.words = R, m.segmentOffsetMs = 0, G = m, c = 0, _ = 0);
|
|
575
|
+
}, re = async () => {
|
|
576
|
+
const m = window.AudioContext || window.webkitAudioContext;
|
|
577
|
+
return s || (s = new m()), s.state === "suspended" && await s.resume(), M || (M = s.createMediaStreamDestination()), s;
|
|
578
|
+
}, fe = (m, T) => {
|
|
579
579
|
if (!s) return 0;
|
|
580
|
-
const
|
|
581
|
-
if (
|
|
580
|
+
const R = s, F = R.currentTime, A = F + 0.02;
|
|
581
|
+
if (T.isFirstAudio) {
|
|
582
582
|
f <= 0 && (f = A);
|
|
583
583
|
const Y = (A - F) * 1e3;
|
|
584
584
|
l = performance.now() + Y;
|
|
585
585
|
}
|
|
586
|
-
|
|
587
|
-
const $ =
|
|
588
|
-
return $.buffer =
|
|
586
|
+
T.onBeforeStart?.(A);
|
|
587
|
+
const $ = R.createBufferSource();
|
|
588
|
+
return $.buffer = m, $.playbackRate.value = g, $.connect(R.destination), M && $.connect(M), n.push($), h ? (n.pop(), A) : (T.isFirstAudio && (o = !0, e.onSpeakingStart()), $.onended = () => {
|
|
589
589
|
const Y = n.indexOf($);
|
|
590
|
-
Y >= 0 && n.splice(Y, 1), e.onNotify(), !
|
|
590
|
+
Y >= 0 && n.splice(Y, 1), e.onNotify(), !h && (L && B ? de(L, B) : te());
|
|
591
591
|
}, $.start(A), A);
|
|
592
|
-
},
|
|
593
|
-
if (
|
|
592
|
+
}, de = async (m, T) => {
|
|
593
|
+
if (h || i || n.length > 0) return;
|
|
594
594
|
if (r.length === 0) {
|
|
595
|
-
|
|
595
|
+
te();
|
|
596
596
|
return;
|
|
597
597
|
}
|
|
598
598
|
i = !0;
|
|
599
|
-
let
|
|
599
|
+
let R = !1;
|
|
600
600
|
try {
|
|
601
|
-
const F = await
|
|
602
|
-
if (
|
|
601
|
+
const F = await re();
|
|
602
|
+
if (h) return;
|
|
603
603
|
const A = r[0];
|
|
604
604
|
if (!A) return;
|
|
605
605
|
const $ = !o;
|
|
606
|
-
if (
|
|
607
|
-
|
|
606
|
+
if (D && (e.shouldHoldForWarmup?.() ?? !1) && (w || $ && A.newStream) || w) {
|
|
607
|
+
pe(A.utterance, m, T);
|
|
608
608
|
for (const Z of r) {
|
|
609
|
-
if (
|
|
609
|
+
if (h) return;
|
|
610
610
|
Z.audioBuffer || (Z.audioBuffer = await Lr(
|
|
611
611
|
F,
|
|
612
612
|
Z.audio,
|
|
613
613
|
Z.sampleRate
|
|
614
|
-
)), a = !0, w || (w = !0, b = 0, Z.newStream && Z.onNewStream?.()), Z.visemesQueued || (
|
|
615
|
-
|
|
616
|
-
|
|
614
|
+
)), a = !0, w || (w = !0, b = 0, Z.newStream && Z.onNewStream?.()), Z.visemesQueued || (X(
|
|
615
|
+
m,
|
|
616
|
+
T,
|
|
617
617
|
Z.visemes,
|
|
618
618
|
Z.words,
|
|
619
619
|
b,
|
|
@@ -621,7 +621,7 @@ function yn(e, t) {
|
|
|
621
621
|
S
|
|
622
622
|
), Z.visemesQueued = !0, b += Math.round(Z.audioBuffer.duration * 1e3), _ = Math.max(
|
|
623
623
|
_,
|
|
624
|
-
|
|
624
|
+
$e(m)
|
|
625
625
|
));
|
|
626
626
|
}
|
|
627
627
|
e.onNotify();
|
|
@@ -632,14 +632,14 @@ function yn(e, t) {
|
|
|
632
632
|
F,
|
|
633
633
|
Q.audio,
|
|
634
634
|
Q.sampleRate
|
|
635
|
-
)),
|
|
636
|
-
a = !0, P(),
|
|
635
|
+
)), h)) return;
|
|
636
|
+
a = !0, P(), pe(Q.utterance, m, T), Q.visemesQueued = !1, Q.newStream && Q.onNewStream?.(), fe(Q.audioBuffer, {
|
|
637
637
|
isFirstAudio: !o,
|
|
638
638
|
isFirstOfStream: !1,
|
|
639
639
|
onBeforeStart: (Z) => {
|
|
640
|
-
f = Z, c = 0, l = performance.now() + (Z - F.currentTime) * 1e3,
|
|
641
|
-
|
|
642
|
-
|
|
640
|
+
f = Z, c = 0, l = performance.now() + (Z - F.currentTime) * 1e3, X(
|
|
641
|
+
m,
|
|
642
|
+
T,
|
|
643
643
|
Q.visemes,
|
|
644
644
|
Q.words,
|
|
645
645
|
0,
|
|
@@ -647,87 +647,87 @@ function yn(e, t) {
|
|
|
647
647
|
S
|
|
648
648
|
), Q.visemesQueued = !0, Q.utterance.segmentOffsetMs = 0;
|
|
649
649
|
}
|
|
650
|
-
}),
|
|
650
|
+
}), R = n.length > 0, _ = $e(m), e.onNotify();
|
|
651
651
|
} catch (F) {
|
|
652
652
|
console.error("[avatarChunkPlayback] audio chunk failed:", F);
|
|
653
653
|
} finally {
|
|
654
|
-
if (i = !1,
|
|
654
|
+
if (i = !1, h) return;
|
|
655
655
|
if (w) {
|
|
656
656
|
r.some(
|
|
657
657
|
(A) => !A.audioBuffer || !A.visemesQueued
|
|
658
|
-
) &&
|
|
658
|
+
) && de(m, T);
|
|
659
659
|
return;
|
|
660
660
|
}
|
|
661
|
-
!
|
|
661
|
+
!R && n.length === 0 && r.length > 0 ? de(m, T) : n.length === 0 && r.length === 0 && te();
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
664
|
return {
|
|
665
|
-
setStreamTtsEngineId: (
|
|
666
|
-
S =
|
|
665
|
+
setStreamTtsEngineId: (m) => {
|
|
666
|
+
S = m;
|
|
667
667
|
},
|
|
668
|
-
setPlaybackSpeed: (
|
|
669
|
-
g = Math.max(0.1, Math.min(1,
|
|
668
|
+
setPlaybackSpeed: (m) => {
|
|
669
|
+
g = Math.max(0.1, Math.min(1, m)), I();
|
|
670
670
|
},
|
|
671
671
|
getPlaybackSpeed: () => g,
|
|
672
|
-
setLipsyncWarmupHoldEnabled: (
|
|
673
|
-
|
|
672
|
+
setLipsyncWarmupHoldEnabled: (m) => {
|
|
673
|
+
D = m, m || k();
|
|
674
674
|
},
|
|
675
675
|
isWarmingUp: () => w,
|
|
676
676
|
releaseWarmupHold: () => {
|
|
677
677
|
if (w) {
|
|
678
678
|
w = !1, b = 0;
|
|
679
|
-
for (const
|
|
680
|
-
|
|
681
|
-
L && B &&
|
|
679
|
+
for (const m of r)
|
|
680
|
+
m.newStream = !1;
|
|
681
|
+
L && B && de(L, B), e.onNotify();
|
|
682
682
|
}
|
|
683
683
|
},
|
|
684
|
-
resetForNewStream: (
|
|
685
|
-
|
|
684
|
+
resetForNewStream: (m) => {
|
|
685
|
+
h = !1, u = !1, S = m, _ = 0;
|
|
686
686
|
},
|
|
687
687
|
/** Next sentence in the same bot turn — keep viseme tail, allow more chunks. */
|
|
688
688
|
resumeBotStream: () => {
|
|
689
|
-
|
|
689
|
+
h = !1, u = !1;
|
|
690
690
|
},
|
|
691
691
|
/** After interrupt — allow the next utterance to queue/play again. */
|
|
692
692
|
clearAborted: () => {
|
|
693
|
-
|
|
693
|
+
h = !1;
|
|
694
694
|
},
|
|
695
695
|
/** Call from a user gesture before bot audio (connect / unlock). */
|
|
696
696
|
primeAudioContext: async () => {
|
|
697
|
-
const
|
|
698
|
-
s || (s = new
|
|
697
|
+
const m = window.AudioContext || window.webkitAudioContext;
|
|
698
|
+
s || (s = new m()), s.state === "suspended" && await s.resume(), s && !M && (M = s.createMediaStreamDestination());
|
|
699
699
|
},
|
|
700
700
|
stop: () => {
|
|
701
|
-
|
|
701
|
+
h = !0, P(), N(), r.length = 0, i = !1, o = !1, a = !1, u = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
|
|
702
702
|
},
|
|
703
|
-
markStreamComplete: (
|
|
704
|
-
if (_ = Math.max(_,
|
|
705
|
-
|
|
703
|
+
markStreamComplete: (m) => {
|
|
704
|
+
if (_ = Math.max(_, $e(m)), u = !0, !a && m.length > 0) {
|
|
705
|
+
V(m);
|
|
706
706
|
return;
|
|
707
707
|
}
|
|
708
|
-
|
|
708
|
+
te();
|
|
709
709
|
},
|
|
710
|
-
playAudioChunk: async (
|
|
711
|
-
if (
|
|
712
|
-
L =
|
|
713
|
-
const Q = gn(Y?.sampleRate), Z = Y?.newStream === !0,
|
|
714
|
-
if (!
|
|
710
|
+
playAudioChunk: async (m, T, R, F, A, $, Y) => {
|
|
711
|
+
if (h) return;
|
|
712
|
+
L = m, B = T;
|
|
713
|
+
const Q = gn(Y?.sampleRate), Z = Y?.newStream === !0, be = C();
|
|
714
|
+
if (!R?.trim()) {
|
|
715
715
|
if (F.length === 0 && A.length === 0) return;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
716
|
+
pe(be, m, T), Z && Y?.onNewStream?.(), X(
|
|
717
|
+
m,
|
|
718
|
+
T,
|
|
719
719
|
F,
|
|
720
720
|
A,
|
|
721
721
|
0,
|
|
722
722
|
!0,
|
|
723
723
|
S
|
|
724
|
-
), _ =
|
|
724
|
+
), _ = $e(m), !o && _ > 0 && V(m), e.onNotify();
|
|
725
725
|
return;
|
|
726
726
|
}
|
|
727
727
|
r.push({
|
|
728
|
-
audio:
|
|
728
|
+
audio: R,
|
|
729
729
|
audioBuffer: null,
|
|
730
|
-
utterance:
|
|
730
|
+
utterance: be,
|
|
731
731
|
visemes: F,
|
|
732
732
|
words: A,
|
|
733
733
|
isNewSegment: $,
|
|
@@ -735,45 +735,45 @@ function yn(e, t) {
|
|
|
735
735
|
newStream: Z,
|
|
736
736
|
onNewStream: Y?.onNewStream,
|
|
737
737
|
visemesQueued: !1
|
|
738
|
-
}), await
|
|
738
|
+
}), await de(m, T);
|
|
739
739
|
},
|
|
740
|
-
queueTimingsOnly: (
|
|
741
|
-
if (
|
|
740
|
+
queueTimingsOnly: (m, T, R, F, A) => {
|
|
741
|
+
if (h) return;
|
|
742
742
|
const $ = C();
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
743
|
+
pe($, m, T), X(
|
|
744
|
+
m,
|
|
745
|
+
T,
|
|
746
|
+
R,
|
|
747
747
|
F,
|
|
748
748
|
0,
|
|
749
749
|
!0,
|
|
750
750
|
S
|
|
751
|
-
), $.segmentOffsetMs = 0, _ =
|
|
751
|
+
), $.segmentOffsetMs = 0, _ = $e(m);
|
|
752
752
|
},
|
|
753
753
|
getPlaybackElapsedMs: () => a && s && f > 0 ? Math.max(
|
|
754
754
|
0,
|
|
755
755
|
(s.currentTime - f) * 1e3
|
|
756
756
|
) : o ? Math.max(0, (performance.now() - l) * g) : 0,
|
|
757
757
|
isSpeaking: () => o ? !0 : !a || !s || f <= 0 ? !1 : (s.currentTime - f) * 1e3 < _,
|
|
758
|
-
getVoiceStream: () =>
|
|
758
|
+
getVoiceStream: () => M ? M.stream : null,
|
|
759
759
|
getPlaybackStartPerf: () => l,
|
|
760
760
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
761
761
|
bargeIn: () => {
|
|
762
|
-
|
|
762
|
+
h = !0, u = !1, P(), N(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
|
|
763
763
|
},
|
|
764
764
|
interrupt: () => {
|
|
765
|
-
|
|
765
|
+
h = !0, u = !1, P(), N(), r.length = 0, i = !1, o = !1, a = !1, c = 0, f = 0, l = 0, _ = 0, L = null, B = null, G = null, k();
|
|
766
766
|
}
|
|
767
767
|
};
|
|
768
768
|
}
|
|
769
|
-
function
|
|
769
|
+
function Ut(e, t) {
|
|
770
770
|
let r = null;
|
|
771
771
|
for (const n of e)
|
|
772
772
|
t < n.vtime || t >= n.vtime + n.vduration || (!r || n.vtime >= r.vtime) && (r = n);
|
|
773
773
|
return r ? r.viseme : "sil";
|
|
774
774
|
}
|
|
775
775
|
function _n(e, t, r = 120) {
|
|
776
|
-
const n =
|
|
776
|
+
const n = Ut(e, t);
|
|
777
777
|
if (n !== "sil") return n;
|
|
778
778
|
let s = null;
|
|
779
779
|
for (const i of e) {
|
|
@@ -807,36 +807,36 @@ function Ys(e, t) {
|
|
|
807
807
|
return null;
|
|
808
808
|
}
|
|
809
809
|
}
|
|
810
|
-
const fr = 0.5, dr = 1.5, vn = "Olivia", Sn = "f786b574-daa5-4673-aa0c-cbe3e8534c02",
|
|
811
|
-
function Or(e, t =
|
|
810
|
+
const fr = 0.5, dr = 1.5, vn = "Olivia", Sn = "f786b574-daa5-4673-aa0c-cbe3e8534c02", Vt = 0.85;
|
|
811
|
+
function Or(e, t = St, r = {}) {
|
|
812
812
|
const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, s = [], i = [], o = [], a = [];
|
|
813
|
-
let u = "", l = "neutral", f = "", c =
|
|
813
|
+
let u = "", l = "neutral", f = "", c = tt;
|
|
814
814
|
const d = /* @__PURE__ */ new Set();
|
|
815
815
|
let g = 0, S = null;
|
|
816
|
-
const
|
|
817
|
-
let
|
|
816
|
+
const h = () => d.forEach((C) => C());
|
|
817
|
+
let M = () => !1;
|
|
818
818
|
const _ = yn(
|
|
819
819
|
{
|
|
820
820
|
onSpeakingStart: () => e("speaking"),
|
|
821
821
|
onSpeakingDone: () => e("done"),
|
|
822
|
-
onNotify:
|
|
823
|
-
shouldHoldForWarmup: () =>
|
|
822
|
+
onNotify: h,
|
|
823
|
+
shouldHoldForWarmup: () => M()
|
|
824
824
|
},
|
|
825
|
-
|
|
826
|
-
),
|
|
825
|
+
tt
|
|
826
|
+
), D = () => _.getPlaybackElapsedMs(), w = (C, k = u) => {
|
|
827
827
|
if (!r.onLipsyncDebug) return;
|
|
828
|
-
const P =
|
|
828
|
+
const P = D(), N = s;
|
|
829
829
|
r.onLipsyncDebug({
|
|
830
830
|
event: C,
|
|
831
831
|
spokenText: k,
|
|
832
832
|
mood: l,
|
|
833
833
|
playbackAnchorPerf: _.getPlaybackStartPerf(),
|
|
834
834
|
playbackElapsedMs: P,
|
|
835
|
-
queueLength:
|
|
836
|
-
activeViseme:
|
|
837
|
-
segments: a.map((
|
|
838
|
-
...
|
|
839
|
-
visemes: [...
|
|
835
|
+
queueLength: N.length,
|
|
836
|
+
activeViseme: Ut(N, P),
|
|
837
|
+
segments: a.map((I) => ({
|
|
838
|
+
...I,
|
|
839
|
+
visemes: [...I.visemes]
|
|
840
840
|
}))
|
|
841
841
|
});
|
|
842
842
|
}, b = (C, k) => {
|
|
@@ -845,31 +845,31 @@ function Or(e, t = kt, r = {}) {
|
|
|
845
845
|
const P = S;
|
|
846
846
|
S = null, P && w(P.event, P.spokenText);
|
|
847
847
|
})));
|
|
848
|
-
}, L = (C, k, P,
|
|
848
|
+
}, L = (C, k, P, N, I) => {
|
|
849
849
|
if (!r.onLipsyncDebug) return;
|
|
850
|
-
const
|
|
851
|
-
(
|
|
850
|
+
const te = s.slice(k), V = P.filter(
|
|
851
|
+
(J) => String(J.symbol ?? J.viseme ?? "").trim()
|
|
852
852
|
);
|
|
853
853
|
a.push({
|
|
854
854
|
spokenText: C,
|
|
855
|
-
audioOffsetMs:
|
|
856
|
-
isNewSegment:
|
|
857
|
-
chunkDurationMs:
|
|
855
|
+
audioOffsetMs: te[0]?.vtime ?? 0,
|
|
856
|
+
isNewSegment: N,
|
|
857
|
+
chunkDurationMs: I,
|
|
858
858
|
receivedAtMs: performance.now(),
|
|
859
|
-
visemes:
|
|
860
|
-
const
|
|
859
|
+
visemes: te.map((J, j) => {
|
|
860
|
+
const X = V[j];
|
|
861
861
|
return {
|
|
862
|
-
rawSymbol: String(
|
|
863
|
-
viseme:
|
|
864
|
-
startSec: Number(
|
|
865
|
-
durationSec: Number(
|
|
866
|
-
vtimeMs:
|
|
867
|
-
vdurationMs:
|
|
862
|
+
rawSymbol: String(X?.symbol ?? X?.viseme ?? J.viseme).trim(),
|
|
863
|
+
viseme: J.viseme,
|
|
864
|
+
startSec: Number(X?.start ?? 0),
|
|
865
|
+
durationSec: Number(X?.duration ?? 0),
|
|
866
|
+
vtimeMs: J.vtime,
|
|
867
|
+
vdurationMs: J.vduration
|
|
868
868
|
};
|
|
869
869
|
})
|
|
870
870
|
});
|
|
871
871
|
}, B = () => {
|
|
872
|
-
_.stop(), s.length = 0, i.length = 0, o.length = 0, l = "neutral", a.length = 0, u = "", e("idle"), b("reset"),
|
|
872
|
+
_.stop(), s.length = 0, i.length = 0, o.length = 0, l = "neutral", a.length = 0, u = "", e("idle"), b("reset"), h();
|
|
873
873
|
};
|
|
874
874
|
return {
|
|
875
875
|
setDeveloperToken: (C) => {
|
|
@@ -884,77 +884,77 @@ function Or(e, t = kt, r = {}) {
|
|
|
884
884
|
const P = f.trim();
|
|
885
885
|
if (!P)
|
|
886
886
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
887
|
-
const
|
|
888
|
-
_.resetForNewStream(
|
|
889
|
-
const
|
|
887
|
+
const N = k?.ttsEngineId ?? c ?? tt;
|
|
888
|
+
_.resetForNewStream(N), _.setStreamTtsEngineId(N);
|
|
889
|
+
const I = k?.voiceId ?? vn, te = k?.speakingRate ?? Vt, V = Math.max(
|
|
890
890
|
fr,
|
|
891
|
-
Math.min(dr,
|
|
892
|
-
),
|
|
891
|
+
Math.min(dr, te)
|
|
892
|
+
), J = {
|
|
893
893
|
user_query: C,
|
|
894
|
-
ttsEngineId:
|
|
895
|
-
speakingRate:
|
|
894
|
+
ttsEngineId: N,
|
|
895
|
+
speakingRate: V,
|
|
896
896
|
tenant: "aiTwin"
|
|
897
897
|
};
|
|
898
|
-
an.has(
|
|
898
|
+
an.has(N) && (J.voice_id = I);
|
|
899
899
|
try {
|
|
900
|
-
const
|
|
900
|
+
const j = await fetch(n, {
|
|
901
901
|
method: "POST",
|
|
902
902
|
headers: {
|
|
903
903
|
"Content-Type": "application/json",
|
|
904
904
|
Authorization: `Bearer ${P}`
|
|
905
905
|
},
|
|
906
|
-
body: JSON.stringify(
|
|
906
|
+
body: JSON.stringify(J)
|
|
907
907
|
});
|
|
908
|
-
if (!
|
|
909
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
910
|
-
const
|
|
911
|
-
if (!
|
|
912
|
-
const
|
|
913
|
-
let
|
|
914
|
-
const
|
|
915
|
-
const
|
|
916
|
-
if (
|
|
917
|
-
if (
|
|
918
|
-
const
|
|
919
|
-
if (
|
|
920
|
-
const Y =
|
|
921
|
-
|
|
908
|
+
if (!j.ok)
|
|
909
|
+
throw new Error(`avatar_ttsWithPoses failed (${j.status})`);
|
|
910
|
+
const X = j.body;
|
|
911
|
+
if (!X) throw new Error("No response body");
|
|
912
|
+
const pe = X.getReader(), re = new TextDecoder();
|
|
913
|
+
let fe = "", de = !0;
|
|
914
|
+
const ue = async (v) => {
|
|
915
|
+
const E = dn(v);
|
|
916
|
+
if (E) {
|
|
917
|
+
if (E.event === "audio") {
|
|
918
|
+
const m = E.data.chunk, T = E.data.visemes ?? [], R = E.data.words ?? [], F = E.data.is_new_segment ?? !1, A = E.data.sample_rate, $ = s.length;
|
|
919
|
+
if (m) {
|
|
920
|
+
const Y = de;
|
|
921
|
+
de = !1, await _.playAudioChunk(
|
|
922
922
|
s,
|
|
923
923
|
i,
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
924
|
+
m,
|
|
925
|
+
T,
|
|
926
|
+
R,
|
|
927
927
|
F,
|
|
928
928
|
{ sampleRate: A, newStream: Y }
|
|
929
929
|
), L(
|
|
930
930
|
C,
|
|
931
931
|
$,
|
|
932
|
-
|
|
932
|
+
T,
|
|
933
933
|
F,
|
|
934
|
-
Ys(
|
|
934
|
+
Ys(m, A)
|
|
935
935
|
), b("audio_chunk", C);
|
|
936
|
-
} else (
|
|
936
|
+
} else (T.length > 0 || R.length > 0) && (_.queueTimingsOnly(
|
|
937
937
|
s,
|
|
938
938
|
i,
|
|
939
|
-
|
|
940
|
-
|
|
939
|
+
T,
|
|
940
|
+
R,
|
|
941
941
|
F
|
|
942
942
|
), L(
|
|
943
943
|
C,
|
|
944
944
|
$,
|
|
945
|
-
|
|
945
|
+
T,
|
|
946
946
|
F,
|
|
947
947
|
null
|
|
948
948
|
), b("audio_chunk", C));
|
|
949
|
-
} else if (
|
|
950
|
-
const
|
|
951
|
-
typeof
|
|
952
|
-
const
|
|
953
|
-
if (Array.isArray(
|
|
949
|
+
} else if (E.event === "metadata") {
|
|
950
|
+
const m = E.data.mood;
|
|
951
|
+
typeof m == "string" && m.trim() && (l = m.trim());
|
|
952
|
+
const T = E.data.sentence_emotions;
|
|
953
|
+
if (Array.isArray(T)) {
|
|
954
954
|
o.length = 0;
|
|
955
|
-
for (const
|
|
956
|
-
if (!
|
|
957
|
-
const F =
|
|
955
|
+
for (const R of T) {
|
|
956
|
+
if (!R || typeof R != "object") continue;
|
|
957
|
+
const F = R;
|
|
958
958
|
o.push({
|
|
959
959
|
sentence_index: Number(F.sentence_index ?? 0),
|
|
960
960
|
text: String(F.text ?? ""),
|
|
@@ -965,28 +965,28 @@ function Or(e, t = kt, r = {}) {
|
|
|
965
965
|
});
|
|
966
966
|
}
|
|
967
967
|
}
|
|
968
|
-
|
|
969
|
-
} else if (
|
|
968
|
+
h(), b("metadata", C);
|
|
969
|
+
} else if (E.event === "error")
|
|
970
970
|
throw new Error(
|
|
971
|
-
String(
|
|
971
|
+
String(E.data.message ?? "avatar_ttsWithPoses stream error")
|
|
972
972
|
);
|
|
973
973
|
}
|
|
974
974
|
};
|
|
975
975
|
for (; ; ) {
|
|
976
|
-
const { done: v, value:
|
|
977
|
-
|
|
978
|
-
const
|
|
976
|
+
const { done: v, value: E } = await pe.read();
|
|
977
|
+
E && (fe += re.decode(E, { stream: !0 }));
|
|
978
|
+
const m = fe.split(`
|
|
979
979
|
|
|
980
980
|
`);
|
|
981
|
-
|
|
982
|
-
for (const
|
|
981
|
+
fe = m.pop() ?? "";
|
|
982
|
+
for (const T of m) await ue(T);
|
|
983
983
|
if (v) {
|
|
984
|
-
|
|
984
|
+
fe.trim() && await ue(fe.trim()), _.markStreamComplete(s), b("bot_stopped", C);
|
|
985
985
|
break;
|
|
986
986
|
}
|
|
987
987
|
}
|
|
988
|
-
} catch (
|
|
989
|
-
throw console.error("[avatarTtsLipsync]",
|
|
988
|
+
} catch (j) {
|
|
989
|
+
throw console.error("[avatarTtsLipsync]", j), B(), e("error"), j;
|
|
990
990
|
}
|
|
991
991
|
},
|
|
992
992
|
stop: B,
|
|
@@ -999,7 +999,7 @@ function Or(e, t = kt, r = {}) {
|
|
|
999
999
|
isWarmingUp: () => _.isWarmingUp(),
|
|
1000
1000
|
releaseWarmupHold: () => _.releaseWarmupHold(),
|
|
1001
1001
|
setLipsyncWarmupHold: (C, k) => {
|
|
1002
|
-
k && (
|
|
1002
|
+
k && (M = k), _.setLipsyncWarmupHoldEnabled(C);
|
|
1003
1003
|
},
|
|
1004
1004
|
getVoiceStream: () => _.getVoiceStream(),
|
|
1005
1005
|
setPlaybackSpeed: (C) => {
|
|
@@ -1053,13 +1053,13 @@ function ti(e) {
|
|
|
1053
1053
|
throw new Error(
|
|
1054
1054
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1055
1055
|
);
|
|
1056
|
-
const r = e.apiBase ??
|
|
1056
|
+
const r = e.apiBase ?? St, n = new URL(`${ei(r)}/ws/voice`);
|
|
1057
1057
|
n.searchParams.set("authToken", t), n.searchParams.set("tenant", "aiTwin");
|
|
1058
1058
|
const s = e.voiceId?.trim();
|
|
1059
1059
|
s && Zs(s) && n.searchParams.set("voiceId", s);
|
|
1060
1060
|
const i = e.personaId?.trim();
|
|
1061
1061
|
i && n.searchParams.set("personaId", i);
|
|
1062
|
-
const o = e.speakingRate ??
|
|
1062
|
+
const o = e.speakingRate ?? Vt;
|
|
1063
1063
|
return n.searchParams.set(
|
|
1064
1064
|
"speaking_rate",
|
|
1065
1065
|
String(Math.max(fr, Math.min(dr, o)))
|
|
@@ -1095,57 +1095,59 @@ function ni(e) {
|
|
|
1095
1095
|
}
|
|
1096
1096
|
function si(e, t = {}) {
|
|
1097
1097
|
const r = [], n = [], s = [], i = [];
|
|
1098
|
-
let o = "", a = "neutral", u =
|
|
1099
|
-
const
|
|
1100
|
-
let _ = !1,
|
|
1098
|
+
let o = "", a = "neutral", u = it, l = !1, f = null, c = null, d = { ...t }, g = 0, S = null;
|
|
1099
|
+
const h = /* @__PURE__ */ new Set(), M = [];
|
|
1100
|
+
let _ = !1, D = null, w = !0, b = "default";
|
|
1101
1101
|
const L = /* @__PURE__ */ new Set();
|
|
1102
|
-
let B = null, G = 0, C = !1, k = null;
|
|
1103
|
-
const
|
|
1102
|
+
let B = null, G = 0, C = !1, k = null, P = !1;
|
|
1103
|
+
const N = () => {
|
|
1104
1104
|
k != null && (clearTimeout(k), k = null);
|
|
1105
|
-
},
|
|
1106
|
-
let
|
|
1107
|
-
const
|
|
1105
|
+
}, I = () => h.forEach((p) => p());
|
|
1106
|
+
let te = () => !1;
|
|
1107
|
+
const V = yn(
|
|
1108
1108
|
{
|
|
1109
1109
|
onSpeakingStart: () => e("speaking"),
|
|
1110
|
-
onSpeakingDone: () =>
|
|
1111
|
-
|
|
1112
|
-
|
|
1110
|
+
onSpeakingDone: () => {
|
|
1111
|
+
P = !1, e("done");
|
|
1112
|
+
},
|
|
1113
|
+
onNotify: I,
|
|
1114
|
+
shouldHoldForWarmup: () => te()
|
|
1113
1115
|
},
|
|
1114
1116
|
u
|
|
1115
|
-
),
|
|
1116
|
-
if (
|
|
1117
|
+
), J = () => {
|
|
1118
|
+
if (D) return D;
|
|
1117
1119
|
const p = new MessageChannel();
|
|
1118
1120
|
return p.port1.onmessage = () => {
|
|
1119
|
-
const x =
|
|
1120
|
-
x !== void 0 &&
|
|
1121
|
-
},
|
|
1122
|
-
},
|
|
1123
|
-
|
|
1124
|
-
},
|
|
1121
|
+
const x = M.shift();
|
|
1122
|
+
x !== void 0 && Z(x), M.length > 0 ? p.port2.postMessage(null) : _ = !1;
|
|
1123
|
+
}, D = p, p;
|
|
1124
|
+
}, j = (p) => {
|
|
1125
|
+
M.push(p), !_ && (_ = !0, J().port2.postMessage(null));
|
|
1126
|
+
}, X = () => V.getPlaybackElapsedMs(), pe = (p, x = o) => {
|
|
1125
1127
|
if (!d.onLipsyncDebug) return;
|
|
1126
|
-
const
|
|
1128
|
+
const z = X(), ne = r;
|
|
1127
1129
|
d.onLipsyncDebug({
|
|
1128
1130
|
event: p,
|
|
1129
1131
|
spokenText: x,
|
|
1130
1132
|
mood: a,
|
|
1131
|
-
playbackAnchorPerf:
|
|
1132
|
-
playbackElapsedMs:
|
|
1133
|
-
queueLength:
|
|
1134
|
-
activeViseme:
|
|
1135
|
-
segments: i.map((
|
|
1136
|
-
...
|
|
1137
|
-
visemes: [...
|
|
1133
|
+
playbackAnchorPerf: V.getPlaybackStartPerf(),
|
|
1134
|
+
playbackElapsedMs: z,
|
|
1135
|
+
queueLength: ne.length,
|
|
1136
|
+
activeViseme: Ut(ne, z),
|
|
1137
|
+
segments: i.map((ce) => ({
|
|
1138
|
+
...ce,
|
|
1139
|
+
visemes: [...ce.visemes]
|
|
1138
1140
|
}))
|
|
1139
1141
|
});
|
|
1140
|
-
},
|
|
1142
|
+
}, re = (p, x) => {
|
|
1141
1143
|
d.onLipsyncDebug && (S = { event: p, spokenText: x }, g === 0 && (g = requestAnimationFrame(() => {
|
|
1142
1144
|
g = 0;
|
|
1143
|
-
const
|
|
1144
|
-
S = null,
|
|
1145
|
+
const z = S;
|
|
1146
|
+
S = null, z && pe(z.event, z.spokenText);
|
|
1145
1147
|
})));
|
|
1146
|
-
},
|
|
1147
|
-
w = !0, L.clear(),
|
|
1148
|
-
},
|
|
1148
|
+
}, fe = () => {
|
|
1149
|
+
w = !0, L.clear(), V.clearAborted();
|
|
1150
|
+
}, de = () => {
|
|
1149
1151
|
const p = ni(f);
|
|
1150
1152
|
if (p) {
|
|
1151
1153
|
b = `bot-${Date.now()}`, p.interruptedTrackIds = { [b]: !0 };
|
|
@@ -1159,223 +1161,225 @@ function si(e, t = {}) {
|
|
|
1159
1161
|
x?.interrupt?.();
|
|
1160
1162
|
} catch {
|
|
1161
1163
|
}
|
|
1162
|
-
},
|
|
1164
|
+
}, ue = (p) => {
|
|
1165
|
+
if (P && V.isSpeaking())
|
|
1166
|
+
return !0;
|
|
1163
1167
|
const x = p.context_id?.trim();
|
|
1164
1168
|
return x && L.has(x) ? !0 : w ? !1 : !(p.type === "avatar_metadata" || Xt(p));
|
|
1165
|
-
},
|
|
1166
|
-
w = !1;
|
|
1169
|
+
}, v = (p) => {
|
|
1170
|
+
w = !1, P = !1;
|
|
1167
1171
|
const x = p.context_id?.trim();
|
|
1168
|
-
x && L.add(x),
|
|
1169
|
-
},
|
|
1172
|
+
x && L.add(x), N(), C = !1, M.length = 0, _ = !1, B?.abort(), B = null, G += 1, de(), V.bargeIn(), E(), e("idle"), re("interrupt"), I();
|
|
1173
|
+
}, E = () => {
|
|
1170
1174
|
r.length = 0, n.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
|
|
1175
|
+
}, m = () => {
|
|
1176
|
+
V.stop(), E(), re("reset"), I();
|
|
1171
1177
|
}, T = () => {
|
|
1172
|
-
|
|
1173
|
-
},
|
|
1174
|
-
T(), e("idle"), D();
|
|
1175
|
-
}, E = (p, x) => {
|
|
1178
|
+
m(), e("idle"), I();
|
|
1179
|
+
}, R = (p, x) => {
|
|
1176
1180
|
typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), Array.isArray(p.sentence_emotions) && p.sentence_emotions.length > 0 && (x && (s.length = 0), s.push(
|
|
1177
1181
|
...Yt(p.sentence_emotions, a)
|
|
1178
1182
|
));
|
|
1179
|
-
},
|
|
1180
|
-
if (
|
|
1183
|
+
}, F = (p) => {
|
|
1184
|
+
if (ue({ ...p, type: "avatar_metadata" }))
|
|
1181
1185
|
return;
|
|
1182
|
-
|
|
1186
|
+
fe(), C = !0;
|
|
1183
1187
|
const x = String(p.spoken_text ?? p.text ?? "").trim();
|
|
1184
|
-
x && (o = x),
|
|
1188
|
+
x && (o = x), V.resetForNewStream(u), typeof p.mood == "string" && p.mood.trim() && (a = p.mood.trim()), s.length = 0, s.push(
|
|
1185
1189
|
...Yt(p.sentence_emotions, a)
|
|
1186
|
-
), Array.isArray(p.gestures) && p.gestures,
|
|
1187
|
-
},
|
|
1190
|
+
), Array.isArray(p.gestures) && p.gestures, re("metadata", x), I();
|
|
1191
|
+
}, A = (p, x, z, ne) => {
|
|
1188
1192
|
if (!d.onLipsyncDebug) return;
|
|
1189
|
-
const
|
|
1190
|
-
(
|
|
1193
|
+
const ce = r.slice(z), Te = ne.filter(
|
|
1194
|
+
(me) => String(me.symbol ?? me.viseme ?? "").trim()
|
|
1191
1195
|
);
|
|
1192
1196
|
i.push({
|
|
1193
1197
|
spokenText: x,
|
|
1194
|
-
audioOffsetMs:
|
|
1198
|
+
audioOffsetMs: ce[0]?.vtime ?? 0,
|
|
1195
1199
|
isNewSegment: !!p.is_new_segment,
|
|
1196
1200
|
chunkDurationMs: p.chunk_duration_ms != null ? Number(p.chunk_duration_ms) : null,
|
|
1197
1201
|
receivedAtMs: performance.now(),
|
|
1198
|
-
visemes:
|
|
1199
|
-
const
|
|
1202
|
+
visemes: ce.map((me, he) => {
|
|
1203
|
+
const _e = Te[he];
|
|
1200
1204
|
return {
|
|
1201
|
-
rawSymbol: String(
|
|
1202
|
-
viseme:
|
|
1203
|
-
startSec: Number(
|
|
1204
|
-
durationSec: Number(
|
|
1205
|
-
vtimeMs:
|
|
1206
|
-
vdurationMs:
|
|
1205
|
+
rawSymbol: String(_e?.symbol ?? _e?.viseme ?? me.viseme).trim(),
|
|
1206
|
+
viseme: me.viseme,
|
|
1207
|
+
startSec: Number(_e?.start ?? 0),
|
|
1208
|
+
durationSec: Number(_e?.duration ?? 0),
|
|
1209
|
+
vtimeMs: me.vtime,
|
|
1210
|
+
vdurationMs: me.vduration
|
|
1207
1211
|
};
|
|
1208
1212
|
})
|
|
1209
1213
|
});
|
|
1210
|
-
},
|
|
1211
|
-
if (
|
|
1212
|
-
|
|
1213
|
-
const x = String(p.spoken_text ?? p.text ?? "").trim(),
|
|
1214
|
-
|
|
1215
|
-
const
|
|
1216
|
-
|
|
1214
|
+
}, $ = (p) => {
|
|
1215
|
+
if (ue(p)) return;
|
|
1216
|
+
N(), Xt(p) && fe();
|
|
1217
|
+
const x = String(p.spoken_text ?? p.text ?? "").trim(), z = Xt(p), ne = p.visemes ?? [], ce = p.words ?? [], Te = String(p.chunk ?? "").trim(), me = C;
|
|
1218
|
+
me && (C = !1), x && (o = x), R(p, z), me ? V.resetForNewStream(u) : z && V.resumeBotStream();
|
|
1219
|
+
const he = r.length;
|
|
1220
|
+
V.playAudioChunk(
|
|
1217
1221
|
r,
|
|
1218
1222
|
n,
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
+
Te,
|
|
1224
|
+
ne,
|
|
1225
|
+
ce,
|
|
1226
|
+
z,
|
|
1223
1227
|
{
|
|
1224
1228
|
sampleRate: p.sample_rate,
|
|
1225
|
-
newStream:
|
|
1229
|
+
newStream: me,
|
|
1226
1230
|
onNewStream: () => {
|
|
1227
1231
|
i.length = 0;
|
|
1228
1232
|
}
|
|
1229
1233
|
}
|
|
1230
1234
|
).then(() => {
|
|
1231
|
-
|
|
1235
|
+
A(p, x, he, ne), re("audio_chunk", x);
|
|
1232
1236
|
});
|
|
1233
|
-
},
|
|
1234
|
-
if (
|
|
1235
|
-
(p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) &&
|
|
1237
|
+
}, Y = (p) => {
|
|
1238
|
+
if (ue(p)) return;
|
|
1239
|
+
(p.is_new_segment || Number(p.audio_offset_ms ?? -1) === 0) && fe(), console.warn(
|
|
1236
1240
|
"[realtimeVoice] avatar_lipsync is deprecated — expect avatar_audio_chunk"
|
|
1237
1241
|
);
|
|
1238
1242
|
const x = String(p.spoken_text ?? p.text ?? "").trim();
|
|
1239
|
-
x && (o = x),
|
|
1240
|
-
const
|
|
1241
|
-
|
|
1243
|
+
x && (o = x), R(p, !!p.is_new_segment);
|
|
1244
|
+
const z = r.length;
|
|
1245
|
+
V.queueTimingsOnly(
|
|
1242
1246
|
r,
|
|
1243
1247
|
n,
|
|
1244
1248
|
p.visemes ?? [],
|
|
1245
1249
|
p.words ?? [],
|
|
1246
1250
|
!!p.is_new_segment
|
|
1247
|
-
),
|
|
1251
|
+
), A(
|
|
1248
1252
|
p,
|
|
1249
1253
|
x,
|
|
1250
|
-
|
|
1254
|
+
z,
|
|
1251
1255
|
p.visemes ?? []
|
|
1252
|
-
),
|
|
1253
|
-
},
|
|
1256
|
+
), re("lipsync", x), I();
|
|
1257
|
+
}, Q = async (p) => {
|
|
1254
1258
|
const x = String(p.text ?? "").trim();
|
|
1255
1259
|
if (!x) return;
|
|
1256
|
-
const
|
|
1257
|
-
if (!
|
|
1260
|
+
const z = d.authToken?.trim();
|
|
1261
|
+
if (!z) {
|
|
1258
1262
|
console.error("[realtimeVoice] avatar_speak requires authToken");
|
|
1259
1263
|
return;
|
|
1260
1264
|
}
|
|
1261
1265
|
B?.abort();
|
|
1262
|
-
const
|
|
1263
|
-
B =
|
|
1264
|
-
const
|
|
1265
|
-
|
|
1266
|
-
const
|
|
1266
|
+
const ne = new AbortController();
|
|
1267
|
+
B = ne;
|
|
1268
|
+
const ce = ++G;
|
|
1269
|
+
fe(), V.resetForNewStream(u), o = x;
|
|
1270
|
+
const me = `${(d.apiBase ?? St).replace(/\/$/, "")}/avatar_ttsWithPoses`, he = d.voiceId?.trim() || Sn, _e = d.speakingRate ?? Vt, ct = Math.max(
|
|
1267
1271
|
fr,
|
|
1268
|
-
Math.min(dr,
|
|
1269
|
-
),
|
|
1272
|
+
Math.min(dr, _e)
|
|
1273
|
+
), Ce = {
|
|
1270
1274
|
user_query: x,
|
|
1271
1275
|
ttsEngineId: u,
|
|
1272
|
-
speakingRate:
|
|
1276
|
+
speakingRate: ct,
|
|
1273
1277
|
tenant: "aiTwin"
|
|
1274
1278
|
};
|
|
1275
|
-
an.has(u) && (
|
|
1279
|
+
an.has(u) && (Ce.voice_id = he);
|
|
1276
1280
|
try {
|
|
1277
|
-
const
|
|
1281
|
+
const Oe = await fetch(me, {
|
|
1278
1282
|
method: "POST",
|
|
1279
1283
|
headers: {
|
|
1280
1284
|
"Content-Type": "application/json",
|
|
1281
|
-
Authorization: `Bearer ${
|
|
1285
|
+
Authorization: `Bearer ${z}`
|
|
1282
1286
|
},
|
|
1283
|
-
body: JSON.stringify(
|
|
1284
|
-
signal:
|
|
1287
|
+
body: JSON.stringify(Ce),
|
|
1288
|
+
signal: ne.signal
|
|
1285
1289
|
});
|
|
1286
|
-
if (!
|
|
1287
|
-
throw new Error(`avatar_ttsWithPoses failed (${
|
|
1288
|
-
const
|
|
1289
|
-
if (!
|
|
1290
|
-
const
|
|
1291
|
-
let
|
|
1292
|
-
const
|
|
1293
|
-
if (
|
|
1290
|
+
if (!Oe.ok)
|
|
1291
|
+
throw new Error(`avatar_ttsWithPoses failed (${Oe.status})`);
|
|
1292
|
+
const Ue = Oe.body;
|
|
1293
|
+
if (!Ue) throw new Error("No response body");
|
|
1294
|
+
const ut = Ue.getReader(), kt = new TextDecoder();
|
|
1295
|
+
let ie = "", lt = !0;
|
|
1296
|
+
const ft = async (je) => {
|
|
1297
|
+
if (ce !== G || ne.signal.aborted || !w)
|
|
1294
1298
|
return;
|
|
1295
|
-
const
|
|
1296
|
-
if (
|
|
1297
|
-
if (
|
|
1298
|
-
const
|
|
1299
|
-
if (
|
|
1300
|
-
const
|
|
1301
|
-
|
|
1299
|
+
const le = dn(je);
|
|
1300
|
+
if (le) {
|
|
1301
|
+
if (le.event === "audio") {
|
|
1302
|
+
const ve = le.data.chunk, we = le.data.visemes ?? [], Ye = le.data.words ?? [], Ee = le.data.is_new_segment ?? !1, Ve = le.data.sample_rate;
|
|
1303
|
+
if (ve) {
|
|
1304
|
+
const ee = lt;
|
|
1305
|
+
lt = !1, await V.playAudioChunk(
|
|
1302
1306
|
r,
|
|
1303
1307
|
n,
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
{ sampleRate:
|
|
1308
|
+
ve,
|
|
1309
|
+
we,
|
|
1310
|
+
Ye,
|
|
1311
|
+
Ee,
|
|
1312
|
+
{ sampleRate: Ve, newStream: ee }
|
|
1309
1313
|
);
|
|
1310
|
-
} else (
|
|
1314
|
+
} else (we.length > 0 || Ye.length > 0) && V.queueTimingsOnly(
|
|
1311
1315
|
r,
|
|
1312
1316
|
n,
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1317
|
+
we,
|
|
1318
|
+
Ye,
|
|
1319
|
+
Ee
|
|
1316
1320
|
);
|
|
1317
|
-
} else if (
|
|
1318
|
-
const
|
|
1319
|
-
typeof
|
|
1320
|
-
const
|
|
1321
|
-
Array.isArray(
|
|
1322
|
-
...Yt(
|
|
1323
|
-
)),
|
|
1324
|
-
} else if (
|
|
1321
|
+
} else if (le.event === "metadata") {
|
|
1322
|
+
const ve = le.data.mood;
|
|
1323
|
+
typeof ve == "string" && ve.trim() && (a = ve.trim());
|
|
1324
|
+
const we = le.data.sentence_emotions;
|
|
1325
|
+
Array.isArray(we) && (s.length = 0, s.push(
|
|
1326
|
+
...Yt(we, a)
|
|
1327
|
+
)), I();
|
|
1328
|
+
} else if (le.event === "error")
|
|
1325
1329
|
throw new Error(
|
|
1326
|
-
String(
|
|
1330
|
+
String(le.data.message ?? "avatar_ttsWithPoses stream error")
|
|
1327
1331
|
);
|
|
1328
1332
|
}
|
|
1329
1333
|
};
|
|
1330
|
-
for (; !(
|
|
1331
|
-
const { done:
|
|
1332
|
-
|
|
1333
|
-
const
|
|
1334
|
+
for (; !(ce !== G || ne.signal.aborted || !w); ) {
|
|
1335
|
+
const { done: je, value: le } = await ut.read();
|
|
1336
|
+
le && (ie += kt.decode(le, { stream: !0 }));
|
|
1337
|
+
const ve = ie.split(`
|
|
1334
1338
|
|
|
1335
1339
|
`);
|
|
1336
|
-
|
|
1337
|
-
for (const
|
|
1338
|
-
if (
|
|
1339
|
-
|
|
1340
|
+
ie = ve.pop() ?? "";
|
|
1341
|
+
for (const we of ve) await ft(we);
|
|
1342
|
+
if (je) {
|
|
1343
|
+
ie.trim() && await ft(ie.trim()), ce === G && !ne.signal.aborted && w && V.markStreamComplete(r);
|
|
1340
1344
|
break;
|
|
1341
1345
|
}
|
|
1342
1346
|
}
|
|
1343
|
-
} catch (
|
|
1344
|
-
if (
|
|
1345
|
-
console.error("[realtimeVoice] avatar_speak failed:",
|
|
1347
|
+
} catch (Oe) {
|
|
1348
|
+
if (ne.signal.aborted || !w) return;
|
|
1349
|
+
console.error("[realtimeVoice] avatar_speak failed:", Oe), e("error"), I();
|
|
1346
1350
|
} finally {
|
|
1347
|
-
B ===
|
|
1351
|
+
B === ne && (B = null);
|
|
1348
1352
|
}
|
|
1349
|
-
},
|
|
1353
|
+
}, Z = (p) => {
|
|
1350
1354
|
const x = ri(p);
|
|
1351
1355
|
if (!x) {
|
|
1352
1356
|
console.warn("[realtimeVoice] server message with no payload", p);
|
|
1353
1357
|
return;
|
|
1354
1358
|
}
|
|
1355
|
-
const
|
|
1356
|
-
switch (
|
|
1359
|
+
const z = String(x.type ?? "unknown");
|
|
1360
|
+
switch (z !== "avatar_metadata" && z !== "avatar_audio_chunk" && z !== "avatar_lipsync" && z !== "avatar_interrupt" && z !== "error" && console.debug("[realtimeVoice] server message", z, x), z) {
|
|
1357
1361
|
case "avatar_metadata":
|
|
1358
|
-
|
|
1362
|
+
F(x);
|
|
1359
1363
|
break;
|
|
1360
1364
|
case "avatar_audio_chunk":
|
|
1361
|
-
|
|
1365
|
+
$(x);
|
|
1362
1366
|
break;
|
|
1363
1367
|
case "avatar_lipsync":
|
|
1364
|
-
|
|
1368
|
+
Y(x);
|
|
1365
1369
|
break;
|
|
1366
1370
|
case "avatar_interrupt":
|
|
1367
|
-
|
|
1371
|
+
v(x);
|
|
1368
1372
|
break;
|
|
1369
1373
|
case "error": {
|
|
1370
|
-
const
|
|
1371
|
-
console.error("[realtimeVoice] server error:",
|
|
1374
|
+
const ne = String(x.message ?? "Voice session error");
|
|
1375
|
+
console.error("[realtimeVoice] server error:", ne), e("error"), I();
|
|
1372
1376
|
break;
|
|
1373
1377
|
}
|
|
1374
1378
|
case "avatar_speak":
|
|
1375
|
-
|
|
1379
|
+
Q(x);
|
|
1376
1380
|
break;
|
|
1377
1381
|
}
|
|
1378
|
-
},
|
|
1382
|
+
}, be = () => f || (c = new Js(), f = new qn({
|
|
1379
1383
|
transport: new Kn({
|
|
1380
1384
|
mediaManager: c,
|
|
1381
1385
|
serializer: new Xs(),
|
|
@@ -1386,34 +1390,33 @@ function si(e, t = {}) {
|
|
|
1386
1390
|
enableMic: !0,
|
|
1387
1391
|
callbacks: {
|
|
1388
1392
|
onBotReady: () => {
|
|
1389
|
-
l = !0, e("idle"),
|
|
1393
|
+
l = !0, e("idle"), I();
|
|
1390
1394
|
},
|
|
1391
1395
|
onDisconnected: () => {
|
|
1392
|
-
l = !1,
|
|
1396
|
+
l = !1, T();
|
|
1393
1397
|
},
|
|
1394
1398
|
onError: (p) => {
|
|
1395
1399
|
const x = typeof p == "object" && p !== null && "data" in p ? String(p.data ?? p) : String(p);
|
|
1396
|
-
console.error("[realtimeVoice]", x, p), e("error"),
|
|
1400
|
+
console.error("[realtimeVoice]", x, p), e("error"), I();
|
|
1397
1401
|
},
|
|
1398
1402
|
onTransportStateChanged: (p) => {
|
|
1399
|
-
p === "error" && (e("error"),
|
|
1403
|
+
p === "error" && (e("error"), I());
|
|
1400
1404
|
},
|
|
1401
1405
|
onServerMessage: (p) => {
|
|
1402
|
-
|
|
1406
|
+
j(p);
|
|
1403
1407
|
},
|
|
1404
1408
|
onUserStartedSpeaking: () => {
|
|
1405
|
-
le({});
|
|
1406
1409
|
},
|
|
1407
1410
|
onBotStartedSpeaking: () => {
|
|
1408
|
-
|
|
1411
|
+
fe(), re("bot_started");
|
|
1409
1412
|
},
|
|
1410
1413
|
onBotStoppedSpeaking: () => {
|
|
1411
|
-
w && (
|
|
1412
|
-
k = null, w && (
|
|
1414
|
+
w && (N(), k = setTimeout(() => {
|
|
1415
|
+
k = null, w && (V.markStreamComplete(r), re("bot_stopped"));
|
|
1413
1416
|
}, 450));
|
|
1414
1417
|
},
|
|
1415
1418
|
onUserTranscript: (p) => {
|
|
1416
|
-
d.onUserTranscript?.(p.text, !!p.final);
|
|
1419
|
+
String(p.text ?? ""), d.onUserTranscript?.(p.text, !!p.final);
|
|
1417
1420
|
},
|
|
1418
1421
|
onBotOutput: (p) => {
|
|
1419
1422
|
d.onBotOutput?.(p.text);
|
|
@@ -1424,21 +1427,21 @@ function si(e, t = {}) {
|
|
|
1424
1427
|
setDeveloperToken: (p) => {
|
|
1425
1428
|
},
|
|
1426
1429
|
setTtsEngineId: (p) => {
|
|
1427
|
-
u = p,
|
|
1430
|
+
u = p, V.setStreamTtsEngineId(p);
|
|
1428
1431
|
},
|
|
1429
1432
|
getTtsEngineId: () => u,
|
|
1430
1433
|
speak: async (p, x) => {
|
|
1431
|
-
const
|
|
1432
|
-
if (
|
|
1434
|
+
const z = p.trim();
|
|
1435
|
+
if (z) {
|
|
1433
1436
|
if (!f || !l)
|
|
1434
1437
|
throw new Error(
|
|
1435
1438
|
"Realtime voice is not connected. Call connect() first."
|
|
1436
1439
|
);
|
|
1437
|
-
|
|
1440
|
+
m(), await f.sendText(z);
|
|
1438
1441
|
}
|
|
1439
1442
|
},
|
|
1440
1443
|
stop: () => {
|
|
1441
|
-
B?.abort(), B = null, G += 1,
|
|
1444
|
+
B?.abort(), B = null, G += 1, fe(), m(), e("idle"), I();
|
|
1442
1445
|
},
|
|
1443
1446
|
connect: async (p) => {
|
|
1444
1447
|
if (p && (d = { ...d, ...p }), !d.authToken?.trim())
|
|
@@ -1446,49 +1449,49 @@ function si(e, t = {}) {
|
|
|
1446
1449
|
"Voice connect requires authToken (same JWT as SSE Authorization Bearer)."
|
|
1447
1450
|
);
|
|
1448
1451
|
e("loading");
|
|
1449
|
-
const x =
|
|
1452
|
+
const x = be();
|
|
1450
1453
|
await x.initDevices();
|
|
1451
|
-
const
|
|
1452
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1454
|
+
const z = ti(d);
|
|
1455
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", z);
|
|
1453
1456
|
try {
|
|
1454
|
-
await x.connect({ wsUrl:
|
|
1455
|
-
} catch (
|
|
1456
|
-
l = !1, e("error"),
|
|
1457
|
-
const
|
|
1458
|
-
throw new Error(`${
|
|
1457
|
+
await x.connect({ wsUrl: z });
|
|
1458
|
+
} catch (ne) {
|
|
1459
|
+
l = !1, e("error"), I();
|
|
1460
|
+
const ce = ne instanceof Error ? ne.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
|
|
1461
|
+
throw new Error(`${ce} — ${z}`);
|
|
1459
1462
|
}
|
|
1460
|
-
l = !0, e("idle"),
|
|
1463
|
+
l = !0, e("idle"), I();
|
|
1461
1464
|
},
|
|
1462
1465
|
disconnect: async () => {
|
|
1463
|
-
if (
|
|
1466
|
+
if (N(), C = !1, M.length = 0, _ = !1, B?.abort(), B = null, G += 1, fe(), f)
|
|
1464
1467
|
try {
|
|
1465
1468
|
await f.disconnect();
|
|
1466
1469
|
} catch (p) {
|
|
1467
1470
|
console.error("[realtimeVoice] disconnect failed:", p);
|
|
1468
1471
|
}
|
|
1469
|
-
l = !1,
|
|
1472
|
+
l = !1, T();
|
|
1470
1473
|
},
|
|
1471
1474
|
isConnected: () => l,
|
|
1472
1475
|
unlockAudio: async () => {
|
|
1473
|
-
await
|
|
1476
|
+
await V.primeAudioContext();
|
|
1474
1477
|
},
|
|
1475
1478
|
getVisemeQueue: () => r,
|
|
1476
1479
|
getWordQueue: () => n,
|
|
1477
1480
|
getSentenceEmotions: () => s,
|
|
1478
1481
|
getStreamMood: () => a,
|
|
1479
|
-
getPlaybackElapsedMs:
|
|
1480
|
-
isSpeaking: () =>
|
|
1481
|
-
isWarmingUp: () =>
|
|
1482
|
-
releaseWarmupHold: () =>
|
|
1482
|
+
getPlaybackElapsedMs: X,
|
|
1483
|
+
isSpeaking: () => V.isSpeaking(),
|
|
1484
|
+
isWarmingUp: () => V.isWarmingUp(),
|
|
1485
|
+
releaseWarmupHold: () => V.releaseWarmupHold(),
|
|
1483
1486
|
setLipsyncWarmupHold: (p, x) => {
|
|
1484
|
-
x && (
|
|
1487
|
+
x && (te = x), V.setLipsyncWarmupHoldEnabled(p);
|
|
1485
1488
|
},
|
|
1486
|
-
getVoiceStream: () =>
|
|
1489
|
+
getVoiceStream: () => V.getVoiceStream(),
|
|
1487
1490
|
setPlaybackSpeed: (p) => {
|
|
1488
|
-
|
|
1491
|
+
V.setPlaybackSpeed(p);
|
|
1489
1492
|
},
|
|
1490
|
-
getPlaybackSpeed: () =>
|
|
1491
|
-
subscribe: (p) => (
|
|
1493
|
+
getPlaybackSpeed: () => V.getPlaybackSpeed(),
|
|
1494
|
+
subscribe: (p) => (h.add(p), () => h.delete(p))
|
|
1492
1495
|
};
|
|
1493
1496
|
}
|
|
1494
1497
|
function Tn(e, t, r) {
|
|
@@ -1509,7 +1512,7 @@ function En(e, t) {
|
|
|
1509
1512
|
function An(e) {
|
|
1510
1513
|
return e ? (e.w ?? 0) > 0 && (e.h ?? 0) > 0 : !1;
|
|
1511
1514
|
}
|
|
1512
|
-
async function
|
|
1515
|
+
async function at(e, t) {
|
|
1513
1516
|
const r = await fetch(e);
|
|
1514
1517
|
if (!r.ok) throw new Error(`Failed to load encrypted asset: ${e}`);
|
|
1515
1518
|
const n = await r.arrayBuffer();
|
|
@@ -1517,7 +1520,7 @@ async function ct(e, t) {
|
|
|
1517
1520
|
}
|
|
1518
1521
|
async function Pn(e, t) {
|
|
1519
1522
|
if (!t) throw new Error("Missing asset key for encrypted JSON");
|
|
1520
|
-
const r = await
|
|
1523
|
+
const r = await at(e, t), n = new TextDecoder().decode(r);
|
|
1521
1524
|
return JSON.parse(n);
|
|
1522
1525
|
}
|
|
1523
1526
|
async function ii(e) {
|
|
@@ -1556,16 +1559,16 @@ function ui(e) {
|
|
|
1556
1559
|
}
|
|
1557
1560
|
async function li(e) {
|
|
1558
1561
|
const t = As();
|
|
1559
|
-
if (!
|
|
1562
|
+
if (!bt()) return t;
|
|
1560
1563
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
1561
|
-
const r = await
|
|
1564
|
+
const r = await at(t, e);
|
|
1562
1565
|
return ui(r);
|
|
1563
1566
|
}
|
|
1564
1567
|
function mr(e, t) {
|
|
1565
1568
|
return `${e}/${t}_minus_sil.png`;
|
|
1566
1569
|
}
|
|
1567
1570
|
const xn = 5;
|
|
1568
|
-
function
|
|
1571
|
+
function Wt(e) {
|
|
1569
1572
|
const t = e?.composite_threshold;
|
|
1570
1573
|
if (typeof t == "number" && t > 0) return t;
|
|
1571
1574
|
const r = e?.crop?.content_threshold;
|
|
@@ -1703,7 +1706,7 @@ function Ur(e, t) {
|
|
|
1703
1706
|
function Vr(e, t) {
|
|
1704
1707
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1705
1708
|
}
|
|
1706
|
-
function
|
|
1709
|
+
function vt(e) {
|
|
1707
1710
|
return `${e}_minus_sil.png`;
|
|
1708
1711
|
}
|
|
1709
1712
|
function hr(e, t) {
|
|
@@ -1712,7 +1715,7 @@ function hr(e, t) {
|
|
|
1712
1715
|
if (!r) return null;
|
|
1713
1716
|
const n = r[1].split("__")[1];
|
|
1714
1717
|
if (!n || n === "sil") return null;
|
|
1715
|
-
const s =
|
|
1718
|
+
const s = vt(n);
|
|
1716
1719
|
return t.has(s) ? s : null;
|
|
1717
1720
|
}
|
|
1718
1721
|
function In(e, t) {
|
|
@@ -1780,7 +1783,7 @@ function wr(e) {
|
|
|
1780
1783
|
function gr(e) {
|
|
1781
1784
|
return Si[e];
|
|
1782
1785
|
}
|
|
1783
|
-
function
|
|
1786
|
+
function Ke(e) {
|
|
1784
1787
|
return Math.max(vi, Math.min(rr, e));
|
|
1785
1788
|
}
|
|
1786
1789
|
function bi(e, t) {
|
|
@@ -1814,7 +1817,7 @@ const ki = {
|
|
|
1814
1817
|
disgust: "disgust",
|
|
1815
1818
|
disgusted: "disgust"
|
|
1816
1819
|
};
|
|
1817
|
-
function
|
|
1820
|
+
function et(e, t = "neutral") {
|
|
1818
1821
|
const r = String(e ?? "").trim().toLowerCase();
|
|
1819
1822
|
return r ? ki[r] ?? t : t;
|
|
1820
1823
|
}
|
|
@@ -1850,11 +1853,11 @@ function xi(e, t) {
|
|
|
1850
1853
|
return null;
|
|
1851
1854
|
}
|
|
1852
1855
|
function Ii(e) {
|
|
1853
|
-
const t =
|
|
1854
|
-
return t >= rr ? rr :
|
|
1856
|
+
const t = Ke(e);
|
|
1857
|
+
return t >= rr ? rr : Ke(t + Pi);
|
|
1855
1858
|
}
|
|
1856
1859
|
function Mi(e, t, r) {
|
|
1857
|
-
const n =
|
|
1860
|
+
const n = Ke(r);
|
|
1858
1861
|
return xi(t, e)?.emphasis ? Ii(n) : n;
|
|
1859
1862
|
}
|
|
1860
1863
|
function $r(e) {
|
|
@@ -1862,13 +1865,13 @@ function $r(e) {
|
|
|
1862
1865
|
const t = e.match(/^brow_(-?\d+)\//);
|
|
1863
1866
|
if (!t?.[1]) return null;
|
|
1864
1867
|
const r = Number.parseInt(t[1], 10);
|
|
1865
|
-
return Number.isFinite(r) ?
|
|
1868
|
+
return Number.isFinite(r) ? Ke(r) : null;
|
|
1866
1869
|
}
|
|
1867
|
-
function
|
|
1870
|
+
function yt(e, t) {
|
|
1868
1871
|
return e + Math.random() * (t - e);
|
|
1869
1872
|
}
|
|
1870
|
-
function
|
|
1871
|
-
return
|
|
1873
|
+
function Dt() {
|
|
1874
|
+
return yt(14, 32);
|
|
1872
1875
|
}
|
|
1873
1876
|
function Ri(e = {}) {
|
|
1874
1877
|
const {
|
|
@@ -1882,124 +1885,124 @@ function Ri(e = {}) {
|
|
|
1882
1885
|
postEmotionChangeDelayMs: u = 380,
|
|
1883
1886
|
minDwellMs: l = 550
|
|
1884
1887
|
} = e;
|
|
1885
|
-
let f = "neutral", c = "neutral", d = 0, g = 0, S = 0,
|
|
1888
|
+
let f = "neutral", c = "neutral", d = 0, g = 0, S = 0, h = {
|
|
1886
1889
|
kind: "idle",
|
|
1887
1890
|
nextBlinkAt: performance.now() + t
|
|
1888
|
-
},
|
|
1889
|
-
function
|
|
1890
|
-
_ = `${
|
|
1891
|
+
}, M = null, _ = "__eyes_open__|neutral|brow:0";
|
|
1892
|
+
function D(k = f) {
|
|
1893
|
+
_ = `${M ?? "__eyes_open__"}|${k}|brow:${g}`;
|
|
1891
1894
|
}
|
|
1892
1895
|
function w(k, P = f) {
|
|
1893
|
-
|
|
1894
|
-
const
|
|
1895
|
-
|
|
1896
|
+
M = k;
|
|
1897
|
+
const N = $r(k);
|
|
1898
|
+
N != null ? g = N : k == null && (g = 0), D(P);
|
|
1896
1899
|
}
|
|
1897
1900
|
function b(k) {
|
|
1898
1901
|
return Rn(k);
|
|
1899
1902
|
}
|
|
1900
|
-
function L(k, P,
|
|
1901
|
-
const
|
|
1902
|
-
if (d =
|
|
1903
|
-
w(b(
|
|
1903
|
+
function L(k, P, N) {
|
|
1904
|
+
const I = Ke(P), te = Ke(N);
|
|
1905
|
+
if (d = te, I === te) {
|
|
1906
|
+
w(b(te));
|
|
1904
1907
|
return;
|
|
1905
1908
|
}
|
|
1906
|
-
const
|
|
1907
|
-
...Ai(
|
|
1908
|
-
b(
|
|
1909
|
+
const V = [
|
|
1910
|
+
...Ai(I, te),
|
|
1911
|
+
b(te)
|
|
1909
1912
|
];
|
|
1910
|
-
|
|
1913
|
+
h = {
|
|
1911
1914
|
kind: "browBlend",
|
|
1912
|
-
paths:
|
|
1915
|
+
paths: V,
|
|
1913
1916
|
index: 0,
|
|
1914
|
-
holdUntil: k +
|
|
1915
|
-
targetBrow:
|
|
1916
|
-
}, w(
|
|
1917
|
+
holdUntil: k + Dt(),
|
|
1918
|
+
targetBrow: te
|
|
1919
|
+
}, w(V[0] ?? null);
|
|
1917
1920
|
}
|
|
1918
1921
|
function B(k, P) {
|
|
1919
|
-
|
|
1922
|
+
h = {
|
|
1920
1923
|
kind: "idle",
|
|
1921
|
-
nextBlinkAt: k +
|
|
1924
|
+
nextBlinkAt: k + yt(r, n)
|
|
1922
1925
|
}, c = P, w(b(d), P);
|
|
1923
1926
|
}
|
|
1924
|
-
function G(k, P,
|
|
1925
|
-
const
|
|
1926
|
-
|
|
1927
|
+
function G(k, P, N) {
|
|
1928
|
+
const I = N ? yi : Math.random() < a ? gi : _i;
|
|
1929
|
+
h = {
|
|
1927
1930
|
kind: "playing",
|
|
1928
|
-
paths: Ti(P,
|
|
1931
|
+
paths: Ti(P, I),
|
|
1929
1932
|
index: 0,
|
|
1930
|
-
holdUntil: k +
|
|
1933
|
+
holdUntil: k + Dt(),
|
|
1931
1934
|
after: "idle",
|
|
1932
1935
|
blinkEmotion: P
|
|
1933
|
-
}, c = P, w(
|
|
1936
|
+
}, c = P, w(h.paths[0] ?? null, P);
|
|
1934
1937
|
}
|
|
1935
1938
|
function C(k) {
|
|
1936
|
-
if (
|
|
1937
|
-
for (; k >=
|
|
1938
|
-
|
|
1939
|
-
const P =
|
|
1940
|
-
w(P), k >=
|
|
1939
|
+
if (h.kind === "browBlend") {
|
|
1940
|
+
for (; k >= h.holdUntil && h.index < h.paths.length - 1; )
|
|
1941
|
+
h.index += 1, h.holdUntil = k + Dt();
|
|
1942
|
+
const P = h.paths[h.index] ?? null;
|
|
1943
|
+
w(P), k >= h.holdUntil && h.index >= h.paths.length - 1 && (g = h.targetBrow, d = h.targetBrow, w(b(h.targetBrow)), h = {
|
|
1941
1944
|
kind: "idle",
|
|
1942
1945
|
nextBlinkAt: k + u
|
|
1943
1946
|
});
|
|
1944
1947
|
return;
|
|
1945
1948
|
}
|
|
1946
|
-
if (
|
|
1947
|
-
w(b(d), c), k >=
|
|
1949
|
+
if (h.kind === "idle") {
|
|
1950
|
+
w(b(d), c), k >= h.nextBlinkAt && G(k, c, !1);
|
|
1948
1951
|
return;
|
|
1949
1952
|
}
|
|
1950
|
-
if (
|
|
1951
|
-
w(b(d),
|
|
1953
|
+
if (h.kind === "doublePause") {
|
|
1954
|
+
w(b(d), h.blinkEmotion), k >= h.resumeAt && G(k, h.blinkEmotion, !0);
|
|
1952
1955
|
return;
|
|
1953
1956
|
}
|
|
1954
|
-
if (
|
|
1955
|
-
for (; k >=
|
|
1956
|
-
|
|
1957
|
-
if (w(
|
|
1958
|
-
if (
|
|
1957
|
+
if (h.kind === "playing") {
|
|
1958
|
+
for (; k >= h.holdUntil && h.index < h.paths.length - 1; )
|
|
1959
|
+
h.index += 1, h.holdUntil = k + Dt();
|
|
1960
|
+
if (w(h.paths[h.index] ?? null, h.blinkEmotion), k >= h.holdUntil && h.index >= h.paths.length - 1) {
|
|
1961
|
+
if (h.after === "resumeIdle") {
|
|
1959
1962
|
B(k + u, f);
|
|
1960
1963
|
return;
|
|
1961
1964
|
}
|
|
1962
|
-
if (
|
|
1963
|
-
|
|
1965
|
+
if (h.after === "doublePause") {
|
|
1966
|
+
h = {
|
|
1964
1967
|
kind: "doublePause",
|
|
1965
|
-
resumeAt: k +
|
|
1966
|
-
blinkEmotion:
|
|
1967
|
-
}, w(b(d),
|
|
1968
|
+
resumeAt: k + yt(i, o),
|
|
1969
|
+
blinkEmotion: h.blinkEmotion
|
|
1970
|
+
}, w(b(d), h.blinkEmotion);
|
|
1968
1971
|
return;
|
|
1969
1972
|
}
|
|
1970
|
-
if (
|
|
1971
|
-
|
|
1973
|
+
if (h.after === "idle" && Math.random() < s) {
|
|
1974
|
+
h = {
|
|
1972
1975
|
kind: "doublePause",
|
|
1973
|
-
resumeAt: k +
|
|
1974
|
-
blinkEmotion:
|
|
1975
|
-
}, w(b(d),
|
|
1976
|
+
resumeAt: k + yt(i, o),
|
|
1977
|
+
blinkEmotion: h.blinkEmotion
|
|
1978
|
+
}, w(b(d), h.blinkEmotion);
|
|
1976
1979
|
return;
|
|
1977
1980
|
}
|
|
1978
|
-
B(k,
|
|
1981
|
+
B(k, h.blinkEmotion);
|
|
1979
1982
|
}
|
|
1980
1983
|
}
|
|
1981
1984
|
}
|
|
1982
1985
|
return {
|
|
1983
1986
|
advance: C,
|
|
1984
1987
|
setTargetEmotion(k) {
|
|
1985
|
-
const P =
|
|
1988
|
+
const P = et(k, f);
|
|
1986
1989
|
if (P === f) return;
|
|
1987
|
-
const
|
|
1988
|
-
l > 0 && P !== f && !(f === "neutral" && P !== "neutral") &&
|
|
1990
|
+
const N = performance.now();
|
|
1991
|
+
l > 0 && P !== f && !(f === "neutral" && P !== "neutral") && N - S < l || (f = P, c = P, S = N);
|
|
1989
1992
|
},
|
|
1990
1993
|
setTargetEyebrow(k) {
|
|
1991
|
-
const P =
|
|
1994
|
+
const P = Ke(k);
|
|
1992
1995
|
if (P === d) return;
|
|
1993
|
-
const
|
|
1994
|
-
d = P, !(P ===
|
|
1996
|
+
const N = performance.now(), I = h.kind === "browBlend" ? $r(M) ?? g : g;
|
|
1997
|
+
d = P, !(P === I && h.kind !== "browBlend") && (h.kind === "playing" || h.kind === "doublePause" || L(N, I, P));
|
|
1995
1998
|
},
|
|
1996
1999
|
getTargetEmotion: () => f,
|
|
1997
2000
|
getTargetEyebrow: () => d,
|
|
1998
|
-
getExpressionPath: () =>
|
|
2001
|
+
getExpressionPath: () => M,
|
|
1999
2002
|
getDrawKey: () => _,
|
|
2000
2003
|
reset() {
|
|
2001
2004
|
f = "neutral", c = "neutral", d = 0, g = 0, S = 0, B(
|
|
2002
|
-
performance.now() +
|
|
2005
|
+
performance.now() + yt(r, n),
|
|
2003
2006
|
"neutral"
|
|
2004
2007
|
);
|
|
2005
2008
|
}
|
|
@@ -2074,18 +2077,18 @@ function Fi(e, t) {
|
|
|
2074
2077
|
return r.sort((n, s) => n.startMs - s.startMs);
|
|
2075
2078
|
}
|
|
2076
2079
|
function Li(e, t, r, n = "neutral") {
|
|
2077
|
-
const s =
|
|
2080
|
+
const s = et(n);
|
|
2078
2081
|
if (t.length === 0) return s;
|
|
2079
2082
|
if (r.length === 0 || e < r[0].wtime)
|
|
2080
|
-
return
|
|
2083
|
+
return et(t[0]?.emotion, s);
|
|
2081
2084
|
const i = Fi(t, r);
|
|
2082
2085
|
let o = null;
|
|
2083
2086
|
for (const l of i)
|
|
2084
2087
|
e >= l.startMs && e <= l.endMs && (o = l);
|
|
2085
2088
|
if (o)
|
|
2086
|
-
return
|
|
2089
|
+
return et(o.sentence.emotion, s);
|
|
2087
2090
|
const a = r[r.length - 1], u = a.wtime + a.wduration;
|
|
2088
|
-
return e > u + Bn ?
|
|
2091
|
+
return e > u + Bn ? et(
|
|
2089
2092
|
t[t.length - 1]?.emotion,
|
|
2090
2093
|
s
|
|
2091
2094
|
) : s;
|
|
@@ -2100,20 +2103,20 @@ function yr(e, t, r, n, s = xn) {
|
|
|
2100
2103
|
f.clearRect(0, 0, r, n), f.drawImage(c, 0, 0, r, n);
|
|
2101
2104
|
const d = f.getImageData(0, 0, r, n);
|
|
2102
2105
|
for (let g = 0; g < u.data.length; g += 4) {
|
|
2103
|
-
const S = d.data[g],
|
|
2104
|
-
Math.max(S,
|
|
2106
|
+
const S = d.data[g], h = d.data[g + 1], M = d.data[g + 2];
|
|
2107
|
+
Math.max(S, h, M) > s && (u.data[g] = S, u.data[g + 1] = h, u.data[g + 2] = M, u.data[g + 3] = 255);
|
|
2105
2108
|
}
|
|
2106
2109
|
}
|
|
2107
2110
|
return o.putImageData(u, 0, 0), i;
|
|
2108
2111
|
}
|
|
2109
|
-
let
|
|
2110
|
-
const
|
|
2112
|
+
let qe = null, nt = null;
|
|
2113
|
+
const Lt = /* @__PURE__ */ new Map();
|
|
2111
2114
|
function Oi() {
|
|
2112
|
-
|
|
2115
|
+
qe = null, nt = null, Lt.clear();
|
|
2113
2116
|
}
|
|
2114
2117
|
cn(Oi);
|
|
2115
2118
|
function Ni(e) {
|
|
2116
|
-
return e ??
|
|
2119
|
+
return e ?? nt ?? void 0;
|
|
2117
2120
|
}
|
|
2118
2121
|
function _r(e) {
|
|
2119
2122
|
return new Promise((t, r) => {
|
|
@@ -2122,9 +2125,9 @@ function _r(e) {
|
|
|
2122
2125
|
});
|
|
2123
2126
|
}
|
|
2124
2127
|
async function Ui(e) {
|
|
2125
|
-
return
|
|
2126
|
-
await
|
|
2127
|
-
) : _r(
|
|
2128
|
+
return bt() ? ci(
|
|
2129
|
+
await at(Ft(), e ?? "")
|
|
2130
|
+
) : _r(Ft());
|
|
2128
2131
|
}
|
|
2129
2132
|
async function qr(e, t, r, n) {
|
|
2130
2133
|
const s = r ? await Pn(e, n) : await fetch(e).then((l) => {
|
|
@@ -2133,7 +2136,7 @@ async function qr(e, t, r, n) {
|
|
|
2133
2136
|
}), i = s.sheets?.[0];
|
|
2134
2137
|
if (!i?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
2135
2138
|
const o = r ? await ai(
|
|
2136
|
-
await
|
|
2139
|
+
await at(
|
|
2137
2140
|
Mn(t, i.path, r),
|
|
2138
2141
|
n ?? ""
|
|
2139
2142
|
)
|
|
@@ -2146,19 +2149,19 @@ async function qr(e, t, r, n) {
|
|
|
2146
2149
|
return { atlas: o, atlasMeta: s, cellByPath: a, sheetByIndex: u, diffBase: t };
|
|
2147
2150
|
}
|
|
2148
2151
|
async function nr(e) {
|
|
2149
|
-
const t = Ni(e), r =
|
|
2152
|
+
const t = Ni(e), r = bt();
|
|
2150
2153
|
if (r && !t)
|
|
2151
2154
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
2152
|
-
if (
|
|
2153
|
-
const i = await
|
|
2155
|
+
if (qe && (!r || nt === (t ?? null))) {
|
|
2156
|
+
const i = await qe;
|
|
2154
2157
|
return {
|
|
2155
|
-
...
|
|
2158
|
+
...st(i),
|
|
2156
2159
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
2157
2160
|
};
|
|
2158
2161
|
}
|
|
2159
|
-
|
|
2162
|
+
nt = t ?? null, Lt.clear();
|
|
2160
2163
|
const n = un();
|
|
2161
|
-
|
|
2164
|
+
qe = (async () => {
|
|
2162
2165
|
const i = await Ui(t), o = await qr(
|
|
2163
2166
|
ln(),
|
|
2164
2167
|
n,
|
|
@@ -2178,14 +2181,14 @@ async function nr(e) {
|
|
|
2178
2181
|
}
|
|
2179
2182
|
return { sil: i, viseme: o, expression: a };
|
|
2180
2183
|
})();
|
|
2181
|
-
const s = await
|
|
2182
|
-
return { ...
|
|
2184
|
+
const s = await qe;
|
|
2185
|
+
return { ...st(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
2183
2186
|
}
|
|
2184
2187
|
async function vr(e) {
|
|
2185
|
-
if (await nr(e), !
|
|
2186
|
-
return
|
|
2188
|
+
if (await nr(e), !qe) throw new Error("Assets not loaded");
|
|
2189
|
+
return qe;
|
|
2187
2190
|
}
|
|
2188
|
-
function
|
|
2191
|
+
function st(e) {
|
|
2189
2192
|
return Tn(
|
|
2190
2193
|
e.viseme.atlasMeta,
|
|
2191
2194
|
e.sil.naturalWidth,
|
|
@@ -2196,13 +2199,13 @@ function Vi(e, t) {
|
|
|
2196
2199
|
const r = document.createElement("canvas");
|
|
2197
2200
|
return r.width = t.w, r.height = t.h, r.getContext("2d", { willReadFrequently: !0 }).drawImage(e.atlas, t.x, t.y, t.w, t.h, 0, 0, t.w, t.h), r;
|
|
2198
2201
|
}
|
|
2199
|
-
async function
|
|
2200
|
-
const n = `${t.diffBase}::${r}`, s =
|
|
2202
|
+
async function Ot(e, t, r) {
|
|
2203
|
+
const n = `${t.diffBase}::${r}`, s = Lt.get(n);
|
|
2201
2204
|
if (s) return s;
|
|
2202
2205
|
const i = (async () => {
|
|
2203
2206
|
const o = t.cellByPath.get(r);
|
|
2204
2207
|
if (!o) throw new Error(`No atlas cell for path: ${r}`);
|
|
2205
|
-
const a = En(t.atlasMeta, o), u =
|
|
2208
|
+
const a = En(t.atlasMeta, o), u = st(e);
|
|
2206
2209
|
if (An(o)) {
|
|
2207
2210
|
const c = Vi(t, o), d = document.createElement("canvas");
|
|
2208
2211
|
d.width = u.width, d.height = u.height;
|
|
@@ -2214,23 +2217,23 @@ async function Nt(e, t, r) {
|
|
|
2214
2217
|
return f;
|
|
2215
2218
|
throw new Error(`Diff PNG wrong size for ${r}`);
|
|
2216
2219
|
})();
|
|
2217
|
-
return
|
|
2220
|
+
return Lt.set(n, i), i;
|
|
2218
2221
|
}
|
|
2219
2222
|
async function Kr(e, t, r, n, s, i) {
|
|
2220
2223
|
if (s) {
|
|
2221
2224
|
const { width: g, height: S } = s;
|
|
2222
2225
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
2223
2226
|
return;
|
|
2224
|
-
const
|
|
2225
|
-
|
|
2226
|
-
const
|
|
2227
|
-
if (
|
|
2227
|
+
const h = document.createElement("canvas");
|
|
2228
|
+
h.width = g, h.height = S;
|
|
2229
|
+
const M = h.getContext("2d");
|
|
2230
|
+
if (M.clearRect(0, 0, g, S), M.drawImage(t, 0, 0, g, S), i && !i()) return;
|
|
2228
2231
|
(e.width !== g || e.height !== S) && (e.width = g, e.height = S);
|
|
2229
2232
|
const _ = e.getContext("2d");
|
|
2230
|
-
_.clearRect(0, 0, g, S), _.drawImage(
|
|
2233
|
+
_.clearRect(0, 0, g, S), _.drawImage(h, 0, 0);
|
|
2231
2234
|
return;
|
|
2232
2235
|
}
|
|
2233
|
-
const o = await vr(), a =
|
|
2236
|
+
const o = await vr(), a = Wt(o.viseme.atlasMeta), { width: u, height: l } = st(o);
|
|
2234
2237
|
(e.width !== u || e.height !== l) && (e.width = u, e.height = l);
|
|
2235
2238
|
const f = [], c = e.getContext("2d");
|
|
2236
2239
|
if (c.clearRect(0, 0, u, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
@@ -2246,15 +2249,15 @@ async function Kr(e, t, r, n, s, i) {
|
|
|
2246
2249
|
c.drawImage(d, 0, 0);
|
|
2247
2250
|
}
|
|
2248
2251
|
async function sr(e, t, r) {
|
|
2249
|
-
const n = await vr(
|
|
2252
|
+
const n = await vr(nt ?? void 0), s = Wt(n.viseme.atlasMeta), { width: i, height: o } = st(n);
|
|
2250
2253
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
2251
2254
|
const a = [];
|
|
2252
2255
|
if (t.mouthPath) {
|
|
2253
2256
|
const f = new Set(n.viseme.cellByPath.keys()), c = hr(t.mouthPath, f) ?? (f.has(t.mouthPath) ? t.mouthPath : null);
|
|
2254
|
-
c && a.push(await
|
|
2257
|
+
c && a.push(await Ot(n, n.viseme, c));
|
|
2255
2258
|
}
|
|
2256
2259
|
t.expressionPath && n.expression && a.push(
|
|
2257
|
-
await
|
|
2260
|
+
await Ot(n, n.expression, t.expressionPath)
|
|
2258
2261
|
);
|
|
2259
2262
|
const u = e.getContext("2d");
|
|
2260
2263
|
if (u.clearRect(0, 0, i, o), a.length === 0) {
|
|
@@ -2271,13 +2274,13 @@ async function sr(e, t, r) {
|
|
|
2271
2274
|
u.drawImage(l, 0, 0);
|
|
2272
2275
|
}
|
|
2273
2276
|
async function Wi(e, t) {
|
|
2274
|
-
const r = await vr(
|
|
2277
|
+
const r = await vr(nt ?? void 0), n = Wt(r.viseme.atlasMeta), { width: s, height: i } = st(r), o = [];
|
|
2275
2278
|
if (e.mouthPath) {
|
|
2276
2279
|
const f = new Set(r.viseme.cellByPath.keys()), c = hr(e.mouthPath, f) ?? (f.has(e.mouthPath) ? e.mouthPath : null);
|
|
2277
|
-
c && o.push(await
|
|
2280
|
+
c && o.push(await Ot(r, r.viseme, c));
|
|
2278
2281
|
}
|
|
2279
2282
|
e.expressionPath && r.expression && o.push(
|
|
2280
|
-
await
|
|
2283
|
+
await Ot(r, r.expression, e.expressionPath)
|
|
2281
2284
|
);
|
|
2282
2285
|
const a = new OffscreenCanvas(s, i), u = a.getContext("2d");
|
|
2283
2286
|
if (o.length === 0)
|
|
@@ -2298,7 +2301,7 @@ let Cn = null;
|
|
|
2298
2301
|
function Gr(e) {
|
|
2299
2302
|
Cn = e;
|
|
2300
2303
|
}
|
|
2301
|
-
function
|
|
2304
|
+
function Ne() {
|
|
2302
2305
|
return Cn;
|
|
2303
2306
|
}
|
|
2304
2307
|
function $i(e) {
|
|
@@ -2390,25 +2393,25 @@ function qi() {
|
|
|
2390
2393
|
},
|
|
2391
2394
|
snapshot(f, c) {
|
|
2392
2395
|
let d = 0, g = 0;
|
|
2393
|
-
for (const
|
|
2394
|
-
if (
|
|
2395
|
-
if (
|
|
2396
|
-
d += 1, t.has(
|
|
2396
|
+
for (const D of f)
|
|
2397
|
+
if (D.viseme !== "sil") {
|
|
2398
|
+
if (D.vtime >= c) break;
|
|
2399
|
+
d += 1, t.has(D.vtime) && (g += 1);
|
|
2397
2400
|
}
|
|
2398
|
-
const S = d > 0 ? Math.round(g / d * 100) : 100,
|
|
2401
|
+
const S = d > 0 ? Math.round(g / d * 100) : 100, h = e.queueSuperseded + e.workerStale + Math.max(0, e.drawsRequested - e.drawsDisplayed), M = d - g, _ = e.bufferTicks > 0 ? Math.round(e.bufferHits / e.bufferTicks * 100) : 100;
|
|
2399
2402
|
return {
|
|
2400
2403
|
...e,
|
|
2401
2404
|
bufferHitRate: _,
|
|
2402
|
-
renderLoss:
|
|
2405
|
+
renderLoss: h,
|
|
2403
2406
|
visemeSlotsTotal: d,
|
|
2404
2407
|
visemeSlotsCovered: g,
|
|
2405
2408
|
visemeCoveragePct: S,
|
|
2406
2409
|
transitionFramesUniqueSampled: r.size,
|
|
2407
2410
|
transitionFramesUniquePainted: n.size,
|
|
2408
2411
|
drawsDeduped: e.rafTicksDeduped,
|
|
2409
|
-
renderSkips: e.rafTicksDeduped +
|
|
2412
|
+
renderSkips: e.rafTicksDeduped + h,
|
|
2410
2413
|
visemesShown: g,
|
|
2411
|
-
visemesSkipped:
|
|
2414
|
+
visemesSkipped: M,
|
|
2412
2415
|
rifeTransitionFramesSkipped: e.transitionFramesMissed
|
|
2413
2416
|
};
|
|
2414
2417
|
}
|
|
@@ -2421,7 +2424,7 @@ function jr(e) {
|
|
|
2421
2424
|
function Sr() {
|
|
2422
2425
|
return { lastDrawnKey: "" };
|
|
2423
2426
|
}
|
|
2424
|
-
function
|
|
2427
|
+
function Ie(e) {
|
|
2425
2428
|
e.lastDrawnKey = "", e.transitionCache = void 0;
|
|
2426
2429
|
}
|
|
2427
2430
|
function ji(e, t) {
|
|
@@ -2448,13 +2451,13 @@ function Ji(e, t) {
|
|
|
2448
2451
|
function Qi() {
|
|
2449
2452
|
return Fn + zi;
|
|
2450
2453
|
}
|
|
2451
|
-
function
|
|
2454
|
+
function Nt(e) {
|
|
2452
2455
|
return e ?? Ln;
|
|
2453
2456
|
}
|
|
2454
2457
|
function br(e, t, r, n, s = Gi) {
|
|
2455
2458
|
if (e.length === 0)
|
|
2456
2459
|
return { diffPath: null, label: "sil" };
|
|
2457
|
-
if (t >=
|
|
2460
|
+
if (t >= $e(e))
|
|
2458
2461
|
return { diffPath: null, label: "sil" };
|
|
2459
2462
|
const i = ji(e, n), o = $s(i, t);
|
|
2460
2463
|
if (o) {
|
|
@@ -2490,21 +2493,21 @@ function br(e, t, r, n, s = Gi) {
|
|
|
2490
2493
|
}
|
|
2491
2494
|
};
|
|
2492
2495
|
}
|
|
2493
|
-
return { diffPath:
|
|
2496
|
+
return { diffPath: vt(o.to), label: o.to };
|
|
2494
2497
|
}
|
|
2495
2498
|
}
|
|
2496
2499
|
const a = _n(e, t, s);
|
|
2497
|
-
return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath:
|
|
2500
|
+
return a === "sil" ? { diffPath: null, label: "sil" } : { diffPath: vt(a), label: a };
|
|
2498
2501
|
}
|
|
2499
2502
|
function kr(e, t) {
|
|
2500
|
-
const r = t ??
|
|
2501
|
-
return `${
|
|
2503
|
+
const r = t ?? Nt(e.expressionPath);
|
|
2504
|
+
return `${Nt(e.mouthPath)}|${r}`;
|
|
2502
2505
|
}
|
|
2503
2506
|
function Yr(e, t, r, n, s, i, o, a, u, l) {
|
|
2504
2507
|
const f = br(t, r, u, i), c = {
|
|
2505
2508
|
mouthPath: f.diffPath,
|
|
2506
2509
|
expressionPath: n
|
|
2507
|
-
}, d = kr(c, s), g =
|
|
2510
|
+
}, d = kr(c, s), g = Ne();
|
|
2508
2511
|
if (f.transitionMeta && g?.onTransitionSample(f.transitionMeta, f.diffPath), d === i.lastDrawnKey) {
|
|
2509
2512
|
g?.onDrawDeduped();
|
|
2510
2513
|
return;
|
|
@@ -2521,7 +2524,7 @@ function Xr(e, t, r, n, s, i, o = null) {
|
|
|
2521
2524
|
c === l && (n.lastDrawnKey = l);
|
|
2522
2525
|
}));
|
|
2523
2526
|
}
|
|
2524
|
-
function On(e, t, r, n, s =
|
|
2527
|
+
function On(e, t, r, n, s = _t, i) {
|
|
2525
2528
|
if (r <= t || e.length === 0) return [];
|
|
2526
2529
|
const o = i ?? Sr(), a = [];
|
|
2527
2530
|
let u = "";
|
|
@@ -2531,7 +2534,7 @@ function On(e, t, r, n, s = St, i) {
|
|
|
2531
2534
|
l,
|
|
2532
2535
|
n,
|
|
2533
2536
|
o
|
|
2534
|
-
), c =
|
|
2537
|
+
), c = Nt(f.diffPath);
|
|
2535
2538
|
c !== u && (u = c, a.push({
|
|
2536
2539
|
displayAtMs: l,
|
|
2537
2540
|
mouthPath: f.diffPath,
|
|
@@ -2566,7 +2569,7 @@ function Tr(e) {
|
|
|
2566
2569
|
return {
|
|
2567
2570
|
enqueue(a, u, l) {
|
|
2568
2571
|
const f = r.findIndex((c) => c.drawKey === u);
|
|
2569
|
-
f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >= Zi && (r.shift(),
|
|
2572
|
+
f >= 0 ? r[f] = { diffs: a, drawKey: u, onDisplayed: l } : (r.length >= Zi && (r.shift(), Ne()?.onQueueSuperseded()), r.push({ diffs: a, drawKey: u, onDisplayed: l })), o();
|
|
2570
2573
|
},
|
|
2571
2574
|
reset() {
|
|
2572
2575
|
t += 1, r.length = 0;
|
|
@@ -2662,7 +2665,7 @@ function ra(e, t, r, n, s, i) {
|
|
|
2662
2665
|
r,
|
|
2663
2666
|
n,
|
|
2664
2667
|
s,
|
|
2665
|
-
|
|
2668
|
+
_t,
|
|
2666
2669
|
i
|
|
2667
2670
|
);
|
|
2668
2671
|
if (o.length === 0) return { ready: 0, total: 0 };
|
|
@@ -2689,7 +2692,7 @@ function na(e) {
|
|
|
2689
2692
|
c.label,
|
|
2690
2693
|
c.mouthPath,
|
|
2691
2694
|
d
|
|
2692
|
-
),
|
|
2695
|
+
), Ne()?.onBufferPrefetched();
|
|
2693
2696
|
} finally {
|
|
2694
2697
|
n.delete(c.mouthKey);
|
|
2695
2698
|
}
|
|
@@ -2708,21 +2711,21 @@ function na(e) {
|
|
|
2708
2711
|
}));
|
|
2709
2712
|
}, u = (c, d, g, S = zt) => {
|
|
2710
2713
|
if (!e.supportsBufferedPlayback) return;
|
|
2711
|
-
const
|
|
2714
|
+
const h = Math.max(0, d - _t * 4), M = On(
|
|
2712
2715
|
c,
|
|
2713
|
-
|
|
2716
|
+
h,
|
|
2714
2717
|
d + S,
|
|
2715
2718
|
g,
|
|
2716
|
-
|
|
2719
|
+
_t,
|
|
2717
2720
|
r
|
|
2718
2721
|
);
|
|
2719
|
-
a(
|
|
2722
|
+
a(M);
|
|
2720
2723
|
}, l = (c, d) => {
|
|
2721
2724
|
s = c, i = d;
|
|
2722
2725
|
}, f = (c, d) => !(s !== c || i !== d);
|
|
2723
2726
|
return {
|
|
2724
2727
|
reset() {
|
|
2725
|
-
t.reset(), o.reset(), n.clear(),
|
|
2728
|
+
t.reset(), o.reset(), n.clear(), Ie(r), s = "", i = null, Ne()?.onBufferReset();
|
|
2726
2729
|
},
|
|
2727
2730
|
markExternallyDisplayed(c, d) {
|
|
2728
2731
|
l(c.split("|")[0] ?? c, d);
|
|
@@ -2749,7 +2752,7 @@ function na(e) {
|
|
|
2749
2752
|
},
|
|
2750
2753
|
getBufferedFrameCount: () => t.size(),
|
|
2751
2754
|
tick(c) {
|
|
2752
|
-
const d =
|
|
2755
|
+
const d = Ne();
|
|
2753
2756
|
d?.onBufferTick(), u(
|
|
2754
2757
|
c.queue,
|
|
2755
2758
|
c.elapsedMs,
|
|
@@ -2760,21 +2763,21 @@ function na(e) {
|
|
|
2760
2763
|
c.elapsedMs,
|
|
2761
2764
|
c.availablePaths,
|
|
2762
2765
|
r
|
|
2763
|
-
), S =
|
|
2766
|
+
), S = Nt(g.diffPath), h = kr(
|
|
2764
2767
|
{ mouthPath: g.diffPath, expressionPath: c.expressionPath },
|
|
2765
2768
|
c.expressionDrawKey
|
|
2766
|
-
),
|
|
2767
|
-
if (f(S, c.expressionPath) || c.playbackState.lastDrawnKey ===
|
|
2768
|
-
return
|
|
2769
|
+
), M = () => (l(S, c.expressionPath), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !0 });
|
|
2770
|
+
if (f(S, c.expressionPath) || c.playbackState.lastDrawnKey === h)
|
|
2771
|
+
return M();
|
|
2769
2772
|
const _ = t.findForMouthKey(
|
|
2770
2773
|
S,
|
|
2771
2774
|
c.elapsedMs,
|
|
2772
|
-
|
|
2775
|
+
_t
|
|
2773
2776
|
);
|
|
2774
|
-
return _ && c.expressionPath != null ? (d?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : _ ? (e.blitBitmap(c.canvas, _.bitmap), l(_.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey =
|
|
2777
|
+
return _ && c.expressionPath != null ? (d?.onBufferHit(), { usedBuffer: !1, underrun: !1, held: !1 }) : _ ? (e.blitBitmap(c.canvas, _.bitmap), l(_.mouthKey, c.expressionPath), c.playbackState.lastDrawnKey = h, c.onStatus({
|
|
2775
2778
|
diffPath: _.mouthPath,
|
|
2776
2779
|
label: _.label
|
|
2777
|
-
}), c.onDisplayed(
|
|
2780
|
+
}), c.onDisplayed(h, _.mouthPath, _.label), d?.onBufferHit(), { usedBuffer: !0, underrun: !1, held: !1 }) : (d?.onBufferUnderrun(), { usedBuffer: !1, underrun: !0, held: !1 });
|
|
2778
2781
|
}
|
|
2779
2782
|
};
|
|
2780
2783
|
}
|
|
@@ -2871,14 +2874,14 @@ async function Qr(e, t, r, n, s) {
|
|
|
2871
2874
|
if (!o?.path) throw new Error(`${e} has no sheets[0].path`);
|
|
2872
2875
|
const a = /* @__PURE__ */ new Map(), u = async (c, d) => {
|
|
2873
2876
|
const g = Mn(t, d, r), S = r ? await ii(
|
|
2874
|
-
await
|
|
2877
|
+
await at(g, s ?? "")
|
|
2875
2878
|
) : await Nn(g);
|
|
2876
2879
|
if (aa(S.width, S.height, n))
|
|
2877
2880
|
return console.info(
|
|
2878
2881
|
`[PixiVisemeCompositor] Sheet ${d} (${S.width}x${S.height}) exceeds MAX_TEXTURE_SIZE=${n}; using per-cell crops.`
|
|
2879
2882
|
), { mode: "cells", bitmap: S };
|
|
2880
|
-
const
|
|
2881
|
-
return
|
|
2883
|
+
const h = ge.from(S);
|
|
2884
|
+
return h.source.scaleMode = "nearest", { mode: "full", texture: h };
|
|
2882
2885
|
};
|
|
2883
2886
|
a.set(o.index, await u(o.index, o.path));
|
|
2884
2887
|
for (const c of i.sheets ?? [])
|
|
@@ -2927,22 +2930,22 @@ async function la(e, t = {}) {
|
|
|
2927
2930
|
s = !0, !i && !o && (i = !0, t.onWebGlContextLost?.());
|
|
2928
2931
|
};
|
|
2929
2932
|
a.addEventListener("webglcontextlost", u);
|
|
2930
|
-
const l = new
|
|
2933
|
+
const l = new xt(ge.EMPTY), f = new xt(ge.EMPTY), c = new xt(ge.EMPTY), d = new xt(ge.EMPTY);
|
|
2931
2934
|
d.visible = !1;
|
|
2932
2935
|
const g = Jr(5), S = Jr(5);
|
|
2933
2936
|
f.filters = [g], c.filters = [S], r.stage.addChild(l), r.stage.addChild(f), r.stage.addChild(c), r.stage.addChild(d);
|
|
2934
|
-
let
|
|
2937
|
+
let h = null, M = null, _ = null, D = null, w = null, b = null, L = 842, B = 1264, G = null, C = 5;
|
|
2935
2938
|
const k = /* @__PURE__ */ new Map();
|
|
2936
|
-
let P = null,
|
|
2937
|
-
const
|
|
2938
|
-
k.clear(), w = null, b = null,
|
|
2939
|
-
}),
|
|
2940
|
-
L = v, B =
|
|
2941
|
-
}, X = () => {
|
|
2942
|
-
f.visible = !1, c.visible = !1, f.texture = we.EMPTY, c.texture = we.EMPTY, P = null, D = null;
|
|
2943
|
-
}, z = () => {
|
|
2944
|
-
d.visible = !1, m && (l.texture = m, l.visible = !0, l.width = L, l.height = B, l.x = 0, l.y = 0);
|
|
2939
|
+
let P = null, N = null, I = null;
|
|
2940
|
+
const te = cn(() => {
|
|
2941
|
+
k.clear(), w = null, b = null, h = null, G = null;
|
|
2942
|
+
}), V = (v, E) => {
|
|
2943
|
+
L = v, B = E, r.renderer.resize(v, E), (e.width !== v || e.height !== E) && (e.width = v, e.height = E);
|
|
2945
2944
|
}, J = () => {
|
|
2945
|
+
f.visible = !1, c.visible = !1, f.texture = ge.EMPTY, c.texture = ge.EMPTY, P = null, N = null;
|
|
2946
|
+
}, j = () => {
|
|
2947
|
+
d.visible = !1, h && (l.texture = h, l.visible = !0, l.width = L, l.height = B, l.x = 0, l.y = 0);
|
|
2948
|
+
}, X = () => {
|
|
2946
2949
|
if (_) {
|
|
2947
2950
|
try {
|
|
2948
2951
|
_.resource = null;
|
|
@@ -2950,50 +2953,50 @@ async function la(e, t = {}) {
|
|
|
2950
2953
|
}
|
|
2951
2954
|
_.destroy(), _ = null;
|
|
2952
2955
|
}
|
|
2953
|
-
|
|
2954
|
-
},
|
|
2955
|
-
const
|
|
2956
|
-
if (!
|
|
2957
|
-
const
|
|
2958
|
-
let
|
|
2959
|
-
if (!
|
|
2960
|
-
const F =
|
|
2956
|
+
M && (M.destroy(!1), M = null), D = null;
|
|
2957
|
+
}, pe = (v, E) => {
|
|
2958
|
+
const m = v.cellByPath.get(E);
|
|
2959
|
+
if (!m || !An(m)) return null;
|
|
2960
|
+
const T = `${v.diffBase}::${E}`;
|
|
2961
|
+
let R = k.get(T);
|
|
2962
|
+
if (!R) {
|
|
2963
|
+
const F = m.sheet ?? 0, A = v.sheets.get(F);
|
|
2961
2964
|
if (!A) return null;
|
|
2962
2965
|
let $, Y = !1;
|
|
2963
2966
|
if (A.mode === "full")
|
|
2964
|
-
$ = new
|
|
2967
|
+
$ = new ge({
|
|
2965
2968
|
source: A.texture.source,
|
|
2966
|
-
frame: new Zn(
|
|
2969
|
+
frame: new Zn(m.x, m.y, m.w, m.h)
|
|
2967
2970
|
});
|
|
2968
2971
|
else {
|
|
2969
|
-
const Q = ua(A.bitmap,
|
|
2970
|
-
$ =
|
|
2972
|
+
const Q = ua(A.bitmap, m);
|
|
2973
|
+
$ = ge.from(Q), $.source.scaleMode = "nearest", Y = !0;
|
|
2971
2974
|
}
|
|
2972
|
-
|
|
2975
|
+
R = { texture: $, ownsSource: Y }, k.set(T, R);
|
|
2973
2976
|
}
|
|
2974
|
-
return { texture:
|
|
2975
|
-
},
|
|
2976
|
-
if (!
|
|
2977
|
-
return v.visible = !1, v.texture =
|
|
2978
|
-
const
|
|
2979
|
-
if (!
|
|
2980
|
-
return v.visible = !1, v.texture =
|
|
2981
|
-
const F = En(
|
|
2982
|
-
return
|
|
2983
|
-
},
|
|
2977
|
+
return { texture: R.texture, cell: m };
|
|
2978
|
+
}, re = (v, E, m, T) => {
|
|
2979
|
+
if (!T || !m)
|
|
2980
|
+
return v.visible = !1, v.texture = ge.EMPTY, !1;
|
|
2981
|
+
const R = pe(m, T);
|
|
2982
|
+
if (!R)
|
|
2983
|
+
return v.visible = !1, v.texture = ge.EMPTY, !1;
|
|
2984
|
+
const F = En(m.atlasMeta, R.cell);
|
|
2985
|
+
return E.setThreshold(C), v.texture = R.texture, v.x = F.x, v.y = F.y, v.width = R.cell.w, v.height = R.cell.h, v.visible = !0, !0;
|
|
2986
|
+
}, fe = (v) => {
|
|
2984
2987
|
if (!v || !w) return null;
|
|
2985
|
-
const
|
|
2986
|
-
return hr(v,
|
|
2987
|
-
},
|
|
2988
|
-
d.visible = !1,
|
|
2989
|
-
const
|
|
2990
|
-
|
|
2988
|
+
const E = G ?? new Set(w.cellByPath.keys());
|
|
2989
|
+
return hr(v, E) ?? (E.has(v) ? v : null);
|
|
2990
|
+
}, de = (v) => {
|
|
2991
|
+
d.visible = !1, j();
|
|
2992
|
+
const E = fe(v.mouthPath), m = v.expressionPath && b && b.cellByPath.has(v.expressionPath) ? v.expressionPath : null;
|
|
2993
|
+
E !== P ? (re(f, g, w, E), P = E) : E ? f.visible = !0 : f.visible = !1, m !== N ? (re(
|
|
2991
2994
|
c,
|
|
2992
2995
|
S,
|
|
2993
2996
|
b,
|
|
2994
|
-
|
|
2995
|
-
),
|
|
2996
|
-
},
|
|
2997
|
+
m
|
|
2998
|
+
), N = m) : m ? c.visible = !0 : c.visible = !1;
|
|
2999
|
+
}, ue = () => {
|
|
2997
3000
|
if (!(o || s || document.hidden))
|
|
2998
3001
|
try {
|
|
2999
3002
|
r.render();
|
|
@@ -3003,40 +3006,40 @@ async function la(e, t = {}) {
|
|
|
3003
3006
|
return {
|
|
3004
3007
|
async loadAssets(v) {
|
|
3005
3008
|
if (o) return { width: L, height: B, visemePaths: [] };
|
|
3006
|
-
const
|
|
3007
|
-
if (
|
|
3009
|
+
const E = bt();
|
|
3010
|
+
if (E && !v)
|
|
3008
3011
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
3009
|
-
const
|
|
3010
|
-
await
|
|
3011
|
-
) : await Nn(
|
|
3012
|
-
|
|
3013
|
-
const
|
|
3012
|
+
const m = E ? await oi(
|
|
3013
|
+
await at(Ft(), v ?? "")
|
|
3014
|
+
) : await Nn(Ft());
|
|
3015
|
+
h && h.destroy(!0), h = ge.from(m), h.source.scaleMode = "linear";
|
|
3016
|
+
const T = un();
|
|
3014
3017
|
w = await Qr(
|
|
3015
3018
|
ln(),
|
|
3016
|
-
E,
|
|
3017
3019
|
T,
|
|
3020
|
+
E,
|
|
3018
3021
|
n,
|
|
3019
3022
|
v
|
|
3020
3023
|
);
|
|
3021
3024
|
try {
|
|
3022
3025
|
b = await Qr(
|
|
3023
3026
|
fn(),
|
|
3024
|
-
E,
|
|
3025
3027
|
T,
|
|
3028
|
+
E,
|
|
3026
3029
|
n,
|
|
3027
3030
|
v
|
|
3028
3031
|
);
|
|
3029
3032
|
} catch {
|
|
3030
3033
|
b = null;
|
|
3031
3034
|
}
|
|
3032
|
-
const
|
|
3035
|
+
const R = Tn(
|
|
3033
3036
|
w.atlasMeta,
|
|
3034
|
-
|
|
3035
|
-
|
|
3037
|
+
m.width,
|
|
3038
|
+
m.height
|
|
3036
3039
|
);
|
|
3037
|
-
return
|
|
3038
|
-
width:
|
|
3039
|
-
height:
|
|
3040
|
+
return V(R.width, R.height), C = Wt(w.atlasMeta), g.setThreshold(C), S.setThreshold(C), G = new Set(w.cellByPath.keys()), k.clear(), j(), J(), ue(), {
|
|
3041
|
+
width: R.width,
|
|
3042
|
+
height: R.height,
|
|
3040
3043
|
visemePaths: [...w.cellByPath.keys()]
|
|
3041
3044
|
};
|
|
3042
3045
|
},
|
|
@@ -3044,43 +3047,43 @@ async function la(e, t = {}) {
|
|
|
3044
3047
|
return G;
|
|
3045
3048
|
},
|
|
3046
3049
|
drawLiveFrame(v) {
|
|
3047
|
-
o || s || !
|
|
3050
|
+
o || s || !h || (de(v), ue());
|
|
3048
3051
|
},
|
|
3049
|
-
drawIdleVideo(v,
|
|
3050
|
-
o || s || document.hidden ||
|
|
3052
|
+
drawIdleVideo(v, E) {
|
|
3053
|
+
o || s || document.hidden || E && !E() || v.readyState < HTMLMediaElement.HAVE_CURRENT_DATA || (J(), d.visible = !1, !M || D !== v ? (X(), _ = new Qn({
|
|
3051
3054
|
resource: v,
|
|
3052
3055
|
autoPlay: !1,
|
|
3053
3056
|
updateFPS: 0
|
|
3054
|
-
}), _.autoUpdate = !1,
|
|
3057
|
+
}), _.autoUpdate = !1, M = new ge({ source: _ }), D = v) : M.source.update(), l.texture = M, l.visible = !0, l.x = 0, l.y = 0, l.width = L, l.height = B, ue());
|
|
3055
3058
|
},
|
|
3056
3059
|
renderSilOnly() {
|
|
3057
|
-
o || s || !
|
|
3060
|
+
o || s || !h || (J(), j(), ue());
|
|
3058
3061
|
},
|
|
3059
3062
|
blitBitmap(v) {
|
|
3060
|
-
o || s || (
|
|
3063
|
+
o || s || (J(), I && (I.destroy(!0), I = null), I = ge.from(v), d.texture = I, d.visible = !0, d.x = 0, d.y = 0, d.width = L, d.height = B, l.visible = !1, ue());
|
|
3061
3064
|
},
|
|
3062
3065
|
async compositePrefetchFrame(v) {
|
|
3063
3066
|
return null;
|
|
3064
3067
|
},
|
|
3065
|
-
renderFrame:
|
|
3068
|
+
renderFrame: ue,
|
|
3066
3069
|
isContextLost() {
|
|
3067
3070
|
return s;
|
|
3068
3071
|
},
|
|
3069
3072
|
dispose() {
|
|
3070
3073
|
if (o) return;
|
|
3071
|
-
o = !0, a.removeEventListener("webglcontextlost", u),
|
|
3072
|
-
for (const { texture:
|
|
3073
|
-
|
|
3074
|
-
k.clear(),
|
|
3075
|
-
const v = (
|
|
3076
|
-
|
|
3074
|
+
o = !0, a.removeEventListener("webglcontextlost", u), te(), X(), I && (I.destroy(!0), I = null);
|
|
3075
|
+
for (const { texture: E, ownsSource: m } of k.values())
|
|
3076
|
+
E.destroy(m);
|
|
3077
|
+
k.clear(), h && (h.destroy(!0), h = null);
|
|
3078
|
+
const v = (E) => {
|
|
3079
|
+
E.mode === "full" ? E.texture.destroy(!0) : E.bitmap.close();
|
|
3077
3080
|
};
|
|
3078
3081
|
if (w)
|
|
3079
|
-
for (const
|
|
3080
|
-
v(
|
|
3082
|
+
for (const E of w.sheets.values())
|
|
3083
|
+
v(E);
|
|
3081
3084
|
if (b)
|
|
3082
|
-
for (const
|
|
3083
|
-
v(
|
|
3085
|
+
for (const E of b.sheets.values())
|
|
3086
|
+
v(E);
|
|
3084
3087
|
g.destroy(!0), S.destroy(!0), r.destroy(
|
|
3085
3088
|
{ removeView: !1 },
|
|
3086
3089
|
{ children: !0, texture: !0 }
|
|
@@ -3088,7 +3091,7 @@ async function la(e, t = {}) {
|
|
|
3088
3091
|
}
|
|
3089
3092
|
};
|
|
3090
3093
|
}
|
|
3091
|
-
const Zr = -1,
|
|
3094
|
+
const Zr = -1, Bt = 1e5, en = /* @__PURE__ */ new Map();
|
|
3092
3095
|
async function fa(e) {
|
|
3093
3096
|
let t = en.get(e);
|
|
3094
3097
|
if (!t) {
|
|
@@ -3146,7 +3149,7 @@ function tn(e, t) {
|
|
|
3146
3149
|
r += 1;
|
|
3147
3150
|
const a = r;
|
|
3148
3151
|
t.onStatus?.(o), await sr(i, {
|
|
3149
|
-
mouthPath:
|
|
3152
|
+
mouthPath: vt(o),
|
|
3150
3153
|
expressionPath: null
|
|
3151
3154
|
});
|
|
3152
3155
|
},
|
|
@@ -3158,52 +3161,52 @@ function tn(e, t) {
|
|
|
3158
3161
|
function ma(e, t, r) {
|
|
3159
3162
|
let n = null, s = 1, i = 0, o = !1, a = !1, u = null;
|
|
3160
3163
|
const l = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
3161
|
-
let c =
|
|
3162
|
-
const d = Tr(async (
|
|
3164
|
+
let c = Bt;
|
|
3165
|
+
const d = Tr(async (D, w, b) => (l.set(w, {
|
|
3163
3166
|
drawKey: b.drawKey,
|
|
3164
3167
|
onDisplayed: b.onDisplayed
|
|
3165
|
-
}), await
|
|
3168
|
+
}), await M(
|
|
3166
3169
|
{
|
|
3167
3170
|
type: "drawFrame",
|
|
3168
|
-
diffPath:
|
|
3169
|
-
expressionDiffPath:
|
|
3171
|
+
diffPath: D.mouthPath,
|
|
3172
|
+
expressionDiffPath: D.expressionPath,
|
|
3170
3173
|
liveSeq: w
|
|
3171
3174
|
},
|
|
3172
3175
|
void 0,
|
|
3173
3176
|
!0
|
|
3174
|
-
), !1)), g = (
|
|
3175
|
-
if (
|
|
3177
|
+
), !1)), g = (D) => {
|
|
3178
|
+
if (D === Zr) {
|
|
3176
3179
|
let L = -1, B;
|
|
3177
3180
|
for (const [G, C] of l)
|
|
3178
3181
|
G >= L && (L = G, B = C);
|
|
3179
3182
|
L >= 0 && l.delete(L), B?.onDisplayed?.(B.drawKey);
|
|
3180
3183
|
return;
|
|
3181
3184
|
}
|
|
3182
|
-
const w = -
|
|
3185
|
+
const w = -D, b = l.get(w);
|
|
3183
3186
|
l.delete(w), b?.onDisplayed?.(b.drawKey);
|
|
3184
|
-
}, S = /* @__PURE__ */ new Map(),
|
|
3185
|
-
a || !n || n.postMessage(
|
|
3186
|
-
},
|
|
3187
|
+
}, S = /* @__PURE__ */ new Map(), h = (D, w) => {
|
|
3188
|
+
a || !n || n.postMessage(D, []);
|
|
3189
|
+
}, M = (D, w, b = !1) => {
|
|
3187
3190
|
if (a) return Promise.resolve();
|
|
3188
3191
|
const L = s++;
|
|
3189
3192
|
return new Promise((B, G) => {
|
|
3190
3193
|
S.set(L, {
|
|
3191
3194
|
resolve: (C) => B(C),
|
|
3192
3195
|
reject: G,
|
|
3193
|
-
generation: typeof
|
|
3196
|
+
generation: typeof D.generation == "number" ? D.generation : void 0,
|
|
3194
3197
|
expectRenderDone: b
|
|
3195
|
-
}),
|
|
3198
|
+
}), h({ ...D, requestId: L });
|
|
3196
3199
|
});
|
|
3197
3200
|
}, _ = (async () => {
|
|
3198
|
-
n = await fa(r), n.onmessage = (
|
|
3201
|
+
n = await fa(r), n.onmessage = (D) => {
|
|
3199
3202
|
if (a) return;
|
|
3200
|
-
const w =
|
|
3203
|
+
const w = D.data;
|
|
3201
3204
|
if (w.type === "status") {
|
|
3202
3205
|
t.onStatus?.(w.label);
|
|
3203
3206
|
return;
|
|
3204
3207
|
}
|
|
3205
3208
|
if (w.type === "frame") {
|
|
3206
|
-
if (w.generation <= -
|
|
3209
|
+
if (w.generation <= -Bt) {
|
|
3207
3210
|
const B = -w.generation, G = f.get(B);
|
|
3208
3211
|
f.delete(B), G?.resolve(w.bitmap);
|
|
3209
3212
|
return;
|
|
@@ -3216,12 +3219,12 @@ function ma(e, t, r) {
|
|
|
3216
3219
|
if (L && !(w.generation === Zr)) {
|
|
3217
3220
|
const G = -w.generation;
|
|
3218
3221
|
if (!d.isLatestSeq(G)) {
|
|
3219
|
-
|
|
3222
|
+
Ne()?.onWorkerStale(), w.bitmap.close();
|
|
3220
3223
|
return;
|
|
3221
3224
|
}
|
|
3222
3225
|
}
|
|
3223
3226
|
if (L && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
3224
|
-
|
|
3227
|
+
Ne()?.onWorkerStale(), w.bitmap.close();
|
|
3225
3228
|
return;
|
|
3226
3229
|
}
|
|
3227
3230
|
ir(e, w.bitmap), w.bitmap.close(), L && g(w.generation);
|
|
@@ -3248,26 +3251,26 @@ function ma(e, t, r) {
|
|
|
3248
3251
|
S.delete(w.requestId), t.onError?.(w.message), b.reject(new Error(w.message));
|
|
3249
3252
|
break;
|
|
3250
3253
|
}
|
|
3251
|
-
}, n.onerror = (
|
|
3254
|
+
}, n.onerror = (D) => {
|
|
3252
3255
|
if (a) return;
|
|
3253
|
-
const w =
|
|
3256
|
+
const w = D.message || "Worker error";
|
|
3254
3257
|
t.onError?.(w);
|
|
3255
3258
|
for (const [, b] of S)
|
|
3256
3259
|
b.reject(new Error(w));
|
|
3257
3260
|
S.clear();
|
|
3258
|
-
}, await
|
|
3261
|
+
}, await M({ type: "init" }), o = !0;
|
|
3259
3262
|
})();
|
|
3260
3263
|
return {
|
|
3261
3264
|
usesWorker: !0,
|
|
3262
3265
|
usesPixi: !1,
|
|
3263
|
-
async loadAssets(
|
|
3266
|
+
async loadAssets(D) {
|
|
3264
3267
|
if (a) return { width: 842, height: 1264 };
|
|
3265
3268
|
if (await _, a) return { width: 842, height: 1264 };
|
|
3266
3269
|
if (!o) throw new Error("Worker init failed");
|
|
3267
|
-
return await
|
|
3270
|
+
return await M({
|
|
3268
3271
|
type: "loadAssets",
|
|
3269
|
-
keyHex:
|
|
3270
|
-
urls: Es(
|
|
3272
|
+
keyHex: D,
|
|
3273
|
+
urls: Es(ze())
|
|
3271
3274
|
}) ?? { width: 842, height: 1264 };
|
|
3272
3275
|
},
|
|
3273
3276
|
getVisemeAtlasPaths() {
|
|
@@ -3275,29 +3278,29 @@ function ma(e, t, r) {
|
|
|
3275
3278
|
},
|
|
3276
3279
|
async renderSilOnly() {
|
|
3277
3280
|
if (a || (await _, a)) return;
|
|
3278
|
-
i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c =
|
|
3279
|
-
const
|
|
3280
|
-
await
|
|
3281
|
-
{ type: "renderSil", generation:
|
|
3281
|
+
i += 1, d.reset(), l.clear(), f.forEach(({ resolve: w }) => w(null)), f.clear(), c = Bt;
|
|
3282
|
+
const D = i;
|
|
3283
|
+
await M({ type: "cancelLiveDraws" }), await M(
|
|
3284
|
+
{ type: "renderSil", generation: D },
|
|
3282
3285
|
void 0,
|
|
3283
3286
|
!0
|
|
3284
3287
|
);
|
|
3285
3288
|
},
|
|
3286
|
-
drawLiveFrame(
|
|
3289
|
+
drawLiveFrame(D, w, b, L) {
|
|
3287
3290
|
a || _.then(() => {
|
|
3288
3291
|
a || d.enqueue(w, b, L);
|
|
3289
3292
|
});
|
|
3290
3293
|
},
|
|
3291
|
-
compositePrefetchFrame(
|
|
3294
|
+
compositePrefetchFrame(D, w) {
|
|
3292
3295
|
return a ? Promise.resolve(null) : _.then(() => {
|
|
3293
3296
|
if (a) return null;
|
|
3294
3297
|
const b = ++c;
|
|
3295
3298
|
return new Promise((L) => {
|
|
3296
|
-
f.set(b, { resolve: L }),
|
|
3299
|
+
f.set(b, { resolve: L }), M(
|
|
3297
3300
|
{
|
|
3298
3301
|
type: "drawFrame",
|
|
3299
|
-
diffPath:
|
|
3300
|
-
expressionDiffPath:
|
|
3302
|
+
diffPath: D.mouthPath,
|
|
3303
|
+
expressionDiffPath: D.expressionPath,
|
|
3301
3304
|
liveSeq: b
|
|
3302
3305
|
},
|
|
3303
3306
|
void 0,
|
|
@@ -3308,18 +3311,18 @@ function ma(e, t, r) {
|
|
|
3308
3311
|
});
|
|
3309
3312
|
});
|
|
3310
3313
|
},
|
|
3311
|
-
blitBitmap(
|
|
3312
|
-
ir(
|
|
3314
|
+
blitBitmap(D, w) {
|
|
3315
|
+
ir(D, w);
|
|
3313
3316
|
},
|
|
3314
3317
|
drawIdleVideo() {
|
|
3315
3318
|
},
|
|
3316
3319
|
supportsBufferedPlayback: !0,
|
|
3317
|
-
async renderViseme(
|
|
3320
|
+
async renderViseme(D, w, b = {}) {
|
|
3318
3321
|
if (a || (await _, a)) return;
|
|
3319
3322
|
i += 1, d.reset(), l.clear();
|
|
3320
3323
|
const L = i;
|
|
3321
3324
|
try {
|
|
3322
|
-
await
|
|
3325
|
+
await M({ type: "cancelLiveDraws" }), await M(
|
|
3323
3326
|
{
|
|
3324
3327
|
type: "renderViseme",
|
|
3325
3328
|
generation: L,
|
|
@@ -3339,9 +3342,9 @@ function ma(e, t, r) {
|
|
|
3339
3342
|
},
|
|
3340
3343
|
dispose() {
|
|
3341
3344
|
if (!a) {
|
|
3342
|
-
a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve:
|
|
3343
|
-
for (const [,
|
|
3344
|
-
|
|
3345
|
+
a = !0, i += 1, d.reset(), l.clear(), f.forEach(({ resolve: D }) => D(null)), f.clear(), c = Bt;
|
|
3346
|
+
for (const [, D] of S)
|
|
3347
|
+
D.resolve();
|
|
3345
3348
|
S.clear(), n?.terminate(), n = null;
|
|
3346
3349
|
}
|
|
3347
3350
|
}
|
|
@@ -3353,7 +3356,7 @@ async function ha(e, t) {
|
|
|
3353
3356
|
maxTextureSize: t.pixiMaxTextureSize
|
|
3354
3357
|
});
|
|
3355
3358
|
let n = 0, s = null, i = !1;
|
|
3356
|
-
const o = Tr(async (a, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (
|
|
3359
|
+
const o = Tr(async (a, u) => i ? !1 : t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame() ? (Ne()?.onWorkerStale(), !1) : (r.drawLiveFrame(a), o.isLatestSeq(u)));
|
|
3357
3360
|
return {
|
|
3358
3361
|
usesWorker: !1,
|
|
3359
3362
|
usesPixi: !0,
|
|
@@ -3393,7 +3396,7 @@ async function ha(e, t) {
|
|
|
3393
3396
|
n += 1;
|
|
3394
3397
|
const l = n;
|
|
3395
3398
|
o.reset(), t.onStatus?.(u), r.drawLiveFrame({
|
|
3396
|
-
mouthPath:
|
|
3399
|
+
mouthPath: vt(u),
|
|
3397
3400
|
expressionPath: null
|
|
3398
3401
|
});
|
|
3399
3402
|
},
|
|
@@ -3512,10 +3515,10 @@ const ga = {
|
|
|
3512
3515
|
fontSize: "0.875rem",
|
|
3513
3516
|
textAlign: "center"
|
|
3514
3517
|
};
|
|
3515
|
-
function
|
|
3518
|
+
function gt(e) {
|
|
3516
3519
|
return fs(e) ? Sn : vn;
|
|
3517
3520
|
}
|
|
3518
|
-
function
|
|
3521
|
+
function Le(e, t) {
|
|
3519
3522
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
3520
3523
|
}
|
|
3521
3524
|
const Ma = Hn(function({
|
|
@@ -3525,18 +3528,18 @@ const Ma = Hn(function({
|
|
|
3525
3528
|
assets: s,
|
|
3526
3529
|
authToken: i,
|
|
3527
3530
|
apiBase: o,
|
|
3528
|
-
ttsEngineId: a =
|
|
3531
|
+
ttsEngineId: a = tt,
|
|
3529
3532
|
voiceId: u,
|
|
3530
|
-
speakingRate: l =
|
|
3533
|
+
speakingRate: l = Vt,
|
|
3531
3534
|
className: f,
|
|
3532
3535
|
style: c,
|
|
3533
3536
|
canvasStyle: d,
|
|
3534
3537
|
onStatusChange: g,
|
|
3535
3538
|
onDisplayStatus: S,
|
|
3536
|
-
onError:
|
|
3537
|
-
onReady:
|
|
3539
|
+
onError: h,
|
|
3540
|
+
onReady: M,
|
|
3538
3541
|
showErrorOverlay: _ = !0,
|
|
3539
|
-
onUserTranscript:
|
|
3542
|
+
onUserTranscript: D,
|
|
3540
3543
|
onBotOutput: w,
|
|
3541
3544
|
onRealtimeLipsyncDebug: b,
|
|
3542
3545
|
onFrameRenderStats: L,
|
|
@@ -3544,458 +3547,458 @@ const Ma = Hn(function({
|
|
|
3544
3547
|
lipsyncPlaybackWarmupMs: G = 1500,
|
|
3545
3548
|
pixiMaxTextureSize: C
|
|
3546
3549
|
}, k) {
|
|
3547
|
-
const P = H(null),
|
|
3548
|
-
|
|
3549
|
-
const
|
|
3550
|
-
|
|
3551
|
-
const
|
|
3550
|
+
const P = H(null), N = H(null), I = H(null), te = H(B);
|
|
3551
|
+
te.current = B;
|
|
3552
|
+
const V = H(G);
|
|
3553
|
+
V.current = G;
|
|
3554
|
+
const J = H(0), j = H(Sr()), X = H(Ri()), pe = H(0), re = H(0), fe = H(0), de = H(null), ue = H(null), v = H(!1), E = H(!1), m = H(!1), T = H("sil"), R = H(0), F = H(!1), A = H(
|
|
3552
3555
|
null
|
|
3553
|
-
), $ = H(!1), [Y, Q] =
|
|
3554
|
-
|
|
3555
|
-
const y =
|
|
3556
|
+
), $ = H(!1), [Y, Q] = Ze("idle"), [Z, be] = Ze(null), [ke, Be] = Ze(!1), [ot, Me] = Ze(!1), [Ht, p] = Ze({ width: 842, height: 1264 }), [x, z] = Ze(0), ne = H(!1), ce = H(i ?? null), Te = o?.trim() || St, me = H(null), he = H(null), _e = H(!1), ct = H({ width: 842, height: 1264 }), Ce = H(null), Oe = H("sil"), Ue = H(void 0), ut = H(/* @__PURE__ */ new Map()), kt = H(M), ie = H(S), lt = H(h), ft = H(D), je = H(w), le = H(b), ve = H(L), we = H(qi());
|
|
3557
|
+
kt.current = M, ie.current = S, lt.current = h, ft.current = D, je.current = w, le.current = b, ve.current = L, He(() => {
|
|
3558
|
+
const y = we.current;
|
|
3556
3559
|
return Gr(y), () => Gr(null);
|
|
3557
3560
|
}, []);
|
|
3558
|
-
const
|
|
3561
|
+
const Ye = xe(
|
|
3559
3562
|
(y) => {
|
|
3560
|
-
const
|
|
3561
|
-
return { ttsEngineId:
|
|
3563
|
+
const O = y?.ttsEngineId ?? a ?? he.current?.ttsEngineId ?? tt, W = y?.voiceId ?? u ?? he.current?.voiceId ?? gt(O);
|
|
3564
|
+
return { ttsEngineId: O, voiceId: W };
|
|
3562
3565
|
},
|
|
3563
3566
|
[a, u]
|
|
3564
|
-
),
|
|
3565
|
-
|
|
3566
|
-
}, []),
|
|
3567
|
+
), Ee = xe((y) => {
|
|
3568
|
+
be(y), lt.current?.(y);
|
|
3569
|
+
}, []), Ve = xe(
|
|
3567
3570
|
(y) => {
|
|
3568
3571
|
Q(y), g?.(y);
|
|
3569
3572
|
},
|
|
3570
3573
|
[g]
|
|
3571
|
-
),
|
|
3572
|
-
Or(
|
|
3573
|
-
onLipsyncDebug: (y) =>
|
|
3574
|
+
), ee = H(
|
|
3575
|
+
Or(Ve, Te, {
|
|
3576
|
+
onLipsyncDebug: (y) => le.current?.(y)
|
|
3574
3577
|
})
|
|
3575
|
-
),
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3578
|
+
), ae = H(null);
|
|
3579
|
+
He(() => (ee.current = Or(
|
|
3580
|
+
Ve,
|
|
3581
|
+
Te,
|
|
3579
3582
|
{
|
|
3580
|
-
onLipsyncDebug: (y) =>
|
|
3583
|
+
onLipsyncDebug: (y) => le.current?.(y)
|
|
3581
3584
|
}
|
|
3582
|
-
), i &&
|
|
3583
|
-
|
|
3584
|
-
const y =
|
|
3585
|
-
y && (y.disconnect(),
|
|
3586
|
-
}), [
|
|
3587
|
-
const Er =
|
|
3588
|
-
|
|
3585
|
+
), i && ee.current.setDeveloperToken(i), ee.current.setTtsEngineId(a), () => {
|
|
3586
|
+
ee.current.stop();
|
|
3587
|
+
const y = ae.current;
|
|
3588
|
+
y && (y.disconnect(), ae.current = null);
|
|
3589
|
+
}), [Ve, i, a, Te]);
|
|
3590
|
+
const Er = xe(() => (ae.current || (ae.current = si(
|
|
3591
|
+
Ve,
|
|
3589
3592
|
{
|
|
3590
3593
|
speakingRate: l,
|
|
3591
|
-
onUserTranscript: (y,
|
|
3592
|
-
onBotOutput: (y) =>
|
|
3593
|
-
onLipsyncDebug: (y) =>
|
|
3594
|
+
onUserTranscript: (y, O) => ft.current?.(y, O),
|
|
3595
|
+
onBotOutput: (y) => je.current?.(y),
|
|
3596
|
+
onLipsyncDebug: (y) => le.current?.(y)
|
|
3594
3597
|
}
|
|
3595
|
-
),
|
|
3596
|
-
|
|
3597
|
-
}, []),
|
|
3598
|
-
|
|
3599
|
-
}, []), Ar =
|
|
3600
|
-
!$.current || !A.current || (
|
|
3601
|
-
if (
|
|
3602
|
-
|
|
3603
|
-
|
|
3598
|
+
), ae.current.setTtsEngineId(a)), ae.current), [Ve, l, a]), Ae = xe(() => {
|
|
3599
|
+
de.current != null && (clearTimeout(de.current), de.current = null);
|
|
3600
|
+
}, []), Fe = xe(() => {
|
|
3601
|
+
ue.current != null && (clearTimeout(ue.current), ue.current = null), m.current = !1;
|
|
3602
|
+
}, []), Ar = xe(() => {
|
|
3603
|
+
!$.current || !A.current || (Fe(), m.current = !0, ue.current = setTimeout(() => {
|
|
3604
|
+
if (ue.current = null, Le(
|
|
3605
|
+
ee.current,
|
|
3606
|
+
ae.current
|
|
3604
3607
|
).isSpeaking()) {
|
|
3605
|
-
|
|
3608
|
+
m.current = !1;
|
|
3606
3609
|
return;
|
|
3607
3610
|
}
|
|
3608
3611
|
if (v.current) {
|
|
3609
|
-
|
|
3612
|
+
m.current = !1;
|
|
3610
3613
|
return;
|
|
3611
3614
|
}
|
|
3612
3615
|
const y = A.current;
|
|
3613
3616
|
if (!y) {
|
|
3614
|
-
|
|
3617
|
+
m.current = !1;
|
|
3615
3618
|
return;
|
|
3616
3619
|
}
|
|
3617
3620
|
y.restart(), y.setActive(!0);
|
|
3618
|
-
const
|
|
3621
|
+
const O = y.getVideo();
|
|
3619
3622
|
let W = !1;
|
|
3620
3623
|
const K = () => {
|
|
3621
|
-
W || (W = !0,
|
|
3624
|
+
W || (W = !0, O.removeEventListener("playing", q), m.current = !1);
|
|
3622
3625
|
}, q = () => {
|
|
3623
3626
|
K();
|
|
3624
3627
|
};
|
|
3625
|
-
if (
|
|
3628
|
+
if (O.addEventListener("playing", q, { once: !0 }), O.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !O.paused) {
|
|
3626
3629
|
K();
|
|
3627
3630
|
return;
|
|
3628
3631
|
}
|
|
3629
3632
|
setTimeout(K, 300);
|
|
3630
3633
|
}, Ki));
|
|
3631
|
-
}, [
|
|
3632
|
-
if (
|
|
3633
|
-
|
|
3634
|
+
}, [Fe]), Xe = xe(() => {
|
|
3635
|
+
if (Ae(), ie.current?.("sil"), v.current = !1, !$.current || !A.current) {
|
|
3636
|
+
m.current = !1;
|
|
3634
3637
|
return;
|
|
3635
3638
|
}
|
|
3636
3639
|
Ar();
|
|
3637
|
-
}, [
|
|
3640
|
+
}, [Ae, Ar]), $t = xe(
|
|
3638
3641
|
async (y) => {
|
|
3639
|
-
const
|
|
3642
|
+
const O = re.current, W = N.current, K = P.current, q = () => {
|
|
3640
3643
|
y?.fallbackOnly || (v.current = !1);
|
|
3641
3644
|
};
|
|
3642
|
-
if (!W || !K || !
|
|
3645
|
+
if (!W || !K || !ke) {
|
|
3643
3646
|
q();
|
|
3644
3647
|
return;
|
|
3645
3648
|
}
|
|
3646
|
-
if (
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
+
if (Le(
|
|
3650
|
+
ee.current,
|
|
3651
|
+
ae.current
|
|
3649
3652
|
).isSpeaking()) {
|
|
3650
3653
|
q();
|
|
3651
3654
|
return;
|
|
3652
3655
|
}
|
|
3653
3656
|
if (y?.fallbackOnly) {
|
|
3654
|
-
if (!v.current || (
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
+
if (!v.current || (Ie(j.current), await W.renderSilOnly(), O !== re.current) || Le(
|
|
3658
|
+
ee.current,
|
|
3659
|
+
ae.current
|
|
3657
3660
|
).isSpeaking())
|
|
3658
3661
|
return;
|
|
3659
|
-
|
|
3662
|
+
Xe();
|
|
3660
3663
|
return;
|
|
3661
3664
|
}
|
|
3662
|
-
if (jr(
|
|
3663
|
-
|
|
3665
|
+
if (jr(j.current)) {
|
|
3666
|
+
Ie(j.current), Xe();
|
|
3664
3667
|
return;
|
|
3665
3668
|
}
|
|
3666
|
-
if (
|
|
3667
|
-
if (
|
|
3668
|
-
|
|
3669
|
-
|
|
3669
|
+
if (te.current && W.supportsBufferedPlayback && !y?.fallbackOnly) {
|
|
3670
|
+
if (Ie(j.current), I.current?.reset(), await W.renderSilOnly(), O !== re.current || Le(
|
|
3671
|
+
ee.current,
|
|
3672
|
+
ae.current
|
|
3670
3673
|
).isSpeaking())
|
|
3671
3674
|
return;
|
|
3672
|
-
|
|
3675
|
+
Xe();
|
|
3673
3676
|
return;
|
|
3674
3677
|
}
|
|
3675
|
-
const
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3678
|
+
const Pe = Xi(
|
|
3679
|
+
Le(
|
|
3680
|
+
ee.current,
|
|
3681
|
+
ae.current
|
|
3679
3682
|
).getVisemeQueue(),
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
),
|
|
3683
|
-
|
|
3684
|
-
|
|
3683
|
+
R.current,
|
|
3684
|
+
T.current
|
|
3685
|
+
), mt = Ji(
|
|
3686
|
+
Pe,
|
|
3687
|
+
Ce.current
|
|
3685
3688
|
);
|
|
3686
|
-
if (
|
|
3687
|
-
if (await W.renderSilOnly(),
|
|
3688
|
-
|
|
3689
|
-
|
|
3689
|
+
if (Ie(j.current), !mt) {
|
|
3690
|
+
if (await W.renderSilOnly(), O !== re.current || Le(
|
|
3691
|
+
ee.current,
|
|
3692
|
+
ae.current
|
|
3690
3693
|
).isSpeaking())
|
|
3691
3694
|
return;
|
|
3692
|
-
|
|
3695
|
+
Xe();
|
|
3693
3696
|
return;
|
|
3694
3697
|
}
|
|
3695
3698
|
try {
|
|
3696
3699
|
await W.renderViseme(K, "sil", {
|
|
3697
|
-
from:
|
|
3700
|
+
from: Pe,
|
|
3698
3701
|
transitionDurationMs: Fn
|
|
3699
3702
|
});
|
|
3700
|
-
} catch (
|
|
3701
|
-
if (
|
|
3702
|
-
throw
|
|
3703
|
+
} catch (Je) {
|
|
3704
|
+
if (Je?.name !== "AbortError")
|
|
3705
|
+
throw Je;
|
|
3703
3706
|
}
|
|
3704
|
-
if (
|
|
3707
|
+
if (O !== re.current) {
|
|
3705
3708
|
q();
|
|
3706
3709
|
return;
|
|
3707
3710
|
}
|
|
3708
|
-
if (
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
+
if (Le(
|
|
3712
|
+
ee.current,
|
|
3713
|
+
ae.current
|
|
3711
3714
|
).isSpeaking()) {
|
|
3712
3715
|
q();
|
|
3713
3716
|
return;
|
|
3714
3717
|
}
|
|
3715
|
-
|
|
3718
|
+
Xe();
|
|
3716
3719
|
},
|
|
3717
|
-
[
|
|
3718
|
-
),
|
|
3719
|
-
if (
|
|
3720
|
-
|
|
3721
|
-
const y =
|
|
3720
|
+
[ke, Xe]
|
|
3721
|
+
), dt = xe(() => {
|
|
3722
|
+
if (E.current || v.current) return;
|
|
3723
|
+
E.current = !0, v.current = !0, Ae();
|
|
3724
|
+
const y = re.current;
|
|
3722
3725
|
$t().finally(() => {
|
|
3723
|
-
|
|
3724
|
-
}),
|
|
3725
|
-
|
|
3726
|
+
E.current = !1;
|
|
3727
|
+
}), de.current = setTimeout(() => {
|
|
3728
|
+
de.current = null, y === re.current && $t({ fallbackOnly: !0 });
|
|
3726
3729
|
}, Qi());
|
|
3727
|
-
}, [
|
|
3730
|
+
}, [Ae, $t]), Pr = xe(async () => {
|
|
3728
3731
|
const y = Math.floor(Date.now() / 1e3);
|
|
3729
|
-
if (
|
|
3730
|
-
return
|
|
3731
|
-
const
|
|
3732
|
-
|
|
3733
|
-
const W = await _s(
|
|
3734
|
-
return
|
|
3732
|
+
if (me.current && y < me.current.expiresAt - 60)
|
|
3733
|
+
return me.current.key;
|
|
3734
|
+
const O = ce.current ?? await jt();
|
|
3735
|
+
ce.current = O, ee.current.setDeveloperToken(O);
|
|
3736
|
+
const W = await _s(O, Te);
|
|
3737
|
+
return me.current = {
|
|
3735
3738
|
key: W.value,
|
|
3736
3739
|
expiresAt: W.expiresAt
|
|
3737
3740
|
}, W.value;
|
|
3738
|
-
}, [
|
|
3739
|
-
|
|
3740
|
-
i && (
|
|
3741
|
-
}, [i]),
|
|
3742
|
-
|
|
3743
|
-
}, [a]),
|
|
3744
|
-
const y = u ??
|
|
3745
|
-
|
|
3741
|
+
}, [Te]);
|
|
3742
|
+
He(() => {
|
|
3743
|
+
i && (ce.current = i, ee.current.setDeveloperToken(i));
|
|
3744
|
+
}, [i]), He(() => {
|
|
3745
|
+
ee.current.setTtsEngineId(a), ae.current?.setTtsEngineId(a), he.current && (he.current.ttsEngineId = a);
|
|
3746
|
+
}, [a]), He(() => {
|
|
3747
|
+
const y = u ?? gt(a);
|
|
3748
|
+
he.current && (he.current.voiceId = y);
|
|
3746
3749
|
}, [u, a]);
|
|
3747
|
-
const
|
|
3750
|
+
const We = Mr(
|
|
3748
3751
|
() => ks(r, n),
|
|
3749
3752
|
[r, n]
|
|
3750
|
-
), Un = Mr(() => s ? JSON.stringify(s) :
|
|
3751
|
-
return
|
|
3752
|
-
if (!t && !s && !
|
|
3753
|
-
|
|
3753
|
+
), Un = Mr(() => s ? JSON.stringify(s) : We ? `face:${We}` : `id:${t ?? ""}`, [s, We, t]);
|
|
3754
|
+
return He(() => {
|
|
3755
|
+
if (!t && !s && !We) {
|
|
3756
|
+
Ee("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
3754
3757
|
return;
|
|
3755
3758
|
}
|
|
3756
3759
|
let y = !1;
|
|
3757
|
-
|
|
3758
|
-
const
|
|
3759
|
-
if (!
|
|
3760
|
+
_e.current = !1, Be(!1), Me(!1), be(null), he.current = null, A.current = null, $.current = !1;
|
|
3761
|
+
const O = P.current;
|
|
3762
|
+
if (!O) return;
|
|
3760
3763
|
let W = null;
|
|
3761
3764
|
return (async () => {
|
|
3762
3765
|
try {
|
|
3763
|
-
let K, q, Se,
|
|
3766
|
+
let K, q, Se, Pe;
|
|
3764
3767
|
if (s)
|
|
3765
|
-
K = s, q = a, Se = u ??
|
|
3766
|
-
else if (
|
|
3767
|
-
|
|
3768
|
+
K = s, q = a, Se = u ?? gt(q);
|
|
3769
|
+
else if (We)
|
|
3770
|
+
ie.current?.("loadFace"), K = Br(We), q = a, Se = u ?? gt(q);
|
|
3768
3771
|
else {
|
|
3769
|
-
|
|
3770
|
-
const
|
|
3772
|
+
ie.current?.("getAiTwin");
|
|
3773
|
+
const U = await Jt(
|
|
3771
3774
|
ms(t),
|
|
3772
3775
|
3e4,
|
|
3773
3776
|
"getAiTwin"
|
|
3774
3777
|
);
|
|
3775
3778
|
if (y) return;
|
|
3776
|
-
if (!
|
|
3779
|
+
if (!U.faceId?.trim())
|
|
3777
3780
|
throw new Error("getAiTwin returned no faceId");
|
|
3778
|
-
q =
|
|
3781
|
+
q = U.ttsEngineId, Se = u ?? U.voiceId ?? gt(q), Pe = U.knowledgeContextId?.trim() || void 0, K = Br(U.faceId);
|
|
3779
3782
|
}
|
|
3780
|
-
|
|
3781
|
-
const
|
|
3782
|
-
W = pa(
|
|
3783
|
-
preferLegacyRenderer:
|
|
3783
|
+
he.current = { ttsEngineId: q, voiceId: Se, personaId: Pe }, Ts(K), A.current = Di();
|
|
3784
|
+
const mt = !!(s && !Ge(s));
|
|
3785
|
+
W = pa(O, {
|
|
3786
|
+
preferLegacyRenderer: mt,
|
|
3784
3787
|
pixiMaxTextureSize: C,
|
|
3785
|
-
onStatus: (
|
|
3786
|
-
y ||
|
|
3788
|
+
onStatus: (U) => {
|
|
3789
|
+
y || ie.current?.(U);
|
|
3787
3790
|
},
|
|
3788
|
-
onError: (
|
|
3789
|
-
y ||
|
|
3791
|
+
onError: (U) => {
|
|
3792
|
+
y || Ee(U);
|
|
3790
3793
|
},
|
|
3791
3794
|
shouldAcceptLiveFrame: () => {
|
|
3792
|
-
const
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
+
const U = Le(
|
|
3796
|
+
ee.current,
|
|
3797
|
+
ae.current
|
|
3795
3798
|
);
|
|
3796
|
-
return (
|
|
3799
|
+
return (U.isSpeaking() || U.isWarmingUp()) && !v.current;
|
|
3797
3800
|
},
|
|
3798
3801
|
onWebGlContextLost: () => {
|
|
3799
|
-
y ||
|
|
3800
|
-
y ||
|
|
3802
|
+
y || ne.current || (ne.current = !0, queueMicrotask(() => {
|
|
3803
|
+
y || z((U) => U + 1);
|
|
3801
3804
|
}));
|
|
3802
3805
|
}
|
|
3803
|
-
}),
|
|
3804
|
-
const
|
|
3805
|
-
if (!
|
|
3806
|
+
}), N.current = W, I.current = na(W), ne.current = !1, ((U) => {
|
|
3807
|
+
const oe = () => {
|
|
3808
|
+
if (!U || V.current <= 0)
|
|
3806
3809
|
return !1;
|
|
3807
|
-
const ye =
|
|
3808
|
-
return ye ?
|
|
3810
|
+
const ye = N.current;
|
|
3811
|
+
return ye ? te.current && ye.supportsBufferedPlayback ? !0 : ye.usesPixi : !1;
|
|
3809
3812
|
};
|
|
3810
|
-
|
|
3811
|
-
})(!0),
|
|
3812
|
-
const
|
|
3813
|
+
ee.current.setLipsyncWarmupHold(U, oe), ae.current?.setLipsyncWarmupHold(U, oe);
|
|
3814
|
+
})(!0), ie.current?.("auth");
|
|
3815
|
+
const ht = ce.current ?? i ?? await Jt(jt(), 3e4, "getAuthToken");
|
|
3813
3816
|
if (y) return;
|
|
3814
|
-
|
|
3815
|
-
const
|
|
3817
|
+
ce.current = ht, ee.current.setDeveloperToken(ht), ee.current.setTtsEngineId(q);
|
|
3818
|
+
const Tt = bt() ? await Pr() : void 0;
|
|
3816
3819
|
if (y) return;
|
|
3817
|
-
|
|
3818
|
-
const
|
|
3819
|
-
W.loadAssets(
|
|
3820
|
+
ie.current?.("loadAssets");
|
|
3821
|
+
const se = await Jt(
|
|
3822
|
+
W.loadAssets(Tt),
|
|
3820
3823
|
18e4,
|
|
3821
3824
|
"load face assets"
|
|
3822
3825
|
);
|
|
3823
|
-
if (!y &&
|
|
3824
|
-
|
|
3825
|
-
y ||
|
|
3826
|
+
if (!y && se.width > 0 && se.height > 0 && (ct.current = se, p(se)), y) return;
|
|
3827
|
+
Ce.current = W.getVisemeAtlasPaths(), _e.current = !0, Be(!0), kt.current?.(), W.renderSilOnly().then(() => {
|
|
3828
|
+
y || ie.current?.("sil");
|
|
3826
3829
|
}), (async () => {
|
|
3827
3830
|
try {
|
|
3828
|
-
const
|
|
3829
|
-
if (await A.current.load(
|
|
3830
|
-
$.current = !0,
|
|
3831
|
-
const
|
|
3832
|
-
W.usesPixi ? W.drawIdleVideo(
|
|
3833
|
-
|
|
3834
|
-
|
|
3831
|
+
const U = await li(Tt);
|
|
3832
|
+
if (await A.current.load(U), y) return;
|
|
3833
|
+
$.current = !0, Me(!0), Ie(j.current), A.current.setActive(!0);
|
|
3834
|
+
const oe = A.current.getVideo();
|
|
3835
|
+
W.usesPixi ? W.drawIdleVideo(oe) : await Kr(
|
|
3836
|
+
O,
|
|
3837
|
+
oe,
|
|
3835
3838
|
null,
|
|
3836
3839
|
void 0,
|
|
3837
|
-
|
|
3838
|
-
), y ||
|
|
3839
|
-
} catch (
|
|
3840
|
+
ct.current
|
|
3841
|
+
), y || ie.current?.("idle");
|
|
3842
|
+
} catch (U) {
|
|
3840
3843
|
if (y) return;
|
|
3841
|
-
$.current = !1,
|
|
3844
|
+
$.current = !1, Me(!1), console.warn("[AiTwin] Idle video unavailable:", U);
|
|
3842
3845
|
}
|
|
3843
3846
|
})();
|
|
3844
3847
|
} catch (K) {
|
|
3845
3848
|
if (y) return;
|
|
3846
3849
|
if (K instanceof Qt) {
|
|
3847
|
-
|
|
3850
|
+
Ee(K.message);
|
|
3848
3851
|
return;
|
|
3849
3852
|
}
|
|
3850
|
-
|
|
3853
|
+
Ee(K instanceof Error ? K.message : "Failed to load AI twin");
|
|
3851
3854
|
}
|
|
3852
3855
|
})(), () => {
|
|
3853
|
-
y = !0, A.current?.dispose(), W?.dispose(),
|
|
3856
|
+
y = !0, A.current?.dispose(), W?.dispose(), N.current = null;
|
|
3854
3857
|
};
|
|
3855
|
-
}, [Un, s,
|
|
3856
|
-
const y = { current: !1 },
|
|
3857
|
-
const W = P.current, K =
|
|
3858
|
-
|
|
3859
|
-
|
|
3858
|
+
}, [Un, s, We, t, a, u, i, C, Pr, Ee, x]), He(() => {
|
|
3859
|
+
const y = { current: !1 }, O = () => {
|
|
3860
|
+
const W = P.current, K = N.current, q = Le(
|
|
3861
|
+
ee.current,
|
|
3862
|
+
ae.current
|
|
3860
3863
|
);
|
|
3861
|
-
if (!W || !K || !
|
|
3862
|
-
|
|
3864
|
+
if (!W || !K || !ke) {
|
|
3865
|
+
pe.current = requestAnimationFrame(O);
|
|
3863
3866
|
return;
|
|
3864
3867
|
}
|
|
3865
3868
|
if (document.hidden) {
|
|
3866
|
-
A.current?.setActive(!1),
|
|
3869
|
+
A.current?.setActive(!1), pe.current = requestAnimationFrame(O);
|
|
3867
3870
|
return;
|
|
3868
3871
|
}
|
|
3869
|
-
const Se = q.isSpeaking(),
|
|
3870
|
-
|
|
3871
|
-
const
|
|
3872
|
-
if (
|
|
3872
|
+
const Se = q.isSpeaking(), Pe = q.isWarmingUp(), mt = Se && !F.current, Je = F.current && !Se;
|
|
3873
|
+
mt && (Ae(), Fe(), v.current = !1, E.current = !1, Ie(j.current), I.current?.reset(), we.current.reset(), Ue.current = void 0, fe.current = 0, T.current = "sil", R.current = 0, A.current?.setActive(!1)), Je && (X.current.reset(), A.current?.setActive(!1), I.current?.reset(), dt());
|
|
3874
|
+
const ht = Je || v.current || m.current, Tt = B && K.supportsBufferedPlayback;
|
|
3875
|
+
if (Pe) {
|
|
3873
3876
|
$.current && A.current?.setActive(!1);
|
|
3874
|
-
const
|
|
3875
|
-
|
|
3876
|
-
const
|
|
3877
|
-
queue:
|
|
3877
|
+
const se = q.getVisemeQueue();
|
|
3878
|
+
se.length > 0 && J.current === 0 && (J.current = performance.now()), X.current.advance(performance.now());
|
|
3879
|
+
const U = X.current.getExpressionPath(), oe = X.current.getDrawKey(), ye = {
|
|
3880
|
+
queue: se,
|
|
3878
3881
|
elapsedMs: 0,
|
|
3879
|
-
expressionPath:
|
|
3880
|
-
expressionDrawKey:
|
|
3881
|
-
availablePaths:
|
|
3882
|
+
expressionPath: U,
|
|
3883
|
+
expressionDrawKey: oe,
|
|
3884
|
+
availablePaths: Ce.current
|
|
3882
3885
|
};
|
|
3883
|
-
let
|
|
3884
|
-
|
|
3886
|
+
let Re = !1;
|
|
3887
|
+
Tt && I.current ? (I.current.warmupTick(ye), Re = I.current.isWarmupReady(
|
|
3885
3888
|
ye,
|
|
3886
|
-
|
|
3889
|
+
V.current
|
|
3887
3890
|
)) : K.usesPixi && Yr(
|
|
3888
3891
|
W,
|
|
3889
|
-
|
|
3892
|
+
se,
|
|
3890
3893
|
0,
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
(
|
|
3895
|
-
K.drawLiveFrame(
|
|
3896
|
-
|
|
3894
|
+
U,
|
|
3895
|
+
oe,
|
|
3896
|
+
j.current,
|
|
3897
|
+
(pt, Et, qt, At) => {
|
|
3898
|
+
K.drawLiveFrame(pt, Et, qt, (De) => {
|
|
3899
|
+
At?.(De), q.isWarmingUp() && De !== "" && !jr({ lastDrawnKey: De }) && (J.current = 0, q.releaseWarmupHold());
|
|
3897
3900
|
});
|
|
3898
3901
|
},
|
|
3899
|
-
(
|
|
3900
|
-
|
|
3902
|
+
(pt) => {
|
|
3903
|
+
ie.current?.(pt.label);
|
|
3901
3904
|
},
|
|
3902
|
-
|
|
3905
|
+
Ce.current
|
|
3903
3906
|
);
|
|
3904
|
-
const
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
), (
|
|
3907
|
+
const Qe = J.current > 0 && performance.now() - J.current > os;
|
|
3908
|
+
ie.current?.(
|
|
3909
|
+
Re ? "buffer ready" : "buffering lipsync…"
|
|
3910
|
+
), (Re || Qe) && (J.current = 0, q.releaseWarmupHold()), F.current = q.isSpeaking(), pe.current = requestAnimationFrame(O);
|
|
3908
3911
|
return;
|
|
3909
3912
|
}
|
|
3910
3913
|
if (Se) {
|
|
3911
3914
|
$.current && A.current?.setActive(!1);
|
|
3912
|
-
const
|
|
3913
|
-
js(
|
|
3914
|
-
const
|
|
3915
|
-
|
|
3915
|
+
const se = q.getVisemeQueue(), U = q.getPlaybackElapsedMs();
|
|
3916
|
+
js(se, U), R.current = U;
|
|
3917
|
+
const oe = se.length > 0 ? Ut(se, U) : "sil";
|
|
3918
|
+
oe !== "sil" && (T.current = oe);
|
|
3916
3919
|
const ye = Li(
|
|
3917
|
-
|
|
3920
|
+
U,
|
|
3918
3921
|
q.getSentenceEmotions(),
|
|
3919
3922
|
q.getWordQueue(),
|
|
3920
3923
|
q.getStreamMood()
|
|
3921
3924
|
);
|
|
3922
|
-
|
|
3925
|
+
X.current.setTargetEmotion(ye), X.current.setTargetEyebrow(
|
|
3923
3926
|
Mi(
|
|
3924
|
-
|
|
3927
|
+
U,
|
|
3925
3928
|
q.getWordQueue(),
|
|
3926
3929
|
gr(ye)
|
|
3927
3930
|
)
|
|
3928
|
-
),
|
|
3929
|
-
const
|
|
3931
|
+
), X.current.advance(performance.now());
|
|
3932
|
+
const Re = X.current.getExpressionPath(), Qe = X.current.getDrawKey(), pt = (De, Kt, wt, Gt) => {
|
|
3930
3933
|
const xr = {
|
|
3931
|
-
label:
|
|
3932
|
-
elapsedMs:
|
|
3934
|
+
label: Oe.current,
|
|
3935
|
+
elapsedMs: U,
|
|
3933
3936
|
mouthPath: Kt.mouthPath,
|
|
3934
|
-
transitionMeta:
|
|
3937
|
+
transitionMeta: Ue.current
|
|
3935
3938
|
};
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
), K.drawLiveFrame(
|
|
3940
|
-
const Vn =
|
|
3941
|
-
|
|
3939
|
+
ut.current.set(wt, xr), I.current?.markExternallyDisplayed(
|
|
3940
|
+
wt,
|
|
3941
|
+
Re
|
|
3942
|
+
), K.drawLiveFrame(De, Kt, wt, (Pt) => {
|
|
3943
|
+
const Vn = ut.current.get(Pt) ?? xr;
|
|
3944
|
+
ut.current.delete(Pt), we.current.onDrawDisplayed(
|
|
3942
3945
|
Vn,
|
|
3943
|
-
|
|
3944
|
-
),
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
), Gt?.(
|
|
3946
|
+
se
|
|
3947
|
+
), I.current?.markExternallyDisplayed(
|
|
3948
|
+
Pt,
|
|
3949
|
+
Re
|
|
3950
|
+
), Gt?.(Pt);
|
|
3948
3951
|
});
|
|
3949
|
-
},
|
|
3950
|
-
|
|
3952
|
+
}, Et = (De) => {
|
|
3953
|
+
Oe.current = De.label, Ue.current = De.transitionMeta, ie.current?.(De.label);
|
|
3951
3954
|
}, qt = B && K.supportsBufferedPlayback;
|
|
3952
|
-
let
|
|
3953
|
-
qt &&
|
|
3955
|
+
let At = !1;
|
|
3956
|
+
qt && I.current && (At = I.current.tick({
|
|
3954
3957
|
canvas: W,
|
|
3955
|
-
queue:
|
|
3956
|
-
elapsedMs:
|
|
3957
|
-
expressionPath:
|
|
3958
|
-
expressionDrawKey:
|
|
3959
|
-
playbackState:
|
|
3960
|
-
availablePaths:
|
|
3961
|
-
onStatus:
|
|
3962
|
-
onDisplayed: (Kt,
|
|
3963
|
-
|
|
3958
|
+
queue: se,
|
|
3959
|
+
elapsedMs: U,
|
|
3960
|
+
expressionPath: Re,
|
|
3961
|
+
expressionDrawKey: Qe,
|
|
3962
|
+
playbackState: j.current,
|
|
3963
|
+
availablePaths: Ce.current,
|
|
3964
|
+
onStatus: Et,
|
|
3965
|
+
onDisplayed: (Kt, wt, Gt) => {
|
|
3966
|
+
we.current.onDrawDisplayed(
|
|
3964
3967
|
{
|
|
3965
3968
|
label: Gt,
|
|
3966
|
-
elapsedMs:
|
|
3967
|
-
mouthPath:
|
|
3968
|
-
transitionMeta:
|
|
3969
|
+
elapsedMs: U,
|
|
3970
|
+
mouthPath: wt,
|
|
3971
|
+
transitionMeta: Ue.current
|
|
3969
3972
|
},
|
|
3970
|
-
|
|
3973
|
+
se
|
|
3971
3974
|
);
|
|
3972
3975
|
}
|
|
3973
|
-
}).usedBuffer),
|
|
3976
|
+
}).usedBuffer), At || Yr(
|
|
3974
3977
|
W,
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
),
|
|
3984
|
-
|
|
3978
|
+
se,
|
|
3979
|
+
U,
|
|
3980
|
+
Re,
|
|
3981
|
+
Qe,
|
|
3982
|
+
j.current,
|
|
3983
|
+
pt,
|
|
3984
|
+
Et,
|
|
3985
|
+
Ce.current
|
|
3986
|
+
), we.current.onRafTickSpeaking(), ve.current?.(
|
|
3987
|
+
we.current.snapshot(se, U)
|
|
3985
3988
|
);
|
|
3986
|
-
} else if (!
|
|
3987
|
-
const
|
|
3988
|
-
if (
|
|
3989
|
-
|
|
3990
|
-
const
|
|
3991
|
-
K.usesPixi ? (K.drawIdleVideo(
|
|
3989
|
+
} else if (!ht && $.current && A.current) {
|
|
3990
|
+
const se = A.current, U = se.getVideo();
|
|
3991
|
+
if (U.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
3992
|
+
se.setActive(!0);
|
|
3993
|
+
const oe = () => !q.isSpeaking() && !v.current && !m.current;
|
|
3994
|
+
K.usesPixi ? (K.drawIdleVideo(U, oe), oe() && ie.current?.("idle")) : y.current || (y.current = !0, Kr(
|
|
3992
3995
|
W,
|
|
3993
|
-
|
|
3996
|
+
U,
|
|
3994
3997
|
null,
|
|
3995
3998
|
void 0,
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
).then(() =>
|
|
3999
|
+
ct.current,
|
|
4000
|
+
oe
|
|
4001
|
+
).then(() => ie.current?.("idle")).finally(() => {
|
|
3999
4002
|
y.current = !1;
|
|
4000
4003
|
}));
|
|
4001
4004
|
} else
|
|
@@ -4003,106 +4006,106 @@ const Ma = Hn(function({
|
|
|
4003
4006
|
W,
|
|
4004
4007
|
null,
|
|
4005
4008
|
"__sil__",
|
|
4006
|
-
|
|
4007
|
-
(
|
|
4008
|
-
(
|
|
4009
|
+
j.current,
|
|
4010
|
+
(oe, ye, Re, Qe) => K.drawLiveFrame(oe, ye, Re, Qe),
|
|
4011
|
+
(oe) => ie.current?.(oe)
|
|
4009
4012
|
);
|
|
4010
|
-
} else
|
|
4013
|
+
} else ht || Xr(
|
|
4011
4014
|
W,
|
|
4012
4015
|
null,
|
|
4013
4016
|
"__sil__",
|
|
4014
|
-
|
|
4015
|
-
(
|
|
4016
|
-
(
|
|
4017
|
+
j.current,
|
|
4018
|
+
(se, U, oe, ye) => K.drawLiveFrame(se, U, oe, ye),
|
|
4019
|
+
(se) => ie.current?.(se)
|
|
4017
4020
|
);
|
|
4018
|
-
F.current = Se,
|
|
4021
|
+
F.current = Se, pe.current = requestAnimationFrame(O);
|
|
4019
4022
|
};
|
|
4020
|
-
return
|
|
4021
|
-
cancelAnimationFrame(
|
|
4023
|
+
return pe.current = requestAnimationFrame(O), () => {
|
|
4024
|
+
cancelAnimationFrame(pe.current), Ae(), Fe(), ee.current.stop(), ae.current?.stop();
|
|
4022
4025
|
};
|
|
4023
4026
|
}, [
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4027
|
+
ke,
|
|
4028
|
+
ot,
|
|
4029
|
+
dt,
|
|
4030
|
+
Ae,
|
|
4031
|
+
Fe
|
|
4029
4032
|
]), $n(
|
|
4030
4033
|
k,
|
|
4031
4034
|
() => ({
|
|
4032
|
-
speakText: async (y,
|
|
4035
|
+
speakText: async (y, O) => {
|
|
4033
4036
|
const W = y.trim();
|
|
4034
4037
|
if (!W) return;
|
|
4035
|
-
const K =
|
|
4036
|
-
if (!K || !
|
|
4038
|
+
const K = N.current;
|
|
4039
|
+
if (!K || !_e.current && !ke)
|
|
4037
4040
|
throw new Error("AI twin is not ready");
|
|
4038
|
-
const { ttsEngineId: q, voiceId: Se } =
|
|
4039
|
-
|
|
4041
|
+
const { ttsEngineId: q, voiceId: Se } = Ye(O);
|
|
4042
|
+
be(null), re.current += 1, Ae(), Fe(), v.current = !1, E.current = !1, T.current = "sil", R.current = 0, Ie(j.current), X.current.reset(), F.current = !1;
|
|
4040
4043
|
try {
|
|
4041
|
-
$.current ? (A.current?.setActive(!1), A.current?.restart(),
|
|
4044
|
+
$.current ? (A.current?.setActive(!1), A.current?.restart(), Ie(j.current)) : await K.renderSilOnly(), await ee.current.speak(W, {
|
|
4042
4045
|
voiceId: Se,
|
|
4043
|
-
speakingRate:
|
|
4046
|
+
speakingRate: O?.speakingRate ?? l,
|
|
4044
4047
|
ttsEngineId: q
|
|
4045
4048
|
});
|
|
4046
|
-
} catch (
|
|
4047
|
-
throw
|
|
4049
|
+
} catch (Pe) {
|
|
4050
|
+
throw Ee(Pe instanceof Error ? Pe.message : "TTS failed"), Pe;
|
|
4048
4051
|
}
|
|
4049
4052
|
},
|
|
4050
4053
|
stop: () => {
|
|
4051
|
-
|
|
4054
|
+
re.current += 1, Ae(), Fe(), v.current = !1, E.current = !1, ee.current.stop(), ae.current?.stop(), Ie(j.current), I.current?.reset(), J.current = 0, F.current = !1, dt();
|
|
4052
4055
|
},
|
|
4053
4056
|
setTtsEngineId: (y) => {
|
|
4054
|
-
|
|
4057
|
+
ee.current.setTtsEngineId(y), ae.current?.setTtsEngineId(y), he.current && (he.current.ttsEngineId = y);
|
|
4055
4058
|
},
|
|
4056
|
-
renderViseme: async (y,
|
|
4057
|
-
const W =
|
|
4058
|
-
if (!W || !K || !
|
|
4059
|
+
renderViseme: async (y, O) => {
|
|
4060
|
+
const W = N.current, K = P.current;
|
|
4061
|
+
if (!W || !K || !_e.current)
|
|
4059
4062
|
throw new Error("AI twin is not ready");
|
|
4060
4063
|
await W.renderViseme(K, y, {
|
|
4061
|
-
from:
|
|
4062
|
-
transitionDurationMs:
|
|
4063
|
-
gapMs:
|
|
4064
|
-
onStatus: (q) =>
|
|
4064
|
+
from: O?.from,
|
|
4065
|
+
transitionDurationMs: O?.transitionDurationMs,
|
|
4066
|
+
gapMs: O?.gapMs,
|
|
4067
|
+
onStatus: (q) => ie.current?.(q)
|
|
4065
4068
|
});
|
|
4066
4069
|
},
|
|
4067
|
-
isReady: () =>
|
|
4070
|
+
isReady: () => _e.current,
|
|
4068
4071
|
getStatus: () => Y,
|
|
4069
4072
|
connect: async (y = {}) => {
|
|
4070
|
-
|
|
4073
|
+
be(null);
|
|
4071
4074
|
try {
|
|
4072
|
-
let
|
|
4073
|
-
|
|
4074
|
-
const W = y.voiceId?.trim() ?? u ??
|
|
4075
|
+
let O = y.authToken?.trim();
|
|
4076
|
+
O || (O = ce.current ?? i ?? await jt(), ce.current = O);
|
|
4077
|
+
const W = y.voiceId?.trim() ?? u ?? he.current?.voiceId, K = y.personaId?.trim() ?? he.current?.personaId, q = Er();
|
|
4075
4078
|
await q.unlockAudio(), await q.connect({
|
|
4076
4079
|
...y,
|
|
4077
|
-
apiBase: y.apiBase?.trim() ||
|
|
4078
|
-
authToken:
|
|
4080
|
+
apiBase: y.apiBase?.trim() || Te,
|
|
4081
|
+
authToken: O,
|
|
4079
4082
|
voiceId: W,
|
|
4080
4083
|
personaId: K,
|
|
4081
4084
|
speakingRate: y.speakingRate ?? l
|
|
4082
4085
|
});
|
|
4083
|
-
} catch (
|
|
4084
|
-
throw
|
|
4085
|
-
|
|
4086
|
-
),
|
|
4086
|
+
} catch (O) {
|
|
4087
|
+
throw Ee(
|
|
4088
|
+
O instanceof Error ? O.message : "Voice connect failed"
|
|
4089
|
+
), O;
|
|
4087
4090
|
}
|
|
4088
4091
|
},
|
|
4089
4092
|
disconnect: async () => {
|
|
4090
|
-
const y =
|
|
4091
|
-
y && (
|
|
4093
|
+
const y = ae.current;
|
|
4094
|
+
y && (re.current += 1, Ae(), Fe(), v.current = !1, E.current = !1, Ie(j.current), I.current?.reset(), J.current = 0, F.current = !1, await y.disconnect(), dt());
|
|
4092
4095
|
},
|
|
4093
|
-
isConnected: () =>
|
|
4094
|
-
getVoiceStream: () =>
|
|
4096
|
+
isConnected: () => ae.current?.isConnected() ?? !1,
|
|
4097
|
+
getVoiceStream: () => ae.current?.getVoiceStream() ?? ee.current?.getVoiceStream() ?? null
|
|
4095
4098
|
}),
|
|
4096
4099
|
[
|
|
4097
|
-
|
|
4100
|
+
ke,
|
|
4098
4101
|
l,
|
|
4099
4102
|
i,
|
|
4100
4103
|
u,
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4104
|
+
Ae,
|
|
4105
|
+
Fe,
|
|
4106
|
+
dt,
|
|
4107
|
+
Ee,
|
|
4108
|
+
Ye,
|
|
4106
4109
|
Er,
|
|
4107
4110
|
Y
|
|
4108
4111
|
]
|
|
@@ -4111,8 +4114,8 @@ const Ma = Hn(function({
|
|
|
4111
4114
|
"canvas",
|
|
4112
4115
|
{
|
|
4113
4116
|
ref: P,
|
|
4114
|
-
width:
|
|
4115
|
-
height:
|
|
4117
|
+
width: Ht.width,
|
|
4118
|
+
height: Ht.height,
|
|
4116
4119
|
style: { ...ya, ...d },
|
|
4117
4120
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
4118
4121
|
}
|
|
@@ -4141,18 +4144,18 @@ export {
|
|
|
4141
4144
|
va as AI_TWIN_THUMBNAIL_FILENAME,
|
|
4142
4145
|
Ma as AiTwin,
|
|
4143
4146
|
Qt as AiTwinNotFoundError,
|
|
4144
|
-
|
|
4147
|
+
tt as DEFAULT_TTS_ENGINE_ID,
|
|
4145
4148
|
bn as MIC_SAMPLE_RATE,
|
|
4146
4149
|
Ps as OCULUS_VISEME_IDS,
|
|
4147
4150
|
kn as PLAYBACK_SAMPLE_RATE,
|
|
4148
4151
|
dr as SPEAKING_RATE_MAX,
|
|
4149
4152
|
fr as SPEAKING_RATE_MIN,
|
|
4150
|
-
|
|
4153
|
+
it as TTS_ENGINE_CARTESIA,
|
|
4151
4154
|
sn as TTS_ENGINE_GOOGLE,
|
|
4152
4155
|
cr as TTS_ENGINE_INWORLD,
|
|
4153
4156
|
Ia as VISEME_IDS,
|
|
4154
4157
|
Sn as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
4155
|
-
|
|
4158
|
+
Vt as VISEME_TEST_SPEAKING_RATE,
|
|
4156
4159
|
vn as VISEME_TEST_VOICE_ID,
|
|
4157
4160
|
ba as aiTwinSourceFilename,
|
|
4158
4161
|
ti as buildVoiceWebSocketUrl,
|
|
@@ -4165,7 +4168,7 @@ export {
|
|
|
4165
4168
|
Ra as getAiTwinThumbnailUrl,
|
|
4166
4169
|
Is as normalizeOculusViseme,
|
|
4167
4170
|
ks as resolveDirectFaceId,
|
|
4168
|
-
|
|
4171
|
+
Ut as resolveVisemeAtTime,
|
|
4169
4172
|
xa as resolveWordAtTime,
|
|
4170
4173
|
Ts as setActiveTwinAssets
|
|
4171
4174
|
};
|