@streamoji/aitwin 0.2.0 → 0.2.2
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 +375 -366
- 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.2", 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,30 +610,31 @@ 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
|
-
speakingRate: R
|
|
636
|
+
speakingRate: R,
|
|
637
|
+
tenant: "aiTwin"
|
|
637
638
|
};
|
|
638
639
|
Bn.has(d) && (W.voice_id = I);
|
|
639
640
|
try {
|
|
@@ -651,19 +652,19 @@ function Pt(e, t = be) {
|
|
|
651
652
|
if (!H) throw new Error("No response body");
|
|
652
653
|
const j = H.getReader(), y = new TextDecoder();
|
|
653
654
|
let T = "";
|
|
654
|
-
const
|
|
655
|
+
const _ = async (x) => {
|
|
655
656
|
const b = nr(x);
|
|
656
657
|
if (b) {
|
|
657
658
|
if (b.event === "audio") {
|
|
658
659
|
const D = b.data.chunk, A = b.data.visemes ?? [], P = b.data.words ?? [], B = b.data.is_new_segment ?? !1;
|
|
659
|
-
D ? await
|
|
660
|
+
D ? await g.playAudioChunk(
|
|
660
661
|
r,
|
|
661
662
|
s,
|
|
662
663
|
D,
|
|
663
664
|
A,
|
|
664
665
|
P,
|
|
665
666
|
B
|
|
666
|
-
) : (A.length > 0 || P.length > 0) &&
|
|
667
|
+
) : (A.length > 0 || P.length > 0) && g.queueTimingsOnly(
|
|
667
668
|
r,
|
|
668
669
|
s,
|
|
669
670
|
A,
|
|
@@ -703,9 +704,9 @@ function Pt(e, t = be) {
|
|
|
703
704
|
|
|
704
705
|
`);
|
|
705
706
|
T = D.pop() ?? "";
|
|
706
|
-
for (const A of D) await
|
|
707
|
+
for (const A of D) await _(A);
|
|
707
708
|
if (x) {
|
|
708
|
-
T.trim() && await
|
|
709
|
+
T.trim() && await _(T.trim()), g.markStreamComplete(r);
|
|
709
710
|
break;
|
|
710
711
|
}
|
|
711
712
|
}
|
|
@@ -718,17 +719,17 @@ function Pt(e, t = be) {
|
|
|
718
719
|
getWordQueue: () => s,
|
|
719
720
|
getSentenceEmotions: () => i,
|
|
720
721
|
getStreamMood: () => o,
|
|
721
|
-
getPlaybackElapsedMs: () =>
|
|
722
|
-
isSpeaking: () =>
|
|
723
|
-
setPlaybackSpeed: (
|
|
724
|
-
|
|
722
|
+
getPlaybackElapsedMs: () => g.getPlaybackElapsedMs(),
|
|
723
|
+
isSpeaking: () => g.isSpeaking(),
|
|
724
|
+
setPlaybackSpeed: (k) => {
|
|
725
|
+
g.setPlaybackSpeed(k);
|
|
725
726
|
},
|
|
726
|
-
getPlaybackSpeed: () =>
|
|
727
|
-
subscribe: (
|
|
727
|
+
getPlaybackSpeed: () => g.getPlaybackSpeed(),
|
|
728
|
+
subscribe: (k) => (l.add(k), () => l.delete(k))
|
|
728
729
|
};
|
|
729
730
|
}
|
|
730
|
-
const
|
|
731
|
-
class
|
|
731
|
+
const rn = 16e3, sn = 24e3;
|
|
732
|
+
class kr extends An {
|
|
732
733
|
constructor() {
|
|
733
734
|
super(
|
|
734
735
|
!0,
|
|
@@ -736,8 +737,8 @@ class Er extends Tn {
|
|
|
736
737
|
void 0,
|
|
737
738
|
void 0,
|
|
738
739
|
512,
|
|
739
|
-
|
|
740
|
-
|
|
740
|
+
rn,
|
|
741
|
+
sn
|
|
741
742
|
);
|
|
742
743
|
}
|
|
743
744
|
/** Pipecat protobuf bot audio is unused — playback comes from avatar_audio_chunk. */
|
|
@@ -766,7 +767,7 @@ function Tr(e) {
|
|
|
766
767
|
const i = e.speakingRate ?? ft;
|
|
767
768
|
return r.searchParams.set(
|
|
768
769
|
"speaking_rate",
|
|
769
|
-
String(Math.max(
|
|
770
|
+
String(Math.max(en, Math.min(tn, i)))
|
|
770
771
|
), e.ttsStream === !1 ? r.searchParams.set("tts_stream", "false") : r.searchParams.set("tts_stream", "true"), r.toString();
|
|
771
772
|
}
|
|
772
773
|
function Bt(e, t) {
|
|
@@ -790,14 +791,14 @@ function Ar(e) {
|
|
|
790
791
|
}
|
|
791
792
|
function Ir(e, t = {}) {
|
|
792
793
|
const n = [], r = [], s = [], i = [];
|
|
793
|
-
let o = "", a = "neutral", f = Ae, l = !1, w = null,
|
|
794
|
+
let o = "", a = "neutral", f = Ae, l = !1, w = null, g = null, m = { ...t }, S = 0, k = null;
|
|
794
795
|
const u = /* @__PURE__ */ new Set(), p = [];
|
|
795
796
|
let d = !1, I = null;
|
|
796
|
-
const
|
|
797
|
+
const E = () => u.forEach((c) => c()), R = Zt(
|
|
797
798
|
{
|
|
798
799
|
onSpeakingStart: () => e("speaking"),
|
|
799
800
|
onSpeakingDone: () => e("done"),
|
|
800
|
-
onNotify:
|
|
801
|
+
onNotify: E
|
|
801
802
|
},
|
|
802
803
|
f
|
|
803
804
|
), W = () => {
|
|
@@ -811,32 +812,32 @@ function Ir(e, t = {}) {
|
|
|
811
812
|
p.push(c), !d && (d = !0, W().port2.postMessage(null));
|
|
812
813
|
}, H = () => R.getPlaybackElapsedMs(), j = (c, v = o) => {
|
|
813
814
|
if (!m.onLipsyncDebug) return;
|
|
814
|
-
const
|
|
815
|
+
const L = H(), z = n;
|
|
815
816
|
m.onLipsyncDebug({
|
|
816
817
|
event: c,
|
|
817
818
|
spokenText: v,
|
|
818
819
|
mood: a,
|
|
819
820
|
playbackAnchorPerf: R.getPlaybackStartPerf(),
|
|
820
|
-
playbackElapsedMs:
|
|
821
|
+
playbackElapsedMs: L,
|
|
821
822
|
queueLength: z.length,
|
|
822
|
-
activeViseme: lt(z,
|
|
823
|
+
activeViseme: lt(z, L),
|
|
823
824
|
segments: i.map((ne) => ({
|
|
824
825
|
...ne,
|
|
825
826
|
visemes: [...ne.visemes]
|
|
826
827
|
}))
|
|
827
828
|
});
|
|
828
829
|
}, y = (c, v) => {
|
|
829
|
-
m.onLipsyncDebug && (
|
|
830
|
+
m.onLipsyncDebug && (k = { event: c, spokenText: v }, S === 0 && (S = requestAnimationFrame(() => {
|
|
830
831
|
S = 0;
|
|
831
|
-
const
|
|
832
|
-
|
|
832
|
+
const L = k;
|
|
833
|
+
k = null, L && j(L.event, L.spokenText);
|
|
833
834
|
})));
|
|
834
835
|
}, T = () => {
|
|
835
836
|
n.length = 0, r.length = 0, i.length = 0, o = "", a = "neutral", s.length = 0;
|
|
836
|
-
},
|
|
837
|
-
R.stop(), T(), y("reset"),
|
|
837
|
+
}, _ = () => {
|
|
838
|
+
R.stop(), T(), y("reset"), E();
|
|
838
839
|
}, x = () => {
|
|
839
|
-
|
|
840
|
+
_(), e("idle"), E();
|
|
840
841
|
}, b = (c, v) => {
|
|
841
842
|
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
843
|
...Bt(c.sentence_emotions, a)
|
|
@@ -845,10 +846,10 @@ function Ir(e, t = {}) {
|
|
|
845
846
|
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
846
847
|
v && (o = v), R.resetForNewStream(f), typeof c.mood == "string" && c.mood.trim() && (a = c.mood.trim()), s.length = 0, s.push(
|
|
847
848
|
...Bt(c.sentence_emotions, a)
|
|
848
|
-
), Array.isArray(c.gestures) && c.gestures, y("metadata", v),
|
|
849
|
-
}, A = (c, v,
|
|
849
|
+
), Array.isArray(c.gestures) && c.gestures, y("metadata", v), E();
|
|
850
|
+
}, A = (c, v, L, z) => {
|
|
850
851
|
if (!m.onLipsyncDebug) return;
|
|
851
|
-
const ne = n.slice(
|
|
852
|
+
const ne = n.slice(L), Re = z.filter(
|
|
852
853
|
(G) => String(G.symbol ?? G.viseme ?? "").trim()
|
|
853
854
|
);
|
|
854
855
|
i.push({
|
|
@@ -857,8 +858,8 @@ function Ir(e, t = {}) {
|
|
|
857
858
|
isNewSegment: !!c.is_new_segment,
|
|
858
859
|
chunkDurationMs: c.chunk_duration_ms != null ? Number(c.chunk_duration_ms) : null,
|
|
859
860
|
receivedAtMs: performance.now(),
|
|
860
|
-
visemes: ne.map((G,
|
|
861
|
-
const Y = Re[
|
|
861
|
+
visemes: ne.map((G, ke) => {
|
|
862
|
+
const Y = Re[ke];
|
|
862
863
|
return {
|
|
863
864
|
rawSymbol: String(Y?.symbol ?? Y?.viseme ?? G.viseme).trim(),
|
|
864
865
|
viseme: G.viseme,
|
|
@@ -870,8 +871,8 @@ function Ir(e, t = {}) {
|
|
|
870
871
|
})
|
|
871
872
|
});
|
|
872
873
|
}, P = (c) => {
|
|
873
|
-
const v = String(c.spoken_text ?? c.text ?? "").trim(),
|
|
874
|
-
v && (o = v), b(c,
|
|
874
|
+
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();
|
|
875
|
+
v && (o = v), b(c, L), L && R.resetForNewStream(f);
|
|
875
876
|
const G = n.length;
|
|
876
877
|
R.playAudioChunk(
|
|
877
878
|
n,
|
|
@@ -879,7 +880,7 @@ function Ir(e, t = {}) {
|
|
|
879
880
|
Re,
|
|
880
881
|
z,
|
|
881
882
|
ne,
|
|
882
|
-
|
|
883
|
+
L,
|
|
883
884
|
() => {
|
|
884
885
|
i.length = 0;
|
|
885
886
|
}
|
|
@@ -892,7 +893,7 @@ function Ir(e, t = {}) {
|
|
|
892
893
|
);
|
|
893
894
|
const v = String(c.spoken_text ?? c.text ?? "").trim();
|
|
894
895
|
v && (o = v), b(c, !!c.is_new_segment);
|
|
895
|
-
const
|
|
896
|
+
const L = n.length;
|
|
896
897
|
R.queueTimingsOnly(
|
|
897
898
|
n,
|
|
898
899
|
r,
|
|
@@ -902,17 +903,17 @@ function Ir(e, t = {}) {
|
|
|
902
903
|
), A(
|
|
903
904
|
c,
|
|
904
905
|
v,
|
|
905
|
-
|
|
906
|
+
L,
|
|
906
907
|
c.visemes ?? []
|
|
907
|
-
), y("lipsync", v),
|
|
908
|
+
), y("lipsync", v), E();
|
|
908
909
|
}, $ = (c) => {
|
|
909
910
|
const v = Ar(c);
|
|
910
911
|
if (!v) {
|
|
911
912
|
console.warn("[realtimeVoice] server message with no payload", c);
|
|
912
913
|
return;
|
|
913
914
|
}
|
|
914
|
-
const
|
|
915
|
-
switch (
|
|
915
|
+
const L = String(v.type ?? "unknown");
|
|
916
|
+
switch (L !== "avatar_metadata" && L !== "avatar_audio_chunk" && L !== "avatar_lipsync" && L !== "error" && console.debug("[realtimeVoice] server message", L, v), L) {
|
|
916
917
|
case "avatar_metadata":
|
|
917
918
|
D(v);
|
|
918
919
|
break;
|
|
@@ -924,7 +925,7 @@ function Ir(e, t = {}) {
|
|
|
924
925
|
break;
|
|
925
926
|
case "error": {
|
|
926
927
|
const z = String(v.message ?? "Voice session error");
|
|
927
|
-
console.error("[realtimeVoice] server error:", z), e("error"),
|
|
928
|
+
console.error("[realtimeVoice] server error:", z), e("error"), E();
|
|
928
929
|
break;
|
|
929
930
|
}
|
|
930
931
|
case "avatar_speak":
|
|
@@ -934,33 +935,33 @@ function Ir(e, t = {}) {
|
|
|
934
935
|
);
|
|
935
936
|
break;
|
|
936
937
|
}
|
|
937
|
-
}, U = () => w || (
|
|
938
|
-
transport: new
|
|
939
|
-
mediaManager:
|
|
940
|
-
recorderSampleRate:
|
|
941
|
-
playerSampleRate:
|
|
938
|
+
}, U = () => w || (g = new kr(), w = new bn({
|
|
939
|
+
transport: new Tn({
|
|
940
|
+
mediaManager: g,
|
|
941
|
+
recorderSampleRate: rn,
|
|
942
|
+
playerSampleRate: sn
|
|
942
943
|
}),
|
|
943
944
|
enableCam: !1,
|
|
944
945
|
enableMic: !0,
|
|
945
946
|
callbacks: {
|
|
946
947
|
onBotReady: () => {
|
|
947
|
-
l = !0, e("idle"),
|
|
948
|
+
l = !0, e("idle"), E();
|
|
948
949
|
},
|
|
949
950
|
onDisconnected: () => {
|
|
950
951
|
l = !1, x();
|
|
951
952
|
},
|
|
952
953
|
onError: (c) => {
|
|
953
954
|
const v = typeof c == "object" && c !== null && "data" in c ? String(c.data ?? c) : String(c);
|
|
954
|
-
console.error("[realtimeVoice]", v, c), e("error"),
|
|
955
|
+
console.error("[realtimeVoice]", v, c), e("error"), E();
|
|
955
956
|
},
|
|
956
957
|
onTransportStateChanged: (c) => {
|
|
957
|
-
c === "error" && (e("error"),
|
|
958
|
+
c === "error" && (e("error"), E());
|
|
958
959
|
},
|
|
959
960
|
onServerMessage: (c) => {
|
|
960
961
|
V(c);
|
|
961
962
|
},
|
|
962
963
|
onUserStartedSpeaking: () => {
|
|
963
|
-
R.bargeIn(), T(), e("idle"), y("user_started"),
|
|
964
|
+
R.bargeIn(), T(), e("idle"), y("user_started"), E();
|
|
964
965
|
},
|
|
965
966
|
onBotStartedSpeaking: () => {
|
|
966
967
|
y("bot_started");
|
|
@@ -984,17 +985,17 @@ function Ir(e, t = {}) {
|
|
|
984
985
|
},
|
|
985
986
|
getTtsEngineId: () => f,
|
|
986
987
|
speak: async (c, v) => {
|
|
987
|
-
const
|
|
988
|
-
if (
|
|
988
|
+
const L = c.trim();
|
|
989
|
+
if (L) {
|
|
989
990
|
if (!w || !l)
|
|
990
991
|
throw new Error(
|
|
991
992
|
"Realtime voice is not connected. Call connect() first."
|
|
992
993
|
);
|
|
993
|
-
|
|
994
|
+
_(), await w.sendText(L);
|
|
994
995
|
}
|
|
995
996
|
},
|
|
996
997
|
stop: () => {
|
|
997
|
-
|
|
998
|
+
_(), e("idle"), E();
|
|
998
999
|
},
|
|
999
1000
|
connect: async (c) => {
|
|
1000
1001
|
if (c && (m = { ...m, ...c }), !m.authToken?.trim())
|
|
@@ -1004,16 +1005,16 @@ function Ir(e, t = {}) {
|
|
|
1004
1005
|
e("loading");
|
|
1005
1006
|
const v = U();
|
|
1006
1007
|
await v.initDevices();
|
|
1007
|
-
const
|
|
1008
|
-
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):",
|
|
1008
|
+
const L = Tr(m);
|
|
1009
|
+
console.info("[realtimeVoice] connecting (avatar_audio_chunk RTVI):", L);
|
|
1009
1010
|
try {
|
|
1010
|
-
await v.connect({ wsUrl:
|
|
1011
|
+
await v.connect({ wsUrl: L });
|
|
1011
1012
|
} catch (z) {
|
|
1012
|
-
l = !1, e("error"),
|
|
1013
|
+
l = !1, e("error"), E();
|
|
1013
1014
|
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} — ${
|
|
1015
|
+
throw new Error(`${ne} — ${L}`);
|
|
1015
1016
|
}
|
|
1016
|
-
l = !0, e("idle"),
|
|
1017
|
+
l = !0, e("idle"), E();
|
|
1017
1018
|
},
|
|
1018
1019
|
disconnect: async () => {
|
|
1019
1020
|
if (p.length = 0, d = !1, w)
|
|
@@ -1096,7 +1097,7 @@ function Br(e) {
|
|
|
1096
1097
|
const t = new Blob([e], { type: "video/mp4" });
|
|
1097
1098
|
return URL.createObjectURL(t);
|
|
1098
1099
|
}
|
|
1099
|
-
async function
|
|
1100
|
+
async function Lr(e) {
|
|
1100
1101
|
const t = Xn();
|
|
1101
1102
|
if (!Ge()) return t;
|
|
1102
1103
|
if (!e) throw new Error("Missing asset key for encrypted idle video");
|
|
@@ -1106,14 +1107,14 @@ async function Or(e) {
|
|
|
1106
1107
|
function dt(e, t) {
|
|
1107
1108
|
return `${e}/${t}_minus_sil.png`;
|
|
1108
1109
|
}
|
|
1109
|
-
const
|
|
1110
|
-
function
|
|
1110
|
+
const on = 5;
|
|
1111
|
+
function an(e) {
|
|
1111
1112
|
const t = e?.composite_threshold;
|
|
1112
1113
|
if (typeof t == "number" && t > 0) return t;
|
|
1113
1114
|
const n = e?.crop?.content_threshold;
|
|
1114
|
-
return typeof n == "number" && n > 0 ? n :
|
|
1115
|
+
return typeof n == "number" && n > 0 ? n : on;
|
|
1115
1116
|
}
|
|
1116
|
-
const
|
|
1117
|
+
const qs = [
|
|
1117
1118
|
"aa",
|
|
1118
1119
|
"E",
|
|
1119
1120
|
"I",
|
|
@@ -1134,7 +1135,7 @@ const Ws = [
|
|
|
1134
1135
|
"t03_0.50",
|
|
1135
1136
|
"t04_0.67",
|
|
1136
1137
|
"t05_0.83"
|
|
1137
|
-
],
|
|
1138
|
+
], Or = it.length, Lt = /* @__PURE__ */ new Set([
|
|
1138
1139
|
"aa__kk",
|
|
1139
1140
|
"aa__nn",
|
|
1140
1141
|
"aa__sil",
|
|
@@ -1241,16 +1242,16 @@ const Ws = [
|
|
|
1241
1242
|
"U__nn",
|
|
1242
1243
|
"U__sil"
|
|
1243
1244
|
]);
|
|
1244
|
-
function
|
|
1245
|
+
function Ot(e, t) {
|
|
1245
1246
|
return `${e}__${t}`;
|
|
1246
1247
|
}
|
|
1247
|
-
function
|
|
1248
|
+
function Ft(e, t) {
|
|
1248
1249
|
return `pairs/${e}/${t}_minus_sil.png`;
|
|
1249
1250
|
}
|
|
1250
1251
|
function Ke(e) {
|
|
1251
1252
|
return `${e}_minus_sil.png`;
|
|
1252
1253
|
}
|
|
1253
|
-
function
|
|
1254
|
+
function Fr(e, t) {
|
|
1254
1255
|
if (t.has(e)) return e;
|
|
1255
1256
|
const n = /^pairs\/([^/]+)\//.exec(e);
|
|
1256
1257
|
if (!n) return null;
|
|
@@ -1259,25 +1260,25 @@ function Lr(e, t) {
|
|
|
1259
1260
|
const s = Ke(r);
|
|
1260
1261
|
return t.has(s) ? s : null;
|
|
1261
1262
|
}
|
|
1262
|
-
function
|
|
1263
|
+
function cn(e, t) {
|
|
1263
1264
|
return e.filter((n) => t.has(n));
|
|
1264
1265
|
}
|
|
1265
1266
|
function Ur(e, t, n) {
|
|
1266
1267
|
const r = ht(e, t);
|
|
1267
|
-
return
|
|
1268
|
+
return cn(r, n).length > 0;
|
|
1268
1269
|
}
|
|
1269
1270
|
function ht(e, t) {
|
|
1270
1271
|
if (e === t) return [];
|
|
1271
|
-
const n = [], r =
|
|
1272
|
-
if (
|
|
1272
|
+
const n = [], r = Ot(e, t);
|
|
1273
|
+
if (Lt.has(r)) {
|
|
1273
1274
|
for (const i of it)
|
|
1274
|
-
n.push(
|
|
1275
|
+
n.push(Ft(r, i));
|
|
1275
1276
|
return n;
|
|
1276
1277
|
}
|
|
1277
|
-
const s =
|
|
1278
|
-
if (
|
|
1279
|
-
for (let i =
|
|
1280
|
-
n.push(
|
|
1278
|
+
const s = Ot(t, e);
|
|
1279
|
+
if (Lt.has(s)) {
|
|
1280
|
+
for (let i = Or - 1; i >= 0; i--)
|
|
1281
|
+
n.push(Ft(s, it[i]));
|
|
1281
1282
|
return n;
|
|
1282
1283
|
}
|
|
1283
1284
|
return [];
|
|
@@ -1362,15 +1363,15 @@ function ve(e, t = "neutral") {
|
|
|
1362
1363
|
const n = String(e ?? "").trim().toLowerCase();
|
|
1363
1364
|
return n ? Jr[n] ?? t : t;
|
|
1364
1365
|
}
|
|
1365
|
-
function
|
|
1366
|
+
function un(e) {
|
|
1366
1367
|
return e === 0 ? null : dt(mt(e), "eyes_standard");
|
|
1367
1368
|
}
|
|
1368
|
-
function
|
|
1369
|
-
return
|
|
1369
|
+
function ln(e) {
|
|
1370
|
+
return un(wt(e));
|
|
1370
1371
|
}
|
|
1371
1372
|
function Nt(e, t) {
|
|
1372
1373
|
const n = mt(wt(e));
|
|
1373
|
-
return !t || t === "eyes_standard" ?
|
|
1374
|
+
return !t || t === "eyes_standard" ? ln(e) : e === "neutral" && t === "eyes_standard" ? null : dt(n, t);
|
|
1374
1375
|
}
|
|
1375
1376
|
function Qr(e, t) {
|
|
1376
1377
|
const n = [];
|
|
@@ -1378,7 +1379,7 @@ function Qr(e, t) {
|
|
|
1378
1379
|
n.push(Nt(e, r));
|
|
1379
1380
|
for (let r = t.length - 2; r >= 0; r--)
|
|
1380
1381
|
n.push(Nt(e, t[r]));
|
|
1381
|
-
return n.push(
|
|
1382
|
+
return n.push(ln(e)), n;
|
|
1382
1383
|
}
|
|
1383
1384
|
function Xr(e) {
|
|
1384
1385
|
return dt(mt(e), "eyes_standard");
|
|
@@ -1408,11 +1409,11 @@ function Vt(e) {
|
|
|
1408
1409
|
const n = Number.parseInt(t[1], 10);
|
|
1409
1410
|
return Number.isFinite(n) ? ye(n) : null;
|
|
1410
1411
|
}
|
|
1411
|
-
function
|
|
1412
|
+
function Oe(e, t) {
|
|
1412
1413
|
return e + Math.random() * (t - e);
|
|
1413
1414
|
}
|
|
1414
1415
|
function We() {
|
|
1415
|
-
return
|
|
1416
|
+
return Oe(14, 32);
|
|
1416
1417
|
}
|
|
1417
1418
|
function ss(e = {}) {
|
|
1418
1419
|
const {
|
|
@@ -1426,25 +1427,25 @@ function ss(e = {}) {
|
|
|
1426
1427
|
postEmotionChangeDelayMs: f = 380,
|
|
1427
1428
|
minDwellMs: l = 550
|
|
1428
1429
|
} = e;
|
|
1429
|
-
let w = "neutral",
|
|
1430
|
+
let w = "neutral", g = "neutral", m = 0, S = 0, k = 0, u = {
|
|
1430
1431
|
kind: "idle",
|
|
1431
1432
|
nextBlinkAt: performance.now() + t
|
|
1432
1433
|
}, p = null, d = "__eyes_open__|neutral|brow:0";
|
|
1433
1434
|
function I(y = w) {
|
|
1434
1435
|
d = `${p ?? "__eyes_open__"}|${y}|brow:${S}`;
|
|
1435
1436
|
}
|
|
1436
|
-
function
|
|
1437
|
+
function E(y, T = w) {
|
|
1437
1438
|
p = y;
|
|
1438
|
-
const
|
|
1439
|
-
|
|
1439
|
+
const _ = Vt(y);
|
|
1440
|
+
_ != null ? S = _ : y == null && (S = 0), I(T);
|
|
1440
1441
|
}
|
|
1441
1442
|
function R(y) {
|
|
1442
|
-
return
|
|
1443
|
+
return un(y);
|
|
1443
1444
|
}
|
|
1444
|
-
function W(y, T,
|
|
1445
|
-
const x = ye(T), b = ye(
|
|
1445
|
+
function W(y, T, _) {
|
|
1446
|
+
const x = ye(T), b = ye(_);
|
|
1446
1447
|
if (m = b, x === b) {
|
|
1447
|
-
|
|
1448
|
+
E(R(b));
|
|
1448
1449
|
return;
|
|
1449
1450
|
}
|
|
1450
1451
|
const D = [
|
|
@@ -1457,16 +1458,16 @@ function ss(e = {}) {
|
|
|
1457
1458
|
index: 0,
|
|
1458
1459
|
holdUntil: y + We(),
|
|
1459
1460
|
targetBrow: b
|
|
1460
|
-
},
|
|
1461
|
+
}, E(D[0] ?? null);
|
|
1461
1462
|
}
|
|
1462
1463
|
function V(y, T) {
|
|
1463
1464
|
u = {
|
|
1464
1465
|
kind: "idle",
|
|
1465
|
-
nextBlinkAt: y +
|
|
1466
|
-
},
|
|
1466
|
+
nextBlinkAt: y + Oe(n, r)
|
|
1467
|
+
}, g = T, E(R(m), T);
|
|
1467
1468
|
}
|
|
1468
|
-
function H(y, T,
|
|
1469
|
-
const x =
|
|
1469
|
+
function H(y, T, _) {
|
|
1470
|
+
const x = _ ? Kr : Math.random() < a ? qr : jr;
|
|
1470
1471
|
u = {
|
|
1471
1472
|
kind: "playing",
|
|
1472
1473
|
paths: Qr(T, x),
|
|
@@ -1474,31 +1475,31 @@ function ss(e = {}) {
|
|
|
1474
1475
|
holdUntil: y + We(),
|
|
1475
1476
|
after: "idle",
|
|
1476
1477
|
blinkEmotion: T
|
|
1477
|
-
},
|
|
1478
|
+
}, g = T, E(u.paths[0] ?? null, T);
|
|
1478
1479
|
}
|
|
1479
1480
|
function j(y) {
|
|
1480
1481
|
if (u.kind === "browBlend") {
|
|
1481
1482
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1482
1483
|
u.index += 1, u.holdUntil = y + We();
|
|
1483
1484
|
const T = u.paths[u.index] ?? null;
|
|
1484
|
-
|
|
1485
|
+
E(T), y >= u.holdUntil && u.index >= u.paths.length - 1 && (S = u.targetBrow, m = u.targetBrow, E(R(u.targetBrow)), u = {
|
|
1485
1486
|
kind: "idle",
|
|
1486
1487
|
nextBlinkAt: y + f
|
|
1487
1488
|
});
|
|
1488
1489
|
return;
|
|
1489
1490
|
}
|
|
1490
1491
|
if (u.kind === "idle") {
|
|
1491
|
-
|
|
1492
|
+
E(R(m), g), y >= u.nextBlinkAt && H(y, g, !1);
|
|
1492
1493
|
return;
|
|
1493
1494
|
}
|
|
1494
1495
|
if (u.kind === "doublePause") {
|
|
1495
|
-
|
|
1496
|
+
E(R(m), u.blinkEmotion), y >= u.resumeAt && H(y, u.blinkEmotion, !0);
|
|
1496
1497
|
return;
|
|
1497
1498
|
}
|
|
1498
1499
|
if (u.kind === "playing") {
|
|
1499
1500
|
for (; y >= u.holdUntil && u.index < u.paths.length - 1; )
|
|
1500
1501
|
u.index += 1, u.holdUntil = y + We();
|
|
1501
|
-
if (
|
|
1502
|
+
if (E(u.paths[u.index] ?? null, u.blinkEmotion), y >= u.holdUntil && u.index >= u.paths.length - 1) {
|
|
1502
1503
|
if (u.after === "resumeIdle") {
|
|
1503
1504
|
V(y + f, w);
|
|
1504
1505
|
return;
|
|
@@ -1506,17 +1507,17 @@ function ss(e = {}) {
|
|
|
1506
1507
|
if (u.after === "doublePause") {
|
|
1507
1508
|
u = {
|
|
1508
1509
|
kind: "doublePause",
|
|
1509
|
-
resumeAt: y +
|
|
1510
|
+
resumeAt: y + Oe(i, o),
|
|
1510
1511
|
blinkEmotion: u.blinkEmotion
|
|
1511
|
-
},
|
|
1512
|
+
}, E(R(m), u.blinkEmotion);
|
|
1512
1513
|
return;
|
|
1513
1514
|
}
|
|
1514
1515
|
if (u.after === "idle" && Math.random() < s) {
|
|
1515
1516
|
u = {
|
|
1516
1517
|
kind: "doublePause",
|
|
1517
|
-
resumeAt: y +
|
|
1518
|
+
resumeAt: y + Oe(i, o),
|
|
1518
1519
|
blinkEmotion: u.blinkEmotion
|
|
1519
|
-
},
|
|
1520
|
+
}, E(R(m), u.blinkEmotion);
|
|
1520
1521
|
return;
|
|
1521
1522
|
}
|
|
1522
1523
|
V(y, u.blinkEmotion);
|
|
@@ -1528,22 +1529,22 @@ function ss(e = {}) {
|
|
|
1528
1529
|
setTargetEmotion(y) {
|
|
1529
1530
|
const T = ve(y, w);
|
|
1530
1531
|
if (T === w) return;
|
|
1531
|
-
const
|
|
1532
|
-
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") &&
|
|
1532
|
+
const _ = performance.now();
|
|
1533
|
+
l > 0 && T !== w && !(w === "neutral" && T !== "neutral") && _ - k < l || (w = T, g = T, k = _);
|
|
1533
1534
|
},
|
|
1534
1535
|
setTargetEyebrow(y) {
|
|
1535
1536
|
const T = ye(y);
|
|
1536
1537
|
if (T === m && u.kind !== "browBlend") return;
|
|
1537
|
-
const
|
|
1538
|
-
m = T, !(T === x && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || W(
|
|
1538
|
+
const _ = performance.now(), x = u.kind === "browBlend" ? Vt(p) ?? S : S;
|
|
1539
|
+
m = T, !(T === x && u.kind !== "browBlend") && (u.kind === "playing" || u.kind === "doublePause" || W(_, x, T));
|
|
1539
1540
|
},
|
|
1540
1541
|
getTargetEmotion: () => w,
|
|
1541
1542
|
getTargetEyebrow: () => m,
|
|
1542
1543
|
getExpressionPath: () => p,
|
|
1543
1544
|
getDrawKey: () => d,
|
|
1544
1545
|
reset() {
|
|
1545
|
-
w = "neutral",
|
|
1546
|
-
performance.now() +
|
|
1546
|
+
w = "neutral", g = "neutral", m = 0, S = 0, k = 0, V(
|
|
1547
|
+
performance.now() + Oe(n, r),
|
|
1547
1548
|
"neutral"
|
|
1548
1549
|
);
|
|
1549
1550
|
}
|
|
@@ -1592,7 +1593,7 @@ function is() {
|
|
|
1592
1593
|
}
|
|
1593
1594
|
};
|
|
1594
1595
|
}
|
|
1595
|
-
const os = 50,
|
|
1596
|
+
const os = 50, fn = 400;
|
|
1596
1597
|
function as(e, t, n) {
|
|
1597
1598
|
return e.filter((r) => {
|
|
1598
1599
|
const s = r.queueIndex ?? -1;
|
|
@@ -1612,7 +1613,7 @@ function cs(e, t) {
|
|
|
1612
1613
|
n.push({
|
|
1613
1614
|
sentence: r,
|
|
1614
1615
|
startMs: Math.max(0, i.wtime - os),
|
|
1615
|
-
endMs: o.wtime + o.wduration +
|
|
1616
|
+
endMs: o.wtime + o.wduration + fn
|
|
1616
1617
|
});
|
|
1617
1618
|
}
|
|
1618
1619
|
return n.sort((r, s) => r.startMs - s.startMs);
|
|
@@ -1629,37 +1630,37 @@ function us(e, t, n, r = "neutral") {
|
|
|
1629
1630
|
if (o)
|
|
1630
1631
|
return ve(o.sentence.emotion, s);
|
|
1631
1632
|
const a = n[n.length - 1], f = a.wtime + a.wduration;
|
|
1632
|
-
return e > f +
|
|
1633
|
+
return e > f + fn ? ve(
|
|
1633
1634
|
t[t.length - 1]?.emotion,
|
|
1634
1635
|
s
|
|
1635
1636
|
) : s;
|
|
1636
1637
|
}
|
|
1637
|
-
function
|
|
1638
|
+
function dn(e, t, n, r, s = on) {
|
|
1638
1639
|
const i = new OffscreenCanvas(n, r), o = i.getContext("2d", { willReadFrequently: !0 });
|
|
1639
1640
|
o.drawImage(e, 0, 0, n, r);
|
|
1640
1641
|
const a = o.getImageData(0, 0, n, r), f = o.createImageData(n, r);
|
|
1641
1642
|
f.data.set(a.data);
|
|
1642
1643
|
const w = new OffscreenCanvas(n, r).getContext("2d", { willReadFrequently: !0 });
|
|
1643
|
-
for (const
|
|
1644
|
-
w.clearRect(0, 0, n, r), w.drawImage(
|
|
1644
|
+
for (const g of t) {
|
|
1645
|
+
w.clearRect(0, 0, n, r), w.drawImage(g, 0, 0, n, r);
|
|
1645
1646
|
const m = w.getImageData(0, 0, n, r);
|
|
1646
1647
|
for (let S = 0; S < f.data.length; S += 4) {
|
|
1647
|
-
const
|
|
1648
|
-
Math.max(
|
|
1648
|
+
const k = m.data[S], u = m.data[S + 1], p = m.data[S + 2];
|
|
1649
|
+
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
1650
|
}
|
|
1650
1651
|
}
|
|
1651
1652
|
return o.putImageData(f, 0, 0), i;
|
|
1652
1653
|
}
|
|
1653
|
-
let pe = null,
|
|
1654
|
+
let pe = null, Fe = null;
|
|
1654
1655
|
const je = /* @__PURE__ */ new Map();
|
|
1655
1656
|
function ls() {
|
|
1656
|
-
pe = null,
|
|
1657
|
+
pe = null, Fe = null, je.clear();
|
|
1657
1658
|
}
|
|
1658
1659
|
Qn(ls);
|
|
1659
1660
|
function fs(e) {
|
|
1660
|
-
return e ??
|
|
1661
|
+
return e ?? Fe ?? void 0;
|
|
1661
1662
|
}
|
|
1662
|
-
function
|
|
1663
|
+
function _t(e) {
|
|
1663
1664
|
return new Promise((t, n) => {
|
|
1664
1665
|
const r = new Image();
|
|
1665
1666
|
r.decoding = "async", r.onload = () => t(r), r.onerror = () => n(new Error(`Failed to load image: ${e}`)), r.src = e;
|
|
@@ -1668,7 +1669,7 @@ function gt(e) {
|
|
|
1668
1669
|
async function ds(e) {
|
|
1669
1670
|
return Ge() ? Pr(
|
|
1670
1671
|
await Ye(Mt(), e ?? "")
|
|
1671
|
-
) :
|
|
1672
|
+
) : _t(Mt());
|
|
1672
1673
|
}
|
|
1673
1674
|
async function $t(e, t, n, r) {
|
|
1674
1675
|
const s = n ? await xr(e, r) : await fetch(e).then((l) => {
|
|
@@ -1681,7 +1682,7 @@ async function $t(e, t, n, r) {
|
|
|
1681
1682
|
Hr(t, i.path, n),
|
|
1682
1683
|
r ?? ""
|
|
1683
1684
|
)
|
|
1684
|
-
) : await
|
|
1685
|
+
) : await _t(`${t}/${i.path}`), a = /* @__PURE__ */ new Map();
|
|
1685
1686
|
for (const l of s.cells ?? [])
|
|
1686
1687
|
l.path && a.set(l.path, l);
|
|
1687
1688
|
const f = /* @__PURE__ */ new Map();
|
|
@@ -1693,14 +1694,14 @@ async function at(e) {
|
|
|
1693
1694
|
const t = fs(e), n = Ge();
|
|
1694
1695
|
if (n && !t)
|
|
1695
1696
|
throw new Error("Encrypted assets enabled but no key provided");
|
|
1696
|
-
if (pe && (!n ||
|
|
1697
|
+
if (pe && (!n || Fe === (t ?? null))) {
|
|
1697
1698
|
const i = await pe;
|
|
1698
1699
|
return {
|
|
1699
1700
|
...Ue(i),
|
|
1700
1701
|
visemePaths: [...i.viseme.cellByPath.keys()]
|
|
1701
1702
|
};
|
|
1702
1703
|
}
|
|
1703
|
-
|
|
1704
|
+
Fe = t ?? null, je.clear();
|
|
1704
1705
|
const r = Zn();
|
|
1705
1706
|
pe = (async () => {
|
|
1706
1707
|
const i = await ds(t), o = await $t(
|
|
@@ -1725,7 +1726,7 @@ async function at(e) {
|
|
|
1725
1726
|
const s = await pe;
|
|
1726
1727
|
return { ...Ue(s), visemePaths: [...s.viseme.cellByPath.keys()] };
|
|
1727
1728
|
}
|
|
1728
|
-
async function
|
|
1729
|
+
async function hn(e) {
|
|
1729
1730
|
if (await at(e), !pe) throw new Error("Assets not loaded");
|
|
1730
1731
|
return pe;
|
|
1731
1732
|
}
|
|
@@ -1748,12 +1749,12 @@ async function Ht(e, t, n) {
|
|
|
1748
1749
|
if (!o) throw new Error(`No atlas cell for path: ${n}`);
|
|
1749
1750
|
const a = Dr(t.atlasMeta, o), f = Ue(e);
|
|
1750
1751
|
if (Mr(o)) {
|
|
1751
|
-
const
|
|
1752
|
+
const g = hs(t, o), m = document.createElement("canvas");
|
|
1752
1753
|
m.width = f.width, m.height = f.height;
|
|
1753
1754
|
const S = m.getContext("2d");
|
|
1754
|
-
return S.fillStyle = "#000", S.fillRect(0, 0, f.width, f.height), S.drawImage(
|
|
1755
|
+
return S.fillStyle = "#000", S.fillRect(0, 0, f.width, f.height), S.drawImage(g, a.x, a.y), m;
|
|
1755
1756
|
}
|
|
1756
|
-
const l = `${t.diffBase}/${n}`, w = await
|
|
1757
|
+
const l = `${t.diffBase}/${n}`, w = await _t(l);
|
|
1757
1758
|
if (w.naturalWidth === f.width && w.naturalHeight === f.height)
|
|
1758
1759
|
return w;
|
|
1759
1760
|
throw new Error(`Diff PNG wrong size for ${n}`);
|
|
@@ -1762,40 +1763,40 @@ async function Ht(e, t, n) {
|
|
|
1762
1763
|
}
|
|
1763
1764
|
async function Wt(e, t, n, r, s, i) {
|
|
1764
1765
|
if (s) {
|
|
1765
|
-
const { width: S, height:
|
|
1766
|
+
const { width: S, height: k } = s;
|
|
1766
1767
|
if (i && !i() || t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
|
|
1767
1768
|
return;
|
|
1768
1769
|
const u = document.createElement("canvas");
|
|
1769
|
-
u.width = S, u.height =
|
|
1770
|
+
u.width = S, u.height = k;
|
|
1770
1771
|
const p = u.getContext("2d");
|
|
1771
|
-
if (p.clearRect(0, 0, S,
|
|
1772
|
-
(e.width !== S || e.height !==
|
|
1772
|
+
if (p.clearRect(0, 0, S, k), p.drawImage(t, 0, 0, S, k), i && !i()) return;
|
|
1773
|
+
(e.width !== S || e.height !== k) && (e.width = S, e.height = k);
|
|
1773
1774
|
const d = e.getContext("2d");
|
|
1774
|
-
d.clearRect(0, 0, S,
|
|
1775
|
+
d.clearRect(0, 0, S, k), d.drawImage(u, 0, 0);
|
|
1775
1776
|
return;
|
|
1776
1777
|
}
|
|
1777
|
-
const o = await
|
|
1778
|
+
const o = await hn(), a = an(o.viseme.atlasMeta), { width: f, height: l } = Ue(o);
|
|
1778
1779
|
(e.width !== f || e.height !== l) && (e.width = f, e.height = l);
|
|
1779
|
-
const w = [],
|
|
1780
|
-
if (
|
|
1780
|
+
const w = [], g = e.getContext("2d");
|
|
1781
|
+
if (g.clearRect(0, 0, f, l), t.readyState < HTMLMediaElement.HAVE_CURRENT_DATA) {
|
|
1781
1782
|
const S = o.sil;
|
|
1782
|
-
|
|
1783
|
+
g.drawImage(S, 0, 0, f, l);
|
|
1783
1784
|
return;
|
|
1784
1785
|
}
|
|
1785
1786
|
if (w.length === 0) {
|
|
1786
|
-
|
|
1787
|
+
g.drawImage(t, 0, 0, f, l);
|
|
1787
1788
|
return;
|
|
1788
1789
|
}
|
|
1789
|
-
const m =
|
|
1790
|
-
|
|
1790
|
+
const m = dn(t, w, f, l, a);
|
|
1791
|
+
g.drawImage(m, 0, 0);
|
|
1791
1792
|
}
|
|
1792
1793
|
async function ct(e, t, n) {
|
|
1793
|
-
const r = await
|
|
1794
|
+
const r = await hn(Fe ?? void 0), s = an(r.viseme.atlasMeta), { width: i, height: o } = Ue(r);
|
|
1794
1795
|
(e.width !== i || e.height !== o) && (e.width = i, e.height = o);
|
|
1795
1796
|
const a = [];
|
|
1796
1797
|
if (t.mouthPath) {
|
|
1797
|
-
const w = new Set(r.viseme.cellByPath.keys()),
|
|
1798
|
-
|
|
1798
|
+
const w = new Set(r.viseme.cellByPath.keys()), g = Fr(t.mouthPath, w) ?? (w.has(t.mouthPath) ? t.mouthPath : null);
|
|
1799
|
+
g && a.push(await Ht(r, r.viseme, g));
|
|
1799
1800
|
}
|
|
1800
1801
|
t.expressionPath && r.expression && a.push(
|
|
1801
1802
|
await Ht(r, r.expression, t.expressionPath)
|
|
@@ -1805,7 +1806,7 @@ async function ct(e, t, n) {
|
|
|
1805
1806
|
f.drawImage(r.sil, 0, 0, i, o);
|
|
1806
1807
|
return;
|
|
1807
1808
|
}
|
|
1808
|
-
const l =
|
|
1809
|
+
const l = dn(
|
|
1809
1810
|
r.sil,
|
|
1810
1811
|
a,
|
|
1811
1812
|
i,
|
|
@@ -1823,7 +1824,7 @@ function ws(e) {
|
|
|
1823
1824
|
t.has(n.vtime) || t.set(n.vtime, n);
|
|
1824
1825
|
return [...t.values()].sort((n, r) => n.vtime - r.vtime);
|
|
1825
1826
|
}
|
|
1826
|
-
function
|
|
1827
|
+
function _s(e) {
|
|
1827
1828
|
const t = ws(e), n = [];
|
|
1828
1829
|
for (let r = 0; r < t.length - 1; r++) {
|
|
1829
1830
|
const s = t[r].viseme, i = t[r + 1].viseme, o = t[r].vtime, a = t[r + 1].vtime;
|
|
@@ -1831,7 +1832,7 @@ function gs(e) {
|
|
|
1831
1832
|
}
|
|
1832
1833
|
return n;
|
|
1833
1834
|
}
|
|
1834
|
-
function
|
|
1835
|
+
function gs(e, t) {
|
|
1835
1836
|
let n = null;
|
|
1836
1837
|
for (const r of e)
|
|
1837
1838
|
t >= r.fromVtime && t < r.toVtime && (n = r);
|
|
@@ -1840,7 +1841,7 @@ function _s(e, t) {
|
|
|
1840
1841
|
function ps(e, t) {
|
|
1841
1842
|
return { gapMs: Math.max(0, t - e), holdEnd: e, transStart: e };
|
|
1842
1843
|
}
|
|
1843
|
-
const
|
|
1844
|
+
const mn = 400, ys = 200, Es = 600, ks = "__sil__";
|
|
1844
1845
|
function Ss() {
|
|
1845
1846
|
return { lastDrawnKey: "" };
|
|
1846
1847
|
}
|
|
@@ -1850,7 +1851,7 @@ function me(e) {
|
|
|
1850
1851
|
function vs(e, t) {
|
|
1851
1852
|
if (t?.transitionCache && t.transitionCache.queueLength === e.length)
|
|
1852
1853
|
return t.transitionCache.transitions;
|
|
1853
|
-
const n =
|
|
1854
|
+
const n = _s(e);
|
|
1854
1855
|
return t && (t.transitionCache = { queueLength: e.length, transitions: n }), n;
|
|
1855
1856
|
}
|
|
1856
1857
|
function bs(e) {
|
|
@@ -1863,29 +1864,29 @@ function Ts(e, t) {
|
|
|
1863
1864
|
return e === "sil" ? !1 : t ? Ur(e, "sil", t) : ht(e, "sil").length > 0;
|
|
1864
1865
|
}
|
|
1865
1866
|
function As() {
|
|
1866
|
-
return
|
|
1867
|
+
return mn + Es;
|
|
1867
1868
|
}
|
|
1868
1869
|
function qt(e) {
|
|
1869
|
-
return e ??
|
|
1870
|
+
return e ?? ks;
|
|
1870
1871
|
}
|
|
1871
1872
|
function Is(e, t, n, r) {
|
|
1872
1873
|
if (e.length === 0)
|
|
1873
1874
|
return { diffPath: null, label: "sil" };
|
|
1874
|
-
const s = vs(e, r), i =
|
|
1875
|
+
const s = vs(e, r), i = gs(s, t);
|
|
1875
1876
|
if (i) {
|
|
1876
1877
|
const a = i.toVtime - i.fromVtime, f = ps(i.fromVtime, i.toVtime);
|
|
1877
1878
|
if (t >= f.transStart && t < i.toVtime) {
|
|
1878
1879
|
let l = ht(i.from, i.to);
|
|
1879
|
-
n && (l =
|
|
1880
|
+
n && (l = cn(l, n));
|
|
1880
1881
|
const w = Vr(l, a);
|
|
1881
1882
|
if (w.length > 0) {
|
|
1882
|
-
const
|
|
1883
|
+
const g = $r(
|
|
1883
1884
|
t,
|
|
1884
1885
|
f.transStart,
|
|
1885
1886
|
i.toVtime,
|
|
1886
1887
|
w.length
|
|
1887
1888
|
);
|
|
1888
|
-
return { diffPath: w[
|
|
1889
|
+
return { diffPath: w[g] ?? w[w.length - 1], label: `${i.from}→${i.to}` };
|
|
1889
1890
|
}
|
|
1890
1891
|
return { diffPath: Ke(i.to), label: i.to };
|
|
1891
1892
|
}
|
|
@@ -1893,28 +1894,28 @@ function Is(e, t, n, r) {
|
|
|
1893
1894
|
const o = lt(e, t);
|
|
1894
1895
|
return o === "sil" ? { diffPath: null, label: "sil" } : { diffPath: Ke(o), label: o };
|
|
1895
1896
|
}
|
|
1896
|
-
function
|
|
1897
|
+
function wn(e, t) {
|
|
1897
1898
|
const n = t ?? qt(e.expressionPath);
|
|
1898
1899
|
return `${qt(e.mouthPath)}|${n}`;
|
|
1899
1900
|
}
|
|
1900
1901
|
function Rs(e, t, n, r, s, i, o, a, f, l) {
|
|
1901
|
-
const w = Is(t, n, f, i),
|
|
1902
|
+
const w = Is(t, n, f, i), g = {
|
|
1902
1903
|
mouthPath: w.diffPath,
|
|
1903
1904
|
expressionPath: r
|
|
1904
|
-
}, m =
|
|
1905
|
-
m !== i.lastDrawnKey && (a(w.label), o(e,
|
|
1905
|
+
}, m = wn(g, s);
|
|
1906
|
+
m !== i.lastDrawnKey && (a(w.label), o(e, g, m, (S) => {
|
|
1906
1907
|
S === m && (i.lastDrawnKey = m);
|
|
1907
1908
|
}));
|
|
1908
1909
|
}
|
|
1909
1910
|
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 =
|
|
1911
|
+
const a = { mouthPath: null, expressionPath: t }, f = o != null ? `|idle@${Math.round(o * 1e3)}` : "", l = wn(a, n) + f;
|
|
1911
1912
|
!(o != null) && l === r.lastDrawnKey || (i(
|
|
1912
1913
|
o != null ? "idle" : "sil"
|
|
1913
|
-
), s(e, a, l, (
|
|
1914
|
-
|
|
1914
|
+
), s(e, a, l, (g) => {
|
|
1915
|
+
g === l && (r.lastDrawnKey = l);
|
|
1915
1916
|
}));
|
|
1916
1917
|
}
|
|
1917
|
-
function
|
|
1918
|
+
function _n(e) {
|
|
1918
1919
|
let t = 0, n = null, r = !1, s = !1;
|
|
1919
1920
|
const i = async () => {
|
|
1920
1921
|
if (!r) {
|
|
@@ -1974,7 +1975,7 @@ function xs(e, t) {
|
|
|
1974
1975
|
}
|
|
1975
1976
|
function zt(e, t) {
|
|
1976
1977
|
let n = 0, r = null;
|
|
1977
|
-
const s =
|
|
1978
|
+
const s = _n(async (i, o) => (await at(), await ct(e, i), s.isLatestSeq(o)));
|
|
1978
1979
|
return {
|
|
1979
1980
|
usesWorker: !1,
|
|
1980
1981
|
async loadAssets(i) {
|
|
@@ -2005,10 +2006,10 @@ function zt(e, t) {
|
|
|
2005
2006
|
}
|
|
2006
2007
|
function Cs(e, t, n) {
|
|
2007
2008
|
let r = null, s = 1, i = 0, o = !1, a = !1, f = null;
|
|
2008
|
-
const l = /* @__PURE__ */ new Map(), w =
|
|
2009
|
+
const l = /* @__PURE__ */ new Map(), w = _n(async (p, d, I) => (l.set(d, {
|
|
2009
2010
|
drawKey: I.drawKey,
|
|
2010
2011
|
onDisplayed: I.onDisplayed
|
|
2011
|
-
}), await
|
|
2012
|
+
}), await k(
|
|
2012
2013
|
{
|
|
2013
2014
|
type: "drawFrame",
|
|
2014
2015
|
diffPath: p.mouthPath,
|
|
@@ -2017,28 +2018,28 @@ function Cs(e, t, n) {
|
|
|
2017
2018
|
},
|
|
2018
2019
|
void 0,
|
|
2019
2020
|
!0
|
|
2020
|
-
), !1)),
|
|
2021
|
+
), !1)), g = (p) => {
|
|
2021
2022
|
if (p === jt) {
|
|
2022
|
-
let
|
|
2023
|
+
let E = -1, R;
|
|
2023
2024
|
for (const [W, V] of l)
|
|
2024
|
-
W >=
|
|
2025
|
-
|
|
2025
|
+
W >= E && (E = W, R = V);
|
|
2026
|
+
E >= 0 && l.delete(E), R?.onDisplayed?.(R.drawKey);
|
|
2026
2027
|
return;
|
|
2027
2028
|
}
|
|
2028
2029
|
const d = -p, I = l.get(d);
|
|
2029
2030
|
l.delete(d), I?.onDisplayed?.(I.drawKey);
|
|
2030
2031
|
}, m = /* @__PURE__ */ new Map(), S = (p, d) => {
|
|
2031
2032
|
a || !r || r.postMessage(p, []);
|
|
2032
|
-
},
|
|
2033
|
+
}, k = (p, d, I = !1) => {
|
|
2033
2034
|
if (a) return Promise.resolve();
|
|
2034
|
-
const
|
|
2035
|
+
const E = s++;
|
|
2035
2036
|
return new Promise((R, W) => {
|
|
2036
|
-
m.set(
|
|
2037
|
+
m.set(E, {
|
|
2037
2038
|
resolve: (V) => R(V),
|
|
2038
2039
|
reject: W,
|
|
2039
2040
|
generation: typeof p.generation == "number" ? p.generation : void 0,
|
|
2040
2041
|
expectRenderDone: I
|
|
2041
|
-
}), S({ ...p, requestId:
|
|
2042
|
+
}), S({ ...p, requestId: E });
|
|
2042
2043
|
});
|
|
2043
2044
|
}, u = (async () => {
|
|
2044
2045
|
r = await Ds(n), r.onmessage = (p) => {
|
|
@@ -2049,23 +2050,23 @@ function Cs(e, t, n) {
|
|
|
2049
2050
|
return;
|
|
2050
2051
|
}
|
|
2051
2052
|
if (d.type === "frame") {
|
|
2052
|
-
const
|
|
2053
|
-
if (!
|
|
2053
|
+
const E = d.generation < 0;
|
|
2054
|
+
if (!E && d.generation !== i) {
|
|
2054
2055
|
d.bitmap.close();
|
|
2055
2056
|
return;
|
|
2056
2057
|
}
|
|
2057
|
-
if (
|
|
2058
|
+
if (E && !(d.generation === jt)) {
|
|
2058
2059
|
const W = -d.generation;
|
|
2059
2060
|
if (!w.isLatestSeq(W)) {
|
|
2060
2061
|
d.bitmap.close();
|
|
2061
2062
|
return;
|
|
2062
2063
|
}
|
|
2063
2064
|
}
|
|
2064
|
-
if (
|
|
2065
|
+
if (E && t.shouldAcceptLiveFrame && !t.shouldAcceptLiveFrame()) {
|
|
2065
2066
|
d.bitmap.close();
|
|
2066
2067
|
return;
|
|
2067
2068
|
}
|
|
2068
|
-
xs(e, d.bitmap), d.bitmap.close(),
|
|
2069
|
+
xs(e, d.bitmap), d.bitmap.close(), E && g(d.generation);
|
|
2069
2070
|
return;
|
|
2070
2071
|
}
|
|
2071
2072
|
const I = m.get(d.requestId);
|
|
@@ -2096,7 +2097,7 @@ function Cs(e, t, n) {
|
|
|
2096
2097
|
for (const [, I] of m)
|
|
2097
2098
|
I.reject(new Error(d));
|
|
2098
2099
|
m.clear();
|
|
2099
|
-
}, await
|
|
2100
|
+
}, await k({ type: "init" }), o = !0;
|
|
2100
2101
|
})();
|
|
2101
2102
|
return {
|
|
2102
2103
|
usesWorker: !0,
|
|
@@ -2104,10 +2105,10 @@ function Cs(e, t, n) {
|
|
|
2104
2105
|
if (a) return { width: 842, height: 1264 };
|
|
2105
2106
|
if (await u, a) return { width: 842, height: 1264 };
|
|
2106
2107
|
if (!o) throw new Error("Worker init failed");
|
|
2107
|
-
return await
|
|
2108
|
+
return await k({
|
|
2108
2109
|
type: "loadAssets",
|
|
2109
2110
|
keyHex: p,
|
|
2110
|
-
urls: Jn(
|
|
2111
|
+
urls: Jn(Ee())
|
|
2111
2112
|
}) ?? { width: 842, height: 1264 };
|
|
2112
2113
|
},
|
|
2113
2114
|
getVisemeAtlasPaths() {
|
|
@@ -2117,26 +2118,26 @@ function Cs(e, t, n) {
|
|
|
2117
2118
|
if (a || (await u, a)) return;
|
|
2118
2119
|
i += 1, w.reset(), l.clear();
|
|
2119
2120
|
const p = i;
|
|
2120
|
-
await
|
|
2121
|
+
await k({ type: "cancelLiveDraws" }), await k(
|
|
2121
2122
|
{ type: "renderSil", generation: p },
|
|
2122
2123
|
void 0,
|
|
2123
2124
|
!0
|
|
2124
2125
|
);
|
|
2125
2126
|
},
|
|
2126
|
-
drawLiveFrame(p, d, I,
|
|
2127
|
+
drawLiveFrame(p, d, I, E) {
|
|
2127
2128
|
a || u.then(() => {
|
|
2128
|
-
a || w.enqueue(d, I,
|
|
2129
|
+
a || w.enqueue(d, I, E);
|
|
2129
2130
|
});
|
|
2130
2131
|
},
|
|
2131
2132
|
async renderViseme(p, d, I = {}) {
|
|
2132
2133
|
if (a || (await u, a)) return;
|
|
2133
2134
|
i += 1, w.reset(), l.clear();
|
|
2134
|
-
const
|
|
2135
|
+
const E = i;
|
|
2135
2136
|
try {
|
|
2136
|
-
await
|
|
2137
|
+
await k({ type: "cancelLiveDraws" }), await k(
|
|
2137
2138
|
{
|
|
2138
2139
|
type: "renderViseme",
|
|
2139
|
-
generation:
|
|
2140
|
+
generation: E,
|
|
2140
2141
|
to: d,
|
|
2141
2142
|
from: I.from,
|
|
2142
2143
|
transitionDurationMs: I.transitionDurationMs,
|
|
@@ -2191,15 +2192,15 @@ function tt(e, t, n) {
|
|
|
2191
2192
|
);
|
|
2192
2193
|
});
|
|
2193
2194
|
}
|
|
2194
|
-
const
|
|
2195
|
+
const Ls = {
|
|
2195
2196
|
position: "relative",
|
|
2196
2197
|
display: "inline-block",
|
|
2197
2198
|
lineHeight: 0
|
|
2198
|
-
},
|
|
2199
|
+
}, Os = {
|
|
2199
2200
|
display: "block",
|
|
2200
2201
|
maxWidth: "100%",
|
|
2201
2202
|
height: "auto"
|
|
2202
|
-
},
|
|
2203
|
+
}, Fs = {
|
|
2203
2204
|
position: "absolute",
|
|
2204
2205
|
inset: 0,
|
|
2205
2206
|
display: "flex",
|
|
@@ -2211,13 +2212,13 @@ const Os = {
|
|
|
2211
2212
|
fontSize: "0.875rem",
|
|
2212
2213
|
textAlign: "center"
|
|
2213
2214
|
};
|
|
2214
|
-
function
|
|
2215
|
-
return
|
|
2215
|
+
function Le(e) {
|
|
2216
|
+
return On(e) ? Er : nn;
|
|
2216
2217
|
}
|
|
2217
2218
|
function we(e, t) {
|
|
2218
2219
|
return t?.isSpeaking() ? t : e.isSpeaking() ? e : t?.isConnected() ? t : e;
|
|
2219
2220
|
}
|
|
2220
|
-
const
|
|
2221
|
+
const Ks = Sn(function({
|
|
2221
2222
|
id: t,
|
|
2222
2223
|
avatarId: n,
|
|
2223
2224
|
faceId: r,
|
|
@@ -2228,23 +2229,23 @@ const qs = En(function({
|
|
|
2228
2229
|
speakingRate: f = ft,
|
|
2229
2230
|
className: l,
|
|
2230
2231
|
style: w,
|
|
2231
|
-
canvasStyle:
|
|
2232
|
+
canvasStyle: g,
|
|
2232
2233
|
onStatusChange: m,
|
|
2233
2234
|
onDisplayStatus: S,
|
|
2234
|
-
onError:
|
|
2235
|
+
onError: k,
|
|
2235
2236
|
onReady: u,
|
|
2236
2237
|
showErrorOverlay: p = !0,
|
|
2237
2238
|
onUserTranscript: d,
|
|
2238
2239
|
onBotOutput: I,
|
|
2239
|
-
onRealtimeLipsyncDebug:
|
|
2240
|
+
onRealtimeLipsyncDebug: E
|
|
2240
2241
|
}, R) {
|
|
2241
|
-
const W =
|
|
2242
|
+
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
2243
|
null
|
|
2243
|
-
), X =
|
|
2244
|
-
|
|
2244
|
+
), 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);
|
|
2245
|
+
gt.current = u, ee.current = S, pt.current = k, yt.current = d, Et.current = I, kt.current = E;
|
|
2245
2246
|
const St = oe(
|
|
2246
2247
|
(h) => {
|
|
2247
|
-
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, C = h?.voiceId ?? a ?? Y.current?.voiceId ??
|
|
2248
|
+
const M = h?.ttsEngineId ?? o ?? Y.current?.ttsEngineId ?? Te, C = h?.voiceId ?? a ?? Y.current?.voiceId ?? Le(M);
|
|
2248
2249
|
return { ttsEngineId: M, voiceId: C };
|
|
2249
2250
|
},
|
|
2250
2251
|
[o, a]
|
|
@@ -2255,9 +2256,9 @@ const qs = En(function({
|
|
|
2255
2256
|
Z(h), m?.(h);
|
|
2256
2257
|
},
|
|
2257
2258
|
[m]
|
|
2258
|
-
), q =
|
|
2259
|
+
), q = F(
|
|
2259
2260
|
Pt(Me, be)
|
|
2260
|
-
), K =
|
|
2261
|
+
), K = F(null);
|
|
2261
2262
|
Se(() => (q.current = Pt(
|
|
2262
2263
|
Me,
|
|
2263
2264
|
be
|
|
@@ -2271,8 +2272,8 @@ const qs = En(function({
|
|
|
2271
2272
|
{
|
|
2272
2273
|
speakingRate: f,
|
|
2273
2274
|
onUserTranscript: (h, M) => yt.current?.(h, M),
|
|
2274
|
-
onBotOutput: (h) =>
|
|
2275
|
-
onLipsyncDebug: (h) =>
|
|
2275
|
+
onBotOutput: (h) => Et.current?.(h),
|
|
2276
|
+
onLipsyncDebug: (h) => kt.current?.(h)
|
|
2276
2277
|
}
|
|
2277
2278
|
), K.current.setTtsEngineId(o)), K.current), [Me, f, o]), ie = oe(() => {
|
|
2278
2279
|
x.current != null && (clearTimeout(x.current), x.current = null);
|
|
@@ -2299,16 +2300,16 @@ const qs = En(function({
|
|
|
2299
2300
|
h.restart(), h.setActive(!0);
|
|
2300
2301
|
const M = h.getVideo();
|
|
2301
2302
|
let C = !1;
|
|
2302
|
-
const
|
|
2303
|
+
const O = () => {
|
|
2303
2304
|
C || (C = !0, M.removeEventListener("playing", N), P.current = !1);
|
|
2304
2305
|
}, N = () => {
|
|
2305
|
-
|
|
2306
|
+
O();
|
|
2306
2307
|
};
|
|
2307
2308
|
if (M.addEventListener("playing", N, { once: !0 }), M.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA && !M.paused) {
|
|
2308
|
-
|
|
2309
|
+
O();
|
|
2309
2310
|
return;
|
|
2310
2311
|
}
|
|
2311
|
-
setTimeout(
|
|
2312
|
+
setTimeout(O, 300);
|
|
2312
2313
|
}, ys));
|
|
2313
2314
|
}, [ue]), Ne = oe(() => {
|
|
2314
2315
|
if (ie(), ee.current?.("sil"), D.current = !1, !X.current || !U.current) {
|
|
@@ -2318,10 +2319,10 @@ const qs = En(function({
|
|
|
2318
2319
|
bt();
|
|
2319
2320
|
}, [ie, bt]), Xe = oe(
|
|
2320
2321
|
async (h) => {
|
|
2321
|
-
const M = T.current, C = V.current,
|
|
2322
|
+
const M = T.current, C = V.current, O = W.current, N = () => {
|
|
2322
2323
|
h?.fallbackOnly || (D.current = !1);
|
|
2323
2324
|
};
|
|
2324
|
-
if (!C || !
|
|
2325
|
+
if (!C || !O || !c) {
|
|
2325
2326
|
N();
|
|
2326
2327
|
return;
|
|
2327
2328
|
}
|
|
@@ -2360,9 +2361,9 @@ const qs = En(function({
|
|
|
2360
2361
|
return;
|
|
2361
2362
|
}
|
|
2362
2363
|
try {
|
|
2363
|
-
await C.renderViseme(
|
|
2364
|
+
await C.renderViseme(O, "sil", {
|
|
2364
2365
|
from: te,
|
|
2365
|
-
transitionDurationMs:
|
|
2366
|
+
transitionDurationMs: mn
|
|
2366
2367
|
});
|
|
2367
2368
|
} catch (de) {
|
|
2368
2369
|
if (de?.name !== "AbortError")
|
|
@@ -2393,12 +2394,12 @@ const qs = En(function({
|
|
|
2393
2394
|
}, As());
|
|
2394
2395
|
}, [ie, Xe]), Tt = oe(async () => {
|
|
2395
2396
|
const h = Math.floor(Date.now() / 1e3);
|
|
2396
|
-
if (
|
|
2397
|
-
return
|
|
2397
|
+
if (ke.current && h < ke.current.expiresAt - 60)
|
|
2398
|
+
return ke.current.key;
|
|
2398
2399
|
const M = G.current ?? await et();
|
|
2399
2400
|
G.current = M, q.current.setDeveloperToken(M);
|
|
2400
2401
|
const C = await qn(M, be);
|
|
2401
|
-
return
|
|
2402
|
+
return ke.current = {
|
|
2402
2403
|
key: C.value,
|
|
2403
2404
|
expiresAt: C.expiresAt
|
|
2404
2405
|
}, C.value;
|
|
@@ -2408,15 +2409,15 @@ const qs = En(function({
|
|
|
2408
2409
|
}, [i]), Se(() => {
|
|
2409
2410
|
q.current.setTtsEngineId(o), K.current?.setTtsEngineId(o), Y.current && (Y.current.ttsEngineId = o);
|
|
2410
2411
|
}, [o]), Se(() => {
|
|
2411
|
-
const h = a ??
|
|
2412
|
+
const h = a ?? Le(o);
|
|
2412
2413
|
Y.current && (Y.current.voiceId = h);
|
|
2413
2414
|
}, [a, o]);
|
|
2414
|
-
const
|
|
2415
|
+
const _e = It(
|
|
2415
2416
|
() => zn(n, r),
|
|
2416
2417
|
[n, r]
|
|
2417
|
-
), gn = It(() => s ? JSON.stringify(s) :
|
|
2418
|
+
), gn = It(() => s ? JSON.stringify(s) : _e ? `face:${_e}` : `id:${t ?? ""}`, [s, _e, t]);
|
|
2418
2419
|
return Se(() => {
|
|
2419
|
-
if (!t && !s && !
|
|
2420
|
+
if (!t && !s && !_e) {
|
|
2420
2421
|
fe("AiTwin requires `assets`, `avatarId`/`faceId`, or `id`");
|
|
2421
2422
|
return;
|
|
2422
2423
|
}
|
|
@@ -2427,11 +2428,11 @@ const qs = En(function({
|
|
|
2427
2428
|
let C = null;
|
|
2428
2429
|
return (async () => {
|
|
2429
2430
|
try {
|
|
2430
|
-
let
|
|
2431
|
+
let O, N, te;
|
|
2431
2432
|
if (s)
|
|
2432
|
-
|
|
2433
|
-
else if (
|
|
2434
|
-
ee.current?.("loadFace"),
|
|
2433
|
+
O = s, N = o, te = a ?? Le(N);
|
|
2434
|
+
else if (_e)
|
|
2435
|
+
ee.current?.("loadFace"), O = Dt(_e), N = o, te = a ?? Le(N);
|
|
2435
2436
|
else {
|
|
2436
2437
|
ee.current?.("getAiTwin");
|
|
2437
2438
|
const Q = await tt(
|
|
@@ -2442,9 +2443,9 @@ const qs = En(function({
|
|
|
2442
2443
|
if (h) return;
|
|
2443
2444
|
if (!Q.faceId?.trim())
|
|
2444
2445
|
throw new Error("getAiTwin returned no faceId");
|
|
2445
|
-
N = Q.ttsEngineId, te = a ?? Q.voiceId ??
|
|
2446
|
+
N = Q.ttsEngineId, te = a ?? Q.voiceId ?? Le(N), O = Dt(Q.faceId);
|
|
2446
2447
|
}
|
|
2447
|
-
Y.current = { ttsEngineId: N, voiceId: te }, Yn(
|
|
2448
|
+
Y.current = { ttsEngineId: N, voiceId: te }, Yn(O), U.current = is(), C = Ps(M, {
|
|
2448
2449
|
onStatus: (Q) => {
|
|
2449
2450
|
h || ee.current?.(Q);
|
|
2450
2451
|
},
|
|
@@ -2468,11 +2469,11 @@ const qs = En(function({
|
|
|
2468
2469
|
"load face assets"
|
|
2469
2470
|
);
|
|
2470
2471
|
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),
|
|
2472
|
+
Qe.current = C.getVisemeAtlasPaths(), De.current = !0, v(!0), gt.current?.(), C.renderSilOnly().then(() => {
|
|
2472
2473
|
h || ee.current?.("sil");
|
|
2473
2474
|
}), (async () => {
|
|
2474
2475
|
try {
|
|
2475
|
-
const Q = await
|
|
2476
|
+
const Q = await Lr(de);
|
|
2476
2477
|
if (await U.current.load(Q), h) return;
|
|
2477
2478
|
X.current = !0, z(!0), me(H.current), U.current.setActive(!0);
|
|
2478
2479
|
const re = U.current.getVideo();
|
|
@@ -2488,34 +2489,34 @@ const qs = En(function({
|
|
|
2488
2489
|
X.current = !1, z(!1), console.warn("[AiTwin] Idle video unavailable:", Q);
|
|
2489
2490
|
}
|
|
2490
2491
|
})();
|
|
2491
|
-
} catch (
|
|
2492
|
+
} catch (O) {
|
|
2492
2493
|
if (h) return;
|
|
2493
|
-
if (
|
|
2494
|
-
fe(
|
|
2494
|
+
if (O instanceof nt) {
|
|
2495
|
+
fe(O.message);
|
|
2495
2496
|
return;
|
|
2496
2497
|
}
|
|
2497
|
-
fe(
|
|
2498
|
+
fe(O instanceof Error ? O.message : "Failed to load AI twin");
|
|
2498
2499
|
}
|
|
2499
2500
|
})(), () => {
|
|
2500
2501
|
h = !0, U.current?.dispose(), C?.dispose(), V.current = null;
|
|
2501
2502
|
};
|
|
2502
|
-
}, [gn, s,
|
|
2503
|
+
}, [gn, s, _e, t, o, a, i, Tt, fe]), Se(() => {
|
|
2503
2504
|
const h = { current: !1 }, M = () => {
|
|
2504
|
-
const C = W.current,
|
|
2505
|
+
const C = W.current, O = V.current, N = we(
|
|
2505
2506
|
q.current,
|
|
2506
2507
|
K.current
|
|
2507
2508
|
);
|
|
2508
|
-
if (!C || !
|
|
2509
|
+
if (!C || !O || !c) {
|
|
2509
2510
|
y.current = requestAnimationFrame(M);
|
|
2510
2511
|
return;
|
|
2511
2512
|
}
|
|
2512
2513
|
const te = N.isSpeaking(), ae = te && !$.current, de = $.current && !te;
|
|
2513
|
-
ae && (ie(), ue(), D.current = !1, A.current = !1, me(H.current),
|
|
2514
|
+
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
2515
|
const le = N.getPlaybackElapsedMs(), Q = de || D.current || P.current;
|
|
2515
2516
|
if (te) {
|
|
2516
2517
|
X.current && U.current?.setActive(!1);
|
|
2517
|
-
const re = N.getVisemeQueue(),
|
|
2518
|
-
|
|
2518
|
+
const re = N.getVisemeQueue(), ge = re.length > 0 ? lt(re, le) : "sil";
|
|
2519
|
+
ge !== "sil" && (B.current = ge);
|
|
2519
2520
|
const he = us(
|
|
2520
2521
|
le,
|
|
2521
2522
|
N.getSentenceEmotions(),
|
|
@@ -2537,15 +2538,15 @@ const qs = En(function({
|
|
|
2537
2538
|
Ce,
|
|
2538
2539
|
Ze,
|
|
2539
2540
|
H.current,
|
|
2540
|
-
(Pe,
|
|
2541
|
+
(Pe, pn, yn, En) => O.drawLiveFrame(Pe, pn, yn, En),
|
|
2541
2542
|
(Pe) => ee.current?.(Pe),
|
|
2542
2543
|
Qe.current
|
|
2543
2544
|
);
|
|
2544
2545
|
} else if (!Q && X.current && U.current) {
|
|
2545
|
-
const re = U.current,
|
|
2546
|
-
|
|
2546
|
+
const re = U.current, ge = re.getVideo();
|
|
2547
|
+
ge.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA ? (re.setActive(!0), h.current || (h.current = !0, Wt(
|
|
2547
2548
|
C,
|
|
2548
|
-
|
|
2549
|
+
ge,
|
|
2549
2550
|
null,
|
|
2550
2551
|
void 0,
|
|
2551
2552
|
Je.current,
|
|
@@ -2557,7 +2558,7 @@ const qs = En(function({
|
|
|
2557
2558
|
null,
|
|
2558
2559
|
"__sil__",
|
|
2559
2560
|
H.current,
|
|
2560
|
-
(he, Ce, Ze, Pe) =>
|
|
2561
|
+
(he, Ce, Ze, Pe) => O.drawLiveFrame(he, Ce, Ze, Pe),
|
|
2561
2562
|
(he) => ee.current?.(he)
|
|
2562
2563
|
);
|
|
2563
2564
|
} else Q || Kt(
|
|
@@ -2565,7 +2566,7 @@ const qs = En(function({
|
|
|
2565
2566
|
null,
|
|
2566
2567
|
"__sil__",
|
|
2567
2568
|
H.current,
|
|
2568
|
-
(re,
|
|
2569
|
+
(re, ge, he, Ce) => O.drawLiveFrame(re, ge, he, Ce),
|
|
2569
2570
|
(re) => ee.current?.(re)
|
|
2570
2571
|
);
|
|
2571
2572
|
$.current = te, y.current = requestAnimationFrame(M);
|
|
@@ -2575,23 +2576,23 @@ const qs = En(function({
|
|
|
2575
2576
|
};
|
|
2576
2577
|
}, [
|
|
2577
2578
|
c,
|
|
2578
|
-
|
|
2579
|
+
L,
|
|
2579
2580
|
xe,
|
|
2580
2581
|
ie,
|
|
2581
2582
|
ue
|
|
2582
|
-
]),
|
|
2583
|
+
]), vn(
|
|
2583
2584
|
R,
|
|
2584
2585
|
() => ({
|
|
2585
2586
|
speakText: async (h, M) => {
|
|
2586
2587
|
const C = h.trim();
|
|
2587
2588
|
if (!C) return;
|
|
2588
|
-
const
|
|
2589
|
-
if (!
|
|
2589
|
+
const O = V.current;
|
|
2590
|
+
if (!O || !De.current && !c)
|
|
2590
2591
|
throw new Error("AI twin is not ready");
|
|
2591
2592
|
const { ttsEngineId: N, voiceId: te } = St(M);
|
|
2592
2593
|
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
2594
|
try {
|
|
2594
|
-
X.current ? (U.current?.setActive(!1), U.current?.restart(), me(H.current)) : await
|
|
2595
|
+
X.current ? (U.current?.setActive(!1), U.current?.restart(), me(H.current)) : await O.renderSilOnly(), await q.current.speak(C, {
|
|
2595
2596
|
voiceId: te,
|
|
2596
2597
|
speakingRate: M?.speakingRate ?? f,
|
|
2597
2598
|
ttsEngineId: N
|
|
@@ -2607,10 +2608,10 @@ const qs = En(function({
|
|
|
2607
2608
|
q.current.setTtsEngineId(h), K.current?.setTtsEngineId(h), Y.current && (Y.current.ttsEngineId = h);
|
|
2608
2609
|
},
|
|
2609
2610
|
renderViseme: async (h, M) => {
|
|
2610
|
-
const C = V.current,
|
|
2611
|
-
if (!C || !
|
|
2611
|
+
const C = V.current, O = W.current;
|
|
2612
|
+
if (!C || !O || !De.current)
|
|
2612
2613
|
throw new Error("AI twin is not ready");
|
|
2613
|
-
await C.renderViseme(
|
|
2614
|
+
await C.renderViseme(O, h, {
|
|
2614
2615
|
from: M?.from,
|
|
2615
2616
|
transitionDurationMs: M?.transitionDurationMs,
|
|
2616
2617
|
gapMs: M?.gapMs,
|
|
@@ -2624,8 +2625,8 @@ const qs = En(function({
|
|
|
2624
2625
|
try {
|
|
2625
2626
|
let M = h.authToken?.trim();
|
|
2626
2627
|
M || (M = G.current ?? i ?? await et(), G.current = M);
|
|
2627
|
-
const C = h.voiceId?.trim() ?? a ?? Y.current?.voiceId,
|
|
2628
|
-
await
|
|
2628
|
+
const C = h.voiceId?.trim() ?? a ?? Y.current?.voiceId, O = vt();
|
|
2629
|
+
await O.unlockAudio(), await O.connect({
|
|
2629
2630
|
...h,
|
|
2630
2631
|
authToken: M,
|
|
2631
2632
|
voiceId: C,
|
|
@@ -2656,45 +2657,53 @@ const qs = En(function({
|
|
|
2656
2657
|
vt,
|
|
2657
2658
|
se
|
|
2658
2659
|
]
|
|
2659
|
-
), /* @__PURE__ */ kn("div", { className: l, style: { ...
|
|
2660
|
+
), /* @__PURE__ */ kn("div", { className: l, style: { ...Ls, ...w }, children: [
|
|
2660
2661
|
/* @__PURE__ */ At(
|
|
2661
2662
|
"canvas",
|
|
2662
2663
|
{
|
|
2663
2664
|
ref: W,
|
|
2664
2665
|
width: ne.width,
|
|
2665
2666
|
height: ne.height,
|
|
2666
|
-
style: { ...
|
|
2667
|
+
style: { ...Os, ...g },
|
|
2667
2668
|
"aria-label": t ? `AI twin ${t}` : "AI twin face"
|
|
2668
2669
|
}
|
|
2669
2670
|
),
|
|
2670
|
-
p && ce ? /* @__PURE__ */ At("div", { style:
|
|
2671
|
+
p && ce ? /* @__PURE__ */ At("div", { style: Fs, children: ce }) : null
|
|
2671
2672
|
] });
|
|
2672
|
-
});
|
|
2673
|
+
}), Us = "thumbnail.webp";
|
|
2674
|
+
function js(e, t = Jt) {
|
|
2675
|
+
const n = e.trim();
|
|
2676
|
+
if (!n)
|
|
2677
|
+
throw new Error("faceId is required");
|
|
2678
|
+
return `${t.replace(/\/$/, "")}/${n}/${Us}`;
|
|
2679
|
+
}
|
|
2673
2680
|
export {
|
|
2674
|
-
|
|
2681
|
+
Us as AI_TWIN_THUMBNAIL_FILENAME,
|
|
2682
|
+
Ks as AiTwin,
|
|
2675
2683
|
nt as AiTwinNotFoundError,
|
|
2676
2684
|
Te as DEFAULT_TTS_ENGINE_ID,
|
|
2677
|
-
|
|
2685
|
+
rn as MIC_SAMPLE_RATE,
|
|
2678
2686
|
rr as OCULUS_VISEME_IDS,
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2687
|
+
sn as PLAYBACK_SAMPLE_RATE,
|
|
2688
|
+
tn as SPEAKING_RATE_MAX,
|
|
2689
|
+
en as SPEAKING_RATE_MIN,
|
|
2682
2690
|
Ae as TTS_ENGINE_CARTESIA,
|
|
2683
|
-
|
|
2691
|
+
Qt as TTS_ENGINE_GOOGLE,
|
|
2684
2692
|
ut as TTS_ENGINE_INWORLD,
|
|
2685
|
-
|
|
2686
|
-
|
|
2693
|
+
qs as VISEME_IDS,
|
|
2694
|
+
Er as VISEME_TEST_CARTESIA_VOICE_ID,
|
|
2687
2695
|
ft as VISEME_TEST_SPEAKING_RATE,
|
|
2688
|
-
|
|
2696
|
+
nn as VISEME_TEST_VOICE_ID,
|
|
2689
2697
|
Tr as buildVoiceWebSocketUrl,
|
|
2690
2698
|
Pt as createAvatarTtsLipsyncController,
|
|
2691
2699
|
Ir as createRealtimeVoiceLipsyncController,
|
|
2692
2700
|
Dt as faceAssetUrls,
|
|
2693
2701
|
Un as fetchAiTwin,
|
|
2694
2702
|
et as fetchDevAuthToken,
|
|
2703
|
+
js as getAiTwinThumbnailUrl,
|
|
2695
2704
|
ir as normalizeOculusViseme,
|
|
2696
2705
|
zn as resolveDirectFaceId,
|
|
2697
2706
|
lt as resolveVisemeAtTime,
|
|
2698
|
-
|
|
2707
|
+
Ws as resolveWordAtTime,
|
|
2699
2708
|
Yn as setActiveTwinAssets
|
|
2700
2709
|
};
|