@lantun/voice-kitten 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +14 -2
- package/dist/audio/audio.constants.d.ts +14 -0
- package/dist/audio/audio.lib.d.ts +5 -0
- package/dist/engine/engine.constants.d.ts +16 -0
- package/dist/engine/engine.d.ts +3 -0
- package/dist/engine/engine.lib.d.ts +11 -0
- package/dist/engine/engine.types.d.ts +37 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +354 -0
- package/dist/npz/npz.lib.d.ts +4 -0
- package/dist/npz/npz.types.d.ts +5 -0
- package/dist/text/text.constants.d.ts +7 -0
- package/dist/text/text.lib.d.ts +7 -0
- package/dist/text/text.types.d.ts +5 -0
- package/dist/worker/worker.constants.d.ts +6 -0
- package/dist/worker/worker.types.d.ts +80 -0
- package/package.json +49 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 rizkianakbar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @lantun/voice-kitten
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lifelike English voices for [Lantun](https://github.com/rizkianakbar/lantun), generated on the reader's device with Kitten TTS. Nothing downloads until a reader picks one of these voices (about 31 MB, once).
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install @lantun/core @lantun/voice-kitten
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { init, registerVoices } from "@lantun/core";
|
|
11
|
+
import { kittenVoices } from "@lantun/voice-kitten";
|
|
12
|
+
|
|
13
|
+
registerVoices(kittenVoices());
|
|
14
|
+
init();
|
|
15
|
+
```
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const SIZE = 512;
|
|
2
|
+
export declare const HALF: number;
|
|
3
|
+
export declare const HOP: number;
|
|
4
|
+
export declare const BINS: number;
|
|
5
|
+
export declare const STD_ABOVE = 1.5;
|
|
6
|
+
export declare const PASS = 2;
|
|
7
|
+
export declare const FLOOR = 0.06;
|
|
8
|
+
export declare const QUIET_SHARE = 0.15;
|
|
9
|
+
export declare const FADE_SAMPLES = 120;
|
|
10
|
+
export declare const HIGH_PASS_HZ = 75;
|
|
11
|
+
export declare const TARGET_RMS = 0.2;
|
|
12
|
+
export declare const MAX_PEAK = 0.95;
|
|
13
|
+
export declare const GAIN_RANGE = 2;
|
|
14
|
+
export declare const HEADER_BYTES = 44;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function highPass(x: Float32Array, sampleRate: number, hz?: number): void;
|
|
2
|
+
export declare function denoise(samples: Float32Array, sampleRate: number): Float32Array<ArrayBuffer>;
|
|
3
|
+
export declare function level(x: Float32Array<ArrayBuffer>, sampleRate: number): Float32Array<ArrayBuffer>;
|
|
4
|
+
export declare function encodeWav(samples: Float32Array, sampleRate: number): ArrayBuffer;
|
|
5
|
+
export declare const SILENCE: string;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Sources } from "../worker/worker.types";
|
|
2
|
+
import type { KittenVoiceName } from "./engine.types";
|
|
3
|
+
export declare const VOICE_NAMES: readonly ["Jasper", "Luna", "Bruno", "Rosie", "Hugo", "Leo"];
|
|
4
|
+
export declare const GENDER: Record<KittenVoiceName, "female" | "male">;
|
|
5
|
+
export declare const PACE: Record<KittenVoiceName, number>;
|
|
6
|
+
export declare const DEFAULT_SOURCES: Sources;
|
|
7
|
+
export declare const LOAD_BYTES: number;
|
|
8
|
+
export declare const DOWNLOAD_BYTES = 31000000;
|
|
9
|
+
export declare const MAX_REALTIME_FACTOR = 0.85;
|
|
10
|
+
export declare const JUDGE_AFTER = 3;
|
|
11
|
+
export declare const MIN_JUDGED_SECONDS = 0.5;
|
|
12
|
+
export declare const CACHE_CLIPS = 10;
|
|
13
|
+
export declare const SPLIT_MIN = 90;
|
|
14
|
+
export declare const MIN_PIECE = 25;
|
|
15
|
+
export declare const CLAUSE: RegExp;
|
|
16
|
+
export declare const WORD_TICK_MS = 30;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Voice } from "@lantun/core";
|
|
2
|
+
import type { ClipEntry, EngineWindow, KittenVoiceName, Part } from "./engine.types";
|
|
3
|
+
export declare function debug(...args: unknown[]): void;
|
|
4
|
+
export declare function ignore(): undefined;
|
|
5
|
+
export declare function revoke(entry: ClipEntry): void;
|
|
6
|
+
export declare function nameOf(voice: Voice | null): KittenVoiceName;
|
|
7
|
+
export declare function keyOf(voice: Voice | null, text: string): string;
|
|
8
|
+
export declare function toVoice(name: KittenVoiceName): Voice;
|
|
9
|
+
export declare function wordOffsets(part: Part): number[];
|
|
10
|
+
export declare function canRun(win?: EngineWindow): boolean;
|
|
11
|
+
export declare function splitFirstClause(text: string): Part[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Sources } from "../worker/worker.types";
|
|
2
|
+
import type { VOICE_NAMES } from "./engine.constants";
|
|
3
|
+
export type KittenVoiceName = (typeof VOICE_NAMES)[number];
|
|
4
|
+
export interface KittenOptions {
|
|
5
|
+
sources?: Partial<Sources>;
|
|
6
|
+
voices?: readonly KittenVoiceName[];
|
|
7
|
+
}
|
|
8
|
+
export interface Part {
|
|
9
|
+
text: string;
|
|
10
|
+
offset: number;
|
|
11
|
+
}
|
|
12
|
+
export interface Clip {
|
|
13
|
+
url: string;
|
|
14
|
+
seconds: number;
|
|
15
|
+
starts: Float32Array;
|
|
16
|
+
}
|
|
17
|
+
export interface ClipEntry {
|
|
18
|
+
id: number;
|
|
19
|
+
clip: Promise<Clip>;
|
|
20
|
+
}
|
|
21
|
+
export interface PartClip extends ClipEntry {
|
|
22
|
+
part: Part;
|
|
23
|
+
}
|
|
24
|
+
export interface Pending {
|
|
25
|
+
resolve: (clip: Clip) => void;
|
|
26
|
+
reject: (err: Error) => void;
|
|
27
|
+
}
|
|
28
|
+
export type EngineWindow = Window & {
|
|
29
|
+
Worker?: typeof Worker;
|
|
30
|
+
Audio?: typeof Audio;
|
|
31
|
+
};
|
|
32
|
+
export type EngineNavigator = Navigator & {
|
|
33
|
+
connection?: {
|
|
34
|
+
saveData?: boolean;
|
|
35
|
+
};
|
|
36
|
+
deviceMemory?: number;
|
|
37
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { VoiceEngine } from "@lantun/core";
|
|
2
|
+
import type { KittenOptions } from "./engine/engine.types";
|
|
3
|
+
export { VOICE_NAMES } from "./engine/engine.constants";
|
|
4
|
+
export type { KittenOptions, KittenVoiceName } from "./engine/engine.types";
|
|
5
|
+
export declare function kittenVoices(options?: KittenOptions): VoiceEngine;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
Float32Array.from({ length: 512 }, (e, t) => .5 - .5 * Math.cos(2 * Math.PI * t / 512)), Float64Array.from({ length: 256 }, (e, t) => Math.cos(2 * Math.PI * t / 512)), Float64Array.from({ length: 256 }, (e, t) => Math.sin(2 * Math.PI * t / 512)), e(512);
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = new Uint16Array(e), n = Math.log2(e);
|
|
4
|
+
for (let r = 0; r < e; r++) {
|
|
5
|
+
let e = 0;
|
|
6
|
+
for (let t = 0; t < n; t++) e |= (r >> t & 1) << n - 1 - t;
|
|
7
|
+
t[r] = e;
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
}
|
|
11
|
+
function t(e, t) {
|
|
12
|
+
let n = e.length * 2, r = new ArrayBuffer(44 + n), i = new DataView(r);
|
|
13
|
+
function a(e, t) {
|
|
14
|
+
for (let n = 0; n < t.length; n++) i.setUint8(e + n, t.charCodeAt(n));
|
|
15
|
+
}
|
|
16
|
+
a(0, "RIFF"), i.setUint32(4, 36 + n, !0), a(8, "WAVE"), a(12, "fmt "), i.setUint32(16, 16, !0), i.setUint16(20, 1, !0), i.setUint16(22, 1, !0), i.setUint32(24, t, !0), i.setUint32(28, t * 2, !0), i.setUint16(32, 2, !0), i.setUint16(34, 16, !0), a(36, "data"), i.setUint32(40, n, !0);
|
|
17
|
+
for (let t = 0; t < e.length; t++) {
|
|
18
|
+
let n = Math.max(-1, Math.min(1, e[t]));
|
|
19
|
+
i.setInt16(44 + t * 2, n * 32767, !0);
|
|
20
|
+
}
|
|
21
|
+
return r;
|
|
22
|
+
}
|
|
23
|
+
var n = `data:audio/wav;base64,${btoa(String.fromCharCode(...new Uint8Array(t(/* @__PURE__ */ new Float32Array(240), 24e3))))}`, r = 24e3, i = [
|
|
24
|
+
"Jasper",
|
|
25
|
+
"Luna",
|
|
26
|
+
"Bruno",
|
|
27
|
+
"Rosie",
|
|
28
|
+
"Hugo",
|
|
29
|
+
"Leo"
|
|
30
|
+
], a = {
|
|
31
|
+
Jasper: "male",
|
|
32
|
+
Luna: "female",
|
|
33
|
+
Bruno: "male",
|
|
34
|
+
Rosie: "female",
|
|
35
|
+
Hugo: "male",
|
|
36
|
+
Leo: "male"
|
|
37
|
+
}, o = {
|
|
38
|
+
Jasper: .78,
|
|
39
|
+
Luna: .87,
|
|
40
|
+
Bruno: .85,
|
|
41
|
+
Rosie: .9,
|
|
42
|
+
Hugo: .87,
|
|
43
|
+
Leo: .98
|
|
44
|
+
}, s = "https://huggingface.co/KittenML/kitten-tts-nano-0.8-int8/resolve/main", c = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.24.2/dist", l = {
|
|
45
|
+
model: `${s}/kitten_tts_nano_v0_8.onnx`,
|
|
46
|
+
voices: `${s}/voices.npz`,
|
|
47
|
+
config: `${s}/config.json`,
|
|
48
|
+
ort: `${c}/ort.wasm.min.mjs`,
|
|
49
|
+
ortWasm: `${c}/ort-wasm-simd-threaded.wasm`,
|
|
50
|
+
phonemizer: "https://cdn.jsdelivr.net/npm/phonemizer@1.2.1/dist/phonemizer.js"
|
|
51
|
+
}, u = 3995e4, d = 31e6, f = /[,;:—](?=\s)/g;
|
|
52
|
+
// src/engine/engine.lib.ts
|
|
53
|
+
function p(...e) {
|
|
54
|
+
try {
|
|
55
|
+
localStorage.getItem("lantun:debug") && console.info("[Lantun] kitten:", ...e);
|
|
56
|
+
} catch {}
|
|
57
|
+
}
|
|
58
|
+
function m() {}
|
|
59
|
+
function h(e) {
|
|
60
|
+
e.clip.then((e) => URL.revokeObjectURL(e.url), m);
|
|
61
|
+
}
|
|
62
|
+
function g(e) {
|
|
63
|
+
let t = e?.name ?? "";
|
|
64
|
+
return i.includes(t) ? t : i[0];
|
|
65
|
+
}
|
|
66
|
+
function _(e, t) {
|
|
67
|
+
return `${g(e)}|${t}`;
|
|
68
|
+
}
|
|
69
|
+
function v(e) {
|
|
70
|
+
return {
|
|
71
|
+
id: `kitten:${e}`,
|
|
72
|
+
name: e,
|
|
73
|
+
lang: "en-US",
|
|
74
|
+
local: !0,
|
|
75
|
+
isDefault: !1,
|
|
76
|
+
engine: "kitten",
|
|
77
|
+
downloadBytes: d,
|
|
78
|
+
gender: a[e]
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function y(e) {
|
|
82
|
+
return Array.from(e.text.matchAll(/\S+/g), (t) => e.offset + (t.index ?? 0));
|
|
83
|
+
}
|
|
84
|
+
function b(e = window) {
|
|
85
|
+
let t = e.navigator;
|
|
86
|
+
return typeof WebAssembly == "object" && typeof e.Worker == "function" && typeof e.Audio == "function" && typeof DecompressionStream == "function" && !t.connection?.saveData && (t.deviceMemory ?? 4) >= 2;
|
|
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
|
+
}];
|
|
105
|
+
}
|
|
106
|
+
return [{
|
|
107
|
+
text: e,
|
|
108
|
+
offset: 0
|
|
109
|
+
}];
|
|
110
|
+
}
|
|
111
|
+
// src/engine/engine.ts
|
|
112
|
+
function S(e, a = {}, s = window) {
|
|
113
|
+
let c = {
|
|
114
|
+
...l,
|
|
115
|
+
...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 = {
|
|
117
|
+
state: "idle",
|
|
118
|
+
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) {
|
|
121
|
+
T = e;
|
|
122
|
+
for (let t of f) t(e);
|
|
123
|
+
}
|
|
124
|
+
function L() {
|
|
125
|
+
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({
|
|
130
|
+
state: "error",
|
|
131
|
+
progress: 0,
|
|
132
|
+
error: "failed"
|
|
133
|
+
});
|
|
134
|
+
}
|
|
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({
|
|
139
|
+
state: "error",
|
|
140
|
+
progress: 0,
|
|
141
|
+
error: "slow"
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
function z(e) {
|
|
145
|
+
let n = S.get(e.id);
|
|
146
|
+
if (S.delete(e.id), !n) return;
|
|
147
|
+
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({
|
|
149
|
+
url: URL.createObjectURL(a),
|
|
150
|
+
seconds: i,
|
|
151
|
+
starts: e.starts
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
function B(e) {
|
|
155
|
+
switch (e.type) {
|
|
156
|
+
case "progress":
|
|
157
|
+
T.state === "loading" && I({
|
|
158
|
+
state: "loading",
|
|
159
|
+
progress: Math.min(.99, e.loaded / u)
|
|
160
|
+
});
|
|
161
|
+
return;
|
|
162
|
+
case "ready":
|
|
163
|
+
I({
|
|
164
|
+
state: "ready",
|
|
165
|
+
progress: 1
|
|
166
|
+
});
|
|
167
|
+
return;
|
|
168
|
+
case "audio":
|
|
169
|
+
z(e);
|
|
170
|
+
return;
|
|
171
|
+
case "error":
|
|
172
|
+
if (e.id === void 0) {
|
|
173
|
+
p("load failed:", e.message), L();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
p(`clip ${e.id} failed:`, e.message), S.get(e.id)?.reject(Error(e.message)), S.delete(e.id);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
function V(e) {
|
|
180
|
+
E?.postMessage(e);
|
|
181
|
+
}
|
|
182
|
+
function H() {
|
|
183
|
+
if (E) return E;
|
|
184
|
+
try {
|
|
185
|
+
E = e();
|
|
186
|
+
} catch {
|
|
187
|
+
return L(), null;
|
|
188
|
+
}
|
|
189
|
+
return E.onmessage = (e) => B(e.data), E.onerror = L, I({
|
|
190
|
+
state: "loading",
|
|
191
|
+
progress: 0
|
|
192
|
+
}), V({
|
|
193
|
+
type: "load",
|
|
194
|
+
sources: c
|
|
195
|
+
}), E;
|
|
196
|
+
}
|
|
197
|
+
function U() {
|
|
198
|
+
for (let [e, t] of C) {
|
|
199
|
+
if (C.size <= 10) return;
|
|
200
|
+
C.delete(e), h(t);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
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, {
|
|
208
|
+
resolve: e,
|
|
209
|
+
reject: n
|
|
210
|
+
}), p(`queue clip ${i}: "${t.slice(0, 40)}"`), V({
|
|
211
|
+
type: "synth",
|
|
212
|
+
id: i,
|
|
213
|
+
text: t,
|
|
214
|
+
voice: a,
|
|
215
|
+
speed: o[a]
|
|
216
|
+
});
|
|
217
|
+
}), c = {
|
|
218
|
+
id: i,
|
|
219
|
+
clip: s
|
|
220
|
+
};
|
|
221
|
+
return s.catch(() => {
|
|
222
|
+
C.get(n)?.id === i && C.delete(n);
|
|
223
|
+
}), C.set(n, c), U(), c;
|
|
224
|
+
}
|
|
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")));
|
|
229
|
+
}
|
|
230
|
+
V({
|
|
231
|
+
type: "drop",
|
|
232
|
+
keep: [...e]
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function K() {
|
|
236
|
+
clearInterval(M), M = void 0, F = null, O && (O.onended = null, O.pause());
|
|
237
|
+
}
|
|
238
|
+
function q() {
|
|
239
|
+
if (O) return O;
|
|
240
|
+
let e = new (s.Audio ?? Audio)();
|
|
241
|
+
return e.preload = "auto", e.preservesPitch = !0, O = e, e;
|
|
242
|
+
}
|
|
243
|
+
function J(e, t, n) {
|
|
244
|
+
let r = q(), i = 0, a = !1;
|
|
245
|
+
function o() {
|
|
246
|
+
return n === j;
|
|
247
|
+
}
|
|
248
|
+
function s(e) {
|
|
249
|
+
o() && t.onError({
|
|
250
|
+
code: e.name === "NotAllowedError" ? "not-allowed" : "audio-failed",
|
|
251
|
+
message: e.message
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
function c(e) {
|
|
255
|
+
o() && e.message !== "dropped" && t.onError({
|
|
256
|
+
code: "synthesis-failed",
|
|
257
|
+
message: e.message
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function l(e, n) {
|
|
261
|
+
if (!o()) return;
|
|
262
|
+
let c = y(e.part), l = 0;
|
|
263
|
+
function d() {
|
|
264
|
+
for (; l < c.length && (n.starts[l] ?? Infinity) <= r.currentTime;) t.onWord(c[l++] ?? 0, !1);
|
|
265
|
+
}
|
|
266
|
+
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());
|
|
268
|
+
}
|
|
269
|
+
function m() {
|
|
270
|
+
r.onended = () => {
|
|
271
|
+
N = performance.now(), o() && (clearInterval(M), d(), i++, u());
|
|
272
|
+
}, r.src = n.url, r.playbackRate = k, r.play().then(f, s);
|
|
273
|
+
}
|
|
274
|
+
A ? F = m : m();
|
|
275
|
+
}
|
|
276
|
+
function u() {
|
|
277
|
+
let n = e[i];
|
|
278
|
+
n ? n.clip.then((e) => l(n, e), c) : t.onEnd();
|
|
279
|
+
}
|
|
280
|
+
u();
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
id: "kitten",
|
|
284
|
+
reliablePause: !0,
|
|
285
|
+
slowStart: !0,
|
|
286
|
+
liveRate: !0,
|
|
287
|
+
status() {
|
|
288
|
+
return T;
|
|
289
|
+
},
|
|
290
|
+
subscribe(e) {
|
|
291
|
+
return f.add(e), () => f.delete(e);
|
|
292
|
+
},
|
|
293
|
+
getVoices() {
|
|
294
|
+
return Promise.resolve(d);
|
|
295
|
+
},
|
|
296
|
+
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({
|
|
300
|
+
state: "idle",
|
|
301
|
+
progress: 0
|
|
302
|
+
})), !H()) {
|
|
303
|
+
t.onError({
|
|
304
|
+
code: "engine-failed",
|
|
305
|
+
message: "HD voice is unavailable on this page."
|
|
306
|
+
});
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
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);
|
|
322
|
+
},
|
|
323
|
+
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);
|
|
327
|
+
},
|
|
328
|
+
setRate(e) {
|
|
329
|
+
k = e, O && (O.playbackRate = e);
|
|
330
|
+
},
|
|
331
|
+
pause() {
|
|
332
|
+
A = !0, O?.pause();
|
|
333
|
+
},
|
|
334
|
+
resume() {
|
|
335
|
+
A = !1;
|
|
336
|
+
let e = F;
|
|
337
|
+
F = null, e ? e() : O?.play().catch(m);
|
|
338
|
+
},
|
|
339
|
+
cancel() {
|
|
340
|
+
j++, K();
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
// 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";
|
|
346
|
+
// src/index.ts
|
|
347
|
+
function w() {
|
|
348
|
+
let e = URL.createObjectURL(new Blob([C], { type: "text/javascript" }));
|
|
349
|
+
return new Worker(e, { type: "module" });
|
|
350
|
+
}
|
|
351
|
+
function T(e) {
|
|
352
|
+
return S(w, e);
|
|
353
|
+
}
|
|
354
|
+
export { i as VOICE_NAMES, T as kittenVoices };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Matrix } from "./npz.types";
|
|
2
|
+
export declare function readZip(buf: ArrayBuffer): Promise<Map<string, Uint8Array>>;
|
|
3
|
+
export declare function readNpy(bytes: Uint8Array): Matrix;
|
|
4
|
+
export declare function readNpz(buf: ArrayBuffer): Promise<Map<string, Matrix>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const PUNCT: string;
|
|
2
|
+
export declare const SYMBOLS: string[];
|
|
3
|
+
export declare const IDS: Map<string, number>;
|
|
4
|
+
export declare const SYMBOL_COUNT: number;
|
|
5
|
+
export declare const TOKENS: RegExp;
|
|
6
|
+
export declare const EDGES: RegExp;
|
|
7
|
+
export declare const SPACE: number;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Encoded, Phonemize } from "./text.types";
|
|
2
|
+
export declare function normalize(text: string): string;
|
|
3
|
+
export declare function ensureEnding(text: string): string;
|
|
4
|
+
export declare function tokenIds(piece: string): number[];
|
|
5
|
+
export declare function assign(words: readonly string[], phonemeWords: number): number[];
|
|
6
|
+
export declare function encode(text: string, phonemize: Phonemize): Promise<Encoded>;
|
|
7
|
+
export declare function wordStarts(words: readonly number[], durations: ArrayLike<number | bigint>, secondsPerFrame: number): Float32Array<ArrayBuffer>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const SAMPLE_RATE = 24000;
|
|
2
|
+
export declare const HOP = 600;
|
|
3
|
+
export declare const CACHE = "lantun-voice-kitten-v1";
|
|
4
|
+
export declare const TRIM_SAMPLES = 5000;
|
|
5
|
+
export declare const LEAD_KEEP_SAMPLES = 1200;
|
|
6
|
+
export declare const PHONEME_CACHE = 5000;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Matrix } from "../npz/npz.types";
|
|
2
|
+
export interface Sources {
|
|
3
|
+
model: string;
|
|
4
|
+
voices: string;
|
|
5
|
+
config: string;
|
|
6
|
+
ort: string;
|
|
7
|
+
ortWasm: string;
|
|
8
|
+
phonemizer: string;
|
|
9
|
+
}
|
|
10
|
+
export type ToWorker = {
|
|
11
|
+
type: "load";
|
|
12
|
+
sources: Sources;
|
|
13
|
+
} | {
|
|
14
|
+
type: "synth";
|
|
15
|
+
id: number;
|
|
16
|
+
text: string;
|
|
17
|
+
voice: string;
|
|
18
|
+
speed: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: "drop";
|
|
21
|
+
keep: number[];
|
|
22
|
+
};
|
|
23
|
+
export type FromWorker = {
|
|
24
|
+
type: "progress";
|
|
25
|
+
loaded: number;
|
|
26
|
+
} | {
|
|
27
|
+
type: "ready";
|
|
28
|
+
} | {
|
|
29
|
+
type: "audio";
|
|
30
|
+
id: number;
|
|
31
|
+
samples: Float32Array<ArrayBuffer>;
|
|
32
|
+
starts: Float32Array<ArrayBuffer>;
|
|
33
|
+
ms: number;
|
|
34
|
+
} | {
|
|
35
|
+
type: "error";
|
|
36
|
+
id?: number;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
export type SynthJob = Extract<ToWorker, {
|
|
40
|
+
type: "synth";
|
|
41
|
+
}>;
|
|
42
|
+
export interface Tensor<T = Float32Array<ArrayBuffer>> {
|
|
43
|
+
data: T;
|
|
44
|
+
}
|
|
45
|
+
export interface Session {
|
|
46
|
+
run(feeds: Record<string, unknown>): Promise<{
|
|
47
|
+
waveform?: Tensor;
|
|
48
|
+
duration?: Tensor<BigInt64Array>;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
export interface Ort {
|
|
52
|
+
env: {
|
|
53
|
+
wasm: {
|
|
54
|
+
wasmPaths?: string;
|
|
55
|
+
wasmBinary?: ArrayBuffer;
|
|
56
|
+
numThreads?: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
Tensor: new (type: string, data: unknown, dims: number[]) => unknown;
|
|
60
|
+
InferenceSession: {
|
|
61
|
+
create(model: ArrayBuffer, opts: object): Promise<Session>;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export interface Phonemizer {
|
|
65
|
+
phonemize: (text: string, lang: string) => Promise<string[]>;
|
|
66
|
+
}
|
|
67
|
+
export interface KittenConfig {
|
|
68
|
+
voice_aliases?: Record<string, string>;
|
|
69
|
+
}
|
|
70
|
+
export interface Runtime {
|
|
71
|
+
ort: Ort;
|
|
72
|
+
session: Session;
|
|
73
|
+
phonemize: (text: string) => Promise<string>;
|
|
74
|
+
voices: Map<string, Matrix>;
|
|
75
|
+
config: KittenConfig;
|
|
76
|
+
}
|
|
77
|
+
export interface Synthesized {
|
|
78
|
+
samples: Float32Array<ArrayBuffer>;
|
|
79
|
+
starts: Float32Array<ArrayBuffer>;
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lantun/voice-kitten",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lifelike, on-device English voices for Lantun, powered by Kitten TTS. Nothing downloads until a reader picks one.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"text-to-speech",
|
|
7
|
+
"tts",
|
|
8
|
+
"kitten-tts",
|
|
9
|
+
"onnx",
|
|
10
|
+
"lantun",
|
|
11
|
+
"voices"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "rizkianakbar",
|
|
15
|
+
"homepage": "https://github.com/rizkianakbar/lantun#readme",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/rizkianakbar/lantun.git",
|
|
19
|
+
"directory": "packages/voice-kitten"
|
|
20
|
+
},
|
|
21
|
+
"bugs": "https://github.com/rizkianakbar/lantun/issues",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"sideEffects": false,
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@lantun/core": "^0.1.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@lantun/core": "^0.1.0",
|
|
41
|
+
"esbuild": "^0.28.2",
|
|
42
|
+
"jsdom": "^30.1.3",
|
|
43
|
+
"typescript": "^7.0.2",
|
|
44
|
+
"vite": "^8.3.5",
|
|
45
|
+
"vitest": "^5.0.5"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
49
|
+
"typecheck": "tsc --noEmit",
|
|
50
|
+
"test": "vitest run"
|
|
51
|
+
}
|
|
6
52
|
}
|