@lantun/voice-kitten 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Browser voices differ by device, and many sound robotic. This add-on gives every
6
6
 
7
7
  **[Hear them in the live demo →](https://lantun.rzknkbr.xyz)** Open an English article, press play, and pick a voice from the voice menu.
8
8
 
9
- ![The Lantun voice picker with lifelike and built-in voices](https://raw.githubusercontent.com/rizkianakbar/lantun/main/docs/screenshots/voice.png)
9
+ <img src="https://raw.githubusercontent.com/rizkianakbar/lantun/v0.1.2/docs/screenshots/voice-dark.png" alt="The Lantun voice picker with lifelike and built-in voices">
10
10
 
11
11
  ## Install
12
12
 
@@ -10,7 +10,8 @@ export declare const MAX_REALTIME_FACTOR = 0.85;
10
10
  export declare const JUDGE_AFTER = 3;
11
11
  export declare const MIN_JUDGED_SECONDS = 0.5;
12
12
  export declare const CACHE_CLIPS = 10;
13
- export declare const SPLIT_MIN = 90;
14
- export declare const MIN_PIECE = 25;
13
+ export declare const OPENING_CHARS = 28;
14
+ export declare const GROWTH = 1.6;
15
+ export declare const CLAUSE_REACH = 1.3;
15
16
  export declare const CLAUSE: RegExp;
16
17
  export declare const WORD_TICK_MS = 30;
@@ -8,4 +8,4 @@ export declare function keyOf(voice: Voice | null, text: string): string;
8
8
  export declare function toVoice(name: KittenVoiceName): Voice;
9
9
  export declare function wordOffsets(part: Part): number[];
10
10
  export declare function canRun(win?: EngineWindow): boolean;
11
- export declare function splitFirstClause(text: string): Part[];
11
+ export declare function rampParts(text: string): Part[];
package/dist/index.js CHANGED
@@ -48,25 +48,25 @@ var n = `data:audio/wav;base64,${btoa(String.fromCharCode(...new Uint8Array(t(/*
48
48
  ort: `${c}/ort.wasm.min.mjs`,
49
49
  ortWasm: `${c}/ort-wasm-simd-threaded.wasm`,
50
50
  phonemizer: "https://cdn.jsdelivr.net/npm/phonemizer@1.2.1/dist/phonemizer.js"
51
- }, u = 3995e4, d = 31e6, f = /[,;:—](?=\s)/g;
51
+ }, u = 3995e4, d = 31e6, f = 1.6, p = 1.3, m = /[,;:—](?=\s)/g;
52
52
  // src/engine/engine.lib.ts
53
- function p(...e) {
53
+ function h(...e) {
54
54
  try {
55
55
  localStorage.getItem("lantun:debug") && console.info("[Lantun] kitten:", ...e);
56
56
  } catch {}
57
57
  }
58
- function m() {}
59
- function h(e) {
60
- e.clip.then((e) => URL.revokeObjectURL(e.url), m);
58
+ function g() {}
59
+ function _(e) {
60
+ e.clip.then((e) => URL.revokeObjectURL(e.url), g);
61
61
  }
62
- function g(e) {
62
+ function v(e) {
63
63
  let t = e?.name ?? "";
64
64
  return i.includes(t) ? t : i[0];
65
65
  }
66
- function _(e, t) {
67
- return `${g(e)}|${t}`;
66
+ function y(e, t) {
67
+ return `${v(e)}|${t}`;
68
68
  }
69
- function v(e) {
69
+ function b(e) {
70
70
  return {
71
71
  id: `kitten:${e}`,
72
72
  name: e,
@@ -78,170 +78,187 @@ function v(e) {
78
78
  gender: a[e]
79
79
  };
80
80
  }
81
- function y(e) {
81
+ function x(e) {
82
82
  return Array.from(e.text.matchAll(/\S+/g), (t) => e.offset + (t.index ?? 0));
83
83
  }
84
- function b(e = window) {
84
+ function S(e = window) {
85
85
  let t = e.navigator;
86
86
  return typeof WebAssembly == "object" && typeof e.Worker == "function" && typeof e.Audio == "function" && typeof DecompressionStream == "function" && !t.connection?.saveData && (t.deviceMemory ?? 4) >= 2;
87
87
  }
88
- function x(e) {
89
- if (e.length < 90) return [{
90
- text: e,
91
- offset: 0
92
- }];
93
- for (let t of e.matchAll(f)) {
94
- let n = (t.index ?? 0) + 1;
95
- if (n < 25) continue;
96
- if (n > e.length - 25) break;
97
- let r = e.slice(n).trimStart();
98
- return [{
99
- text: e.slice(0, n),
100
- offset: 0
101
- }, {
102
- text: r,
103
- offset: e.length - r.length
104
- }];
88
+ function C(e, t, n) {
89
+ let r = t + n / 2, i = e.slice(t, t + Math.round(n * p) + 1), a = -1;
90
+ for (let e of i.matchAll(m)) {
91
+ let n = t + (e.index ?? 0) + 1;
92
+ n > r && (a = n);
105
93
  }
106
- return [{
107
- text: e,
108
- offset: 0
109
- }];
94
+ if (a > 0) return a;
95
+ let o = e.lastIndexOf(" ", t + n);
96
+ return o > r ? o : e.indexOf(" ", t + n);
97
+ }
98
+ function w(e) {
99
+ let t = [], n = 0, r = 28;
100
+ for (; e.length - n > r * f;) {
101
+ let i = C(e, n, r);
102
+ if (i <= n) break;
103
+ for (t.push({
104
+ text: e.slice(n, i).trimEnd(),
105
+ offset: n
106
+ }), n = i; /\s/.test(e[n] ?? "");) n++;
107
+ r = Math.round(r * f);
108
+ }
109
+ return t.push({
110
+ text: e.slice(n),
111
+ offset: n
112
+ }), t;
110
113
  }
111
114
  // src/engine/engine.ts
112
- function S(e, a = {}, s = window) {
115
+ function T(e, a = {}, s = window) {
113
116
  let c = {
114
117
  ...l,
115
118
  ...a.sources
116
- }, d = b(s) ? (a.voices ?? i).map(v) : [], f = /* @__PURE__ */ new Set(), S = /* @__PURE__ */ new Map(), C = /* @__PURE__ */ new Map(), w = [], T = {
119
+ }, d = S(s) ? (a.voices ?? i).map(b) : [], f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), C = [], T = {
117
120
  state: "idle",
118
121
  progress: 0
119
- }, E = null, D = 1, O = null, k = 1, A = !1, j = 0, M, N = 0, P = null, F = null;
120
- function I(e) {
122
+ }, E = null, D = 1, O = null, k = 1, A = !1, j = 0, M, N = 0, P = null, F = null, I = !1;
123
+ function L(e) {
121
124
  T = e;
122
125
  for (let t of f) t(e);
123
126
  }
124
- function L() {
127
+ function R() {
125
128
  E?.terminate(), E = null;
126
- for (let e of S.values()) e.reject(/* @__PURE__ */ Error("Voice engine failed to load"));
127
- S.clear();
128
- for (let e of C.values()) h(e);
129
- C.clear(), I({
129
+ for (let e of p.values()) e.reject(/* @__PURE__ */ Error("Voice engine failed to load"));
130
+ p.clear();
131
+ for (let e of m.values()) _(e);
132
+ m.clear(), L({
130
133
  state: "error",
131
134
  progress: 0,
132
135
  error: "failed"
133
136
  });
134
137
  }
135
- function R(e, t) {
136
- if (t < .5 || (w.push(e / 1e3 / t * k), w.length < 4)) return;
137
- let n = w.slice(1).slice(-3), r = n.reduce((e, t) => e + t, 0) / n.length;
138
- r > .85 && (p(`too slow: synthesis takes ${r.toFixed(2)}× the listening time`), I({
138
+ function z(e, t) {
139
+ if (t < .5 || (C.push(e / 1e3 / t * k), C.length < 4)) return;
140
+ let n = C.slice(1).slice(-3), r = n.reduce((e, t) => e + t, 0) / n.length;
141
+ r > .85 && (h(`too slow: synthesis takes ${r.toFixed(2)}× the listening time`), L({
139
142
  state: "error",
140
143
  progress: 0,
141
144
  error: "slow"
142
145
  }));
143
146
  }
144
- function z(e) {
145
- let n = S.get(e.id);
146
- if (S.delete(e.id), !n) return;
147
+ function B(e) {
148
+ let n = p.get(e.id);
149
+ if (p.delete(e.id), !n) return;
147
150
  let i = e.samples.length / r, a = new Blob([t(e.samples, r)], { type: "audio/wav" });
148
- p(`clip ${e.id}: ${Math.round(e.ms)} ms for ${i.toFixed(1)} s of audio`), R(e.ms, i), n.resolve({
151
+ h(`clip ${e.id}: ${Math.round(e.ms)} ms for ${i.toFixed(1)} s of audio`), z(e.ms, i), n.resolve({
149
152
  url: URL.createObjectURL(a),
150
153
  seconds: i,
151
154
  starts: e.starts
152
155
  });
153
156
  }
154
- function B(e) {
157
+ function V(e) {
155
158
  switch (e.type) {
156
159
  case "progress":
157
- T.state === "loading" && I({
160
+ T.state === "loading" && L({
158
161
  state: "loading",
159
162
  progress: Math.min(.99, e.loaded / u)
160
163
  });
161
164
  return;
162
165
  case "ready":
163
- I({
166
+ L({
164
167
  state: "ready",
165
168
  progress: 1
166
169
  });
167
170
  return;
168
171
  case "audio":
169
- z(e);
172
+ B(e);
170
173
  return;
171
174
  case "error":
172
175
  if (e.id === void 0) {
173
- p("load failed:", e.message), L();
176
+ h("load failed:", e.message), R();
174
177
  return;
175
178
  }
176
- p(`clip ${e.id} failed:`, e.message), S.get(e.id)?.reject(Error(e.message)), S.delete(e.id);
179
+ h(`clip ${e.id} failed:`, e.message), p.get(e.id)?.reject(Error(e.message)), p.delete(e.id);
177
180
  }
178
181
  }
179
- function V(e) {
182
+ function H(e) {
180
183
  E?.postMessage(e);
181
184
  }
182
- function H() {
185
+ function U() {
183
186
  if (E) return E;
184
187
  try {
185
188
  E = e();
186
189
  } catch {
187
- return L(), null;
190
+ return R(), null;
188
191
  }
189
- return E.onmessage = (e) => B(e.data), E.onerror = L, I({
192
+ return E.onmessage = (e) => V(e.data), E.onerror = R, L({
190
193
  state: "loading",
191
194
  progress: 0
192
- }), V({
195
+ }), H({
193
196
  type: "load",
194
197
  sources: c
195
198
  }), E;
196
199
  }
197
- function U() {
198
- for (let [e, t] of C) {
199
- if (C.size <= 10) return;
200
- C.delete(e), h(t);
200
+ function W() {
201
+ for (let [e, t] of m) {
202
+ if (m.size <= 10) return;
203
+ m.delete(e), _(t);
201
204
  }
202
205
  }
203
- function W(e, t) {
204
- let n = _(e, t), r = C.get(n);
205
- if (r) return C.delete(n), C.set(n, r), r;
206
- let i = D++, a = g(e), s = new Promise((e, n) => {
207
- S.set(i, {
206
+ function G(e, t, n = !1) {
207
+ let r = y(e, t), i = m.get(r);
208
+ if (i) return m.delete(r), m.set(r, i), i;
209
+ let a = D++, s = v(e), c = new Promise((e, r) => {
210
+ p.set(a, {
208
211
  resolve: e,
209
- reject: n
210
- }), p(`queue clip ${i}: "${t.slice(0, 40)}"`), V({
212
+ reject: r
213
+ }), h(`queue clip ${a}: "${t.slice(0, 40)}"`), H({
211
214
  type: "synth",
212
- id: i,
215
+ id: a,
213
216
  text: t,
214
- voice: a,
215
- speed: o[a]
217
+ voice: s,
218
+ speed: o[s],
219
+ urgent: n
216
220
  });
217
- }), c = {
218
- id: i,
219
- clip: s
221
+ }), l = {
222
+ id: a,
223
+ clip: c
220
224
  };
221
- return s.catch(() => {
222
- C.get(n)?.id === i && C.delete(n);
223
- }), C.set(n, c), U(), c;
225
+ return c.catch(() => {
226
+ m.get(r)?.id === a && m.delete(r);
227
+ }), m.set(r, l), W(), l;
228
+ }
229
+ function K(e, t, n) {
230
+ let r = m.get(y(e, t));
231
+ return r ? [{
232
+ part: {
233
+ text: t,
234
+ offset: 0
235
+ },
236
+ ...r
237
+ }] : w(t).map((t) => ({
238
+ part: t,
239
+ ...G(e, t.text, n)
240
+ }));
224
241
  }
225
- function G(e) {
226
- for (let [t, n] of C) {
227
- let r = S.get(n.id);
228
- r && !e.has(n.id) && (C.delete(t), S.delete(n.id), r.reject(/* @__PURE__ */ Error("dropped")));
242
+ function q(e) {
243
+ for (let [t, n] of m) {
244
+ let r = p.get(n.id);
245
+ r && !e.has(n.id) && (m.delete(t), p.delete(n.id), r.reject(/* @__PURE__ */ Error("dropped")));
229
246
  }
230
- V({
247
+ H({
231
248
  type: "drop",
232
249
  keep: [...e]
233
250
  });
234
251
  }
235
- function K() {
252
+ function J() {
236
253
  clearInterval(M), M = void 0, F = null, O && (O.onended = null, O.pause());
237
254
  }
238
- function q() {
255
+ function Y() {
239
256
  if (O) return O;
240
257
  let e = new (s.Audio ?? Audio)();
241
258
  return e.preload = "auto", e.preservesPitch = !0, O = e, e;
242
259
  }
243
- function J(e, t, n) {
244
- let r = q(), i = 0, a = !1;
260
+ function X(e, t, n) {
261
+ let r = Y(), i = 0, a = !1;
245
262
  function o() {
246
263
  return n === j;
247
264
  }
@@ -259,23 +276,23 @@ function S(e, a = {}, s = window) {
259
276
  }
260
277
  function l(e, n) {
261
278
  if (!o()) return;
262
- let c = y(e.part), l = 0;
279
+ let c = x(e.part), l = 0;
263
280
  function d() {
264
281
  for (; l < c.length && (n.starts[l] ?? Infinity) <= r.currentTime;) t.onWord(c[l++] ?? 0, !1);
265
282
  }
266
283
  function f() {
267
- o() && (a || (a = !0, t.onStart?.()), N && p(`silence before "${e.part.text.slice(0, 30)}": ${Math.round(performance.now() - N)} ms`), N = 0, clearInterval(M), M = setInterval(d, 30), d());
284
+ o() && (a || (a = !0, t.onStart?.()), N && h(`silence before "${e.part.text.slice(0, 30)}": ${Math.round(performance.now() - N)} ms`), N = 0, clearInterval(M), M = setInterval(d, 30), d());
268
285
  }
269
- function m() {
286
+ function p() {
270
287
  r.onended = () => {
271
288
  N = performance.now(), o() && (clearInterval(M), d(), i++, u());
272
289
  }, r.src = n.url, r.playbackRate = k, r.play().then(f, s);
273
290
  }
274
- A ? F = m : m();
291
+ A ? F = p : p();
275
292
  }
276
293
  function u() {
277
294
  let n = e[i];
278
- n ? n.clip.then((e) => l(n, e), c) : t.onEnd();
295
+ n ? n.clip.then((e) => l(n, e), c) : (I = !1, t.onEnd());
279
296
  }
280
297
  u();
281
298
  }
@@ -294,36 +311,27 @@ function S(e, a = {}, s = window) {
294
311
  return Promise.resolve(d);
295
312
  },
296
313
  speak(e, t) {
297
- K();
298
- let r = ++j, i = q();
299
- if (A = !1, k = e.rate, i.src || (i.src = n, i.play().catch(m)), T.state === "error" && (w.length = 0, I({
314
+ J();
315
+ let r = ++j, i = Y();
316
+ if (A = !1, I = !0, k = e.rate, i.src || (i.src = n, i.play().catch(g)), T.state === "error" && (C.length = 0, L({
300
317
  state: "idle",
301
318
  progress: 0
302
- })), !H()) {
319
+ })), !U()) {
303
320
  t.onError({
304
321
  code: "engine-failed",
305
322
  message: "HD voice is unavailable on this page."
306
323
  });
307
324
  return;
308
325
  }
309
- let a = C.get(_(e.voice, e.text)), o = a ? [{
310
- part: {
311
- text: e.text,
312
- offset: 0
313
- },
314
- ...a
315
- }] : x(e.text).map((t) => ({
316
- part: t,
317
- ...W(e.voice, t.text)
318
- })), s = new Set(o.map((e) => e.id));
319
- P = s, queueMicrotask(() => {
320
- P === s && G(s);
321
- }), J(o, t, r);
326
+ let a = K(e.voice, e.text, !0), o = new Set(a.map((e) => e.id));
327
+ P = o, queueMicrotask(() => {
328
+ P === o && q(o);
329
+ }), X(a, t, r);
322
330
  },
323
331
  prepare(e) {
324
- if (T.state === "error" || !H()) return;
325
- let t = W(e.voice, e.text);
326
- P?.add(t.id), t.clip.catch(m);
332
+ if (T.state === "error" || !U()) return;
333
+ let t = I ? [G(e.voice, e.text)] : K(e.voice, e.text, !1);
334
+ for (let e of t) P?.add(e.id), e.clip.catch(g);
327
335
  },
328
336
  setRate(e) {
329
337
  k = e, O && (O.playbackRate = e);
@@ -334,21 +342,21 @@ function S(e, a = {}, s = window) {
334
342
  resume() {
335
343
  A = !1;
336
344
  let e = F;
337
- F = null, e ? e() : O?.play().catch(m);
345
+ F = null, e ? e() : O?.play().catch(g);
338
346
  },
339
347
  cancel() {
340
- j++, K();
348
+ j++, I = !1, J();
341
349
  }
342
350
  };
343
351
  }
344
352
  // src/worker/worker.ts?worker-source
345
- var C = "var L=Float32Array.from({length:512},(t,e)=>.5-.5*Math.cos(2*Math.PI*e/512)),Q=Float64Array.from({length:256},(t,e)=>Math.cos(2*Math.PI*e/512)),X=Float64Array.from({length:256},(t,e)=>Math.sin(2*Math.PI*e/512)),tt=et(512);function et(t){let e=new Uint16Array(t),r=Math.log2(t);for(let s=0;s<t;s++){let n=0;for(let i=0;i<r;i++)n|=(s>>i&1)<<r-1-i;e[s]=n}return e}function nt(t,e,r=75){let s=2*Math.PI*r/e,n=Math.sin(s)/Math.SQRT2,i=Math.cos(s),c=1+n,o=(1+i)/2/c,a=-(1+i)/c,l=-2*i/c,f=(1-n)/c,p=0,m=0,y=0,h=0;for(let d=0;d<t.length;d++){let b=t[d],u=o*b+a*p+o*m-l*y-f*h;m=p,p=b,h=y,y=u,t[d]=u}}function R(t,e,r){for(let n=0;n<512;n++){let i=tt[n];if(n<i){let c=t[n],o=e[n];t[n]=t[i],e[n]=e[i],t[i]=c,e[i]=o}}let s=r?1:-1;for(let n=2;n<=512;n<<=1){let i=n>>1,c=512/n;for(let o=0;o<512;o+=n)for(let a=0;a<i;a++){let l=Q[a*c],f=s*X[a*c],p=o+a,m=p+i,y=t[m],h=e[m],d=y*l-h*f,b=y*f+h*l,u=t[p],w=e[p];t[m]=u-d,e[m]=w-b,t[p]=u+d,e[p]=w+b}}}function rt(t,e){let r=new Float64Array(e);for(let c=0;c<e;c++){let o=0;for(let a=0;a<257;a++)o+=t[c*257+a]**2;r[c]=o}let n=Array.from({length:e},(c,o)=>o).sort((c,o)=>r[c]-r[o]).slice(0,Math.max(4,Math.floor(e*.15))),i=new Float32Array(257);for(let c=0;c<257;c++){let o=0,a=0;for(let p of n){let m=t[p*257+c]??0;o+=m,a+=m*m}let l=o/n.length,f=Math.max(0,a/n.length-l*l);i[c]=l+1.5*Math.sqrt(f)}return i}function ot(t){let e=Math.min(120,t.length>>1);for(let r=0;r<e;r++){let s=r/e,n=t.length-1-r;t[r]=t[r]*s,t[n]=t[n]*s}}function k(t,e){let r=Float32Array.from(t);nt(r,e);let s=Math.max(1,Math.ceil((r.length+512)/128)),n=new Float32Array(s*128+512);n.set(r,256);let i=new Float32Array(s*512),c=new Float32Array(s*512),o=new Float32Array(s*257);for(let h=0;h<s;h++){let d=i.subarray(h*512,(h+1)*512),b=c.subarray(h*512,(h+1)*512);for(let u=0;u<512;u++)d[u]=n[h*128+u]*L[u];R(d,b,!1);for(let u=0;u<257;u++){let w=d[u],A=b[u];o[h*257+u]=Math.sqrt(w*w+A*A)}}let a=rt(o,s),l=new Float32Array(n.length),f=new Float32Array(n.length),p=new Float32Array(257),m=new Float32Array(257).fill(1);for(let h=0;h<s;h++){for(let u=0;u<257;u++){let w=o[h*257+u]/(a[u]+1e-9),A=Math.min(1,Math.max(0,(w-1)/1));p[u]=.06+(1-.06)*A*A*(3-2*A)}for(let u=0;u<257;u++){let w=p[u],A=((p[u-1]??w)+2*w+(p[u+1]??w))/4;m[u]=Math.max(A,m[u]*.5)}let d=i.subarray(h*512,(h+1)*512),b=c.subarray(h*512,(h+1)*512);for(let u=0;u<257;u++){let w=m[u];d[u]=d[u]*w,b[u]=b[u]*w,u>0&&u<256&&(d[512-u]=d[u],b[512-u]=-b[u])}R(d,b,!0);for(let u=0;u<512;u++){let w=L[u],A=h*128+u;l[A]=l[A]+d[u]/512*w,f[A]=f[A]+w*w}}let y=new Float32Array(r.length);for(let h=0;h<r.length;h++){let d=f[h+256];y[h]=d>1e-6?l[h+256]/d:0}return ot(y),y}function C(t,e){let r=Math.round(e*.02),s=[],n=0;for(let o=0;o+r<=t.length;o+=r){let a=0;for(let l=o;l<o+r;l++){let f=t[l];a+=f*f,n=Math.max(n,Math.abs(f))}s.push(Math.sqrt(a/r))}if(!s.length||n===0)return t;s.sort((o,a)=>o-a);let i=s[Math.floor(s.length*.9)]??0,c=Math.min(2,Math.max(1/2,.2/(i||1)),.95/n);for(let o=0;o<t.length;o++)t[o]=t[o]*c;return t}function st(t,e){let r=t.length*2,s=new ArrayBuffer(44+r),n=new DataView(s);function i(c,o){for(let a=0;a<o.length;a++)n.setUint8(c+a,o.charCodeAt(a))}i(0,\"RIFF\"),n.setUint32(4,36+r,!0),i(8,\"WAVE\"),i(12,\"fmt \"),n.setUint32(16,16,!0),n.setUint16(20,1,!0),n.setUint16(22,1,!0),n.setUint32(24,e,!0),n.setUint32(28,e*2,!0),n.setUint16(32,2,!0),n.setUint16(34,16,!0),i(36,\"data\"),n.setUint32(40,r,!0);for(let c=0;c<t.length;c++){let o=Math.max(-1,Math.min(1,t[c]));n.setInt16(44+c*2,o*32767,!0)}return s}var Tt=`data:audio/wav;base64,${btoa(String.fromCharCode(...new Uint8Array(st(new Float32Array(240),24e3))))}`;async function at(t){let e=new Response(t).body;if(!e)throw new Error(\"Streams are unavailable\");let r=e.pipeThrough(new DecompressionStream(\"deflate-raw\"));return new Uint8Array(await new Response(r).arrayBuffer())}async function it(t){let e=new DataView(t),r=t.byteLength-22;for(;r>=0&&e.getUint32(r,!0)!==101010256;)r--;if(r<0)throw new Error(\"Not a zip file\");let s=e.getUint16(r+10,!0),n=e.getUint32(r+16,!0),i=new Map,c=new TextDecoder;for(let o=0;o<s;o++){if(e.getUint32(n,!0)!==33639248)throw new Error(\"Corrupt zip directory\");let a=e.getUint16(n+10,!0),l=e.getUint32(n+20,!0),f=e.getUint16(n+28,!0),p=e.getUint16(n+30,!0),m=e.getUint16(n+32,!0),y=e.getUint32(n+42,!0),h=c.decode(new Uint8Array(t,n+46,f)),d=y+30+e.getUint16(y+26,!0)+e.getUint16(y+28,!0),b=new Uint8Array(t,d,l);if(a===0)i.set(h,b);else if(a===8)i.set(h,await at(b));else throw new Error(`Unsupported zip method ${a}`);n+=46+f+p+m}return i}function ct(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=t[6]!==void 0&&t[6]>=2,s=r?e.getUint32(8,!0):e.getUint16(8,!0),n=(r?12:10)+s,i=new TextDecoder().decode(t.subarray(r?12:10,n)),c=/'descr':\\s*'([^']+)'/.exec(i)?.[1],o=(/'shape':\\s*\\(([^)]*)\\)/.exec(i)?.[1]??\"\").split(\",\").map(m=>m.trim()).filter(Boolean).map(Number);if(/'fortran_order':\\s*True/.test(i))throw new Error(\"Fortran-order arrays are not supported\");let a=o.length>1?o[0]??1:1,l=o.slice(o.length>1?1:0).reduce((m,y)=>m*y,1),f=t.slice(n),p;if(c===\"<f4\")p=new Float32Array(f.buffer);else if(c===\"<f8\")p=Float32Array.from(new Float64Array(f.buffer));else throw new Error(`Unsupported npy dtype ${c}`);return{data:p,rows:a,cols:l}}async function B(t){let e=new Map;for(let[r,s]of await it(t))r.endsWith(\".npy\")&&e.set(r.slice(0,-4),ct(s));return e}var I=`[${';:,.!?\\xA1\\xBF\\u2014\\u2026\"\\xAB\\xBB\\u201C\\u201D()[]{}'.replace(/[\\]\\\\[^-]/g,\"\\\\$&\")}]`,N=[\"$\",...';:,.!?\\xA1\\xBF\\u2014\\u2026\"\\xAB\\xBB\"\" ',...\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",...\"\\u0251\\u0250\\u0252\\xE6\\u0253\\u0299\\u03B2\\u0254\\u0255\\xE7\\u0257\\u0256\\xF0\\u02A4\\u0259\\u0258\\u025A\\u025B\\u025C\\u025D\\u025E\\u025F\\u0284\\u0261\\u0260\\u0262\\u029B\\u0266\\u0267\\u0127\\u0265\\u029C\\u0268\\u026A\\u029D\\u026D\\u026C\\u026B\\u026E\\u029F\\u0271\\u026F\\u0270\\u014B\\u0273\\u0272\\u0274\\xF8\\u0275\\u0278\\u03B8\\u0153\\u0276\\u0298\\u0279\\u027A\\u027E\\u027B\\u0280\\u0281\\u027D\\u0282\\u0283\\u0288\\u02A7\\u0289\\u028A\\u028B\\u2C71\\u028C\\u0263\\u0264\\u028D\\u03C7\\u028E\\u028F\\u0291\\u0290\\u0292\\u0294\\u02A1\\u0295\\u02A2\\u01C0\\u01C1\\u01C2\\u01C3\\u02C8\\u02CC\\u02D0\\u02D1\\u02BC\\u02B4\\u02B0\\u02B1\\u02B2\\u02B7\\u02E0\\u02E4\\u02DE\\u2193\\u2191\\u2192\\u2197\\u2198'\\u0329'\\u1D7B\"],v=new Map(N.map((t,e)=>[t,e])),Rt=N.length,O=/[\\p{L}\\p{M}\\p{N}_]+|[^\\p{L}\\p{M}\\p{N}_\\s]/gu,z=new RegExp(`^(${I}*)(.*?)(${I}*)$`,\"su\"),D=v.get(\" \");function ut(t){return t.replace(/[‘’‚‛′]/g,\"'\").replace(/[“”„‟″]/g,'\"').replace(/[–―]/g,\"\\u2014\").replace(/\\s+/g,\" \").trim()}function lt(t){return/[.!?,;:]$/.test(t)?t:`${t},`}function ft(t){let e=[];for(let r of(t.match(O)??[]).join(\" \")){let s=v.get(r);s!==void 0&&e.push(s)}return e}function mt(t,e){if(t.length===e)return t.map((o,a)=>a);let r=t.map(o=>Math.max(1,o.length)),s=r.reduce((o,a)=>o+a,0),n=[],i=0,c=r[0]??0;for(let o=0;o<e;o++){let a=(o+.5)/e*s;for(;a>c&&i<t.length-1;)c+=r[++i]??0;n.push(i)}return n}async function H(t,e){let r=t.match(/\\S+/g)??[],s=r.map((l,f)=>{let[,p=\"\",m=\"\",y=\"\"]=z.exec(ut(f===r.length-1?lt(l):l))??[];return{lead:p,core:m,trail:y}}),n=s.map(()=>\"\"),i=[];async function c(){let l=i.filter(m=>s[m]?.core);if(i=[],!l.length)return;let f=(await e(l.map(m=>s[m]?.core).join(\" \"))).trim().split(/\\s+/).filter(Boolean),p=mt(l.map(m=>s[m]?.core??\"\"),f.length);f.forEach((m,y)=>{let h=l[p[y]??0]??0;n[h]=n[h]?`${n[h]} ${m}`:m})}for(let[l,f]of s.entries())f.lead&&await c(),i.push(l),f.trail&&await c();await c();let o=[0],a=[];for(let[l,f]of s.entries()){let p=ft(f.lead+(n[l]??\"\")+f.trail);p.length&&o.length>1&&o.push(D),a.push(o.length),o.push(...p)}return o.push(10,0),{ids:o,words:a}}function $(t,e,r){let s=new Float64Array(e.length+1);for(let n=0;n<e.length;n++)s[n+1]=s[n]+Number(e[n]);return Float32Array.from(t,n=>s[Math.min(n,e.length)]*r)}var W=\"lantun-voice-kitten-v1\";var K=0,S=null,P=[],T=!1;function x(t,e=[]){self.postMessage(t,e)}function j(t){return String(t?.message??t)}function q(t){K+=t,x({type:\"progress\",loaded:K})}function gt(t,e){let r=new Uint8Array(e),s=0;for(let n of t)r.set(n,s),s+=n.length;return r}function yt(){return new Promise(t=>setTimeout(t,0))}async function _(t){let e=await caches.open(W).catch(()=>null),r=await e?.match(t);if(r){let a=await r.arrayBuffer();return q(a.byteLength),a}let s=await fetch(t);if(!s.ok||!s.body)throw new Error(`HTTP ${s.status} for ${t}`);let n=s.body.getReader(),i=[],c=0;for(;;){let{done:a,value:l}=await n.read();if(a)break;i.push(l),c+=l.length,q(l.length)}let o=gt(i,c);return await e?.put(t,new Response(o)).catch(()=>{}),o.buffer}async function wt(t){let[e,r,s,n,i,c]=await Promise.all([import(t.ort),import(t.phonemizer),_(t.model),_(t.ortWasm),_(t.voices).then(B),fetch(t.config).then(f=>f.json())]);e.env.wasm.wasmBinary=n,e.env.wasm.wasmPaths=t.ortWasm.slice(0,t.ortWasm.lastIndexOf(\"/\")+1),e.env.wasm.numThreads=self.crossOriginIsolated?Math.min(4,navigator.hardwareConcurrency||1):1;let o=await e.InferenceSession.create(s,{executionProviders:[\"wasm\"],graphOptimizationLevel:\"all\"}),a=new Map;async function l(f){let p=a.get(f);if(p!==void 0)return p;let m=(await r.phonemize(f,\"en-us\")).join(\" \").replace(/_/g,\"\").replace(/\\n/g,\" \");return a.size>5e3&&a.clear(),a.set(f,m),m}return{ort:e,session:o,phonemize:l,voices:i,config:c}}async function bt(t,e,r,s){let n=t.voices.get(t.config.voice_aliases?.[r]??r);if(!n)throw new Error(`Unknown voice ${r}`);let{ids:i,words:c}=await H(e,t.phonemize),o=Math.min(e.length,n.rows-1),{Tensor:a}=t.ort,l=await t.session.run({input_ids:new a(\"int64\",BigInt64Array.from(i,BigInt),[1,i.length]),style:new a(\"float32\",n.data.slice(o*n.cols,(o+1)*n.cols),[1,n.cols]),speed:new a(\"float32\",new Float32Array([s]),[1])}),f=l.waveform?.data,p=l.duration?.data;if(!f||!p)throw new Error(\"Model returned no audio\");let m=Math.max(0,Number(p[0]??0)*600-1200),y=$(c,p,600/24e3).map(d=>Math.max(0,d-m/24e3)),h=f.subarray(m,Math.max(m,f.length-5e3));return{samples:C(k(h,24e3),24e3),starts:y}}async function At(t){try{let e=await S,r=performance.now(),{samples:s,starts:n}=await bt(e,t.text,t.voice,t.speed);x({type:\"audio\",id:t.id,samples:s,starts:n,ms:performance.now()-r},[s.buffer,n.buffer])}catch(e){x({type:\"error\",id:t.id,message:j(e)})}}async function V(){if(!(T||!S)){T=!0;try{let t=P.shift();for(;t;)await At(t),await yt(),t=P.shift()}finally{T=!1}}}function Mt(t){let e=t.data;switch(e.type){case\"load\":S??(S=wt(e.sources)),S.then(()=>x({type:\"ready\"}),r=>x({type:\"error\",message:j(r)})),V();return;case\"synth\":P.push(e),V();return;case\"drop\":{let r=new Set(e.keep);P=P.filter(s=>r.has(s.id))}}}self.onmessage=Mt;\n";
353
+ var E = "var R=Float32Array.from({length:512},(t,e)=>.5-.5*Math.cos(2*Math.PI*e/512)),Q=Float64Array.from({length:256},(t,e)=>Math.cos(2*Math.PI*e/512)),Y=Float64Array.from({length:256},(t,e)=>Math.sin(2*Math.PI*e/512)),X=tt(512);function tt(t){let e=new Uint16Array(t),r=Math.log2(t);for(let o=0;o<t;o++){let n=0;for(let i=0;i<r;i++)n|=(o>>i&1)<<r-1-i;e[o]=n}return e}function et(t,e,r=75){let o=2*Math.PI*r/e,n=Math.sin(o)/Math.SQRT2,i=Math.cos(o),c=1+n,s=(1+i)/2/c,a=-(1+i)/c,l=-2*i/c,f=(1-n)/c,p=0,m=0,y=0,h=0;for(let d=0;d<t.length;d++){let b=t[d],u=s*b+a*p+s*m-l*y-f*h;m=p,p=b,h=y,y=u,t[d]=u}}function k(t,e,r){for(let n=0;n<512;n++){let i=X[n];if(n<i){let c=t[n],s=e[n];t[n]=t[i],e[n]=e[i],t[i]=c,e[i]=s}}let o=r?1:-1;for(let n=2;n<=512;n<<=1){let i=n>>1,c=512/n;for(let s=0;s<512;s+=n)for(let a=0;a<i;a++){let l=Q[a*c],f=o*Y[a*c],p=s+a,m=p+i,y=t[m],h=e[m],d=y*l-h*f,b=y*f+h*l,u=t[p],w=e[p];t[m]=u-d,e[m]=w-b,t[p]=u+d,e[p]=w+b}}}function nt(t,e){let r=new Float64Array(e);for(let c=0;c<e;c++){let s=0;for(let a=0;a<257;a++)s+=t[c*257+a]**2;r[c]=s}let n=Array.from({length:e},(c,s)=>s).sort((c,s)=>r[c]-r[s]).slice(0,Math.max(4,Math.floor(e*.15))),i=new Float32Array(257);for(let c=0;c<257;c++){let s=0,a=0;for(let p of n){let m=t[p*257+c]??0;s+=m,a+=m*m}let l=s/n.length,f=Math.max(0,a/n.length-l*l);i[c]=l+1.5*Math.sqrt(f)}return i}function rt(t){let e=Math.min(120,t.length>>1);for(let r=0;r<e;r++){let o=r/e,n=t.length-1-r;t[r]=t[r]*o,t[n]=t[n]*o}}function I(t,e){let r=Float32Array.from(t);et(r,e);let o=Math.max(1,Math.ceil((r.length+512)/128)),n=new Float32Array(o*128+512);n.set(r,256);let i=new Float32Array(o*512),c=new Float32Array(o*512),s=new Float32Array(o*257);for(let h=0;h<o;h++){let d=i.subarray(h*512,(h+1)*512),b=c.subarray(h*512,(h+1)*512);for(let u=0;u<512;u++)d[u]=n[h*128+u]*R[u];k(d,b,!1);for(let u=0;u<257;u++){let w=d[u],A=b[u];s[h*257+u]=Math.sqrt(w*w+A*A)}}let a=nt(s,o),l=new Float32Array(n.length),f=new Float32Array(n.length),p=new Float32Array(257),m=new Float32Array(257).fill(1);for(let h=0;h<o;h++){for(let u=0;u<257;u++){let w=s[h*257+u]/(a[u]+1e-9),A=Math.min(1,Math.max(0,(w-1)/1));p[u]=.06+(1-.06)*A*A*(3-2*A)}for(let u=0;u<257;u++){let w=p[u],A=((p[u-1]??w)+2*w+(p[u+1]??w))/4;m[u]=Math.max(A,m[u]*.5)}let d=i.subarray(h*512,(h+1)*512),b=c.subarray(h*512,(h+1)*512);for(let u=0;u<257;u++){let w=m[u];d[u]=d[u]*w,b[u]=b[u]*w,u>0&&u<256&&(d[512-u]=d[u],b[512-u]=-b[u])}k(d,b,!0);for(let u=0;u<512;u++){let w=R[u],A=h*128+u;l[A]=l[A]+d[u]/512*w,f[A]=f[A]+w*w}}let y=new Float32Array(r.length);for(let h=0;h<r.length;h++){let d=f[h+256];y[h]=d>1e-6?l[h+256]/d:0}return rt(y),y}function L(t,e){let r=Math.round(e*.02),o=[],n=0;for(let s=0;s+r<=t.length;s+=r){let a=0;for(let l=s;l<s+r;l++){let f=t[l];a+=f*f,n=Math.max(n,Math.abs(f))}o.push(Math.sqrt(a/r))}if(!o.length||n===0)return t;o.sort((s,a)=>s-a);let i=o[Math.floor(o.length*.9)]??0,c=Math.min(2,Math.max(1/2,.2/(i||1)),.95/n);for(let s=0;s<t.length;s++)t[s]=t[s]*c;return t}function ot(t,e){let r=t.length*2,o=new ArrayBuffer(44+r),n=new DataView(o);function i(c,s){for(let a=0;a<s.length;a++)n.setUint8(c+a,s.charCodeAt(a))}i(0,\"RIFF\"),n.setUint32(4,36+r,!0),i(8,\"WAVE\"),i(12,\"fmt \"),n.setUint32(16,16,!0),n.setUint16(20,1,!0),n.setUint16(22,1,!0),n.setUint32(24,e,!0),n.setUint32(28,e*2,!0),n.setUint16(32,2,!0),n.setUint16(34,16,!0),i(36,\"data\"),n.setUint32(40,r,!0);for(let c=0;c<t.length;c++){let s=Math.max(-1,Math.min(1,t[c]));n.setInt16(44+c*2,s*32767,!0)}return o}var Tt=`data:audio/wav;base64,${btoa(String.fromCharCode(...new Uint8Array(ot(new Float32Array(240),24e3))))}`;async function st(t){let e=new Response(t).body;if(!e)throw new Error(\"Streams are unavailable\");let r=e.pipeThrough(new DecompressionStream(\"deflate-raw\"));return new Uint8Array(await new Response(r).arrayBuffer())}async function at(t){let e=new DataView(t),r=t.byteLength-22;for(;r>=0&&e.getUint32(r,!0)!==101010256;)r--;if(r<0)throw new Error(\"Not a zip file\");let o=e.getUint16(r+10,!0),n=e.getUint32(r+16,!0),i=new Map,c=new TextDecoder;for(let s=0;s<o;s++){if(e.getUint32(n,!0)!==33639248)throw new Error(\"Corrupt zip directory\");let a=e.getUint16(n+10,!0),l=e.getUint32(n+20,!0),f=e.getUint16(n+28,!0),p=e.getUint16(n+30,!0),m=e.getUint16(n+32,!0),y=e.getUint32(n+42,!0),h=c.decode(new Uint8Array(t,n+46,f)),d=y+30+e.getUint16(y+26,!0)+e.getUint16(y+28,!0),b=new Uint8Array(t,d,l);if(a===0)i.set(h,b);else if(a===8)i.set(h,await st(b));else throw new Error(`Unsupported zip method ${a}`);n+=46+f+p+m}return i}function it(t){let e=new DataView(t.buffer,t.byteOffset,t.byteLength),r=t[6]!==void 0&&t[6]>=2,o=r?e.getUint32(8,!0):e.getUint16(8,!0),n=(r?12:10)+o,i=new TextDecoder().decode(t.subarray(r?12:10,n)),c=/'descr':\\s*'([^']+)'/.exec(i)?.[1],s=(/'shape':\\s*\\(([^)]*)\\)/.exec(i)?.[1]??\"\").split(\",\").map(m=>m.trim()).filter(Boolean).map(Number);if(/'fortran_order':\\s*True/.test(i))throw new Error(\"Fortran-order arrays are not supported\");let a=s.length>1?s[0]??1:1,l=s.slice(s.length>1?1:0).reduce((m,y)=>m*y,1),f=t.slice(n),p;if(c===\"<f4\")p=new Float32Array(f.buffer);else if(c===\"<f8\")p=Float32Array.from(new Float64Array(f.buffer));else throw new Error(`Unsupported npy dtype ${c}`);return{data:p,rows:a,cols:l}}async function C(t){let e=new Map;for(let[r,o]of await at(t))r.endsWith(\".npy\")&&e.set(r.slice(0,-4),it(o));return e}var B=`[${';:,.!?\\xA1\\xBF\\u2014\\u2026\"\\xAB\\xBB\\u201C\\u201D()[]{}'.replace(/[\\]\\\\[^-]/g,\"\\\\$&\")}]`,ct=[\"$\",...';:,.!?\\xA1\\xBF\\u2014\\u2026\"\\xAB\\xBB\"\" ',...\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\",...\"\\u0251\\u0250\\u0252\\xE6\\u0253\\u0299\\u03B2\\u0254\\u0255\\xE7\\u0257\\u0256\\xF0\\u02A4\\u0259\\u0258\\u025A\\u025B\\u025C\\u025D\\u025E\\u025F\\u0284\\u0261\\u0260\\u0262\\u029B\\u0266\\u0267\\u0127\\u0265\\u029C\\u0268\\u026A\\u029D\\u026D\\u026C\\u026B\\u026E\\u029F\\u0271\\u026F\\u0270\\u014B\\u0273\\u0272\\u0274\\xF8\\u0275\\u0278\\u03B8\\u0153\\u0276\\u0298\\u0279\\u027A\\u027E\\u027B\\u0280\\u0281\\u027D\\u0282\\u0283\\u0288\\u02A7\\u0289\\u028A\\u028B\\u2C71\\u028C\\u0263\\u0264\\u028D\\u03C7\\u028E\\u028F\\u0291\\u0290\\u0292\\u0294\\u02A1\\u0295\\u02A2\\u01C0\\u01C1\\u01C2\\u01C3\\u02C8\\u02CC\\u02D0\\u02D1\\u02BC\\u02B4\\u02B0\\u02B1\\u02B2\\u02B7\\u02E0\\u02E4\\u02DE\\u2193\\u2191\\u2192\\u2197\\u2198'\\u0329'\\u1D7B\"],T=new Map(ct.map((t,e)=>[t,e])),N=/[\\p{L}\\p{M}\\p{N}_]+|[^\\p{L}\\p{M}\\p{N}_\\s]/gu,z=new RegExp(`^(${B}*)(.*?)(${B}*)$`,\"su\"),O=T.get(\" \");function ut(t){return t.replace(/[‘’‚‛′]/g,\"'\").replace(/[“”„‟″]/g,'\"').replace(/[–―]/g,\"\\u2014\").replace(/\\s+/g,\" \").trim()}function lt(t){return/[.!?,;:]$/.test(t)?t:`${t},`}function ft(t){let e=[];for(let r of(t.match(N)??[]).join(\" \")){let o=T.get(r);o!==void 0&&e.push(o)}return e}function mt(t,e){if(t.length===e)return t.map((s,a)=>a);let r=t.map(s=>Math.max(1,s.length)),o=r.reduce((s,a)=>s+a,0),n=[],i=0,c=r[0]??0;for(let s=0;s<e;s++){let a=(s+.5)/e*o;for(;a>c&&i<t.length-1;)c+=r[++i]??0;n.push(i)}return n}async function D(t,e){let r=t.match(/\\S+/g)??[],o=r.map((l,f)=>{let[,p=\"\",m=\"\",y=\"\"]=z.exec(ut(f===r.length-1?lt(l):l))??[];return{lead:p,core:m,trail:y}}),n=o.map(()=>\"\"),i=[];async function c(){let l=i.filter(m=>o[m]?.core);if(i=[],!l.length)return;let f=(await e(l.map(m=>o[m]?.core).join(\" \"))).trim().split(/\\s+/).filter(Boolean),p=mt(l.map(m=>o[m]?.core??\"\"),f.length);f.forEach((m,y)=>{let h=l[p[y]??0]??0;n[h]=n[h]?`${n[h]} ${m}`:m})}for(let[l,f]of o.entries())f.lead&&await c(),i.push(l),f.trail&&await c();await c();let s=[0],a=[];for(let[l,f]of o.entries()){let p=ft(f.lead+(n[l]??\"\")+f.trail);p.length&&s.length>1&&s.push(O),a.push(s.length),s.push(...p)}return s.push(10,0),{ids:s,words:a}}function H(t,e,r){let o=new Float64Array(e.length+1);for(let n=0;n<e.length;n++)o[n+1]=o[n]+Number(e[n]);return Float32Array.from(t,n=>o[Math.min(n,e.length)]*r)}var $=\"lantun-voice-kitten-v1\";var G=0,P=null,M=[],_=!1;function x(t,e=[]){self.postMessage(t,e)}function V(t){return String(t?.message??t)}function K(t){G+=t,x({type:\"progress\",loaded:G})}function gt(t,e){let r=new Uint8Array(e),o=0;for(let n of t)r.set(n,o),o+=n.length;return r}function yt(){return new Promise(t=>setTimeout(t,0))}async function F(t){let e=await caches.open($).catch(()=>null),r=await e?.match(t);if(r){let a=await r.arrayBuffer();return K(a.byteLength),a}let o=await fetch(t);if(!o.ok||!o.body)throw new Error(`HTTP ${o.status} for ${t}`);let n=o.body.getReader(),i=[],c=0;for(;;){let{done:a,value:l}=await n.read();if(a)break;i.push(l),c+=l.length,K(l.length)}let s=gt(i,c);return await e?.put(t,new Response(s)).catch(()=>{}),s.buffer}async function wt(t){let[e,r,o,n,i,c]=await Promise.all([import(t.ort),import(t.phonemizer),F(t.model),F(t.ortWasm),F(t.voices).then(C),F(t.config).then(f=>JSON.parse(new TextDecoder().decode(f)))]);e.env.wasm.wasmBinary=n,e.env.wasm.wasmPaths=t.ortWasm.slice(0,t.ortWasm.lastIndexOf(\"/\")+1),e.env.wasm.numThreads=self.crossOriginIsolated?Math.min(4,navigator.hardwareConcurrency||1):1;let s=await e.InferenceSession.create(o,{executionProviders:[\"wasm\"],graphOptimizationLevel:\"all\"}),a=new Map;async function l(f){let p=a.get(f);if(p!==void 0)return p;let m=(await r.phonemize(f,\"en-us\")).join(\" \").replace(/_/g,\"\").replace(/\\n/g,\" \");return a.size>5e3&&a.clear(),a.set(f,m),m}return{ort:e,session:s,phonemize:l,voices:i,config:c}}async function bt(t,e,r,o){let n=t.voices.get(t.config.voice_aliases?.[r]??r);if(!n)throw new Error(`Unknown voice ${r}`);let{ids:i,words:c}=await D(e,t.phonemize),s=Math.min(e.length,n.rows-1),{Tensor:a}=t.ort,l=await t.session.run({input_ids:new a(\"int64\",BigInt64Array.from(i,BigInt),[1,i.length]),style:new a(\"float32\",n.data.slice(s*n.cols,(s+1)*n.cols),[1,n.cols]),speed:new a(\"float32\",new Float32Array([o]),[1])}),f=l.waveform?.data,p=l.duration?.data;if(!f||!p)throw new Error(\"Model returned no audio\");let m=Math.max(0,Number(p[0]??0)*600-1200),y=H(c,p,600/24e3).map(d=>Math.max(0,d-m/24e3)),h=f.subarray(m,Math.max(m,f.length-5e3));return{samples:L(I(h,24e3),24e3),starts:y}}async function At(t){try{let e=await P,r=performance.now(),{samples:o,starts:n}=await bt(e,t.text,t.voice,t.speed);x({type:\"audio\",id:t.id,samples:o,starts:n,ms:performance.now()-r},[o.buffer,n.buffer])}catch(e){x({type:\"error\",id:t.id,message:V(e)})}}async function q(){if(!(_||!P)){_=!0;try{let t=M.shift();for(;t;)await At(t),await yt(),t=M.shift()}finally{_=!1}}}function Et(t){let e=t.data;switch(e.type){case\"load\":P??(P=wt(e.sources)),P.then(()=>x({type:\"ready\"}),r=>x({type:\"error\",message:V(r)})),q();return;case\"synth\":{let r=e.urgent?M.findIndex(o=>!o.urgent):-1;M.splice(r<0?M.length:r,0,e),q();return}case\"drop\":{let r=new Set(e.keep);M=M.filter(o=>r.has(o.id))}}}self.onmessage=Et;\n";
346
354
  // src/index.ts
347
- function w() {
348
- let e = URL.createObjectURL(new Blob([C], { type: "text/javascript" }));
355
+ function D() {
356
+ let e = URL.createObjectURL(new Blob([E], { type: "text/javascript" }));
349
357
  return new Worker(e, { type: "module" });
350
358
  }
351
- function T(e) {
352
- return S(w, e);
359
+ function O(e) {
360
+ return T(D, e);
353
361
  }
354
- export { i as VOICE_NAMES, T as kittenVoices };
362
+ export { i as VOICE_NAMES, O as kittenVoices };
@@ -1,7 +1,6 @@
1
1
  export declare const PUNCT: string;
2
2
  export declare const SYMBOLS: string[];
3
3
  export declare const IDS: Map<string, number>;
4
- export declare const SYMBOL_COUNT: number;
5
4
  export declare const TOKENS: RegExp;
6
5
  export declare const EDGES: RegExp;
7
6
  export declare const SPACE: number;
@@ -16,6 +16,7 @@ export type ToWorker = {
16
16
  text: string;
17
17
  voice: string;
18
18
  speed: number;
19
+ urgent: boolean;
19
20
  } | {
20
21
  type: "drop";
21
22
  keep: number[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lantun/voice-kitten",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Lifelike, on-device English voices for Lantun, powered by Kitten TTS. Nothing downloads until a reader picks one.",
5
5
  "keywords": [
6
6
  "text-to-speech",
@@ -34,10 +34,10 @@
34
34
  "access": "public"
35
35
  },
36
36
  "peerDependencies": {
37
- "@lantun/core": "^0.1.1"
37
+ "@lantun/core": "^0.1.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@lantun/core": "^0.1.1",
40
+ "@lantun/core": "^0.1.2",
41
41
  "esbuild": "^0.28.2",
42
42
  "jsdom": "^30.1.3",
43
43
  "typescript": "^7.0.2",