@streamoji/aitwin 0.2.4 → 0.2.5

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