@somniumism/kokoro-js-ja 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +119 -0
  3. package/dist/kokoro.cjs +1 -0
  4. package/dist/kokoro.js +1 -0
  5. package/dist/kokoro.web.js +1 -0
  6. package/package.json +67 -0
  7. package/types/kokoro.d.ts +336 -0
  8. package/types/kokoro.d.ts.map +1 -0
  9. package/types/phonemize.d.ts +9 -0
  10. package/types/phonemize.d.ts.map +1 -0
  11. package/types/splitter.d.ts +59 -0
  12. package/types/splitter.d.ts.map +1 -0
  13. package/types/voices.d.ts +261 -0
  14. package/types/voices.d.ts.map +1 -0
  15. package/voices/af_alloy.bin +0 -0
  16. package/voices/af_aoede.bin +0 -0
  17. package/voices/af_bella.bin +0 -0
  18. package/voices/af_heart.bin +0 -0
  19. package/voices/af_jessica.bin +0 -0
  20. package/voices/af_kore.bin +0 -0
  21. package/voices/af_nicole.bin +0 -0
  22. package/voices/af_nova.bin +0 -0
  23. package/voices/af_river.bin +0 -0
  24. package/voices/af_sarah.bin +0 -0
  25. package/voices/af_sky.bin +0 -0
  26. package/voices/am_adam.bin +0 -0
  27. package/voices/am_echo.bin +0 -0
  28. package/voices/am_eric.bin +0 -0
  29. package/voices/am_fenrir.bin +0 -0
  30. package/voices/am_liam.bin +0 -0
  31. package/voices/am_michael.bin +0 -0
  32. package/voices/am_onyx.bin +0 -0
  33. package/voices/am_puck.bin +0 -0
  34. package/voices/am_santa.bin +0 -0
  35. package/voices/bf_alice.bin +0 -0
  36. package/voices/bf_emma.bin +0 -0
  37. package/voices/bf_isabella.bin +0 -0
  38. package/voices/bf_lily.bin +0 -0
  39. package/voices/bm_daniel.bin +0 -0
  40. package/voices/bm_fable.bin +0 -0
  41. package/voices/bm_george.bin +0 -0
  42. package/voices/bm_lewis.bin +0 -0
  43. package/voices/ef_dora.bin +0 -0
  44. package/voices/em_alex.bin +0 -0
  45. package/voices/em_santa.bin +0 -0
  46. package/voices/ff_siwis.bin +0 -0
  47. package/voices/hf_alpha.bin +0 -0
  48. package/voices/hf_beta.bin +0 -0
  49. package/voices/hm_omega.bin +0 -0
  50. package/voices/hm_psi.bin +0 -0
  51. package/voices/if_sara.bin +0 -0
  52. package/voices/im_nicola.bin +0 -0
  53. package/voices/jf_alpha.bin +0 -0
  54. package/voices/jf_gongitsune.bin +0 -0
  55. package/voices/jf_nezumi.bin +0 -0
  56. package/voices/jf_tebukuro.bin +0 -0
  57. package/voices/jm_kumo.bin +0 -0
  58. package/voices/pf_dora.bin +0 -0
  59. package/voices/pm_alex.bin +0 -0
  60. package/voices/pm_santa.bin +0 -0
  61. package/voices/zf_xiaobei.bin +0 -0
  62. package/voices/zf_xiaoni.bin +0 -0
  63. package/voices/zf_xiaoxiao.bin +0 -0
  64. package/voices/zf_xiaoyi.bin +0 -0
  65. package/voices/zm_yunjian.bin +0 -0
  66. package/voices/zm_yunxi.bin +0 -0
  67. package/voices/zm_yunxia.bin +0 -0
  68. package/voices/zm_yunyang.bin +0 -0
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@somniumism/kokoro-js-ja",
3
+ "version": "1.2.1",
4
+ "type": "module",
5
+ "exports": {
6
+ "types": "./types/kokoro.d.ts",
7
+ "node": {
8
+ "import": "./dist/kokoro.js",
9
+ "require": "./dist/kokoro.cjs"
10
+ },
11
+ "default": "./dist/kokoro.js"
12
+ },
13
+ "scripts": {
14
+ "build": "rm -rf dist types && rollup -c && tsc",
15
+ "format": "prettier --write . --print-width 1000",
16
+ "test": "vitest run"
17
+ },
18
+ "keywords": [
19
+ "kokoro",
20
+ "tts",
21
+ "text-to-speech",
22
+ "japanese",
23
+ "日本語"
24
+ ],
25
+ "author": {
26
+ "name": "hexgrad",
27
+ "email": "hello@hexgrad.com"
28
+ },
29
+ "browser": {
30
+ "path": false,
31
+ "fs/promises": false
32
+ },
33
+ "contributors": [
34
+ "Xenova"
35
+ ],
36
+ "license": "Apache-2.0",
37
+ "description": "High-quality text-to-speech for the web with Japanese language support",
38
+ "dependencies": {
39
+ "@huggingface/transformers": "^3.5.1",
40
+ "phonemizer": "^1.2.1"
41
+ },
42
+ "devDependencies": {
43
+ "@rollup/plugin-node-resolve": "^16.0.0",
44
+ "@rollup/plugin-terser": "^0.4.4",
45
+ "prettier": "3.4.2",
46
+ "rollup": "^4.30.1",
47
+ "typescript": "^5.7.3",
48
+ "vitest": "^3.1.2"
49
+ },
50
+ "files": [
51
+ "types",
52
+ "dist",
53
+ "voices",
54
+ "README.md",
55
+ "LICENSE"
56
+ ],
57
+ "homepage": "https://github.com/hexgrad/kokoro",
58
+ "repository": {
59
+ "type": "git",
60
+ "url": "git+https://github.com/hexgrad/kokoro.git"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "jsdelivr": "./dist/kokoro.web.js",
66
+ "unpkg": "./dist/kokoro.web.js"
67
+ }
@@ -0,0 +1,336 @@
1
+ /**
2
+ * @typedef {Object} GenerateOptions
3
+ * @property {keyof typeof VOICES} [voice="af_heart"] The voice
4
+ * @property {number} [speed=1] The speaking speed
5
+ */
6
+ /**
7
+ * @typedef {Object} StreamProperties
8
+ * @property {RegExp} [split_pattern] The pattern to split the input text. If unset, the default sentence splitter will be used.
9
+ * @typedef {GenerateOptions & StreamProperties} StreamGenerateOptions
10
+ */
11
+ export class KokoroTTS {
12
+ /**
13
+ * Load a KokoroTTS model from the Hugging Face Hub.
14
+ * @param {string} model_id The model id
15
+ * @param {Object} options Additional options
16
+ * @param {"fp32"|"fp16"|"q8"|"q4"|"q4f16"} [options.dtype="fp32"] The data type to use.
17
+ * @param {"wasm"|"webgpu"|"cpu"|null} [options.device=null] The device to run the model on.
18
+ * @param {import("@huggingface/transformers").ProgressCallback} [options.progress_callback=null] A callback function that is called with progress information.
19
+ * @returns {Promise<KokoroTTS>} The loaded model
20
+ */
21
+ static from_pretrained(model_id: string, { dtype, device, progress_callback }?: {
22
+ dtype?: "fp32" | "fp16" | "q8" | "q4" | "q4f16";
23
+ device?: "wasm" | "webgpu" | "cpu" | null;
24
+ progress_callback?: import("@huggingface/transformers").ProgressCallback;
25
+ }): Promise<KokoroTTS>;
26
+ /**
27
+ * Create a new KokoroTTS instance.
28
+ * @param {import('@huggingface/transformers').StyleTextToSpeech2Model} model The model
29
+ * @param {import('@huggingface/transformers').PreTrainedTokenizer} tokenizer The tokenizer
30
+ */
31
+ constructor(model: import("@huggingface/transformers").StyleTextToSpeech2Model, tokenizer: import("@huggingface/transformers").PreTrainedTokenizer);
32
+ model: StyleTextToSpeech2Model;
33
+ tokenizer: import("@huggingface/transformers").PreTrainedTokenizer;
34
+ get voices(): Readonly<{
35
+ af_heart: {
36
+ name: string;
37
+ language: string;
38
+ gender: string;
39
+ traits: string;
40
+ targetQuality: string;
41
+ overallGrade: string;
42
+ };
43
+ af_alloy: {
44
+ name: string;
45
+ language: string;
46
+ gender: string;
47
+ targetQuality: string;
48
+ overallGrade: string;
49
+ };
50
+ af_aoede: {
51
+ name: string;
52
+ language: string;
53
+ gender: string;
54
+ targetQuality: string;
55
+ overallGrade: string;
56
+ };
57
+ af_bella: {
58
+ name: string;
59
+ language: string;
60
+ gender: string;
61
+ traits: string;
62
+ targetQuality: string;
63
+ overallGrade: string;
64
+ };
65
+ af_jessica: {
66
+ name: string;
67
+ language: string;
68
+ gender: string;
69
+ targetQuality: string;
70
+ overallGrade: string;
71
+ };
72
+ af_kore: {
73
+ name: string;
74
+ language: string;
75
+ gender: string;
76
+ targetQuality: string;
77
+ overallGrade: string;
78
+ };
79
+ af_nicole: {
80
+ name: string;
81
+ language: string;
82
+ gender: string;
83
+ traits: string;
84
+ targetQuality: string;
85
+ overallGrade: string;
86
+ };
87
+ af_nova: {
88
+ name: string;
89
+ language: string;
90
+ gender: string;
91
+ targetQuality: string;
92
+ overallGrade: string;
93
+ };
94
+ af_river: {
95
+ name: string;
96
+ language: string;
97
+ gender: string;
98
+ targetQuality: string;
99
+ overallGrade: string;
100
+ };
101
+ af_sarah: {
102
+ name: string;
103
+ language: string;
104
+ gender: string;
105
+ targetQuality: string;
106
+ overallGrade: string;
107
+ };
108
+ af_sky: {
109
+ name: string;
110
+ language: string;
111
+ gender: string;
112
+ targetQuality: string;
113
+ overallGrade: string;
114
+ };
115
+ am_adam: {
116
+ name: string;
117
+ language: string;
118
+ gender: string;
119
+ targetQuality: string;
120
+ overallGrade: string;
121
+ };
122
+ am_echo: {
123
+ name: string;
124
+ language: string;
125
+ gender: string;
126
+ targetQuality: string;
127
+ overallGrade: string;
128
+ };
129
+ am_eric: {
130
+ name: string;
131
+ language: string;
132
+ gender: string;
133
+ targetQuality: string;
134
+ overallGrade: string;
135
+ };
136
+ am_fenrir: {
137
+ name: string;
138
+ language: string;
139
+ gender: string;
140
+ targetQuality: string;
141
+ overallGrade: string;
142
+ };
143
+ am_liam: {
144
+ name: string;
145
+ language: string;
146
+ gender: string;
147
+ targetQuality: string;
148
+ overallGrade: string;
149
+ };
150
+ am_michael: {
151
+ name: string;
152
+ language: string;
153
+ gender: string;
154
+ targetQuality: string;
155
+ overallGrade: string;
156
+ };
157
+ am_onyx: {
158
+ name: string;
159
+ language: string;
160
+ gender: string;
161
+ targetQuality: string;
162
+ overallGrade: string;
163
+ };
164
+ am_puck: {
165
+ name: string;
166
+ language: string;
167
+ gender: string;
168
+ targetQuality: string;
169
+ overallGrade: string;
170
+ };
171
+ am_santa: {
172
+ name: string;
173
+ language: string;
174
+ gender: string;
175
+ targetQuality: string;
176
+ overallGrade: string;
177
+ };
178
+ bf_emma: {
179
+ name: string;
180
+ language: string;
181
+ gender: string;
182
+ traits: string;
183
+ targetQuality: string;
184
+ overallGrade: string;
185
+ };
186
+ bf_isabella: {
187
+ name: string;
188
+ language: string;
189
+ gender: string;
190
+ targetQuality: string;
191
+ overallGrade: string;
192
+ };
193
+ bm_george: {
194
+ name: string;
195
+ language: string;
196
+ gender: string;
197
+ targetQuality: string;
198
+ overallGrade: string;
199
+ };
200
+ bm_lewis: {
201
+ name: string;
202
+ language: string;
203
+ gender: string;
204
+ targetQuality: string;
205
+ overallGrade: string;
206
+ };
207
+ bf_alice: {
208
+ name: string;
209
+ language: string;
210
+ gender: string;
211
+ traits: string;
212
+ targetQuality: string;
213
+ overallGrade: string;
214
+ };
215
+ bf_lily: {
216
+ name: string;
217
+ language: string;
218
+ gender: string;
219
+ traits: string;
220
+ targetQuality: string;
221
+ overallGrade: string;
222
+ };
223
+ bm_daniel: {
224
+ name: string;
225
+ language: string;
226
+ gender: string;
227
+ traits: string;
228
+ targetQuality: string;
229
+ overallGrade: string;
230
+ };
231
+ bm_fable: {
232
+ name: string;
233
+ language: string;
234
+ gender: string;
235
+ traits: string;
236
+ targetQuality: string;
237
+ overallGrade: string;
238
+ };
239
+ jf_alpha: {
240
+ name: string;
241
+ language: string;
242
+ gender: string;
243
+ traits: string;
244
+ targetQuality: string;
245
+ overallGrade: string;
246
+ };
247
+ jf_gongitsune: {
248
+ name: string;
249
+ language: string;
250
+ gender: string;
251
+ traits: string;
252
+ targetQuality: string;
253
+ overallGrade: string;
254
+ };
255
+ jf_nezumi: {
256
+ name: string;
257
+ language: string;
258
+ gender: string;
259
+ traits: string;
260
+ targetQuality: string;
261
+ overallGrade: string;
262
+ };
263
+ jf_tebukuro: {
264
+ name: string;
265
+ language: string;
266
+ gender: string;
267
+ traits: string;
268
+ targetQuality: string;
269
+ overallGrade: string;
270
+ };
271
+ jm_kumo: {
272
+ name: string;
273
+ language: string;
274
+ gender: string;
275
+ traits: string;
276
+ targetQuality: string;
277
+ overallGrade: string;
278
+ };
279
+ }>;
280
+ list_voices(): void;
281
+ _validate_voice(voice: any): "b" | "a";
282
+ /**
283
+ * Generate audio from text.
284
+ *
285
+ * @param {string} text The input text
286
+ * @param {GenerateOptions} options Additional options
287
+ * @returns {Promise<RawAudio>} The generated audio
288
+ */
289
+ generate(text: string, { voice, speed }?: GenerateOptions): Promise<RawAudio>;
290
+ /**
291
+ * Generate audio from input ids.
292
+ * @param {Tensor} input_ids The input ids
293
+ * @param {GenerateOptions} options Additional options
294
+ * @returns {Promise<RawAudio>} The generated audio
295
+ */
296
+ generate_from_ids(input_ids: Tensor, { voice, speed }?: GenerateOptions): Promise<RawAudio>;
297
+ /**
298
+ * Generate audio from text in a streaming fashion.
299
+ * @param {string|TextSplitterStream} text The input text
300
+ * @param {StreamGenerateOptions} options Additional options
301
+ * @returns {AsyncGenerator<{text: string, phonemes: string, audio: RawAudio}, void, void>}
302
+ */
303
+ stream(text: string | TextSplitterStream, { voice, speed, split_pattern }?: StreamGenerateOptions): AsyncGenerator<{
304
+ text: string;
305
+ phonemes: string;
306
+ audio: RawAudio;
307
+ }, void, void>;
308
+ }
309
+ export namespace env {
310
+ let cacheDir: string;
311
+ let wasmPaths: import("onnxruntime-common").Env.WasmPrefixOrFilePaths;
312
+ }
313
+ export { TextSplitterStream };
314
+ export type GenerateOptions = {
315
+ /**
316
+ * The voice
317
+ */
318
+ voice?: keyof typeof VOICES;
319
+ /**
320
+ * The speaking speed
321
+ */
322
+ speed?: number;
323
+ };
324
+ export type StreamProperties = {
325
+ /**
326
+ * The pattern to split the input text. If unset, the default sentence splitter will be used.
327
+ */
328
+ split_pattern?: RegExp;
329
+ };
330
+ export type StreamGenerateOptions = GenerateOptions & StreamProperties;
331
+ import { StyleTextToSpeech2Model } from "@huggingface/transformers";
332
+ import { RawAudio } from "@huggingface/transformers";
333
+ import { Tensor } from "@huggingface/transformers";
334
+ import { TextSplitterStream } from "./splitter.js";
335
+ import { VOICES } from "./voices.js";
336
+ //# sourceMappingURL=kokoro.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kokoro.d.ts","sourceRoot":"","sources":["../src/kokoro.js"],"names":[],"mappings":"AAQA;;;;GAIG;AAEH;;;;GAIG;AAEH;IAWE;;;;;;;;OAQG;IACH,iCAPW,MAAM,yCAEd;QAAkD,KAAK,GAA/C,MAAM,GAAC,MAAM,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,0 +1,9 @@
1
+ /**
2
+ * Phonemize text using the eSpeak-NG phonemizer
3
+ * @param {string} text The text to phonemize
4
+ * @param {"a"|"b"} language The language to use
5
+ * @param {boolean} norm Whether to normalize the text
6
+ * @returns {Promise<string>} The phonemized text
7
+ */
8
+ export function phonemize(text: string, language?: "a" | "b", norm?: boolean): Promise<string>;
9
+ //# sourceMappingURL=phonemize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phonemize.d.ts","sourceRoot":"","sources":["../src/phonemize.js"],"names":[],"mappings":"AAsKA;;;;;;GAMG;AACH,gCALW,MAAM,aACN,GAAG,GAAC,GAAG,SACP,OAAO,GACL,OAAO,CAAC,MAAM,CAAC,CAgC3B"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Splits the input text into an array of sentences.
3
+ * @param {string} text The text to split.
4
+ * @returns {string[]} An array of sentences.
5
+ */
6
+ export function split(text: string): string[];
7
+ /**
8
+ * A simple stream-based text splitter that emits complete sentences.
9
+ */
10
+ export class TextSplitterStream {
11
+ _buffer: string;
12
+ _sentences: any[];
13
+ _resolver: (value: any) => void;
14
+ _closed: boolean;
15
+ /**
16
+ * Push one or more text chunks into the stream.
17
+ * @param {...string} texts Text fragments to process.
18
+ */
19
+ push(...texts: string[]): void;
20
+ /**
21
+ * Closes the stream, signaling that no more text will be pushed.
22
+ * This will flush any remaining text in the buffer as a sentence
23
+ * and allow the consuming process to finish processing the stream.
24
+ */
25
+ close(): void;
26
+ /**
27
+ * Flushes any remaining text in the buffer as a sentence.
28
+ */
29
+ flush(): void;
30
+ /**
31
+ * Resolve the pending promise to signal that sentences are available.
32
+ * @private
33
+ */
34
+ private _resolve;
35
+ /**
36
+ * Processes the internal buffer to extract complete sentences.
37
+ * If the potential sentence boundary is at the end of the current buffer,
38
+ * it waits for more text before splitting.
39
+ * @private
40
+ */
41
+ private _process;
42
+ /**
43
+ * Returns the array of sentences currently available.
44
+ * @type {string[]} The array of sentences.
45
+ * @readonly
46
+ */
47
+ readonly get sentences(): string[];
48
+ /**
49
+ * Async iterator to yield sentences as they become available.
50
+ * @returns {AsyncGenerator<string, void, void>}
51
+ */
52
+ [Symbol.asyncIterator](): AsyncGenerator<string, void, void>;
53
+ /**
54
+ * Synchronous iterator that flushes the buffer and returns all sentences.
55
+ * @returns {Iterator<string>}
56
+ */
57
+ [Symbol.iterator](): Iterator<string>;
58
+ }
59
+ //# sourceMappingURL=splitter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitter.d.ts","sourceRoot":"","sources":["../src/splitter.js"],"names":[],"mappings":"AA8UA;;;;GAIG;AACH,4BAHW,MAAM,GACJ,MAAM,EAAE,CAMpB;AA9OD;;GAEG;AACH;IAEI,gBAAiB;IACjB,kBAAoB;IACpB,gCAAqB;IACrB,iBAAoB;IAGtB;;;OAGG;IACH,eAFe,MAAM,EAAA,QAOpB;IAED;;;;OAIG;IACH,cAMC;IAED;;OAEG;IACH,cAOC;IAED;;;OAGG;IACH,iBAKC;IAED;;;;;OAKG;IACH,iBAuHC;IAoCD;;;;OAIG;IACH,0BAHU,MAAM,EAAE,CAKjB;IAzCD;;;OAGG;IACH,0BAFa,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,CAmB9C;IAED;;;OAGG;IACH,qBAFa,QAAQ,CAAC,MAAM,CAAC,CAO5B;CAUF"}