@streamoji/aitwin 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/aitwin.cjs +2 -2
- package/dist/aitwin.js +373 -365
- package/dist/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/aitwin.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
1
|
import { jsxs as kn, jsx as At } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { PipecatClient as
|
|
4
|
-
import { WebSocketTransport as
|
|
5
|
-
const
|
|
6
|
-
publicBase:
|
|
7
|
-
},
|
|
8
|
-
version:
|
|
9
|
-
},
|
|
2
|
+
import { forwardRef as Sn, useRef as F, useState as Be, useCallback as oe, useEffect as Se, useMemo as It, useImperativeHandle as vn } from "react";
|
|
3
|
+
import { PipecatClient as bn } from "@pipecat-ai/client-js";
|
|
4
|
+
import { WebSocketTransport as Tn, DailyMediaManager as An } from "@pipecat-ai/websocket-transport";
|
|
5
|
+
const In = "https://pub-607ad1fc22e2400eb57d17240aab857c.r2.dev", Yt = {
|
|
6
|
+
publicBase: In
|
|
7
|
+
}, Rn = "0.2.1", Dn = {
|
|
8
|
+
version: Rn
|
|
9
|
+
}, Mn = {}, be = "https://ai.streamoji.com", Jt = `${Yt.publicBase}/custom-faces`, xn = `${Yt.publicBase}/aitwin-workers/v${Dn.version}/visemeDiffPreview.worker.js`;
|
|
10
10
|
function Cn(e) {
|
|
11
11
|
if (e) return e;
|
|
12
|
-
const t = typeof import.meta < "u" ?
|
|
12
|
+
const t = typeof import.meta < "u" ? Mn?.VITE_AITWIN_WORKER_URL : void 0;
|
|
13
13
|
return t?.trim() ? t.trim() : xn;
|
|
14
14
|
}
|
|
15
|
-
const Pn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin",
|
|
15
|
+
const Pn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAiTwin", Qt = "eng_a7f2b9c1", ut = "eng_d4e8f3a2", Ae = "eng_c9b1e6d4", Te = Ae, Bn = /* @__PURE__ */ new Set([
|
|
16
16
|
ut,
|
|
17
17
|
Ae
|
|
18
|
-
]),
|
|
19
|
-
[
|
|
18
|
+
]), Xt = {
|
|
19
|
+
[Qt]: "oculus_direct",
|
|
20
20
|
[Ae]: "oculus_direct",
|
|
21
21
|
[ut]: "inworld_word"
|
|
22
22
|
}, Rt = {
|
|
23
|
-
google:
|
|
23
|
+
google: Qt,
|
|
24
24
|
inworld: ut,
|
|
25
25
|
cartesia: Ae
|
|
26
26
|
};
|
|
27
|
-
function
|
|
28
|
-
return
|
|
27
|
+
function Ln(e) {
|
|
28
|
+
return Xt[e];
|
|
29
29
|
}
|
|
30
|
-
function
|
|
30
|
+
function On(e) {
|
|
31
31
|
return e === Ae;
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
if (e.ttsEngineId && e.ttsEngineId in
|
|
33
|
+
function Fn(e) {
|
|
34
|
+
if (e.ttsEngineId && e.ttsEngineId in Xt)
|
|
35
35
|
return e.ttsEngineId;
|
|
36
36
|
const t = e.tts?.toLowerCase();
|
|
37
37
|
return t && t in Rt ? Rt[t] : Te;
|
|
@@ -55,7 +55,7 @@ async function Un(e, t = Pn) {
|
|
|
55
55
|
const { tts: i, ...o } = s.data;
|
|
56
56
|
return {
|
|
57
57
|
...o,
|
|
58
|
-
ttsEngineId:
|
|
58
|
+
ttsEngineId: Fn(s.data)
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
const Nn = "https://us-central1-streamoji-265f4.cloudfunctions.net/getAuthToken", Vn = "client_6TNvp3SCs4Og0a1ijm9TommXLql1", $n = "kk8Fq8EmexzP10jMIEwY3R44M5RKUEm1", Hn = "6TNvp3SCs4Og0a1ijm9TommXLql1", Wn = "Swaraj Mali";
|
|
@@ -136,7 +136,7 @@ function qe(e) {
|
|
|
136
136
|
function Ie(e) {
|
|
137
137
|
return qe(e).encrypted;
|
|
138
138
|
}
|
|
139
|
-
function Dt(e, t =
|
|
139
|
+
function Dt(e, t = Jt) {
|
|
140
140
|
const n = `${t.replace(/\/$/, "")}/${e}`;
|
|
141
141
|
return { twinBase: n, binBase: n, encrypted: !0 };
|
|
142
142
|
}
|
|
@@ -163,7 +163,7 @@ function Jn(e, t) {
|
|
|
163
163
|
encrypted: e.encrypted
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
|
-
function
|
|
166
|
+
function Ee() {
|
|
167
167
|
if (!rt)
|
|
168
168
|
throw new Error("Twin assets not configured; call setActiveTwinAssets first");
|
|
169
169
|
return rt;
|
|
@@ -172,26 +172,26 @@ function Qn(e) {
|
|
|
172
172
|
return st.add(e), () => st.delete(e);
|
|
173
173
|
}
|
|
174
174
|
function Mt() {
|
|
175
|
-
const e =
|
|
175
|
+
const e = Ee();
|
|
176
176
|
return Ie(e) ? `${e.binBase}/sil.bin` : `${e.twinBase}/sil.png`;
|
|
177
177
|
}
|
|
178
178
|
function Xn() {
|
|
179
|
-
const e =
|
|
179
|
+
const e = Ee();
|
|
180
180
|
return Ie(e) ? `${e.binBase}/idle.bin` : `${e.twinBase}/idle.mp4`;
|
|
181
181
|
}
|
|
182
182
|
function Zn() {
|
|
183
|
-
const e =
|
|
183
|
+
const e = Ee();
|
|
184
184
|
return Ie(e) ? e.binBase : e.twinBase;
|
|
185
185
|
}
|
|
186
186
|
function Ge() {
|
|
187
|
-
return Ie(
|
|
187
|
+
return Ie(Ee());
|
|
188
188
|
}
|
|
189
189
|
function er() {
|
|
190
|
-
const e =
|
|
190
|
+
const e = Ee();
|
|
191
191
|
return Ie(e) ? `${e.binBase}/atlas.bin` : `${e.twinBase}/atlas.json`;
|
|
192
192
|
}
|
|
193
193
|
function tr() {
|
|
194
|
-
const e =
|
|
194
|
+
const e = Ee();
|
|
195
195
|
return Ie(e) ? `${e.binBase}/expression_atlas.bin` : `${e.twinBase}/expression_atlas.json`;
|
|
196
196
|
}
|
|
197
197
|
function nr(e) {
|
|
@@ -331,7 +331,7 @@ function wr(e) {
|
|
|
331
331
|
const r = t.length % 4;
|
|
332
332
|
return r !== 0 && (t += "=".repeat(4 - r)), t;
|
|
333
333
|
}
|
|
334
|
-
function
|
|
334
|
+
function _r(e) {
|
|
335
335
|
return e.length >= 4 && e[0] === 82 && e[1] === 73 && e[2] === 70 && e[3] === 70;
|
|
336
336
|
}
|
|
337
337
|
function xt(e, t, n = mr) {
|
|
@@ -345,15 +345,15 @@ function xt(e, t, n = mr) {
|
|
|
345
345
|
const o = e.createBuffer(1, i.length, n);
|
|
346
346
|
return o.copyToChannel(i, 0), o;
|
|
347
347
|
}
|
|
348
|
-
function
|
|
348
|
+
function gr(e) {
|
|
349
349
|
const t = wr(e), n = window.atob(t), r = new Uint8Array(n.length);
|
|
350
350
|
for (let s = 0; s < n.length; s++)
|
|
351
351
|
r[s] = n.charCodeAt(s);
|
|
352
352
|
return r;
|
|
353
353
|
}
|
|
354
354
|
async function pr(e, t) {
|
|
355
|
-
const n =
|
|
356
|
-
if (
|
|
355
|
+
const n = gr(t);
|
|
356
|
+
if (_r(n)) {
|
|
357
357
|
const r = n.buffer.slice(
|
|
358
358
|
n.byteOffset,
|
|
359
359
|
n.byteOffset + n.byteLength
|
|
@@ -384,55 +384,55 @@ function yr(e, t) {
|
|
|
384
384
|
return n;
|
|
385
385
|
return null;
|
|
386
386
|
}
|
|
387
|
-
function
|
|
387
|
+
function Zt(e, t) {
|
|
388
388
|
const n = [], r = [];
|
|
389
|
-
let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0,
|
|
389
|
+
let s = null, i = !1, o = !1, a = !1, f = !1, l = 0, w = 0, g = 0, m = 0, S = null, k = 1, u = t, p = !1;
|
|
390
390
|
const d = () => {
|
|
391
391
|
S != null && (clearTimeout(S), S = null);
|
|
392
392
|
}, I = () => {
|
|
393
|
-
for (const
|
|
393
|
+
for (const _ of r)
|
|
394
394
|
try {
|
|
395
|
-
|
|
395
|
+
_.stop();
|
|
396
396
|
} catch {
|
|
397
397
|
}
|
|
398
398
|
r.length = 0;
|
|
399
|
-
},
|
|
400
|
-
for (const
|
|
401
|
-
|
|
399
|
+
}, E = () => {
|
|
400
|
+
for (const _ of r)
|
|
401
|
+
_.playbackRate.value = k;
|
|
402
402
|
}, R = () => {
|
|
403
403
|
!f || i || r.length > 0 || n.length > 0 || (o = !1, d(), e.onSpeakingDone(), e.onNotify());
|
|
404
|
-
}, W = (
|
|
405
|
-
const x = Ct(
|
|
404
|
+
}, W = (_) => {
|
|
405
|
+
const x = Ct(_);
|
|
406
406
|
if (x <= 0) {
|
|
407
407
|
e.onSpeakingDone(), e.onNotify();
|
|
408
408
|
return;
|
|
409
409
|
}
|
|
410
410
|
o = !0, l = performance.now(), e.onSpeakingStart(), e.onNotify(), d();
|
|
411
|
-
const b =
|
|
411
|
+
const b = k > 0 ? x / k : x;
|
|
412
412
|
S = setTimeout(() => {
|
|
413
413
|
p || (o = !1, S = null, e.onSpeakingDone(), e.onNotify());
|
|
414
414
|
}, b);
|
|
415
|
-
}, V = (
|
|
416
|
-
x.length !== 0 && (D && (
|
|
415
|
+
}, V = (_, x, b, D) => {
|
|
416
|
+
x.length !== 0 && (D && (g = b), x.forEach((A) => {
|
|
417
417
|
const B = String(A.word ?? "").trim();
|
|
418
418
|
if (!B) return;
|
|
419
419
|
const $ = Math.round((A.start ?? 0) * 1e3), U = A.duration != null ? Math.round(A.duration * 1e3) : A.end != null ? Math.max(1, Math.round((A.end - (A.start ?? 0)) * 1e3)) : 0;
|
|
420
|
-
|
|
420
|
+
_.push({
|
|
421
421
|
word: B,
|
|
422
|
-
wtime:
|
|
422
|
+
wtime: g + $,
|
|
423
423
|
wduration: U,
|
|
424
|
-
queueIndex:
|
|
424
|
+
queueIndex: _.length,
|
|
425
425
|
gesture: A.gesture ?? null,
|
|
426
426
|
emphasis: A.emphasis === !0
|
|
427
427
|
});
|
|
428
428
|
}));
|
|
429
|
-
}, H = (
|
|
430
|
-
b.length !== 0 && (A && (
|
|
429
|
+
}, H = (_, x, b, D, A, P) => {
|
|
430
|
+
b.length !== 0 && (A && (g = D), b.forEach((B) => {
|
|
431
431
|
const $ = String(B.symbol ?? B.viseme ?? "").trim();
|
|
432
432
|
if (!$) return;
|
|
433
|
-
const U = Math.round((B.start ?? 0) * 1e3), X = Math.max(1, Math.round((B.duration ?? 0) * 1e3)), se =
|
|
433
|
+
const U = Math.round((B.start ?? 0) * 1e3), X = Math.max(1, Math.round((B.duration ?? 0) * 1e3)), se = g + U;
|
|
434
434
|
let Z;
|
|
435
|
-
if (
|
|
435
|
+
if (Ln(P) === "oculus_direct")
|
|
436
436
|
Z = ir($);
|
|
437
437
|
else {
|
|
438
438
|
const ce = yr(x, se), J = ce ? cr(ce, se) : 0;
|
|
@@ -442,30 +442,30 @@ function Xt(e, t) {
|
|
|
442
442
|
J
|
|
443
443
|
);
|
|
444
444
|
}
|
|
445
|
-
|
|
445
|
+
_.push({
|
|
446
446
|
viseme: Z,
|
|
447
447
|
weight: 1,
|
|
448
448
|
vtime: se,
|
|
449
449
|
vduration: X
|
|
450
450
|
});
|
|
451
451
|
}), e.onNotify());
|
|
452
|
-
}, j = (
|
|
452
|
+
}, j = (_, x, b, D, A, P, B) => {
|
|
453
453
|
V(x, D, A, P), H(
|
|
454
|
-
|
|
454
|
+
_,
|
|
455
455
|
x,
|
|
456
456
|
b,
|
|
457
457
|
A,
|
|
458
458
|
P,
|
|
459
459
|
B
|
|
460
460
|
);
|
|
461
|
-
}, y = async (
|
|
461
|
+
}, y = async (_, x, b, D, A, P, B) => {
|
|
462
462
|
if (p || !b?.trim()) {
|
|
463
463
|
(D.length > 0 || A.length > 0) && !a && j(
|
|
464
|
-
|
|
464
|
+
_,
|
|
465
465
|
x,
|
|
466
466
|
D,
|
|
467
467
|
A,
|
|
468
|
-
|
|
468
|
+
g,
|
|
469
469
|
P,
|
|
470
470
|
u
|
|
471
471
|
);
|
|
@@ -493,12 +493,12 @@ function Xt(e, t) {
|
|
|
493
493
|
const ce = !o;
|
|
494
494
|
Z < se && (Z = se + 0.1), m = Z + X.duration;
|
|
495
495
|
const J = U.createBufferSource();
|
|
496
|
-
if (J.buffer = X, J.playbackRate.value =
|
|
496
|
+
if (J.buffer = X, J.playbackRate.value = k, J.connect(U.destination), r.push(J), p) {
|
|
497
497
|
r.pop();
|
|
498
498
|
return;
|
|
499
499
|
}
|
|
500
500
|
if (ce) {
|
|
501
|
-
o = !0, e.onSpeakingStart(), w = Z,
|
|
501
|
+
o = !0, e.onSpeakingStart(), w = Z, g = 0, _.length = 0, x.length = 0, B?.();
|
|
502
502
|
const v = (Z - se) * 1e3;
|
|
503
503
|
l = performance.now() + v;
|
|
504
504
|
}
|
|
@@ -508,7 +508,7 @@ function Xt(e, t) {
|
|
|
508
508
|
}, J.start(Z);
|
|
509
509
|
const c = (Z - w) * 1e3;
|
|
510
510
|
j(
|
|
511
|
-
|
|
511
|
+
_,
|
|
512
512
|
x,
|
|
513
513
|
D,
|
|
514
514
|
A,
|
|
@@ -522,7 +522,7 @@ function Xt(e, t) {
|
|
|
522
522
|
i = !1;
|
|
523
523
|
const $ = n.shift();
|
|
524
524
|
$ ? await y(
|
|
525
|
-
|
|
525
|
+
_,
|
|
526
526
|
x,
|
|
527
527
|
$.audio,
|
|
528
528
|
$.visemes,
|
|
@@ -533,36 +533,36 @@ function Xt(e, t) {
|
|
|
533
533
|
}
|
|
534
534
|
};
|
|
535
535
|
return {
|
|
536
|
-
setStreamTtsEngineId: (
|
|
537
|
-
u =
|
|
536
|
+
setStreamTtsEngineId: (_) => {
|
|
537
|
+
u = _;
|
|
538
538
|
},
|
|
539
|
-
setPlaybackSpeed: (
|
|
540
|
-
|
|
539
|
+
setPlaybackSpeed: (_) => {
|
|
540
|
+
k = Math.max(0.1, Math.min(1, _)), E();
|
|
541
541
|
},
|
|
542
|
-
getPlaybackSpeed: () =>
|
|
543
|
-
resetForNewStream: (
|
|
544
|
-
p = !1, f = !1, u =
|
|
542
|
+
getPlaybackSpeed: () => k,
|
|
543
|
+
resetForNewStream: (_) => {
|
|
544
|
+
p = !1, f = !1, u = _;
|
|
545
545
|
},
|
|
546
546
|
/** Call from a user gesture before bot audio (connect / unlock). */
|
|
547
547
|
primeAudioContext: async () => {
|
|
548
|
-
const
|
|
549
|
-
s || (s = new
|
|
548
|
+
const _ = window.AudioContext || window.webkitAudioContext;
|
|
549
|
+
s || (s = new _()), s.state === "suspended" && await s.resume();
|
|
550
550
|
},
|
|
551
551
|
stop: () => {
|
|
552
|
-
p = !0, d(), I(), n.length = 0, i = !1, o = !1, a = !1, f = !1,
|
|
552
|
+
p = !0, d(), I(), n.length = 0, i = !1, o = !1, a = !1, f = !1, g = 0, m = 0, w = 0, l = 0;
|
|
553
553
|
},
|
|
554
|
-
markStreamComplete: (
|
|
555
|
-
if (f = !0, !a &&
|
|
556
|
-
W(
|
|
554
|
+
markStreamComplete: (_) => {
|
|
555
|
+
if (f = !0, !a && _.length > 0) {
|
|
556
|
+
W(_);
|
|
557
557
|
return;
|
|
558
558
|
}
|
|
559
559
|
R();
|
|
560
560
|
},
|
|
561
561
|
playAudioChunk: y,
|
|
562
|
-
queueTimingsOnly: (
|
|
563
|
-
let P =
|
|
564
|
-
A &&
|
|
565
|
-
|
|
562
|
+
queueTimingsOnly: (_, x, b, D, A) => {
|
|
563
|
+
let P = g;
|
|
564
|
+
A && _.length > 0 && (P = Ct(_)), j(
|
|
565
|
+
_,
|
|
566
566
|
x,
|
|
567
567
|
b,
|
|
568
568
|
D,
|
|
@@ -574,7 +574,7 @@ function Xt(e, t) {
|
|
|
574
574
|
getPlaybackElapsedMs: () => o ? a && s && w > 0 ? Math.max(
|
|
575
575
|
0,
|
|
576
576
|
(s.currentTime - w) * 1e3
|
|
577
|
-
) : Math.max(0, (performance.now() - l) *
|
|
577
|
+
) : Math.max(0, (performance.now() - l) * k) : 0,
|
|
578
578
|
isSpeaking: () => o,
|
|
579
579
|
getPlaybackStartPerf: () => l,
|
|
580
580
|
/** User spoke over the bot — drop in-flight chunks until the next utterance. */
|
|
@@ -592,17 +592,17 @@ function lt(e, t) {
|
|
|
592
592
|
t < r.vtime || t >= r.vtime + r.vduration || (!n || r.vtime >= n.vtime) && (n = r);
|
|
593
593
|
return n ? n.viseme : "sil";
|
|
594
594
|
}
|
|
595
|
-
function
|
|
595
|
+
function Ws(e, t) {
|
|
596
596
|
for (const n of e)
|
|
597
597
|
if (t >= n.wtime && t < n.wtime + n.wduration)
|
|
598
598
|
return n;
|
|
599
599
|
return null;
|
|
600
600
|
}
|
|
601
|
-
const
|
|
601
|
+
const en = 0.5, tn = 1.5, nn = "Olivia", Er = "f786b574-daa5-4673-aa0c-cbe3e8534c02", ft = 0.85;
|
|
602
602
|
function Pt(e, t = be) {
|
|
603
603
|
const n = `${t.replace(/\/$/, "")}/avatar_ttsWithPoses`, r = [], s = [], i = [];
|
|
604
604
|
let o = "neutral", a = "", f = Te;
|
|
605
|
-
const l = /* @__PURE__ */ new Set(), w = () => l.forEach((
|
|
605
|
+
const l = /* @__PURE__ */ new Set(), w = () => l.forEach((k) => k()), g = Zt(
|
|
606
606
|
{
|
|
607
607
|
onSpeakingStart: () => e("speaking"),
|
|
608
608
|
onSpeakingDone: () => e("done"),
|
|
@@ -610,28 +610,28 @@ function Pt(e, t = be) {
|
|
|
610
610
|
},
|
|
611
611
|
Te
|
|
612
612
|
), m = () => {
|
|
613
|
-
|
|
613
|
+
g.stop(), r.length = 0, s.length = 0, i.length = 0, o = "neutral", e("idle"), w();
|
|
614
614
|
};
|
|
615
615
|
return {
|
|
616
|
-
setDeveloperToken: (
|
|
617
|
-
a =
|
|
616
|
+
setDeveloperToken: (k) => {
|
|
617
|
+
a = k;
|
|
618
618
|
},
|
|
619
|
-
setTtsEngineId: (
|
|
620
|
-
f =
|
|
619
|
+
setTtsEngineId: (k) => {
|
|
620
|
+
f = k;
|
|
621
621
|
},
|
|
622
622
|
getTtsEngineId: () => f,
|
|
623
|
-
speak: async (
|
|
623
|
+
speak: async (k, u) => {
|
|
624
624
|
m(), e("loading");
|
|
625
625
|
const p = a.trim();
|
|
626
626
|
if (!p)
|
|
627
627
|
throw new Error("Developer token required for avatar_ttsWithPoses");
|
|
628
628
|
const d = u?.ttsEngineId ?? f ?? Te;
|
|
629
|
-
|
|
630
|
-
const I = u?.voiceId ??
|
|
631
|
-
|
|
632
|
-
Math.min(
|
|
629
|
+
g.resetForNewStream(d), g.setStreamTtsEngineId(d);
|
|
630
|
+
const I = u?.voiceId ?? nn, E = u?.speakingRate ?? ft, R = Math.max(
|
|
631
|
+
en,
|
|
632
|
+
Math.min(tn, E)
|
|
633
633
|
), W = {
|
|
634
|
-
user_query:
|
|
634
|
+
user_query: k,
|
|
635
635
|
ttsEngineId: d,
|
|
636
636
|
speakingRate: R
|
|
637
637
|
};
|
|
@@ -651,19 +651,19 @@ function Pt(e, t = be) {
|
|
|
651
651
|
if (!H) throw new Error("No response body");
|
|
652
652
|
const j = H.getReader(), y = new TextDecoder();
|
|
653
653
|
let T = "";
|
|
654
|
-
const
|
|
654
|
+
const _ = async (x) => {
|
|
655
655
|
const b = nr(x);
|
|
656
656
|
if (b) {
|
|
657
657
|
if (b.event === "audio") {
|
|
658
658
|
const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], B = b.data.is_new_segment ?? !1;
|
|
659
|
-
D ? await
|
|
659
|
+
D ? await g.playAudioChunk(
|
|
660
660
|
r,
|
|
661
661
|
s,
|
|
662
662
|
D,
|
|
663
663
|
A,
|
|
664
664
|
P,
|
|
665
665
|
B
|
|
666
|
-
) : (A.length > 0 || P.length > 0) &&
|
|
666
|
+
) : (A.length > 0 || P.length > 0) && g.queueTimingsOnly(
|
|
667
667
|
r,
|
|
668
668
|
s,
|
|
669
669
|
A,
|
|
@@ -703,9 +703,9 @@ function Pt(e, t = be) {
|
|
|
703
703
|
|
|
704
704
|
`);
|
|
705
705
|
T = D.pop() ?? "";
|
|
706
|
-
for (const A of D) await
|
|
706
|
+
for (const A of D) await _(A);
|
|
707
707
|
if (x) {
|
|
708
|
-
T.trim() && await
|
|
708
|
+
T.trim() && await _(T.trim()), g.markStreamComplete(r);
|
|
709
709
|
break;
|
|
710
710
|
}
|
|
711
711
|
}
|
|
@@ -718,17 +718,17 @@ function Pt(e, t = be) {
|
|
|
718
718
|
getWordQueue: () => s,
|
|
719
719
|
getSentenceEmotions: () => i,
|
|
720
720
|
getStreamMood: () => o,
|
|
721
|
-
getPlaybackElapsedMs: () =>
|
|
722
|
-
isSpeaking: () =>
|
|
723
|
-
setPlaybackSpeed: (
|
|
724
|
-
|
|
721
|
+
getPlaybackElapsedMs: () => g.getPlaybackElapsedMs(),
|
|
722
|
+
isSpeaking: () => g.isSpeaking(),
|
|
723
|
+
setPlaybackSpeed: (k) => {
|
|
724
|
+
g.setPlaybackSpeed(k);
|
|
725
725
|
},
|
|
726
|
-
getPlaybackSpeed: () =>
|
|
727
|
-
subscribe: (
|
|
726
|
+
getPlaybackSpeed: () => g.getPlaybackSpeed(),
|
|
727
|
+
subscribe: (k) => (l.add(k), () => l.delete(k))
|
|
728
728
|
};
|
|
729
729
|
}
|
|
730
|
-
const
|
|
731
|
-
class
|
|
730
|
+
const rn = 16e3, sn = 24e3;
|
|
731
|
+
class kr extends An {
|
|
732
732
|
constructor() {
|
|
733
733
|
super(
|
|
734
734
|
!0,
|
|
@@ -736,8 +736,8 @@ class Er extends Tn {
|
|
|
736
736
|
void 0,
|
|
737
737
|
void 0,
|
|
738
738
|
512,
|
|
739
|
-
|
|
740
|
-
|
|
739
|
+
rn,
|
|
740
|
+
sn
|
|
741
741
|
);
|
|
742
742
|
}
|
|
743
743
|
/** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
|
|
@@ -766,7 +766,7 @@ function Tr(e) {
|
|
|
766
766
|
const i = e.speakingRate ?? ft;
|
|
767
767
|
return r.searchParams.set(
|
|
768
768
|
"speaking_rate",
|
|
769
|
-
String(Math.max(
|
|
769
|
+
String(Math.max(en, Math.min(tn, i)))
|
|
770
770
|
), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
|
|
771
771
|
}
|
|
772
772
|
function Bt(e, t) {
|
|
@@ -790,14 +790,14 @@ function Ar(e) {
|
|
|
790
790
|
}
|
|
791
791
|
function Ir(e, t = {}) {
|
|
792
792
|
const n = [], r = [], s = [], i = [];
|
|
793
|
-
let o = "", a = "neutral", f = Ae, l = !1, w = null,
|
|
793
|
+
let o = "", a = "neutral", f = Ae, l = !1, w = null, g = null, m = { ...t }, S = 0, k = null;
|
|
794
794
|
const u = /* @__PURE__ */ new Set(), p = [];
|
|
795
795
|
let d = !1, I = null;
|
|
796
|
-
const
|
|
796
|
+
const E = () => u.forEach((c) => c()), R = Zt(
|
|
797
797
|
{
|
|
798
798
|
onSpeakingStart: () => e("speaking"),
|
|
799
799
|
onSpeakingDone: () => e("done"),
|
|
800
|
-
onNotify:
|
|
800
|
+
onNotify: E
|
|
801
801
|
},
|
|
802
802
|
f
|
|
803
803
|
), W = () => {
|
|
@@ -811,32 +811,32 @@ function Ir(e, t = {}) {
|
|
|
811
811
|
p.push(c), !d && (d = !0, W().port2.postMessage(null));
|
|
812
812
|
}, H = () => R.getPlaybackElapsedMs(), j = (c, v = o) => {
|
|
813
813
|
if (!m.onLipsyncDebug) return;
|
|
814
|
-
const
|
|
814
|
+
const L = H(), z = n;
|
|
815
815
|
m.onLipsyncDebug({
|
|
816
816
|
event: c,
|
|
817
817
|
spokenText: v,
|
|
818
818
|
mood: a,
|
|
819
819
|
playbackAnchorPerf: R.getPlaybackStartPerf(),
|
|
820
|
-
playbackElapsedMs:
|
|
820
|
+
playbackElapsedMs: L,
|
|
821
821
|
queueLength: z.length,
|
|
822
|
-
activeViseme: lt(z,
|
|
822
|
+
activeViseme: lt(z, L),
|
|
823
823
|
segments: i.map((ne) => ({
|
|
824
824
|
...ne,
|
|
825
825
|
visemes: [...ne.visemes]
|
|
826
826
|
}))
|
|
827
827
|
});
|
|
828
828
|
}, y = (c, v) => {
|
|
829
|
-
m.onLipsyncDebug && (
|
|
829
|
+
m.onLipsyncDebug && (k = { event: c, spokenText: v }, S === 0 && (S = requestAnimationFrame(() => {
|
|
830
830
|
S = 0;
|
|
831
|
-
const
|
|
832
|
-
|
|
831
|
+
const L = k;
|
|
832
|
+
k = null, L && j(L.event, L.spokenText);
|
|
833
833
|
})));
|
|
834
834
|
}, T = () => {
|
|
835
835
|
n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
|
|
836
|
-
},
|
|
837
|
-
R.stop(), T(), y("reset"),
|
|
836
|
+
}, _ = () => {
|
|
837
|
+
R.stop(), T(), y("reset"), E();
|
|
838
838
|
}, x = () => {
|
|
839
|
-
|
|
839
|
+
_(), e("idle"), E();
|
|
840
840
|
}, b = (c, v) => {
|
|
841
841
|
typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), Array.isArray(c.sentence_emotions) && c.sentence_emotions.length > 0 && (v && (s.length = 0), s.push(
|
|
842
842
|
...Bt(c.sentence_emotions, a)
|
|
@@ -845,10 +845,10 @@ function Ir(e, t = {}) {
|
|
|
845
845
|
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
846
846
|
v && (o = v), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
|
|
847
847
|
...Bt(c.sentence_emotions, a)
|
|
848
|
-
), Array.isArray(c.gestures) && c.gestures, y("metadata", v),
|
|
849
|
-
}, A = (c, v,
|
|
848
|
+
), Array.isArray(c.gestures) && c.gestures, y("metadata", v), E();
|
|
849
|
+
}, A = (c, v, L, z) => {
|
|
850
850
|
if (!m.onLipsyncDebug) return;
|
|
851
|
-
const ne = n.slice(
|
|
851
|
+
const ne = n.slice(L), Re = z.filter(
|
|
852
852
|
(G) => String(G.symbol ?? G.viseme ?? "").trim()
|
|
853
853
|
);
|
|
854
854
|
i.push({
|
|
@@ -857,8 +857,8 @@ function Ir(e, t = {}) {
|
|
|
857
857
|
isNewSegment: !!c.is_new_segment,
|
|
858
858
|
chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
|
|
859
859
|
receivedAtMs: performance.now(),
|
|
860
|
-
visemes: ne.map((G,
|
|
861
|
-
const Y = Re[
|
|
860
|
+
visemes: ne.map((G, ke) => {
|
|
861
|
+
const Y = Re[ke];
|
|
862
862
|
return {
|
|
863
863
|
rawSymbol: String(Y?.symbol ?? Y?.viseme ?? G.viseme).trim(),
|
|
864
864
|
viseme: G.viseme,
|
|
@@ -870,8 +870,8 @@ function Ir(e, t = {}) {
|
|
|
870
870
|
})
|
|
871
871
|
});
|
|
872
872
|
}, P = (c) => {
|
|
873
|
-
const v = String(c.spoken_text ?? c.text ?? "").trim(),
|
|
874
|
-
v && (o = v), b(c,
|
|
873
|
+
const v = String(c.spoken_text ?? c.text ?? "").trim(), L = !!c.is_new_segment || Number(c.chunk_index ?? -1) === 0, z = c.visemes ?? [], ne = c.words ?? [], Re = String(c.chunk ?? "").trim();
|
|
874
|
+
v && (o = v), b(c, L), L && R.resetForNewStream(f);
|
|
875
875
|
const G = n.length;
|
|
876
876
|
R.playAudioChunk(
|
|
877
877
|
n,
|
|
@@ -879,7 +879,7 @@ function Ir(e, t = {}) {
|
|
|
879
879
|
Re,
|
|
880
880
|
z,
|
|
881
881
|
ne,
|
|
882
|
-
|
|
882
|
+
L,
|
|
883
883
|
() => {
|
|
884
884
|
i.length = 0;
|
|
885
885
|
}
|
|
@@ -892,7 +892,7 @@ function Ir(e, t = {}) {
|
|
|
892
892
|
);
|
|
893
893
|
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
894
894
|
v && (o = v), b(c, !!c.is_new_segment);
|
|
895
|
-
const
|
|
895
|
+
const L = n.length;
|
|
896
896
|
R.queueTimingsOnly(
|
|
897
897
|
n,
|
|
898
898
|
r,
|
|
@@ -902,17 +902,17 @@ function Ir(e, t = {}) {
|
|
|
902
902
|
), A(
|
|
903
903
|
c,
|
|
904
904
|
v,
|
|
905
|
-
|
|
905
|
+
L,
|
|
906
906
|
c.visemes ?? []
|
|
907
|
-
), y("lipsync", v),
|
|
907
|
+
), y("lipsync", v), E();
|
|
908
908
|
}, $ = (c) => {
|
|
909
909
|
const v = Ar(c);
|
|
910
910
|
if (!v) {
|
|
911
911
|
console.warn("[realtimeVoice] server message with no payload", c);
|
|
912
912
|
return;
|
|
913
913
|
}
|
|
914
|
-
const
|
|
915
|
-
switch (
|
|
914
|
+
const L = String(v.type ?? "unknown");
|
|
915
|
+
switch (L !== "avatar_metadata" && L !== "avatar_audio_chunk" && L !== "avatar_lipsync" && L !== "error" && console.debug("[realtimeVoice] server message", L, v), L) {
|
|
916
916
|
case "avatar_metadata":
|
|
917
917
|
D(v);
|
|
918
918
|
break;
|
|
@@ -924,7 +924,7 @@ function Ir(e, t = {}) {
|
|
|
924
924
|
break;
|
|
925
925
|
case "error": {
|
|
926
926
|
const z = String(v.message ?? "Voice session error");
|
|
927
|
-
console.error("[realtimeVoice] server error:", z), e("error"),
|
|
927
|
+
console.error("[realtimeVoice] server error:", z), e("error"), E();
|
|
928
928
|
break;
|
|
929
929
|
}
|
|
930
930
|
case "avatar_speak":
|
|
@@ -934,33 +934,33 @@ function Ir(e, t = {}) {
|
|
|
934
934
|
);
|
|
935
935
|
break;
|
|
936
936
|
}
|
|
937
|
-
}, U = () => w || (
|
|
938
|
-
transport: new
|
|
939
|
-
mediaManager:
|
|
940
|
-
recorderSampleRate:
|
|
941
|
-
playerSampleRate:
|
|
937
|
+
}, U = () => w || (g = new kr(), w = new bn({
|
|
938
|
+
transport: new Tn({
|
|
939
|
+
mediaManager: g,
|
|
940
|
+
recorderSampleRate: rn,
|
|
941
|
+
playerSampleRate: sn
|
|
942
942
|
}),
|
|
943
943
|
enableCam: !1,
|
|
944
944
|
enableMic: !0,
|
|
945
945
|
callbacks: {
|
|
946
946
|
onBotReady: () => {
|
|
947
|
-
l = !0, e("idle"),
|
|
947
|
+
l = !0, e("idle"), E();
|
|
948
948
|
},
|
|
949
949
|
onDisconnected: () => {
|
|
950
950
|
l = !1, x();
|
|
951
951
|
},
|
|
952
952
|
onError: (c) => {
|
|
953
953
|
const v = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
|
|
954
|
-
console.error("[realtimeVoice]", v, c), e("error"),
|
|
954
|
+
console.error("[realtimeVoice]", v, c), e("error"), E();
|
|
955
955
|
},
|
|
956
956
|
onTransportStateChanged: (c) => {
|
|
957
|
-
c === "error" && (e("error"),
|
|
957
|
+
c === "error" && (e("error"), E());
|
|
958
958
|
},
|
|
959
959
|
onServerMessage: (c) => {
|
|
960
960
|
V(c);
|
|
961
961
|
},
|
|
962
962
|
onUserStartedSpeaking: () => {
|
|
963
|
-
R.bargeIn(), T(), e("idle"), y("user_started"),
|
|
963
|
+
R.bargeIn(), T(), e("idle"), y("user_started"), E();
|
|
964
964
|
},
|
|
965
965
|
onBotStartedSpeaking: () => {
|
|
966
966
|
y("bot_started");
|
|
@@ -984,17 +984,17 @@ function Ir(e, t = {}) {
|
|
|
984
984
|
},
|
|
985
985
|
getTtsEngineId: () => f,
|
|
986
986
|
speak: async (c, v) => {
|
|
987
|
-
const
|
|
988
|
-
if (
|
|
987
|
+
const L = c.trim();
|
|
988
|
+
if (L) {
|
|
989
989
|
if (!w || !l)
|
|
990
990
|
throw new Error(
|
|
991
991
|
"Realtime voice is not connected. Call connect() first."
|
|
992
992
|
);
|
|
993
|
-
|
|
993
|
+
_(), await w.sendText(L);
|
|
994
994
|
}
|
|
995
995
|
},
|
|
996
996
|
stop: () => {
|
|
997
|
-
|
|
997
|
+
_(), e("idle"), E();
|
|
998
998
|
},
|
|
999
999
|
connect: async (c) => {
|
|
1000
1000
|
if (c && (m = { ...m, ...c }), !m.authToken?.trim())
|
|
@@ -1004,16 +1004,16 @@ function Ir(e, t = {}) {
|
|
|
1004
1004
|
e("loading");
|
|
1005
1005
|
const v = U();
|
|
1006
1006
|
await v.initDevices();
|
|
1007
|
-
const
|
|
1008
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1007
|
+
const L = Tr(m);
|
|
1008
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", L);
|
|
1009
1009
|
try {
|
|
1010
|
-
await v.connect({ wsUrl:
|
|
1010
|
+
await v.connect({ wsUrl: L });
|
|
1011
1011
|
} catch (z) {
|
|
1012
|
-
l = !1, e("error"),
|
|
1012
|
+
l = !1, e("error"), E();
|
|
1013
1013
|
const ne = z instanceof Error ? z.message : "Realtime voice connect failed (WebSocket 101 only means upgrade OK — check authToken/origin/RTVI handshake)";
|
|
1014
|
-
throw new Error(`${ne} — ${
|
|
1014
|
+
throw new Error(`${ne} — ${L}`);
|
|
1015
1015
|
}
|
|
1016
|
-
l = !0, e("idle"),
|
|
1016
|
+
l = !0, e("idle"), E();
|
|
1017
1017
|
},
|
|
1018
1018
|
disconnect: async () => {
|
|
1019
1019
|
if (p.length = 0, d = !1, w)
|
|
@@ -1096,7 +1096,7 @@ function Br(e) {
|
|
|
1096
1096
|
const t = new Blob([e], { type: "video/mp4" });
|
|
1097
1097
|
return URL.createObjectURL(t);
|
|
1098
1098
|
}
|
|
1099
|
-
async function
|
|
1099
|
+
async function Lr(e) {
|
|
1100
1100
|
const t = Xn();
|
|
1101
1101
|
if (!Ge()) return t;
|
|
1102
1102
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
@@ -1106,14 +1106,14 @@ async function Or(e) {
|
|
|
1106
1106
|
function dt(e, t) {
|
|
1107
1107
|
return `${e}/${t}_minus_sil.png`;
|
|
1108
1108
|
}
|
|
1109
|
-
const
|
|
1110
|
-
function
|
|
1109
|
+
const on = 5;
|
|
1110
|
+
function an(e) {
|
|
1111
1111
|
const t = e?.composite_threshold;
|
|
1112
1112
|
if (typeof t == "number" && t > 0) return t;
|
|
1113
1113
|
const n = e?.crop?.content_threshold;
|
|
1114
|
-
return typeof n == "number" && n > 0 ? n :
|
|
1114
|
+
return typeof n == "number" && n > 0 ? n : on;
|
|
1115
1115
|
}
|
|
1116
|
-
const
|
|
1116
|
+
const qs = [
|
|
1117
1117
|
"aa",
|
|
1118
1118
|
"E",
|
|
1119
1119
|
"I",
|
|
@@ -1134,7 +1134,7 @@ const Ws = [
|
|
|
1134
1134
|
"t03_0.50",
|
|
1135
1135
|
"t04_0.67",
|
|
1136
1136
|
"t05_0.83"
|
|
1137
|
-
],
|
|
1137
|
+
], Or = it.length, Lt = /* @__PURE__ */ new Set([
|
|
1138
1138
|
"aa__kk",
|
|
1139
1139
|
"aa__nn",
|
|
1140
1140
|
"aa__sil",
|
|
@@ -1241,16 +1241,16 @@ const Ws = [
|
|
|
1241
1241
|
"U__nn",
|
|
1242
1242
|
"U__sil"
|
|
1243
1243
|
]);
|
|
1244
|
-
function
|
|
1244
|
+
function Ot(e, t) {
|
|
1245
1245
|
return `${e}__${t}`;
|
|
1246
1246
|
}
|
|
1247
|
-
function
|
|
1247
|
+
function Ft(e, t) {
|
|
1248
1248
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1249
1249
|
}
|
|
1250
1250
|
function Ke(e) {
|
|
1251
1251
|
return `${e}_minus_sil.png`;
|
|
1252
1252
|
}
|
|
1253
|
-
function
|
|
1253
|
+
function Fr(e, t) {
|
|
1254
1254
|
if (t.has(e)) return e;
|
|
1255
1255
|
const n = /^pairs\/([^/]+)\//.exec(e);
|
|
1256
1256
|
if (!n) return null;
|
|
@@ -1259,25 +1259,25 @@ function Lr(e, t) {
|
|
|
1259
1259
|
const s = Ke(r);
|
|
1260
1260
|
return t.has(s) ? s : null;
|
|
1261
1261
|
}
|
|
1262
|
-
function
|
|
1262
|
+
function cn(e, t) {
|
|
1263
1263
|
return e.filter((n) => t.has(n));
|
|
1264
1264
|
}
|
|
1265
1265
|
function Ur(e, t, n) {
|
|
1266
1266
|
const r = ht(e, t);
|
|
1267
|
-
return
|
|
1267
|
+
return cn(r, n).length > 0;
|
|
1268
1268
|
}
|
|
1269
1269
|
function ht(e, t) {
|
|
1270
1270
|
if (e === t) return [];
|
|
1271
|
-
const n = [], r =
|
|
1272
|
-
if (
|
|
1271
|
+
const n = [], r = Ot(e, t);
|
|
1272
|
+
if (Lt.has(r)) {
|
|
1273
1273
|
for (const i of it)
|
|
1274
|
-
n.push(
|
|
1274
|
+
n.push(Ft(r, i));
|
|
1275
1275
|
return n;
|
|
1276
1276
|
}
|
|
1277
|
-
const s =
|
|
1278
|
-
if (
|
|
1279
|
-
for (let i =
|
|
1280
|
-
n.push(
|
|
1277
|
+
const s = Ot(t, e);
|
|
1278
|
+
if (Lt.has(s)) {
|
|
1279
|
+
for (let i = Or - 1; i >= 0; i--)
|
|
1280
|
+
n.push(Ft(s, it[i]));
|
|
1281
1281
|
return n;
|
|
1282
1282
|
}
|
|
1283
1283
|
return [];
|
|
@@ -1362,15 +1362,15 @@ function ve(e, t = "neutral") {
|
|
|
1362
1362
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1363
1363
|
return n ? Jr[n] ?? t : t;
|
|
1364
1364
|
}
|
|
1365
|
-
function
|
|
1365
|
+
function un(e) {
|
|
1366
1366
|
return e === 0 ? null : dt(mt(e), "eyes_standard");
|
|
1367
1367
|
}
|
|
1368
|
-
function
|
|
1369
|
-
return
|
|
1368
|
+
function ln(e) {
|
|
1369
|
+
return un(wt(e));
|
|
1370
1370
|
}
|
|
1371
1371
|
function Nt(e, t) {
|
|
1372
1372
|
const n = mt(wt(e));
|
|
1373
|
-
return !t || t === "eyes_standard" ?
|
|
1373
|
+
return !t || t === "eyes_standard" ? ln(e) : e === "neutral" && t === "eyes_standard" ? null : dt(n, t);
|
|
1374
1374
|
}
|
|
1375
1375
|
function Qr(e, t) {
|
|
1376
1376
|
const n = [];
|
|
@@ -1378,7 +1378,7 @@ function Qr(e, t) {
|
|
|
1378
1378
|
n.push(Nt(e, r));
|
|
1379
1379
|
for (let r = t.length - 2; r >= 0; r--)
|
|
1380
1380
|
n.push(Nt(e, t[r]));
|
|
1381
|
-
return n.push(
|
|
1381
|
+
return n.push(ln(e)), n;
|
|
1382
1382
|
}
|
|
1383
1383
|
function Xr(e) {
|
|
1384
1384
|
return dt(mt(e), "eyes_standard");
|
|
@@ -1408,11 +1408,11 @@ function Vt(e) {
|
|
|
1408
1408
|
const n = Number.parseInt(t[1], 10);
|
|
1409
1409
|
return Number.isFinite(n) ? ye(n) : null;
|
|
1410
1410
|
}
|
|
1411
|
-
function
|
|
1411
|
+
function Oe(e, t) {
|
|
1412
1412
|
return e + Math.random() * (t - e);
|
|
1413
1413
|
}
|
|
1414
1414
|
function We() {
|
|
1415
|
-
return
|
|
1415
|
+
return Oe(14, 32);
|
|
1416
1416
|
}
|
|
1417
1417
|
function ss(e = {}) {
|
|
1418
1418
|
const {
|
|
@@ -1426,25 +1426,25 @@ function ss(e = {}) {
|
|
|
1426
1426
|
postEmotionChangeDelayMs: f = 380,
|
|
1427
1427
|
minDwellMs: l = 550
|
|
1428
1428
|
} = e;
|
|
1429
|
-
let w = "neutral",
|
|
1429
|
+
let w = "neutral", g = "neutral", m = 0, S = 0, k = 0, u = {
|
|
1430
1430
|
kind: "idle",
|
|
1431
1431
|
nextBlinkAt: performance.now() + t
|
|
1432
1432
|
}, p = null, d = "__eyes_open__|neutral|brow:0";
|
|
1433
1433
|
function I(y = w) {
|
|
1434
1434
|
d = `${p ?? "__eyes_open__"}|${y}|brow:${S}`;
|
|
1435
1435
|
}
|
|
1436
|
-
function
|
|
1436
|
+
function E(y, T = w) {
|
|
1437
1437
|
p = y;
|
|
1438
|
-
const
|
|
1439
|
-
|
|
1438
|
+
const _ = Vt(y);
|
|
1439
|
+
_ != null ? S = _ : y == null && (S = 0), I(T);
|
|
1440
1440
|
}
|
|
1441
1441
|
function R(y) {
|
|
1442
|
-
return
|
|
1442
|
+
return un(y);
|
|
1443
1443
|
}
|
|
1444
|
-
function W(y, T,
|
|
1445
|
-
const x = ye(T), b = ye(
|
|
1444
|
+
function W(y, T, _) {
|
|
1445
|
+
const x = ye(T), b = ye(_);
|
|
1446
1446
|
if (m = b, x === b) {
|
|
1447
|
-
|
|
1447
|
+
E(R(b));
|
|
1448
1448
|
return;
|
|
1449
1449
|
}
|
|
1450
1450
|
const D = [
|
|
@@ -1457,16 +1457,16 @@ function ss(e = {}) {
|
|
|
1457
1457
|
index: 0,
|
|
1458
1458
|
holdUntil: y + We(),
|
|
1459
1459
|
targetBrow: b
|
|
1460
|
-
},
|
|
1460
|
+
}, E(D[0] ?? null);
|
|
1461
1461
|
}
|
|
1462
1462
|
function V(y, T) {
|
|
1463
1463
|
u = {
|
|
1464
1464
|
kind: "idle",
|
|
1465
|
-
nextBlinkAt: y +
|
|
1466
|
-
},
|
|
1465
|
+
nextBlinkAt: y + Oe(n, r)
|
|
1466
|
+
}, g = T, E(R(m), T);
|
|
1467
1467
|
}
|
|
1468
|
-
function H(y, T,
|
|
1469
|
-
const x =
|
|
1468
|
+
function H(y, T, _) {
|
|
1469
|
+
const x = _ ? Kr : Math.random() < a ? qr : jr;
|
|
1470
1470
|
u = {
|
|
1471
1471
|
kind: "playing",
|
|
1472
1472
|
paths: Qr(T, x),
|
|
@@ -1474,31 +1474,31 @@ function ss(e = {}) {
|
|
|
1474
1474
|
holdUntil: y + We(),
|
|
1475
1475
|
after: "idle",
|
|
1476
1476
|
blinkEmotion: T
|
|
1477
|
-
},
|
|
1477
|
+
}, g = T, E(u.paths[0] ?? null, T);
|
|
1478
1478
|
}
|
|
1479
1479
|
function j(y) {
|
|
1480
1480
|
if (u.kind === "browBlend") {
|
|
1481
1481
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1482
1482
|
u.index += 1, u.holdUntil = y + We();
|
|
1483
1483
|
const T = u.paths[u.index] ?? null;
|
|
1484
|
-
|
|
1484
|
+
E(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (S = u.targetBrow, m = u.targetBrow, E(R(u.targetBrow)), u = {
|
|
1485
1485
|
kind: "idle",
|
|
1486
1486
|
nextBlinkAt: y + f
|
|
1487
1487
|
});
|
|
1488
1488
|
return;
|
|
1489
1489
|
}
|
|
1490
1490
|
if (u.kind === "idle") {
|
|
1491
|
-
|
|
1491
|
+
E(R(m), g), y >= u.nextBlinkAt && H(y, g, !1);
|
|
1492
1492
|
return;
|
|
1493
1493
|
}
|
|
1494
1494
|
if (u.kind === "doublePause") {
|
|
1495
|
-
|
|
1495
|
+
E(R(m), u.blinkEmotion), y >= u.resumeAt && H(y, u.blinkEmotion, !0);
|
|
1496
1496
|
return;
|
|
1497
1497
|
}
|
|
1498
1498
|
if (u.kind === "playing") {
|
|
1499
1499
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1500
1500
|
u.index += 1, u.holdUntil = y + We();
|
|
1501
|
-
if (
|
|
1501
|
+
if (E(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
|
|
1502
1502
|
if (u.after === "resumeIdle") {
|
|
1503
1503
|
V(y + f, w);
|
|
1504
1504
|
return;
|
|
@@ -1506,17 +1506,17 @@ function ss(e = {}) {
|
|
|
1506
1506
|
if (u.after === "doublePause") {
|
|
1507
1507
|
u = {
|
|
1508
1508
|
kind: "doublePause",
|
|
1509
|
-
resumeAt: y +
|
|
1509
|
+
resumeAt: y + Oe(i, o),
|
|
1510
1510
|
blinkEmotion: u.blinkEmotion
|
|
1511
|
-
},
|
|
1511
|
+
}, E(R(m), u.blinkEmotion);
|
|
1512
1512
|
return;
|
|
1513
1513
|
}
|
|
1514
1514
|
if (u.after === "idle" && Math.random() < s) {
|
|
1515
1515
|
u = {
|
|
1516
1516
|
kind: "doublePause",
|
|
1517
|
-
resumeAt: y +
|
|
1517
|
+
resumeAt: y + Oe(i, o),
|
|
1518
1518
|
blinkEmotion: u.blinkEmotion
|
|
1519
|
-
},
|
|
1519
|
+
}, E(R(m), u.blinkEmotion);
|
|
1520
1520
|
return;
|
|
1521
1521
|
}
|
|
1522
1522
|
V(y, u.blinkEmotion);
|
|
@@ -1528,22 +1528,22 @@ function ss(e = {}) {
|
|
|
1528
1528
|
setTargetEmotion(y) {
|
|
1529
1529
|
const T = ve(y, w);
|
|
1530
1530
|
if (T === w) return;
|
|
1531
|
-
const
|
|
1532
|
-
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") &&
|
|
1531
|
+
const _ = performance.now();
|
|
1532
|
+
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && _ - k < l || (w = T, g = T, k = _);
|
|
1533
1533
|
},
|
|
1534
1534
|
setTargetEyebrow(y) {
|
|
1535
1535
|
const T = ye(y);
|
|
1536
1536
|
if (T === m && u.kind !== "browBlend") return;
|
|
1537
|
-
const
|
|
1538
|
-
m = T, !(T === x && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || W(
|
|
1537
|
+
const _ = performance.now(), x = u.kind === "browBlend" ? Vt(p) ?? S : S;
|
|
1538
|
+
m = T, !(T === x && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || W(_, x, T));
|
|
1539
1539
|
},
|
|
1540
1540
|
getTargetEmotion: () => w,
|
|
1541
1541
|
getTargetEyebrow: () => m,
|
|
1542
1542
|
getExpressionPath: () => p,
|
|
1543
1543
|
getDrawKey: () => d,
|
|
1544
1544
|
reset() {
|
|
1545
|
-
w = "neutral",
|
|
1546
|
-
performance.now() +
|
|
1545
|
+
w = "neutral", g = "neutral", m = 0, S = 0, k = 0, V(
|
|
1546
|
+
performance.now() + Oe(n, r),
|
|
1547
1547
|
"neutral"
|
|
1548
1548
|
);
|
|
1549
1549
|
}
|
|
@@ -1592,7 +1592,7 @@ function is() {
|
|
|
1592
1592
|
}
|
|
1593
1593
|
};
|
|
1594
1594
|
}
|
|
1595
|
-
const os = 50,
|
|
1595
|
+
const os = 50, fn = 400;
|
|
1596
1596
|
function as(e, t, n) {
|
|
1597
1597
|
return e.filter((r) => {
|
|
1598
1598
|
const s = r.queueIndex ?? -1;
|
|
@@ -1612,7 +1612,7 @@ function cs(e, t) {
|
|
|
1612
1612
|
n.push({
|
|
1613
1613
|
sentence: r,
|
|
1614
1614
|
startMs: Math.max(0, i.wtime - os),
|
|
1615
|
-
endMs: o.wtime + o.wduration +
|
|
1615
|
+
endMs: o.wtime + o.wduration + fn
|
|
1616
1616
|
});
|
|
1617
1617
|
}
|
|
1618
1618
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
@@ -1629,37 +1629,37 @@ function us(e, t, n, r = "neutral") {
|
|
|
1629
1629
|
if (o)
|
|
1630
1630
|
return ve(o.sentence.emotion, s);
|
|
1631
1631
|
const a = n[n.length - 1], f = a.wtime + a.wduration;
|
|
1632
|
-
return e > f +
|
|
1632
|
+
return e > f + fn ? ve(
|
|
1633
1633
|
t[t.length - 1]?.emotion,
|
|
1634
1634
|
s
|
|
1635
1635
|
) : s;
|
|
1636
1636
|
}
|
|
1637
|
-
function
|
|
1637
|
+
function dn(e, t, n, r, s = on) {
|
|
1638
1638
|
const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
|
|
1639
1639
|
o.drawImage(e, 0, 0, n, r);
|
|
1640
1640
|
const a = o.getImageData(0, 0, n, r), f = o.createImageData(n, r);
|
|
1641
1641
|
f.data.set(a.data);
|
|
1642
1642
|
const w = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
|
|
1643
|
-
for (const
|
|
1644
|
-
w.clearRect(0, 0, n, r), w.drawImage(
|
|
1643
|
+
for (const g of t) {
|
|
1644
|
+
w.clearRect(0, 0, n, r), w.drawImage(g, 0, 0, n, r);
|
|
1645
1645
|
const m = w.getImageData(0, 0, n, r);
|
|
1646
1646
|
for (let S = 0; S < f.data.length; S += 4) {
|
|
1647
|
-
const
|
|
1648
|
-
Math.max(
|
|
1647
|
+
const k = m.data[S], u = m.data[S + 1], p = m.data[S + 2];
|
|
1648
|
+
Math.max(k, u, p) > s && (f.data[S] = k, f.data[S + 1] = u, f.data[S + 2] = p, f.data[S + 3] = 255);
|
|
1649
1649
|
}
|
|
1650
1650
|
}
|
|
1651
1651
|
return o.putImageData(f, 0, 0), i;
|
|
1652
1652
|
}
|
|
1653
|
-
let pe = null,
|
|
1653
|
+
let pe = null, Fe = null;
|
|
1654
1654
|
const je = /* @__PURE__ */ new Map();
|
|
1655
1655
|
function ls() {
|
|
1656
|
-
pe = null,
|
|
1656
|
+
pe = null, Fe = null, je.clear();
|
|
1657
1657
|
}
|
|
1658
1658
|
Qn(ls);
|
|
1659
1659
|
function fs(e) {
|
|
1660
|
-
return e ??
|
|
1660
|
+
return e ?? Fe ?? void 0;
|
|
1661
1661
|
}
|
|
1662
|
-
function
|
|
1662
|
+
function _t(e) {
|
|
1663
1663
|
return new Promise((t, n) => {
|
|
1664
1664
|
const r = new Image();
|
|
1665
1665
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
@@ -1668,7 +1668,7 @@ function gt(e) {
|
|
|
1668
1668
|
async function ds(e) {
|
|
1669
1669
|
return Ge() ? Pr(
|
|
1670
1670
|
await Ye(Mt(), e ?? "")
|
|
1671
|
-
) :
|
|
1671
|
+
) : _t(Mt());
|
|
1672
1672
|
}
|
|
1673
1673
|
async function $t(e, t, n, r) {
|
|
1674
1674
|
const s = n ? await xr(e, r) : await fetch(e).then((l) => {
|
|
@@ -1681,7 +1681,7 @@ async function $t(e, t, n, r) {
|
|
|
1681
1681
|
Hr(t, i.path, n),
|
|
1682
1682
|
r ?? ""
|
|
1683
1683
|
)
|
|
1684
|
-
) : await
|
|
1684
|
+
) : await _t(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
|
|
1685
1685
|
for (const l of s.cells ?? [])
|
|
1686
1686
|
l.path && a.set(l.path, l);
|
|
1687
1687
|
const f = /* @__PURE__ */ new Map();
|
|
@@ -1693,14 +1693,14 @@ async function at(e) {
|
|
|
1693
1693
|
const t = fs(e), n = Ge();
|
|
1694
1694
|
if (n && !t)
|
|
1695
1695
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
1696
|
-
if (pe && (!n ||
|
|
1696
|
+
if (pe && (!n || Fe === (t ?? null))) {
|
|
1697
1697
|
const i = await pe;
|
|
1698
1698
|
return {
|
|
1699
1699
|
...Ue(i),
|
|
1700
1700
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
1701
1701
|
};
|
|
1702
1702
|
}
|
|
1703
|
-
|
|
1703
|
+
Fe = t ?? null, je.clear();
|
|
1704
1704
|
const r = Zn();
|
|
1705
1705
|
pe = (async () => {
|
|
1706
1706
|
const i = await ds(t), o = await $t(
|
|
@@ -1725,7 +1725,7 @@ async function at(e) {
|
|
|
1725
1725
|
const s = await pe;
|
|
1726
1726
|
return { ...Ue(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
1727
1727
|
}
|
|
1728
|
-
async function
|
|
1728
|
+
async function hn(e) {
|
|
1729
1729
|
if (await at(e), !pe) throw new Error("Assets not loaded");
|
|
1730
1730
|
return pe;
|
|
1731
1731
|
}
|
|
@@ -1748,12 +1748,12 @@ async function Ht(e, t, n) {
|
|
|
1748
1748
|
if (!o) throw new Error(`No atlas cell for path: ${n}`);
|
|
1749
1749
|
const a = Dr(t.atlasMeta, o), f = Ue(e);
|
|
1750
1750
|
if (Mr(o)) {
|
|
1751
|
-
const
|
|
1751
|
+
const g = hs(t, o), m = document.createElement("canvas");
|
|
1752
1752
|
m.width = f.width, m.height = f.height;
|
|
1753
1753
|
const S = m.getContext("2d");
|
|
1754
|
-
return S.fillStyle = "#000", S.fillRect(0, 0, f.width, f.height), S.drawImage(
|
|
1754
|
+
return S.fillStyle = "#000", S.fillRect(0, 0, f.width, f.height), S.drawImage(g, a.x, a.y), m;
|
|
1755
1755
|
}
|
|
1756
|
-
const l = `${t.diffBase}/${n}`, w = await
|
|
1756
|
+
const l = `${t.diffBase}/${n}`, w = await _t(l);
|
|
1757
1757
|
if (w.naturalWidth === f.width && w.naturalHeight === f.height)
|
|
1758
1758
|
return w;
|
|
1759
1759
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
@@ -1762,40 +1762,40 @@ async function Ht(e, t, n) {
|
|
|
1762
1762
|
}
|
|
1763
1763
|
async function Wt(e, t, n, r, s, i) {
|
|
1764
1764
|
if (s) {
|
|
1765
|
-
const { width: S, height:
|
|
1765
|
+
const { width: S, height: k } = s;
|
|
1766
1766
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
1767
1767
|
return;
|
|
1768
1768
|
const u = document.createElement("canvas");
|
|
1769
|
-
u.width = S, u.height =
|
|
1769
|
+
u.width = S, u.height = k;
|
|
1770
1770
|
const p = u.getContext("2d");
|
|
1771
|
-
if (p.clearRect(0, 0, S,
|
|
1772
|
-
(e.width !== S || e.height !==
|
|
1771
|
+
if (p.clearRect(0, 0, S, k), p.drawImage(t, 0, 0, S, k), i && !i()) return;
|
|
1772
|
+
(e.width !== S || e.height !== k) && (e.width = S, e.height = k);
|
|
1773
1773
|
const d = e.getContext("2d");
|
|
1774
|
-
d.clearRect(0, 0, S,
|
|
1774
|
+
d.clearRect(0, 0, S, k), d.drawImage(u, 0, 0);
|
|
1775
1775
|
return;
|
|
1776
1776
|
}
|
|
1777
|
-
const o = await
|
|
1777
|
+
const o = await hn(), a = an(o.viseme.atlasMeta), { width: f, height: l } = Ue(o);
|
|
1778
1778
|
(e.width !== f || e.height !== l) && (e.width = f, e.height = l);
|
|
1779
|
-
const w = [],
|
|
1780
|
-
if (
|
|
1779
|
+
const w = [], g = e.getContext("2d");
|
|
1780
|
+
if (g.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
1781
1781
|
const S = o.sil;
|
|
1782
|
-
|
|
1782
|
+
g.drawImage(S, 0, 0, f, l);
|
|
1783
1783
|
return;
|
|
1784
1784
|
}
|
|
1785
1785
|
if (w.length === 0) {
|
|
1786
|
-
|
|
1786
|
+
g.drawImage(t, 0, 0, f, l);
|
|
1787
1787
|
return;
|
|
1788
1788
|
}
|
|
1789
|
-
const m =
|
|
1790
|
-
|
|
1789
|
+
const m = dn(t, w, f, l, a);
|
|
1790
|
+
g.drawImage(m, 0, 0);
|
|
1791
1791
|
}
|
|
1792
1792
|
async function ct(e, t, n) {
|
|
1793
|
-
const r = await
|
|
1793
|
+
const r = await hn(Fe ?? void 0), s = an(r.viseme.atlasMeta), { width: i, height: o } = Ue(r);
|
|
1794
1794
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
1795
1795
|
const a = [];
|
|
1796
1796
|
if (t.mouthPath) {
|
|
1797
|
-
const w = new Set(r.viseme.cellByPath.keys()),
|
|
1798
|
-
|
|
1797
|
+
const w = new Set(r.viseme.cellByPath.keys()), g = Fr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
|
|
1798
|
+
g && a.push(await Ht(r, r.viseme, g));
|
|
1799
1799
|
}
|
|
1800
1800
|
t.expressionPath && r.expression && a.push(
|
|
1801
1801
|
await Ht(r, r.expression, t.expressionPath)
|
|
@@ -1805,7 +1805,7 @@ async function ct(e, t, n) {
|
|
|
1805
1805
|
f.drawImage(r.sil, 0, 0, i, o);
|
|
1806
1806
|
return;
|
|
1807
1807
|
}
|
|
1808
|
-
const l =
|
|
1808
|
+
const l = dn(
|
|
1809
1809
|
r.sil,
|
|
1810
1810
|
a,
|
|
1811
1811
|
i,
|
|
@@ -1823,7 +1823,7 @@ function ws(e) {
|
|
|
1823
1823
|
t.has(n.vtime) || t.set(n.vtime, n);
|
|
1824
1824
|
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
1825
1825
|
}
|
|
1826
|
-
function
|
|
1826
|
+
function _s(e) {
|
|
1827
1827
|
const t = ws(e), n = [];
|
|
1828
1828
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1829
1829
|
const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
|
|
@@ -1831,7 +1831,7 @@ function gs(e) {
|
|
|
1831
1831
|
}
|
|
1832
1832
|
return n;
|
|
1833
1833
|
}
|
|
1834
|
-
function
|
|
1834
|
+
function gs(e, t) {
|
|
1835
1835
|
let n = null;
|
|
1836
1836
|
for (const r of e)
|
|
1837
1837
|
t >= r.fromVtime && t < r.toVtime && (n = r);
|
|
@@ -1840,7 +1840,7 @@ function _s(e, t) {
|
|
|
1840
1840
|
function ps(e, t) {
|
|
1841
1841
|
return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
|
|
1842
1842
|
}
|
|
1843
|
-
const
|
|
1843
|
+
const mn = 400, ys = 200, Es = 600, ks = "__sil__";
|
|
1844
1844
|
function Ss() {
|
|
1845
1845
|
return { lastDrawnKey: "" };
|
|
1846
1846
|
}
|
|
@@ -1850,7 +1850,7 @@ function me(e) {
|
|
|
1850
1850
|
function vs(e, t) {
|
|
1851
1851
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
1852
1852
|
return t.transitionCache.transitions;
|
|
1853
|
-
const n =
|
|
1853
|
+
const n = _s(e);
|
|
1854
1854
|
return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
|
|
1855
1855
|
}
|
|
1856
1856
|
function bs(e) {
|
|
@@ -1863,29 +1863,29 @@ function Ts(e, t) {
|
|
|
1863
1863
|
return e === "sil" ? !1 : t ? Ur(e, "sil", t) : ht(e, "sil").length > 0;
|
|
1864
1864
|
}
|
|
1865
1865
|
function As() {
|
|
1866
|
-
return
|
|
1866
|
+
return mn + Es;
|
|
1867
1867
|
}
|
|
1868
1868
|
function qt(e) {
|
|
1869
|
-
return e ??
|
|
1869
|
+
return e ?? ks;
|
|
1870
1870
|
}
|
|
1871
1871
|
function Is(e, t, n, r) {
|
|
1872
1872
|
if (e.length === 0)
|
|
1873
1873
|
return { diffPath: null, label: "sil" };
|
|
1874
|
-
const s = vs(e, r), i =
|
|
1874
|
+
const s = vs(e, r), i = gs(s, t);
|
|
1875
1875
|
if (i) {
|
|
1876
1876
|
const a = i.toVtime - i.fromVtime, f = ps(i.fromVtime, i.toVtime);
|
|
1877
1877
|
if (t >= f.transStart && t < i.toVtime) {
|
|
1878
1878
|
let l = ht(i.from, i.to);
|
|
1879
|
-
n && (l =
|
|
1879
|
+
n && (l = cn(l, n));
|
|
1880
1880
|
const w = Vr(l, a);
|
|
1881
1881
|
if (w.length > 0) {
|
|
1882
|
-
const
|
|
1882
|
+
const g = $r(
|
|
1883
1883
|
t,
|
|
1884
1884
|
f.transStart,
|
|
1885
1885
|
i.toVtime,
|
|
1886
1886
|
w.length
|
|
1887
1887
|
);
|
|
1888
|
-
return { diffPath: w[
|
|
1888
|
+
return { diffPath: w[g] ?? w[w.length - 1], label: `${i.from}→${i.to}` };
|
|
1889
1889
|
}
|
|
1890
1890
|
return { diffPath: Ke(i.to), label: i.to };
|
|
1891
1891
|
}
|
|
@@ -1893,28 +1893,28 @@ function Is(e, t, n, r) {
|
|
|
1893
1893
|
const o = lt(e, t);
|
|
1894
1894
|
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Ke(o), label: o };
|
|
1895
1895
|
}
|
|
1896
|
-
function
|
|
1896
|
+
function wn(e, t) {
|
|
1897
1897
|
const n = t ?? qt(e.expressionPath);
|
|
1898
1898
|
return `${qt(e.mouthPath)}|${n}`;
|
|
1899
1899
|
}
|
|
1900
1900
|
function Rs(e, t, n, r, s, i, o, a, f, l) {
|
|
1901
|
-
const w = Is(t, n, f, i),
|
|
1901
|
+
const w = Is(t, n, f, i), g = {
|
|
1902
1902
|
mouthPath: w.diffPath,
|
|
1903
1903
|
expressionPath: r
|
|
1904
|
-
}, m =
|
|
1905
|
-
m !== i.lastDrawnKey && (a(w.label), o(e,
|
|
1904
|
+
}, m = wn(g, s);
|
|
1905
|
+
m !== i.lastDrawnKey && (a(w.label), o(e, g, m, (S) => {
|
|
1906
1906
|
S === m && (i.lastDrawnKey = m);
|
|
1907
1907
|
}));
|
|
1908
1908
|
}
|
|
1909
1909
|
function Kt(e, t, n, r, s, i, o = null) {
|
|
1910
|
-
const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l =
|
|
1910
|
+
const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = wn(a, n) + f;
|
|
1911
1911
|
!(o != null) && l === r.lastDrawnKey || (i(
|
|
1912
1912
|
o != null ? "idle" : "sil"
|
|
1913
|
-
), s(e, a, l, (
|
|
1914
|
-
|
|
1913
|
+
), s(e, a, l, (g) => {
|
|
1914
|
+
g === l && (r.lastDrawnKey = l);
|
|
1915
1915
|
}));
|
|
1916
1916
|
}
|
|
1917
|
-
function
|
|
1917
|
+
function _n(e) {
|
|
1918
1918
|
let t = 0, n = null, r = !1, s = !1;
|
|
1919
1919
|
const i = async () => {
|
|
1920
1920
|
if (!r) {
|
|
@@ -1974,7 +1974,7 @@ function xs(e, t) {
|
|
|
1974
1974
|
}
|
|
1975
1975
|
function zt(e, t) {
|
|
1976
1976
|
let n = 0, r = null;
|
|
1977
|
-
const s =
|
|
1977
|
+
const s = _n(async (i, o) => (await at(), await ct(e, i), s.isLatestSeq(o)));
|
|
1978
1978
|
return {
|
|
1979
1979
|
usesWorker: !1,
|
|
1980
1980
|
async loadAssets(i) {
|
|
@@ -2005,10 +2005,10 @@ function zt(e, t) {
|
|
|
2005
2005
|
}
|
|
2006
2006
|
function Cs(e, t, n) {
|
|
2007
2007
|
let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
|
|
2008
|
-
const l = /* @__PURE__ */ new Map(), w =
|
|
2008
|
+
const l = /* @__PURE__ */ new Map(), w = _n(async (p, d, I) => (l.set(d, {
|
|
2009
2009
|
drawKey: I.drawKey,
|
|
2010
2010
|
onDisplayed: I.onDisplayed
|
|
2011
|
-
}), await
|
|
2011
|
+
}), await k(
|
|
2012
2012
|
{
|
|
2013
2013
|
type: "drawFrame",
|
|
2014
2014
|
diffPath: p.mouthPath,
|
|
@@ -2017,28 +2017,28 @@ function Cs(e, t, n) {
|
|
|
2017
2017
|
},
|
|
2018
2018
|
void 0,
|
|
2019
2019
|
!0
|
|
2020
|
-
), !1)),
|
|
2020
|
+
), !1)), g = (p) => {
|
|
2021
2021
|
if (p === jt) {
|
|
2022
|
-
let
|
|
2022
|
+
let E = -1, R;
|
|
2023
2023
|
for (const [W, V] of l)
|
|
2024
|
-
W >=
|
|
2025
|
-
|
|
2024
|
+
W >= E && (E = W, R = V);
|
|
2025
|
+
E >= 0 && l.delete(E), R?.onDisplayed?.(R.drawKey);
|
|
2026
2026
|
return;
|
|
2027
2027
|
}
|
|
2028
2028
|
const d = -p, I = l.get(d);
|
|
2029
2029
|
l.delete(d), I?.onDisplayed?.(I.drawKey);
|
|
2030
2030
|
}, m = /* @__PURE__ */ new Map(), S = (p, d) => {
|
|
2031
2031
|
a || !r || r.postMessage(p, []);
|
|
2032
|
-
},
|
|
2032
|
+
}, k = (p, d, I = !1) => {
|
|
2033
2033
|
if (a) return Promise.resolve();
|
|
2034
|
-
const
|
|
2034
|
+
const E = s++;
|
|
2035
2035
|
return new Promise((R, W) => {
|
|
2036
|
-
m.set(
|
|
2036
|
+
m.set(E, {
|
|
2037
2037
|
resolve: (V) => R(V),
|
|
2038
2038
|
reject: W,
|
|
2039
2039
|
generation: typeof p.generation == "number" ? p.generation : void 0,
|
|
2040
2040
|
expectRenderDone: I
|
|
2041
|
-
}), S({ ...p, requestId:
|
|
2041
|
+
}), S({ ...p, requestId: E });
|
|
2042
2042
|
});
|
|
2043
2043
|
}, u = (async () => {
|
|
2044
2044
|
r = await Ds(n), r.onmessage = (p) => {
|
|
@@ -2049,23 +2049,23 @@ function Cs(e, t, n) {
|
|
|
2049
2049
|
return;
|
|
2050
2050
|
}
|
|
2051
2051
|
if (d.type === "frame") {
|
|
2052
|
-
const
|
|
2053
|
-
if (!
|
|
2052
|
+
const E = d.generation < 0;
|
|
2053
|
+
if (!E && d.generation !== i) {
|
|
2054
2054
|
d.bitmap.close();
|
|
2055
2055
|
return;
|
|
2056
2056
|
}
|
|
2057
|
-
if (
|
|
2057
|
+
if (E && !(d.generation === jt)) {
|
|
2058
2058
|
const W = -d.generation;
|
|
2059
2059
|
if (!w.isLatestSeq(W)) {
|
|
2060
2060
|
d.bitmap.close();
|
|
2061
2061
|
return;
|
|
2062
2062
|
}
|
|
2063
2063
|
}
|
|
2064
|
-
if (
|
|
2064
|
+
if (E && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
2065
2065
|
d.bitmap.close();
|
|
2066
2066
|
return;
|
|
2067
2067
|
}
|
|
2068
|
-
xs(e, d.bitmap), d.bitmap.close(),
|
|
2068
|
+
xs(e, d.bitmap), d.bitmap.close(), E && g(d.generation);
|
|
2069
2069
|
return;
|
|
2070
2070
|
}
|
|
2071
2071
|
const I = m.get(d.requestId);
|
|
@@ -2096,7 +2096,7 @@ function Cs(e, t, n) {
|
|
|
2096
2096
|
for (const [, I] of m)
|
|
2097
2097
|
I.reject(new Error(d));
|
|
2098
2098
|
m.clear();
|
|
2099
|
-
}, await
|
|
2099
|
+
}, await k({ type: "init" }), o = !0;
|
|
2100
2100
|
})();
|
|
2101
2101
|
return {
|
|
2102
2102
|
usesWorker: !0,
|
|
@@ -2104,10 +2104,10 @@ function Cs(e, t, n) {
|
|
|
2104
2104
|
if (a) return { width: 842, height: 1264 };
|
|
2105
2105
|
if (await u, a) return { width: 842, height: 1264 };
|
|
2106
2106
|
if (!o) throw new Error("Worker init failed");
|
|
2107
|
-
return await
|
|
2107
|
+
return await k({
|
|
2108
2108
|
type: "loadAssets",
|
|
2109
2109
|
keyHex: p,
|
|
2110
|
-
urls: Jn(
|
|
2110
|
+
urls: Jn(Ee())
|
|
2111
2111
|
}) ?? { width: 842, height: 1264 };
|
|
2112
2112
|
},
|
|
2113
2113
|
getVisemeAtlasPaths() {
|
|
@@ -2117,26 +2117,26 @@ function Cs(e, t, n) {
|
|
|
2117
2117
|
if (a || (await u, a)) return;
|
|
2118
2118
|
i += 1, w.reset(), l.clear();
|
|
2119
2119
|
const p = i;
|
|
2120
|
-
await
|
|
2120
|
+
await k({ type: "cancelLiveDraws" }), await k(
|
|
2121
2121
|
{ type: "renderSil", generation: p },
|
|
2122
2122
|
void 0,
|
|
2123
2123
|
!0
|
|
2124
2124
|
);
|
|
2125
2125
|
},
|
|
2126
|
-
drawLiveFrame(p, d, I,
|
|
2126
|
+
drawLiveFrame(p, d, I, E) {
|
|
2127
2127
|
a || u.then(() => {
|
|
2128
|
-
a || w.enqueue(d, I,
|
|
2128
|
+
a || w.enqueue(d, I, E);
|
|
2129
2129
|
});
|
|
2130
2130
|
},
|
|
2131
2131
|
async renderViseme(p, d, I = {}) {
|
|
2132
2132
|
if (a || (await u, a)) return;
|
|
2133
2133
|
i += 1, w.reset(), l.clear();
|
|
2134
|
-
const
|
|
2134
|
+
const E = i;
|
|
2135
2135
|
try {
|
|
2136
|
-
await
|
|
2136
|
+
await k({ type: "cancelLiveDraws" }), await k(
|
|
2137
2137
|
{
|
|
2138
2138
|
type: "renderViseme",
|
|
2139
|
-
generation:
|
|
2139
|
+
generation: E,
|
|
2140
2140
|
to: d,
|
|
2141
2141
|
from: I.from,
|
|
2142
2142
|
transitionDurationMs: I.transitionDurationMs,
|
|
@@ -2191,15 +2191,15 @@ function tt(e, t, n) {
|
|
|
2191
2191
|
);
|
|
2192
2192
|
});
|
|
2193
2193
|
}
|
|
2194
|
-
const
|
|
2194
|
+
const Ls = {
|
|
2195
2195
|
position: "relative",
|
|
2196
2196
|
display: "inline-block",
|
|
2197
2197
|
lineHeight: 0
|
|
2198
|
-
},
|
|
2198
|
+
}, Os = {
|
|
2199
2199
|
display: "block",
|
|
2200
2200
|
maxWidth: "100%",
|
|
2201
2201
|
height: "auto"
|
|
2202
|
-
},
|
|
2202
|
+
}, Fs = {
|
|
2203
2203
|
position: "absolute",
|
|
2204
2204
|
inset: 0,
|
|
2205
2205
|
display: "flex",
|
|
@@ -2211,13 +2211,13 @@ const Os = {
|
|
|
2211
2211
|
fontSize: "0.875rem",
|
|
2212
2212
|
textAlign: "center"
|
|
2213
2213
|
};
|
|
2214
|
-
function
|
|
2215
|
-
return
|
|
2214
|
+
function Le(e) {
|
|
2215
|
+
return On(e) ? Er : nn;
|
|
2216
2216
|
}
|
|
2217
2217
|
function we(e, t) {
|
|
2218
2218
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
2219
2219
|
}
|
|
2220
|
-
const
|
|
2220
|
+
const Ks = Sn(function({
|
|
2221
2221
|
id: t,
|
|
2222
2222
|
avatarId: n,
|
|
2223
2223
|
faceId: r,
|
|
@@ -2228,23 +2228,23 @@ const qs = En(function({
|
|
|
2228
2228
|
speakingRate: f = ft,
|
|
2229
2229
|
className: l,
|
|
2230
2230
|
style: w,
|
|
2231
|
-
canvasStyle:
|
|
2231
|
+
canvasStyle: g,
|
|
2232
2232
|
onStatusChange: m,
|
|
2233
2233
|
onDisplayStatus: S,
|
|
2234
|
-
onError:
|
|
2234
|
+
onError: k,
|
|
2235
2235
|
onReady: u,
|
|
2236
2236
|
showErrorOverlay: p = !0,
|
|
2237
2237
|
onUserTranscript: d,
|
|
2238
2238
|
onBotOutput: I,
|
|
2239
|
-
onRealtimeLipsyncDebug:
|
|
2239
|
+
onRealtimeLipsyncDebug: E
|
|
2240
2240
|
}, R) {
|
|
2241
|
-
const W =
|
|
2241
|
+
const W = F(null), V = F(null), H = F(Ss()), j = F(ss()), y = F(0), T = F(0), _ = F(0), x = F(null), b = F(null), D = F(!1), A = F(!1), P = F(!1), B = F("sil"), $ = F(!1), U = F(
|
|
2242
2242
|
null
|
|
2243
|
-
), X =
|
|
2244
|
-
|
|
2243
|
+
), X = F(!1), [se, Z] = Be("idle"), [ce, J] = Be(null), [c, v] = Be(!1), [L, z] = Be(!1), [ne, Re] = Be({ width: 842, height: 1264 }), G = F(i ?? null), ke = F(null), Y = F(null), De = F(!1), Je = F({ width: 842, height: 1264 }), Qe = F(null), gt = F(u), ee = F(S), pt = F(k), yt = F(d), Et = F(I), kt = F(E);
|
|
2244
|
+
gt.current = u, ee.current = S, pt.current = k, yt.current = d, Et.current = I, kt.current = E;
|
|
2245
2245
|
const St = oe(
|
|
2246
2246
|
(h) => {
|
|
2247
|
-
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, C = h?.voiceId ?? a ?? Y.current?.voiceId ??
|
|
2247
|
+
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, C = h?.voiceId ?? a ?? Y.current?.voiceId ?? Le(M);
|
|
2248
2248
|
return { ttsEngineId: M, voiceId: C };
|
|
2249
2249
|
},
|
|
2250
2250
|
[o, a]
|
|
@@ -2255,9 +2255,9 @@ const qs = En(function({
|
|
|
2255
2255
|
Z(h), m?.(h);
|
|
2256
2256
|
},
|
|
2257
2257
|
[m]
|
|
2258
|
-
), q =
|
|
2258
|
+
), q = F(
|
|
2259
2259
|
Pt(Me, be)
|
|
2260
|
-
), K =
|
|
2260
|
+
), K = F(null);
|
|
2261
2261
|
Se(() => (q.current = Pt(
|
|
2262
2262
|
Me,
|
|
2263
2263
|
be
|
|
@@ -2271,8 +2271,8 @@ const qs = En(function({
|
|
|
2271
2271
|
{
|
|
2272
2272
|
speakingRate: f,
|
|
2273
2273
|
onUserTranscript: (h, M) => yt.current?.(h, M),
|
|
2274
|
-
onBotOutput: (h) =>
|
|
2275
|
-
onLipsyncDebug: (h) =>
|
|
2274
|
+
onBotOutput: (h) => Et.current?.(h),
|
|
2275
|
+
onLipsyncDebug: (h) => kt.current?.(h)
|
|
2276
2276
|
}
|
|
2277
2277
|
), K.current.setTtsEngineId(o)), K.current), [Me, f, o]), ie = oe(() => {
|
|
2278
2278
|
x.current != null && (clearTimeout(x.current), x.current = null);
|
|
@@ -2299,16 +2299,16 @@ const qs = En(function({
|
|
|
2299
2299
|
h.restart(), h.setActive(!0);
|
|
2300
2300
|
const M = h.getVideo();
|
|
2301
2301
|
let C = !1;
|
|
2302
|
-
const
|
|
2302
|
+
const O = () => {
|
|
2303
2303
|
C || (C = !0, M.removeEventListener("playing", N), P.current = !1);
|
|
2304
2304
|
}, N = () => {
|
|
2305
|
-
|
|
2305
|
+
O();
|
|
2306
2306
|
};
|
|
2307
2307
|
if (M.addEventListener("playing", N, { once: !0 }), M.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !M.paused) {
|
|
2308
|
-
|
|
2308
|
+
O();
|
|
2309
2309
|
return;
|
|
2310
2310
|
}
|
|
2311
|
-
setTimeout(
|
|
2311
|
+
setTimeout(O, 300);
|
|
2312
2312
|
}, ys));
|
|
2313
2313
|
}, [ue]), Ne = oe(() => {
|
|
2314
2314
|
if (ie(), ee.current?.("sil"), D.current = !1, !X.current || !U.current) {
|
|
@@ -2318,10 +2318,10 @@ const qs = En(function({
|
|
|
2318
2318
|
bt();
|
|
2319
2319
|
}, [ie, bt]), Xe = oe(
|
|
2320
2320
|
async (h) => {
|
|
2321
|
-
const M = T.current, C = V.current,
|
|
2321
|
+
const M = T.current, C = V.current, O = W.current, N = () => {
|
|
2322
2322
|
h?.fallbackOnly || (D.current = !1);
|
|
2323
2323
|
};
|
|
2324
|
-
if (!C || !
|
|
2324
|
+
if (!C || !O || !c) {
|
|
2325
2325
|
N();
|
|
2326
2326
|
return;
|
|
2327
2327
|
}
|
|
@@ -2360,9 +2360,9 @@ const qs = En(function({
|
|
|
2360
2360
|
return;
|
|
2361
2361
|
}
|
|
2362
2362
|
try {
|
|
2363
|
-
await C.renderViseme(
|
|
2363
|
+
await C.renderViseme(O, "sil", {
|
|
2364
2364
|
from: te,
|
|
2365
|
-
transitionDurationMs:
|
|
2365
|
+
transitionDurationMs: mn
|
|
2366
2366
|
});
|
|
2367
2367
|
} catch (de) {
|
|
2368
2368
|
if (de?.name !== "AbortError")
|
|
@@ -2393,12 +2393,12 @@ const qs = En(function({
|
|
|
2393
2393
|
}, As());
|
|
2394
2394
|
}, [ie, Xe]), Tt = oe(async () => {
|
|
2395
2395
|
const h = Math.floor(Date.now() / 1e3);
|
|
2396
|
-
if (
|
|
2397
|
-
return
|
|
2396
|
+
if (ke.current && h < ke.current.expiresAt - 60)
|
|
2397
|
+
return ke.current.key;
|
|
2398
2398
|
const M = G.current ?? await et();
|
|
2399
2399
|
G.current = M, q.current.setDeveloperToken(M);
|
|
2400
2400
|
const C = await qn(M, be);
|
|
2401
|
-
return
|
|
2401
|
+
return ke.current = {
|
|
2402
2402
|
key: C.value,
|
|
2403
2403
|
expiresAt: C.expiresAt
|
|
2404
2404
|
}, C.value;
|
|
@@ -2408,15 +2408,15 @@ const qs = En(function({
|
|
|
2408
2408
|
}, [i]), Se(() => {
|
|
2409
2409
|
q.current.setTtsEngineId(o), K.current?.setTtsEngineId(o), Y.current && (Y.current.ttsEngineId = o);
|
|
2410
2410
|
}, [o]), Se(() => {
|
|
2411
|
-
const h = a ??
|
|
2411
|
+
const h = a ?? Le(o);
|
|
2412
2412
|
Y.current && (Y.current.voiceId = h);
|
|
2413
2413
|
}, [a, o]);
|
|
2414
|
-
const
|
|
2414
|
+
const _e = It(
|
|
2415
2415
|
() => zn(n, r),
|
|
2416
2416
|
[n, r]
|
|
2417
|
-
), gn = It(() => s ? JSON.stringify(s) :
|
|
2417
|
+
), gn = It(() => s ? JSON.stringify(s) : _e ? `face:${_e}` : `id:${t ?? ""}`, [s, _e, t]);
|
|
2418
2418
|
return Se(() => {
|
|
2419
|
-
if (!t && !s && !
|
|
2419
|
+
if (!t && !s && !_e) {
|
|
2420
2420
|
fe("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
2421
2421
|
return;
|
|
2422
2422
|
}
|
|
@@ -2427,11 +2427,11 @@ const qs = En(function({
|
|
|
2427
2427
|
let C = null;
|
|
2428
2428
|
return (async () => {
|
|
2429
2429
|
try {
|
|
2430
|
-
let
|
|
2430
|
+
let O, N, te;
|
|
2431
2431
|
if (s)
|
|
2432
|
-
|
|
2433
|
-
else if (
|
|
2434
|
-
ee.current?.("loadFace"),
|
|
2432
|
+
O = s, N = o, te = a ?? Le(N);
|
|
2433
|
+
else if (_e)
|
|
2434
|
+
ee.current?.("loadFace"), O = Dt(_e), N = o, te = a ?? Le(N);
|
|
2435
2435
|
else {
|
|
2436
2436
|
ee.current?.("getAiTwin");
|
|
2437
2437
|
const Q = await tt(
|
|
@@ -2442,9 +2442,9 @@ const qs = En(function({
|
|
|
2442
2442
|
if (h) return;
|
|
2443
2443
|
if (!Q.faceId?.trim())
|
|
2444
2444
|
throw new Error("getAiTwin returned no faceId");
|
|
2445
|
-
N = Q.ttsEngineId, te = a ?? Q.voiceId ??
|
|
2445
|
+
N = Q.ttsEngineId, te = a ?? Q.voiceId ?? Le(N), O = Dt(Q.faceId);
|
|
2446
2446
|
}
|
|
2447
|
-
Y.current = { ttsEngineId: N, voiceId: te }, Yn(
|
|
2447
|
+
Y.current = { ttsEngineId: N, voiceId: te }, Yn(O), U.current = is(), C = Ps(M, {
|
|
2448
2448
|
onStatus: (Q) => {
|
|
2449
2449
|
h || ee.current?.(Q);
|
|
2450
2450
|
},
|
|
@@ -2468,11 +2468,11 @@ const qs = En(function({
|
|
|
2468
2468
|
"load face assets"
|
|
2469
2469
|
);
|
|
2470
2470
|
if (!h && le.width > 0 && le.height > 0 && (Je.current = le, Re(le)), h) return;
|
|
2471
|
-
Qe.current = C.getVisemeAtlasPaths(), De.current = !0, v(!0),
|
|
2471
|
+
Qe.current = C.getVisemeAtlasPaths(), De.current = !0, v(!0), gt.current?.(), C.renderSilOnly().then(() => {
|
|
2472
2472
|
h || ee.current?.("sil");
|
|
2473
2473
|
}), (async () => {
|
|
2474
2474
|
try {
|
|
2475
|
-
const Q = await
|
|
2475
|
+
const Q = await Lr(de);
|
|
2476
2476
|
if (await U.current.load(Q), h) return;
|
|
2477
2477
|
X.current = !0, z(!0), me(H.current), U.current.setActive(!0);
|
|
2478
2478
|
const re = U.current.getVideo();
|
|
@@ -2488,34 +2488,34 @@ const qs = En(function({
|
|
|
2488
2488
|
X.current = !1, z(!1), console.warn("[AiTwin] Idle video unavailable:", Q);
|
|
2489
2489
|
}
|
|
2490
2490
|
})();
|
|
2491
|
-
} catch (
|
|
2491
|
+
} catch (O) {
|
|
2492
2492
|
if (h) return;
|
|
2493
|
-
if (
|
|
2494
|
-
fe(
|
|
2493
|
+
if (O instanceof nt) {
|
|
2494
|
+
fe(O.message);
|
|
2495
2495
|
return;
|
|
2496
2496
|
}
|
|
2497
|
-
fe(
|
|
2497
|
+
fe(O instanceof Error ? O.message : "Failed to load AI twin");
|
|
2498
2498
|
}
|
|
2499
2499
|
})(), () => {
|
|
2500
2500
|
h = !0, U.current?.dispose(), C?.dispose(), V.current = null;
|
|
2501
2501
|
};
|
|
2502
|
-
}, [gn, s,
|
|
2502
|
+
}, [gn, s, _e, t, o, a, i, Tt, fe]), Se(() => {
|
|
2503
2503
|
const h = { current: !1 }, M = () => {
|
|
2504
|
-
const C = W.current,
|
|
2504
|
+
const C = W.current, O = V.current, N = we(
|
|
2505
2505
|
q.current,
|
|
2506
2506
|
K.current
|
|
2507
2507
|
);
|
|
2508
|
-
if (!C || !
|
|
2508
|
+
if (!C || !O || !c) {
|
|
2509
2509
|
y.current = requestAnimationFrame(M);
|
|
2510
2510
|
return;
|
|
2511
2511
|
}
|
|
2512
2512
|
const te = N.isSpeaking(), ae = te && !$.current, de = $.current && !te;
|
|
2513
|
-
ae && (ie(), ue(), D.current = !1, A.current = !1, me(H.current),
|
|
2513
|
+
ae && (ie(), ue(), D.current = !1, A.current = !1, me(H.current), _.current = 0, B.current = "sil", U.current?.setActive(!1)), de && (j.current.reset(), U.current?.setActive(!1), xe());
|
|
2514
2514
|
const le = N.getPlaybackElapsedMs(), Q = de || D.current || P.current;
|
|
2515
2515
|
if (te) {
|
|
2516
2516
|
X.current && U.current?.setActive(!1);
|
|
2517
|
-
const re = N.getVisemeQueue(),
|
|
2518
|
-
|
|
2517
|
+
const re = N.getVisemeQueue(), ge = re.length > 0 ? lt(re, le) : "sil";
|
|
2518
|
+
ge !== "sil" && (B.current = ge);
|
|
2519
2519
|
const he = us(
|
|
2520
2520
|
le,
|
|
2521
2521
|
N.getSentenceEmotions(),
|
|
@@ -2537,15 +2537,15 @@ const qs = En(function({
|
|
|
2537
2537
|
Ce,
|
|
2538
2538
|
Ze,
|
|
2539
2539
|
H.current,
|
|
2540
|
-
(Pe,
|
|
2540
|
+
(Pe, pn, yn, En) => O.drawLiveFrame(Pe, pn, yn, En),
|
|
2541
2541
|
(Pe) => ee.current?.(Pe),
|
|
2542
2542
|
Qe.current
|
|
2543
2543
|
);
|
|
2544
2544
|
} else if (!Q && X.current && U.current) {
|
|
2545
|
-
const re = U.current,
|
|
2546
|
-
|
|
2545
|
+
const re = U.current, ge = re.getVideo();
|
|
2546
|
+
ge.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), h.current || (h.current = !0, Wt(
|
|
2547
2547
|
C,
|
|
2548
|
-
|
|
2548
|
+
ge,
|
|
2549
2549
|
null,
|
|
2550
2550
|
void 0,
|
|
2551
2551
|
Je.current,
|
|
@@ -2557,7 +2557,7 @@ const qs = En(function({
|
|
|
2557
2557
|
null,
|
|
2558
2558
|
"__sil__",
|
|
2559
2559
|
H.current,
|
|
2560
|
-
(he, Ce, Ze, Pe) =>
|
|
2560
|
+
(he, Ce, Ze, Pe) => O.drawLiveFrame(he, Ce, Ze, Pe),
|
|
2561
2561
|
(he) => ee.current?.(he)
|
|
2562
2562
|
);
|
|
2563
2563
|
} else Q || Kt(
|
|
@@ -2565,7 +2565,7 @@ const qs = En(function({
|
|
|
2565
2565
|
null,
|
|
2566
2566
|
"__sil__",
|
|
2567
2567
|
H.current,
|
|
2568
|
-
(re,
|
|
2568
|
+
(re, ge, he, Ce) => O.drawLiveFrame(re, ge, he, Ce),
|
|
2569
2569
|
(re) => ee.current?.(re)
|
|
2570
2570
|
);
|
|
2571
2571
|
$.current = te, y.current = requestAnimationFrame(M);
|
|
@@ -2575,23 +2575,23 @@ const qs = En(function({
|
|
|
2575
2575
|
};
|
|
2576
2576
|
}, [
|
|
2577
2577
|
c,
|
|
2578
|
-
|
|
2578
|
+
L,
|
|
2579
2579
|
xe,
|
|
2580
2580
|
ie,
|
|
2581
2581
|
ue
|
|
2582
|
-
]),
|
|
2582
|
+
]), vn(
|
|
2583
2583
|
R,
|
|
2584
2584
|
() => ({
|
|
2585
2585
|
speakText: async (h, M) => {
|
|
2586
2586
|
const C = h.trim();
|
|
2587
2587
|
if (!C) return;
|
|
2588
|
-
const
|
|
2589
|
-
if (!
|
|
2588
|
+
const O = V.current;
|
|
2589
|
+
if (!O || !De.current && !c)
|
|
2590
2590
|
throw new Error("AI twin is not ready");
|
|
2591
2591
|
const { ttsEngineId: N, voiceId: te } = St(M);
|
|
2592
2592
|
J(null), T.current += 1, ie(), ue(), D.current = !1, A.current = !1, B.current = "sil", me(H.current), j.current.reset(), $.current = !1;
|
|
2593
2593
|
try {
|
|
2594
|
-
X.current ? (U.current?.setActive(!1), U.current?.restart(), me(H.current)) : await
|
|
2594
|
+
X.current ? (U.current?.setActive(!1), U.current?.restart(), me(H.current)) : await O.renderSilOnly(), await q.current.speak(C, {
|
|
2595
2595
|
voiceId: te,
|
|
2596
2596
|
speakingRate: M?.speakingRate ?? f,
|
|
2597
2597
|
ttsEngineId: N
|
|
@@ -2607,10 +2607,10 @@ const qs = En(function({
|
|
|
2607
2607
|
q.current.setTtsEngineId(h), K.current?.setTtsEngineId(h), Y.current && (Y.current.ttsEngineId = h);
|
|
2608
2608
|
},
|
|
2609
2609
|
renderViseme: async (h, M) => {
|
|
2610
|
-
const C = V.current,
|
|
2611
|
-
if (!C || !
|
|
2610
|
+
const C = V.current, O = W.current;
|
|
2611
|
+
if (!C || !O || !De.current)
|
|
2612
2612
|
throw new Error("AI twin is not ready");
|
|
2613
|
-
await C.renderViseme(
|
|
2613
|
+
await C.renderViseme(O, h, {
|
|
2614
2614
|
from: M?.from,
|
|
2615
2615
|
transitionDurationMs: M?.transitionDurationMs,
|
|
2616
2616
|
gapMs: M?.gapMs,
|
|
@@ -2624,8 +2624,8 @@ const qs = En(function({
|
|
|
2624
2624
|
try {
|
|
2625
2625
|
let M = h.authToken?.trim();
|
|
2626
2626
|
M || (M = G.current ?? i ?? await et(), G.current = M);
|
|
2627
|
-
const C = h.voiceId?.trim() ?? a ?? Y.current?.voiceId,
|
|
2628
|
-
await
|
|
2627
|
+
const C = h.voiceId?.trim() ?? a ?? Y.current?.voiceId, O = vt();
|
|
2628
|
+
await O.unlockAudio(), await O.connect({
|
|
2629
2629
|
...h,
|
|
2630
2630
|
authToken: M,
|
|
2631
2631
|
voiceId: C,
|
|
@@ -2656,45 +2656,53 @@ const qs = En(function({
|
|
|
2656
2656
|
vt,
|
|
2657
2657
|
se
|
|
2658
2658
|
]
|
|
2659
|
-
), /* @__PURE__ */ kn("div", { className: l, style: { ...
|
|
2659
|
+
), /* @__PURE__ */ kn("div", { className: l, style: { ...Ls, ...w }, children: [
|
|
2660
2660
|
/* @__PURE__ */ At(
|
|
2661
2661
|
"canvas",
|
|
2662
2662
|
{
|
|
2663
2663
|
ref: W,
|
|
2664
2664
|
width: ne.width,
|
|
2665
2665
|
height: ne.height,
|
|
2666
|
-
style: { ...
|
|
2666
|
+
style: { ...Os, ...g },
|
|
2667
2667
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
2668
2668
|
}
|
|
2669
2669
|
),
|
|
2670
|
-
p && ce ? /* @__PURE__ */ At("div", { style:
|
|
2670
|
+
p && ce ? /* @__PURE__ */ At("div", { style: Fs, children: ce }) : null
|
|
2671
2671
|
] });
|
|
2672
|
-
});
|
|
2672
|
+
}), Us = "thumbnail.webp";
|
|
2673
|
+
function js(e, t = Jt) {
|
|
2674
|
+
const n = e.trim();
|
|
2675
|
+
if (!n)
|
|
2676
|
+
throw new Error("faceId is required");
|
|
2677
|
+
return `${t.replace(/\/$/, "")}/${n}/${Us}`;
|
|
2678
|
+
}
|
|
2673
2679
|
export {
|
|
2674
|
-
|
|
2680
|
+
Us as AI_TWIN_THUMBNAIL_FILENAME,
|
|
2681
|
+
Ks as AiTwin,
|
|
2675
2682
|
nt as AiTwinNotFoundError,
|
|
2676
2683
|
Te as DEFAULT_TTS_ENGINE_ID,
|
|
2677
|
-
|
|
2684
|
+
rn as MIC_SAMPLE_RATE,
|
|
2678
2685
|
rr as OCULUS_VISEME_IDS,
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2686
|
+
sn as PLAYBACK_SAMPLE_RATE,
|
|
2687
|
+
tn as SPEAKING_RATE_MAX,
|
|
2688
|
+
en as SPEAKING_RATE_MIN,
|
|
2682
2689
|
Ae as TTS_ENGINE_CARTESIA,
|
|
2683
|
-
|
|
2690
|
+
Qt as TTS_ENGINE_GOOGLE,
|
|
2684
2691
|
ut as TTS_ENGINE_INWORLD,
|
|
2685
|
-
|
|
2686
|
-
|
|
2692
|
+
qs as VISEME_IDS,
|
|
2693
|
+
Er as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
2687
2694
|
ft as VISEME_TEST_SPEAKING_RATE,
|
|
2688
|
-
|
|
2695
|
+
nn as VISEME_TEST_VOICE_ID,
|
|
2689
2696
|
Tr as buildVoiceWebSocketUrl,
|
|
2690
2697
|
Pt as createAvatarTtsLipsyncController,
|
|
2691
2698
|
Ir as createRealtimeVoiceLipsyncController,
|
|
2692
2699
|
Dt as faceAssetUrls,
|
|
2693
2700
|
Un as fetchAiTwin,
|
|
2694
2701
|
et as fetchDevAuthToken,
|
|
2702
|
+
js as getAiTwinThumbnailUrl,
|
|
2695
2703
|
ir as normalizeOculusViseme,
|
|
2696
2704
|
zn as resolveDirectFaceId,
|
|
2697
2705
|
lt as resolveVisemeAtTime,
|
|
2698
|
-
|
|
2706
|
+
Ws as resolveWordAtTime,
|
|
2699
2707
|
Yn as setActiveTwinAssets
|
|
2700
2708
|
};
|