@uzen/kokoro-js 1.2.3
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 +201 -0
- package/README.md +166 -0
- package/dist/kokoro.cjs +1 -0
- package/dist/kokoro.js +1 -0
- package/dist/kokoro.web.js +1 -0
- package/package.json +62 -0
- package/types/kokoro.d.ts +626 -0
- package/types/kokoro.d.ts.map +1 -0
- package/types/phonemize.d.ts +9 -0
- package/types/phonemize.d.ts.map +1 -0
- package/types/splitter.d.ts +59 -0
- package/types/splitter.d.ts.map +1 -0
- package/types/voices.d.ts +521 -0
- package/types/voices.d.ts.map +1 -0
- package/types/zh-data.d.ts +21 -0
- package/types/zh-data.d.ts.map +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# Kokoro TTS
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://www.npmjs.com/package/@uzen/kokoro-js"><img alt="NPM" src="https://img.shields.io/npm/v/@uzen%2Fkokoro-js"></a>
|
|
5
|
+
<a href="https://www.npmjs.com/package/@uzen/kokoro-js"><img alt="NPM Downloads" src="https://img.shields.io/npm/dw/@uzen%2Fkokoro-js"></a>
|
|
6
|
+
<a href="https://www.jsdelivr.com/package/npm/@uzen/kokoro-js"><img alt="jsDelivr Hits" src="https://img.shields.io/jsdelivr/npm/hw/@uzen%2Fkokoro-js"></a>
|
|
7
|
+
<a href="https://github.com/hexgrad/kokoro/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/github/license/hexgrad/kokoro?color=blue"></a>
|
|
8
|
+
<a href="https://huggingface.co/spaces/webml-community/kokoro-webgpu"><img alt="Demo" src="https://img.shields.io/badge/Hugging_Face-demo-green"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
Kokoro is a frontier TTS model for its size of 82 million parameters (text in/audio out). This JavaScript library allows the model to be run 100% locally in the browser thanks to [🤗 Transformers.js](https://huggingface.co/docs/transformers.js). Try it out using our [online demo](https://huggingface.co/spaces/webml-community/kokoro-webgpu)!
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
First, install the `@uzen/kokoro-js` library from [NPM](https://npmjs.com/package/@uzen/kokoro-js) using:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm i @uzen/kokoro-js
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Voice `.bin` files are not bundled in the npm package. Download the voices you need from the `voices/` directory of [`onnx-community/Kokoro-82M-v1.1-zh-ONNX`](https://huggingface.co/onnx-community/Kokoro-82M-v1.1-zh-ONNX/tree/main/voices), then make them available to the runtime:
|
|
22
|
+
|
|
23
|
+
- Browser/Vite apps: place files such as `zf_001.bin` under `public/kokoro/voices/`; the default `voicePath` is `/kokoro/voices`.
|
|
24
|
+
- Node.js: place the files in a local directory and pass `voicePath`, for example `voicePath: "./voices"`.
|
|
25
|
+
|
|
26
|
+
You can then generate speech as follows:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { KokoroTTS } from "@uzen/kokoro-js";
|
|
30
|
+
|
|
31
|
+
const model_id = "onnx-community/Kokoro-82M-v1.1-zh-ONNX";
|
|
32
|
+
const tts = await KokoroTTS.from_pretrained(model_id, {
|
|
33
|
+
dtype: "q8", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
|
|
34
|
+
device: "wasm", // Options: "wasm", "webgpu" (web) or "cpu" (node). If using "webgpu", we recommend using dtype="fp32".
|
|
35
|
+
// voicePath: "./voices", // Node.js example. Browser default is "/kokoro/voices".
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const text = "你好,欢迎使用 Kokoro 中文语音。";
|
|
39
|
+
const audio = await tts.generate(text, {
|
|
40
|
+
// Use `tts.list_voices()` to list all available voices
|
|
41
|
+
voice: "zf_001",
|
|
42
|
+
});
|
|
43
|
+
audio.save("audio.wav");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or if you'd prefer to stream the output, you can do that with:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { KokoroTTS, TextSplitterStream } from "@uzen/kokoro-js";
|
|
50
|
+
|
|
51
|
+
const model_id = "onnx-community/Kokoro-82M-v1.1-zh-ONNX";
|
|
52
|
+
const tts = await KokoroTTS.from_pretrained(model_id, {
|
|
53
|
+
dtype: "fp32", // Options: "fp32", "fp16", "q8", "q4", "q4f16"
|
|
54
|
+
// device: "webgpu", // Options: "wasm", "webgpu" (web) or "cpu" (node).
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// First, set up the stream
|
|
58
|
+
const splitter = new TextSplitterStream();
|
|
59
|
+
const stream = tts.stream(splitter, { voice: "zf_001" });
|
|
60
|
+
(async () => {
|
|
61
|
+
let i = 0;
|
|
62
|
+
for await (const { text, phonemes, audio } of stream) {
|
|
63
|
+
console.log({ text, phonemes });
|
|
64
|
+
audio.save(`audio-${i++}.wav`);
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
|
|
68
|
+
// Next, add text to the stream. Note that the text can be added at different times.
|
|
69
|
+
// For this example, let's pretend we're consuming text from an LLM, one word at a time.
|
|
70
|
+
const text = "Kokoro 是一个轻量级本地语音模型,支持中文和中英混合文本。它可以在浏览器里通过 Transformers.js 运行,也可以在 Node.js 中生成音频文件。";
|
|
71
|
+
const tokens = text.match(/\s*\S+/g);
|
|
72
|
+
for (const token of tokens) {
|
|
73
|
+
splitter.push(token);
|
|
74
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Finally, close the stream to signal that no more text will be added.
|
|
78
|
+
splitter.close();
|
|
79
|
+
|
|
80
|
+
// Alternatively, if you'd like to keep the stream open, but flush any remaining text, you can use the `flush` method.
|
|
81
|
+
// splitter.flush();
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Voices/Samples
|
|
85
|
+
|
|
86
|
+
> [!TIP]
|
|
87
|
+
> You can find samples for each of the voices in the [model card](https://huggingface.co/onnx-community/Kokoro-82M-v1.1-zh-ONNX#samples) on Hugging Face.
|
|
88
|
+
|
|
89
|
+
### American English
|
|
90
|
+
|
|
91
|
+
| Name | Traits | Target Quality | Training Duration | Overall Grade |
|
|
92
|
+
| ------------ | ------ | -------------- | ----------------- | ------------- |
|
|
93
|
+
| **af_heart** | 🚺❤️ | | | **A** |
|
|
94
|
+
| af_alloy | 🚺 | B | MM minutes | C |
|
|
95
|
+
| af_aoede | 🚺 | B | H hours | C+ |
|
|
96
|
+
| af_bella | 🚺🔥 | **A** | **HH hours** | **A-** |
|
|
97
|
+
| af_jessica | 🚺 | C | MM minutes | D |
|
|
98
|
+
| af_kore | 🚺 | B | H hours | C+ |
|
|
99
|
+
| af_nicole | 🚺🎧 | B | **HH hours** | B- |
|
|
100
|
+
| af_nova | 🚺 | B | MM minutes | C |
|
|
101
|
+
| af_river | 🚺 | C | MM minutes | D |
|
|
102
|
+
| af_sarah | 🚺 | B | H hours | C+ |
|
|
103
|
+
| af_sky | 🚺 | B | _M minutes_ 🤏 | C- |
|
|
104
|
+
| am_adam | 🚹 | D | H hours | F+ |
|
|
105
|
+
| am_echo | 🚹 | C | MM minutes | D |
|
|
106
|
+
| am_eric | 🚹 | C | MM minutes | D |
|
|
107
|
+
| am_fenrir | 🚹 | B | H hours | C+ |
|
|
108
|
+
| am_liam | 🚹 | C | MM minutes | D |
|
|
109
|
+
| am_michael | 🚹 | B | H hours | C+ |
|
|
110
|
+
| am_onyx | 🚹 | C | MM minutes | D |
|
|
111
|
+
| am_puck | 🚹 | B | H hours | C+ |
|
|
112
|
+
| am_santa | 🚹 | C | _M minutes_ 🤏 | D- |
|
|
113
|
+
|
|
114
|
+
### Chinese (Mandarin) — v1.1 zh voices
|
|
115
|
+
|
|
116
|
+
| Name | Gender | Name | Gender | Name | Gender |
|
|
117
|
+
| -------- | ------ | ------- | ------ | ------- | ------ |
|
|
118
|
+
| zf_001 | 🚺 | zf_046 | 🚺 | zm_052 | 🚹 |
|
|
119
|
+
| zf_002 | 🚺 | zf_047 | 🚺 | zm_053 | 🚹 |
|
|
120
|
+
| zf_003 | 🚺 | zf_048 | 🚺 | zm_054 | 🚹 |
|
|
121
|
+
| zf_004 | 🚺 | zf_049 | 🚺 | zm_055 | 🚹 |
|
|
122
|
+
| zf_005 | 🚺 | zf_051 | 🚺 | zm_056 | 🚹 |
|
|
123
|
+
| zf_006 | 🚺 | zf_059 | 🚺 | zm_057 | 🚹 |
|
|
124
|
+
| zf_007 | 🚺 | zf_060 | 🚺 | zm_058 | 🚹 |
|
|
125
|
+
| zf_008 | 🚺 | zf_067 | 🚺 | zm_061 | 🚹 |
|
|
126
|
+
| zf_017 | 🚺 | zf_070 | 🚺 | zm_062 | 🚹 |
|
|
127
|
+
| zf_018 | 🚺 | zf_071 | 🚺 | zm_063 | 🚹 |
|
|
128
|
+
| zf_019 | 🚺 | zf_072 | 🚺 | zm_064 | 🚹 |
|
|
129
|
+
| zf_021 | 🚺 | zf_073 | 🚺 | zm_065 | 🚹 |
|
|
130
|
+
| zf_022 | 🚺 | zf_074 | 🚺 | zm_066 | 🚹 |
|
|
131
|
+
| zf_023 | 🚺 | zf_075 | 🚺 | zm_068 | 🚹 |
|
|
132
|
+
| zf_024 | 🚺 | zf_076 | 🚺 | zm_069 | 🚹 |
|
|
133
|
+
| zf_026 | 🚺 | zf_077 | 🚺 | zm_080 | 🚹 |
|
|
134
|
+
| zf_027 | 🚺 | zf_078 | 🚺 | zm_081 | 🚹 |
|
|
135
|
+
| zf_028 | 🚺 | zf_079 | 🚺 | zm_082 | 🚹 |
|
|
136
|
+
| zf_032 | 🚺 | zf_083 | 🚺 | zm_089 | 🚹 |
|
|
137
|
+
| zf_036 | 🚺 | zf_084 | 🚺 | zm_091 | 🚹 |
|
|
138
|
+
| zf_038 | 🚺 | zf_085 | 🚺 | zm_095 | 🚹 |
|
|
139
|
+
| zf_039 | 🚺 | zf_086 | 🚺 | zm_096 | 🚹 |
|
|
140
|
+
| zf_040 | 🚺 | zf_087 | 🚺 | zm_097 | 🚹 |
|
|
141
|
+
| zf_042 | 🚺 | zf_088 | 🚺 | zm_098 | 🚹 |
|
|
142
|
+
| zf_043 | 🚺 | zf_090 | 🚺 | zm_100 | 🚹 |
|
|
143
|
+
| zf_044 | 🚺 | zf_092 | 🚺 | zm_009 | 🚹 |
|
|
144
|
+
| zf_092 | 🚺 | zf_093 | 🚺 | zm_010 | 🚹 |
|
|
145
|
+
| zf_094 | 🚺 | zf_099 | 🚺 | zm_011 | 🚹 |
|
|
146
|
+
| zm_012 | 🚹 | zm_020 | 🚹 | zm_029 | 🚹 |
|
|
147
|
+
| zm_013 | 🚹 | zm_025 | 🚹 | zm_030 | 🚹 |
|
|
148
|
+
| zm_014 | 🚹 | zm_031 | 🚹 | zm_033 | 🚹 |
|
|
149
|
+
| zm_015 | 🚹 | zm_034 | 🚹 | zm_035 | 🚹 |
|
|
150
|
+
| zm_016 | 🚹 | zm_037 | 🚹 | zm_041 | 🚹 |
|
|
151
|
+
| zm_045 | 🚹 | zm_050 | 🚹 | | |
|
|
152
|
+
|
|
153
|
+
Use with v1.1 zh model: `onnx-community/Kokoro-82M-v1.1-zh-ONNX`.
|
|
154
|
+
|
|
155
|
+
### British English
|
|
156
|
+
|
|
157
|
+
| Name | Traits | Target Quality | Training Duration | Overall Grade |
|
|
158
|
+
| ----------- | ------ | -------------- | ----------------- | ------------- |
|
|
159
|
+
| bf_alice | 🚺 | C | MM minutes | D |
|
|
160
|
+
| bf_emma | 🚺 | B | **HH hours** | B- |
|
|
161
|
+
| bf_isabella | 🚺 | B | MM minutes | C |
|
|
162
|
+
| bf_lily | 🚺 | C | MM minutes | D |
|
|
163
|
+
| bm_daniel | 🚹 | C | MM minutes | D |
|
|
164
|
+
| bm_fable | 🚹 | B | MM minutes | C |
|
|
165
|
+
| bm_george | 🚹 | B | MM minutes | C |
|
|
166
|
+
| bm_lewis | 🚹 | C | H hours | D+ |
|
package/dist/kokoro.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("@huggingface/transformers"),n=require("phonemizer"),t=require("pinyin-pro"),a=require("path"),l=require("fs/promises");const r=new Map([[",",","],["。","."],["!","!"],["?","?"],[";",";"],[":",":"],["、",","]]),s=["零","一","二","三","四","五","六","七","八","九"],g=/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+[0-5]$/,i=/^[零一二三四五六七八九十百千万亿两]+$/,o=["千万美元","百万美元","千万块","百万块","千万吨","百万吨","万美元","亿元","万元","美元","千克","毫克","微克","公里","公分","公尺","公寸","公釐","千米","分米","厘米","毫米","微米","小时","分钟","封","艘","把","目","套","段","人","所","朵","匹","张","座","回","场","尾","条","个","首","阙","阵","网","炮","顶","丘","棵","只","支","袭","辆","挑","担","颗","壳","窠","曲","墙","群","腔","砣","客","贯","扎","捆","刀","令","打","手","罗","坡","山","岭","江","溪","钟","队","单","双","对","出","口","头","脚","板","跳","枝","件","贴","针","线","管","名","位","身","堂","课","本","页","家","户","层","丝","毫","厘","分","钱","两","斤","铢","石","钧","锱","忽","克","寸","尺","丈","里","寻","常","铺","程","米","撮","勺","合","升","斗","盘","碗","碟","叠","桶","笼","盆","盒","杯","斛","锅","簋","篮","罐","瓶","壶","卮","盏","箩","箱","煲","啖","袋","钵","年","月","日","季","刻","时","周","天","秒","旬","纪","岁","世","更","夜","春","夏","秋","冬","代","伏","辈","丸","泡","粒","幢","堆","道","面","片","块","元","角","毛","吨","百","千","万","亿"].sort(((e,n)=>n.length-e.length)),c=new Map([["我想去",["我想","去"]],["你的",["你","的"]],["能不能",["能","不能"]],["买了",["买","了"]],["吃了",["吃","了"]],["了两把",["了","两把"]],["吃了一碗",["吃","了","一碗"]],["学不好",["学","不好"]],["做的",["做","的"]],["先去",["先","去"]],["热腾腾的",["热腾腾","的"]]]),u=new Set(["上海","里","你","我们","药品","计算机","喜欢","著名","千古","做"]),h=new Set(["买","来","开","吃"]),m=new Set(["一辈","丈人","丈夫","上司","上头","下巴","下水","不由","世故","东家","东西","两口","丧气","丫头","主意","买卖","事情","云彩","交情","亲家","亲戚","人家","什么","介绍","休息","伙计","似的","位置","体面","作坊","佩服","使唤","便宜","倒腾","兄弟","先生","关系","养活","冒失","冤家","冤枉","冷战","凉快","凑合","凤凰","出息","分析","利害","利索","利落","别人","别扭","刺激","刺猬","前头","力气","功夫","动弹","动静","勤快","匀称","包涵","包袱","千斤","厉害","厚道","口袋","叫唤","吆喝","合同","吉他","名堂","名字","后头","吓唬","含糊","告示","告诉","和尚","咕噜","咖喱","咳嗽","哆嗦","哈欠","哑巴","唾沫","商量","喇叭","喇嘛","喉咙","喜欢","喽啰","嘀咕","嘟囔","嘱咐","嘴巴","困难","在乎","地方","地道","壮实","外甥","多么","多少","大人","大夫","大意","大方","大爷","太阳","头发","女婿","奴才","妖精","妥当","妯娌","姐夫","姑娘","委屈","姥爷","娘家","婆家","媒人","媳妇","嫁妆","字号","学问","官司","实在","客气","家伙","寒碜","寡妇","对付","对头","将军","将就","小伙","小气","少爷","尾巴","屁股","岁数","工夫","差事","巴掌","巴结","师傅","师父","希罕","帐篷","帮手","干事","幸福","庄稼","应酬","开通","弄堂","弟兄","张罗","得罪","心思","志气","忙活","快活","念叨","念头","怎么","思量","怪物","悟性","惦记","意思","意识","懒得","戏弄","戒指","扁担","扎实","扑腾","打发","打听","打扮","打算","打量","扫帚","扫把","折腾","护士","报复","抬举","拖沓","招呼","招牌","拨弄","拳头","拾掇","指头","指甲","挑剔","挖苦","提防","收成","收拾","故事","新鲜","时候","明白","暖和","月亮","月饼","朋友","木匠","木头","本事","机灵","枇杷","枕头","架势","柴火","栅栏","核桃","棉花","棒槌","棺材","槟榔","模糊","欺负","正经","母亲","比方","泥鳅","活泼","浪头","消息","清楚","温和","溜达","滑溜","漂亮","火候","灯笼","炊帚","点心","烂糊","烟筒","烧饼","热闹","照顾","熟悉","爱人","父亲","爽快","牌楼","牙碜","牢骚","牲口","特务","状元","狐狸","玄乎","玫瑰","玻璃","琉璃","琢磨","琵琶","甘蔗","甜头","生意","畜生","疏忽","疙瘩","疟疾","痛快","痢疾","白净","盘算","盘缠","相声","眉毛","眨巴","眯缝","眼睛","知识","石匠","石头","石榴","码头","砚台","祖宗","福气","秀才","秀气","秧歌","称呼","稀罕","稳当","窗户","窝囊","窟窿","笑话","笑语","笤帚","答应","算盘","算计","篱笆","簸箕","粮食","精神","糊涂","糟蹋","糨糊","累赘","红火","结实","编辑","罐头","罗嗦","翻腾","老婆","老实","老爷","耳朵","耷拉","耽搁","耽误","聪明","胡同","胡琴","胡萝","胭脂","胳膊","能耐","脊梁","脑袋","脾气","膏药","自在","舌头","舒坦","舒服","芝麻","苍蝇","苗头","苗条","荒唐","荸荠","菩萨","萝卜","葡萄","葫芦","薄荷","蘑菇","蚂蚱","蛤蟆","蜡烛","行当","行李","街坊","衙门","衣服","衣裳","补丁","裁缝","见识","规矩","计划","认识","记号","记性","讲究","豆腐","财主","费用","趔趄","跟头","跳蚤","踏实","转悠","软和","过去","运气","这个","这么","连累","迷糊","造化","逻辑","道士","邋遢","那个","那么","部分","里头","里脊","钥匙","铁匠","铃铛","铺盖","锄头","门道","闺女","阔气","队伍","难为","风筝","馄饨","馒头","首饰","马虎","骆驼","骨头","高粱","鸳鸯","麻利","麻烦"]),f=new Set(["的","地","得"]),z=new Set(["地标"]),d=new Set(["们","子","上","下"]),_=new Set(["吧","呢","吗","啊","呀","嘛","呗"]),p=new Set(["小院儿","胡同儿","范儿","老汉儿","撒欢儿","寻老礼儿","妥妥儿"]),$=new Set(["虐儿","为儿","护儿","瞒儿","救儿","替儿","有儿","一儿","我儿","俺儿","妻儿","拐儿","聋儿","乞儿","患儿","幼儿","孤儿","婴儿","婴幼儿","连体儿","脑瘫儿","流浪儿","体弱儿","混血儿","蜜雪儿","舫儿","祖儿","美儿","应采儿","可儿","侄儿","孙儿","侄孙儿","女儿","男儿","红孩儿","花儿","虫儿","马儿","鸟儿","猪儿","猫儿","狗儿","少儿","花朵儿"]),w=new Map([["一百二十三个","ㄧ4ㄅㄞ3ㄦ4ㄕ十2/ㄙㄢ1ㄍㄜ5"],["一百二十三","ㄧ4ㄅㄞ3ㄦ4ㄕ十2/ㄙㄢ1"],["价格是十二点五元","ㄐ压4ㄍㄜ2/ㄕ十4/ㄕ十2ㄦ4ㄉ言3/ㄨ3元2"],["完成率是百分之九十五","万2ㄔㄥ2ㄌㄩ4/ㄕ十4/ㄅㄞ3ㄈㄣ1ㄓ十1ㄐ又3ㄕ十2ㄨ3"],["二零二六年","ㄦ4ㄌ应2ㄦ4/ㄌ又4ㄋ言2"],["二零二三年","ㄦ4ㄌ应2/ㄦ4ㄙㄢ1ㄋ言2"],["二零二四年","ㄦ4ㄌ应2ㄦ4/ㄙㄭ4ㄋ言2"],["二零二五年","ㄦ4ㄌ应2ㄦ4/ㄨ3ㄋ言2"],["二零二六年十二月三十一日","ㄦ4ㄌ应2ㄦ4/ㄌ又4ㄋ言2/ㄕ十2ㄦ4月4/ㄙㄢ1ㄕ十2ㄧ2ㄖ十4"],["二零二五年十二月三十一日","ㄦ4ㄌ应2ㄦ4/ㄨ3ㄋ言2/ㄕ十2ㄦ4月4/ㄙㄢ1ㄕ十2ㄧ2ㄖ十4"],["今天是","ㄐ阴1ㄊ言1/ㄕ十4"],["今天是二零二六年六月十六日","ㄐ阴1ㄊ言1/ㄕ十4/ㄦ4ㄌ应2ㄦ4/ㄌ又4ㄋ言2/ㄌ又4月4/ㄕ十2ㄌ又4ㄖ十4"],["百分之十二点五","ㄅㄞ3ㄈㄣ1ㄓ十1ㄕ十2/ㄦ4ㄉ言3ㄨ3"],["十五点半","ㄕ十2ㄨ3ㄉ言3/ㄅㄢ4"],["八点零五分","ㄅㄚ1ㄉ言3/ㄌ应2ㄨ3ㄈㄣ1"],["八点半","ㄅㄚ1ㄉ言3ㄅㄢ4"],["十二点半","ㄕ十2ㄦ4ㄉ言3/ㄅㄢ4"],["这个","ㄓㄜ4ㄍㄜ5"],["一个","ㄧ2ㄍㄜ5"],["今天天气","ㄐ阴1ㄊ言1ㄊ言1ㄑㄧ4"],["今天下午","ㄐ阴1ㄊ言1ㄒ压4ㄨ3"],["三点","ㄙㄢ1ㄉ言3"],["儿化","ㄦ2ㄏ穵4"],["小院儿","ㄒ要3元R4"],["胡同儿","ㄏㄨ2ㄊ中R5"],["媳妇儿","ㄒㄧ2ㄈㄨR5"],["少儿","ㄕㄠ4ㄦ2"],["不怕困难","ㄅㄨ2ㄆㄚ4ㄎ文4ㄋㄢ5"],["两只小狗","ㄌ阳2ㄓ十3/ㄒ要2ㄍㄡ3"],["一点一支持","ㄧ4ㄉ言3/ㄧ4ㄓ十1ㄔ十2"],["长长的路","ㄔㄤ2ㄔㄤ2ㄉㄜ5/ㄌㄨ4"],["发卡行","ㄈㄚ4ㄎㄚ3ㄏㄤ2"],["放款行","ㄈㄤ4ㄎ万3ㄏㄤ2"],["茧行","ㄐ言3ㄏㄤ2"],["各地","ㄍㄜ4ㄉㄧ5"],["色差","ㄙㄜ4ㄔㄚ1"],["借还款","ㄐㄝ4/ㄏ万2ㄎ万3"],["还款","ㄏ万2ㄎ万3"],["还款成功","ㄏ万2ㄎ万3/ㄔㄥ2ㄍ中1"],["时间为准","ㄕ十2ㄐ言1/为2ㄓ文3"],["他的","ㄊㄚ1/ㄉㄜ5"],["好吧","ㄏㄠ3/ㄅㄚ5"],["慢慢地","ㄇㄢ4ㄇㄢ4/ㄉㄜ5"],["听不到","ㄊ应1/ㄅㄨ2ㄉㄠ4"],["试试看","ㄕ十4ㄕ十5ㄎㄢ4"],["早上","ㄗㄠ3ㄕㄤ4"],["树下","ㄕㄨ4ㄒ压5"],["热腾腾","ㄖㄜ4ㄊㄥ2ㄊㄥ2"],["人工智能","ㄖㄣ2ㄍ中1ㄓ十4ㄋㄥ2"],["量子","ㄌ阳4ㄗㄭ3"],["计算机","ㄐㄧ4ㄙ万4ㄐㄧ1"],["这件","ㄓㄜ4ㄐ言4"],["一举两得","ㄧ4ㄐㄩ3ㄌ阳3ㄉㄜ5"],["一分为二儿","ㄧ4ㄈㄣ1为2ㄦ4"],["一分为二地看","ㄧ4ㄈㄣ1为2ㄦ4/ㄉㄜ5/ㄎㄢ4"],["一概而论","ㄧ2ㄍㄞ4ㄦ2ㄌ文4"],["学不好","ㄒ月2/ㄅㄨ4ㄏㄠ3"],["嗲","ㄉㄧㄚ3"],["呗","ㄅㄟ5"],["咗","ㄗㄨㄛ5"],["嘞","ㄌㄟ5"],["个","ㄍㄜ5"],["撒欢儿","ㄙㄚ1ㄏ万R1"],["寻老礼儿","ㄒ云2ㄌㄠ3ㄌㄧR3"],["妥妥儿","ㄊ我3ㄊ我R5"],["老板很好","ㄌㄠ2ㄅㄢ2ㄏㄣ3/ㄏㄠ3"],["一百一十一","ㄧ1ㄅㄞ3ㄧ1ㄕ十2/ㄧ1"],["一点五倍","ㄧ4ㄉ言3/ㄨ3ㄅㄟ4"],["价格为十二点五元","ㄐ压4ㄍㄜ2/为4/ㄕ十2ㄦ4ㄉ言3/ㄨ3元2"],["增长百分之三点五","ㄗㄥ1ㄓㄤ3/ㄅㄞ3ㄈㄣ1ㄓ十1ㄙㄢ1ㄉ言3/ㄨ3"],["四个半小时","ㄙㄭ4ㄍㄜ5/ㄅㄢ4ㄒ要3ㄕ十2"],["需要四个半小时","ㄒㄩ1要4/ㄙㄭ4ㄍㄜ5/ㄅㄢ4ㄒ要3ㄕ十2"],["一九八零年","ㄧ1ㄐ又3ㄅㄚ1/ㄌ应2/ㄋ言2"],["二零零八年八月八日","ㄦ4ㄌ应2ㄌ应2ㄅㄚ1ㄋ言2/ㄅㄚ1月4ㄅㄚ1/ㄖ十4"]]),b=[...w.keys()].sort(((e,n)=>n.length-e.length)),M=new Set(["开户行","行号","掺和","国际化","高楼大厦","热腾腾","牛肉面"]),F=new Map([["b","ㄅ"],["p","ㄆ"],["m","ㄇ"],["f","ㄈ"],["d","ㄉ"],["t","ㄊ"],["n","ㄋ"],["l","ㄌ"],["g","ㄍ"],["k","ㄎ"],["h","ㄏ"],["j","ㄐ"],["q","ㄑ"],["x","ㄒ"],["zh","ㄓ"],["ch","ㄔ"],["sh","ㄕ"],["r","ㄖ"],["z","ㄗ"],["c","ㄘ"],["s","ㄙ"]]),y=new Map([["a","ㄚ"],["o","ㄛ"],["e","ㄜ"],["ai","ㄞ"],["ei","ㄟ"],["ao","ㄠ"],["ou","ㄡ"],["an","ㄢ"],["en","ㄣ"],["ang","ㄤ"],["eng","ㄥ"],["er","ㄦ"],["i","ㄧ"],["ii","ㄭ"],["iii","十"],["ia","压"],["ie","ㄝ"],["iao","要"],["iou","又"],["ian","言"],["in","阴"],["iang","阳"],["ing","应"],["iong","用"],["u","ㄨ"],["ua","穵"],["uo","我"],["uai","外"],["uei","为"],["uan","万"],["uen","文"],["uang","王"],["ueng","瓮"],["ong","中"],["v","ㄩ"],["ve","月"],["van","元"],["vn","云"]]),v="undefined"!=typeof Intl&&Intl.Segmenter?new Intl.Segmenter("zh",{granularity:"word"}):null;function x(e){if(e.includes("."))return e;if(e.includes(":")){let[n,t]=e.split(":").map(Number);return 0===t?`${n} o'clock`:t<10?`${n} oh ${t}`:`${n} ${t}`}let n=parseInt(e.slice(0,4),10);if(n<1100||n%1e3<10)return e;let t=e.slice(0,2),a=parseInt(e.slice(2,4),10),l=e.endsWith("s")?"s":"";if(n%1e3>=100&&n%1e3<=999){if(0===a)return`${t} hundred${l}`;if(a<10)return`${t} oh ${a}${l}`}return`${t} ${a}${l}`}function k(e){const n="$"===e[0]?"dollar":"pound";if(isNaN(Number(e.slice(1))))return`${e.slice(1)} ${n}s`;if(!e.includes(".")){let t="1"===e.slice(1)?"":"s";return`${e.slice(1)} ${n}${t}`}const[t,a]=e.slice(1).split("."),l=parseInt(a.padEnd(2,"0"),10);return`${t} ${n}${"1"===t?"":"s"} and ${l} ${"$"===e[0]?1===l?"cent":"cents":1===l?"penny":"pence"}`}function S(e){let[n,t]=e.split(".");return`${n} point ${t.split("").join(" ")}`}function A(e){if(e<10)return s[e];if(e<100){const n=Math.floor(e/10),t=e%10;return`${1===n?"":s[n]}十${0===t?"":s[t]}`}if(e<1e3){const n=Math.floor(e/100),t=e%100;return`${s[n]}百${0===t?"":t<10?`零${s[t]}`:A(t)}`}if(e<1e4){const n=Math.floor(e/1e3),t=e%1e3;return`${s[n]}千${0===t?"":t<100?`零${A(t)}`:A(t)}`}return String(e)}function j(e){return A(e)}function N(e){if(e<1e4)return j(e);const n=Math.floor(e/1e8),t=Math.floor(e%1e8/1e4),a=e%1e4,l=[];return n>0&&l.push(`${N(n)}亿`),t>0&&(n>0&&t<1e3&&l.push("零"),l.push(`${j(t)}万`)),a>0&&((n>0||t>0&&a<1e3)&&l.push("零"),l.push(j(a))),l.join("").replace(/零+/g,"零").replace(/零$/g,"")}function W(e){return[...e].map((e=>s[Number(e)])).join("")}function Z(e){return W(e).replace(/一/g,"幺")}function E(e,n=!0){return n?e.replace(/^\+/,"").split(/\s+/).filter(Boolean).map(Z).join(","):e.split("-").map(Z).join(",")}function T(e){const[n,t=""]=e.split(".");let a=N(Number(n));return t.replace(/0+$/,"")&&(a+=`点${W(t.replace(/0+$/,""))}`),a}const R=new RegExp(`(?<![\\d./A-Za-z])(\\d+)([多余几+])?(${o.join("|")})(?![\\d./A-Za-z])`,"g");function L(e){const n=A(Number(e));return e.startsWith("0")?`零${n}`:n}function I(e,n,t=""){let a=`${A(Number(e))}点`;return 0!==Number(n)&&(a+=30===Number(n)?"半":`${L(n)}分`),t&&0!==Number(t)&&(a+=`${L(t)}秒`),a}function P(e){return e.replace(/(\d{4})([- /.])(0[1-9]|1[0-2])\2(0[1-9]|[12]\d|3[01])/g,((e,n,t,a,l)=>`${W(n)}年${A(Number(a))}月${A(Number(l))}日`)).replace(/([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?([~-])([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?/g,((e,n,t,a="",l,r,s,g="")=>`${I(n,t,a)}至${I(r,s,g)}`)).replace(/([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?/g,((e,n,t,a="")=>I(n,t,a))).replace(/(\d{4})年(?:(0?[1-9]|1[0-2])月)?(?:(0?[1-9]|[12]\d|30|31)([日号]))?/g,((e,n,t="",a="",l="")=>{const r=t?`${A(Number(t))}月`:"",s=a?`${A(Number(a))}${l}`:"";return`${W(n)}年${r}${s}`})).replace(R,((e,n,t="",a)=>function(e,n="",t){return`${T(e)}${"+"===n?"多":n}${t}`}(n,t,a))).replace(/(?<!\d)((?:\+?86\s?)?1(?:[38]\d|5[0-35-9]|7[678]|9[89])\d{8})(?!\d)/g,(e=>E(e))).replace(/(?<!\d)((?:0(?:10|2[1-3]|[3-9]\d{2})-?)?[1-9]\d{6,7})(?!\d)/g,(e=>E(e,!1))).replace(/(?<!\d)400-?\d{3}-?\d{4}(?!\d)/g,(e=>E(e,!1))).replace(/(电话|号码|热线|客服)(\d{5})(?!\d)/g,((e,n,t)=>`${n}${Z(t)}`)).replace(/(?<![\d./A-Za-z])([1-9]\d{0,3})\/([1-9]\d{0,3})(?![\d./A-Za-z])/g,((e,n,t)=>function(e,n){return`${A(Number(n))}分之${A(Number(e))}`}(n,t))).replace(/(?<![\d.])([+-]?)(\d+(?:\.\d+)?)%/g,((e,n,t)=>function(e,n){return`${"+"===e?"正":"-"===e?"负":""}百分之${T(n)}`}(n,t))).replace(/(?<![\d./A-Za-z])(\d+(?:\.\d+)?)(℃|°C|kg|cm)(?![\d./A-Za-z])/gi,((e,n,t)=>function(e,n){const t=n.toLowerCase(),a=T(e);return"℃"===t||"°c"===t?`摄氏${a}度`:"kg"===t?`${a}千克`:"cm"===t?`${a}厘米`:`${a}${n}`}(n,t))).replace(/(\bv)(\d+\.\d+)(?![\d./A-Za-z])/gi,((e,n,t)=>`${n}${T(t)}`)).replace(/(?<![\d./A-Za-z])\d+\.\d+(?![\d./A-Za-z])/g,(e=>T(e))).replace(/(?<![\d./A-Za-z])([1-9]\d{0,3})[~-]([1-9]\d{0,3})(?![\d./A-Za-z])/g,((e,n,t)=>function(e,n){return`${A(Number(e))}到${A(Number(n))}`}(n,t))).replace(/(?<![\d.])-(\d{1,4})(?![\d.])/g,((e,n)=>`负${A(Number(n))}`)).replace(/\b\d{1,4}\b/g,(e=>A(Number(e))))}function O(e){const n=function(e){const n=e.match(/^([a-züv:]+)([0-5])$/i);return n?{base:n[1].toLowerCase().replace(/u:/g,"v").replace(/ü/g,"v"),tone:"0"===n[2]?"5":n[2]}:null}(e);if(!n)return e;let{initial:t,final:a}=function(e){for(const n of["zh","ch","sh"])if(e.startsWith(n))return{initial:n,final:e.slice(n.length)};const n=e.at(0);return F.has(n)?{initial:n,final:e.slice(1)}:e.startsWith("yi")?{initial:"",final:e.replace(/^yi/,"i")}:e.startsWith("yu")?{initial:"",final:e.replace(/^yu/,"v")}:e.startsWith("y")?{initial:"",final:`i${e.slice(1)}`}:e.startsWith("wu")?{initial:"",final:e.replace(/^wu/,"u")}:e.startsWith("w")?{initial:"",final:`u${e.slice(1)}`}:{initial:"",final:e}}(n.base);["j","q","x"].includes(t)&&a.startsWith("u")&&(a=`v${a.slice(1)}`),a=function(e){return"iu"===e?"iou":"ui"===e?"uei":"un"===e?"uen":e}(a),["z","c","s"].includes(t)&&"i"===a?a="ii":["zh","ch","sh","r"].includes(t)&&"i"===a&&(a="iii");const l=F.get(t)??"",r=y.get(a);return r?`${l}${r}${n.tone}`:e}function B(e){if("了"===e)return"ㄌㄜ5";const n=t.pinyin(e,{type:"array",toneType:"num"}).map(O),a=e.endsWith("元")&&[...e.slice(0,-1)].every((e=>i.test(e)));if(e.length>1&&[...e].every((e=>i.test(e))))for(let t=0;t<n.length;t++)"一"===e[t]&&n[t].endsWith("4")&&(n[t]=n[t].slice(0,-1)+"1");if(e.length>1&&e.endsWith("地")){if("di4"===t.pinyin(e[e.length-1],{toneType:"num"})){const e=O("de5");g.test(n[n.length-1])&&(n[n.length-1]=e)}}3===n.length&&"一"===e[1]&&e[0]===e[2]&&"ㄧ1"===n[1]&&(n[1]="ㄧ5"),3===n.length&&"不"===e[1]&&"ㄅㄨ4"===n[1]&&(n[1]="ㄅㄨ5");const l=n.map((e=>!!g.test(e)&&e.endsWith("3")));for(let t=0;t<n.length-1;t+=1)e.startsWith("第一")&&1===t&&"ㄧ1"===n[t]||"ㄧ1"===n[t]&&[...e].every(((e,n)=>n===t||i.test(e)))||("ㄧ1"===n[t]&&/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+4$/.test(n[t+1])?n[t]="ㄧ2":"ㄧ1"===n[t]&&/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+[1-3]$/.test(n[t+1])?n[t]="ㄧ4":"ㄅㄨ4"===n[t]&&/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+4$/.test(n[t+1])&&(n[t]="ㄅㄨ2"),!a&&g.test(n[t])&&n[t].endsWith("3")&&g.test(n[t+1])&&n[t+1].endsWith("3")&&(n[t]=`${n[t].slice(0,-1)}2`));if(m.has(e)||m.has(e.slice(-2))){const e=n[n.length-1];g.test(e)&&(n[n.length-1]=`${e.slice(0,-1)}5`)}if(3===n.length&&l.every(Boolean)){const t=v?[...v.segment(e)].filter((e=>e.segment.trim().length>0)).map((e=>e.segment)):[e];2===t.length&&1===t[0].length&&2===t[1].length&&(n[0]=n[0].slice(0,-1)+"3")}!a&&4===n.length&&l.every(Boolean)&&n[3].endsWith("3")&&(n[0]=n[0].slice(0,-1)+"2",n[2]=n[2].slice(0,-1)+"2",n[1].endsWith("2")&&(n[1]=n[1].slice(0,-1)+"3")),2===n.length&&e[0]===e[1]&&g.test(n[0])&&g.test(n[1])&&(/^(?:慢慢|刚刚|常|渐渐|万万)$/.test(e)||/^[零一二三四五六七八九]+$/.test(e)||(n[1]=`${n[1].slice(0,-1)}5`));for(let t=1;t<n.length;t+=1){const a=e[t];f.has(a)&&g.test(n[t])&&(n[t]=`${n[t].slice(0,-1)}5`)}if(n.length>1){const t=e[e.length-1];d.has(t)&&g.test(n[n.length-1])&&(n[n.length-1]=`${n[n.length-1].slice(0,-1)}5`)}if(n.length>1){const t=e[e.length-1];_.has(t)&&g.test(n[n.length-1])&&(n[n.length-1]=`${n[n.length-1].slice(0,-1)}5`)}if(n.length>1&&e.endsWith("儿")&&g.test(n[n.length-1])){const t=n[n.length-1].slice(-1);if("2"===t||"5"===t)if(p.has(e)){const e=n.length-2;if(g.test(n[e])){const t=n[e];n[e]=t.slice(0,-1)+"R"+t.slice(-1),n.pop()}}else if(!$.has(e)&&"女儿"!==e&&"花儿"!==e&&"少儿"!==e){const e=n.length-2;if(g.test(n[e])&&!/R/.test(n[e])){const t=n[e];n[e]=t.slice(0,-1)+"R"+t.slice(-1),n.pop()}}}return n.join("").replace(/\s+([,.;:!?,。!?;:、])/g,"$1").replace(/\s+/g," ").trim()}function q(e,n){if(!n||0===n.size)return e;const t=[];let a=0;for(;a<e.length;){let l=e[a],r=1;for(let t=2;t<=4&&a+t<=e.length;t++){const s=e.slice(a,a+t).join("");n.has(s)&&(l=s,r=t)}t.push(l),a+=r}return t}function C(e){const n=[];for(let t=0;t<e.length;t+=1){let a=e[t];if(i.test(a)){const l=t;for(;t+1<e.length&&i.test(e[t+1]);)a+=e[t+1],t+=1;if(t+1<e.length&&"元"===e[t+1])a+=e[t+1],t+=1;else{if(t+2<e.length&&"个"===e[t+1]&&"半"===e[t+2]){n.push(`${a}个`),n.push("半"),t+=2;continue}t=l,a=e[t]}}"半"===a&&t+1<e.length&&"小时"===e[t+1]?(n.push("半小时"),t+=1):n.push(a)}return n}function D(e){return e.flatMap((e=>c.get(e)??[e]))}function V(e,n){return n>0&&"个"===e[n]&&i.test(e[n-1])&&"半"===e[n+1]}function Y(e){return function(e){const n=[];let a=0;for(;a<e.length;){let l=null;for(const n of b)if(e.startsWith(n,a)&&!V(e,a)){l=n;break}if(l){n.push(w.get(l)),a+=l.length;continue}let r=a+1;for(;r<e.length;){let n=!1;for(const t of b)if(e.startsWith(t,r)&&!V(e,r)){n=!0;break}if(n)break;r+=1}const s=e.slice(a,r);let g=v?[...v.segment(s)].filter((({segment:e})=>e.trim().length>0)).map((({segment:e})=>e)):[s];g=D(g),g=q(g,M),g=C(g);const i=[];for(let e=0;e<g.length;e+=1){let n=g[e];if("儿"===n&&i.length>0)i[i.length-1]+="儿";else{if("一"===n||n.length>1&&"一"===n[0]){if(n.length>1&&i.length>0){const e=n.slice(1),t=i[i.length-1];if(1===t.length&&t===e[0]){i[i.length-1]=t+n;continue}}if("一"===n&&e+1<g.length&&i.length>0){const n=i[i.length-1],t=g[e+1];if(1===n.length&&n===t[0]){i[i.length-1]=n+"一"+t,e+=1;continue}}"一"===n&&e+1<g.length&&(e+=1,n="一"+g[e])}else if(("不"===n||n.length>1&&"不"===n[0])&&!["不太","不能"].includes(n)){if(n.length>1&&i.length>0){const e=i[i.length-1];if(1===e.length){i[i.length-1]=e+n;continue}}if("不"===n&&e+1<g.length&&i.length>0){const n=i[i.length-1];if(1===n.length){i[i.length-1]=n+"不"+g[e+1],e+=1;continue}}"不"===n&&e+1<g.length&&(e+=1,n="不"+g[e])}else{if(["了","着","过"].includes(n)&&i.length>0){if("了"===n&&h.has(i[i.length-1])){i.push(n);continue}i[i.length-1]+=n;continue}if(["日","号"].includes(n)&&i.length>0){i[i.length-1]+=n;continue}if(f.has(n)&&i.length>0&&!("地"===n&&e+1<g.length&&z.has(`${n}${g[e+1]}`))){const e=i[i.length-1];if(u.has(e)){i.push(n);continue}if(e.length>0){i[i.length-1]=e+n;continue}}}if(i.length>0&&"第"===i[i.length-1])i[i.length-1]+=n;else{if(i.length>0){const e=i[i.length-1];if(["了","着","过"].includes(e)||["了","着","过"].includes(n)){i.push(n);continue}const a=e[e.length-1],l=n[0],r=t.pinyin(a,{toneType:"num"}),s=t.pinyin(l,{toneType:"num"});if(r.endsWith("3")&&s.endsWith("3")&&e.length+n.length<=3){i[i.length-1]+=n;continue}}if(1===n.length&&i.length>0){const e=i[i.length-1];if(e===n){i[i.length-1]=e+n;continue}if(["了","着","过"].includes(e)||["了","着","过"].includes(n)){i.push(n);continue}const a=e[e.length-1],l=t.pinyin(a,{toneType:"num"}),r=t.pinyin(n[0],{toneType:"num"});if(l.endsWith("3")&&r.endsWith("3")){i[i.length-1]+=n;continue}}i.push(n)}}}const o=i.map((e=>B(e))).join("/");o&&n.push(o),a=r}return n.join("/")}(e)}async function G(e){const n=P(function(e){return e.replace(/[,。!?;:、]/g,(e=>r.get(e)??e))}(e)).match(/[\u4E00-\u9FFF]+|[^\u4E00-\u9FFF]+/g)??[];return(await Promise.all(n.map((async e=>/[\u4E00-\u9FFF]/.test(e)?Y(e):/[A-Za-z]/.test(e)?Q(e,"a"):e)))).join(" ").replace(/\s+([,.;:!?])/g,"$1").replace(/❓\./g,"❓ .").replace(/\s+/g," ").trim()}function H(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const J=new RegExp(`(\\s*[${H(';:,.!?¡¿—…"«»“”(){}[]')}]+\\s*)+`,"g"),K=new Map([["uzen","jˈuː.zən"]]),X=new RegExp(`\\b(${[...K.keys()].map(H).join("|")})\\b`,"gi");async function Q(e,t="a",a=!0){if("z"===t)return G(e);a&&(e=function(e){return e.replace(/[‘’]/g,"'").replace(/«/g,"“").replace(/»/g,"”").replace(/[“”]/g,'"').replace(/\(/g,"«").replace(/\)/g,"»").replace(/、/g,", ").replace(/。/g,". ").replace(/!/g,"! ").replace(/,/g,", ").replace(/:/g,": ").replace(/;/g,"; ").replace(/?/g,"? ").replace(/[^\S \n]/g," ").replace(/ +/," ").replace(/(?<=\n) +(?=\n)/g,"").replace(/\bD[Rr]\.(?= [A-Z])/g,"Doctor").replace(/\b(?:Mr\.|MR\.(?= [A-Z]))/g,"Mister").replace(/\b(?:Ms\.|MS\.(?= [A-Z]))/g,"Miss").replace(/\b(?:Mrs\.|MRS\.(?= [A-Z]))/g,"Mrs").replace(/\betc\.(?! [A-Z])/gi,"etc").replace(/\b(y)eah?\b/gi,"$1e'a").replace(/\d*\.\d+|\b\d{4}s?\b|(?<!:)\b(?:[1-9]|1[0-2]):[0-5]\d\b(?!:)/g,x).replace(/(?<=\d),(?=\d)/g,"").replace(/[$£]\d+(?:\.\d+)?(?: hundred| thousand| (?:[bm]|tr)illion)*\b|[$£]\d+\.\d\d?\b/gi,k).replace(/\d*\.\d+/g,S).replace(/(?<=\d)-(?=\d)/g," to ").replace(/(?<=\d)S/g," S").replace(/(?<=[BCDFGHJ-NP-TV-Z])'?s\b/g,"'S").replace(/(?<=X')S\b/g,"s").replace(/(?:[A-Za-z]\.){2,} [a-z]/g,(e=>e.replace(/\./g,"-"))).replace(/(?<=[A-Z])\.(?=[A-Z])/gi,"-").trim()}(e));const l=function(e,n){const t=[];let a=0;for(const l of e.matchAll(n)){const n=l[0];a<l.index&&t.push({match:!1,text:e.slice(a,l.index)}),n.length>0&&t.push({match:!0,text:n}),a=l.index+n.length}return a<e.length&&t.push({match:!1,text:e.slice(a)}),t}(e,J),r="a"===t?"en-us":"en",s=(await Promise.all(l.map((async({match:e,text:t})=>e?t:async function(e,t){const a=[];let l=0;for(const r of e.matchAll(X)){const s=e.slice(l,r.index),g=r.index+r[0].length;l<r.index?a.push((await n.phonemize(s,t)).join(" ")):r.index>0&&/\s/.test(e[r.index-1])&&a.push(" "),a.push(K.get(r[0].toLowerCase())),g<e.length&&/\s/.test(e[g])&&a.push(" "),l=g}return l<e.length&&a.push((await n.phonemize(e.slice(l),t)).join(" ")),a.join("")}(t,r))))).join("");let g=s.replace(/kəkˈoːɹoʊ/g,"kˈoʊkəɹoʊ").replace(/kəkˈɔːɹəʊ/g,"kˈəʊkəɹəʊ").replace(/ʲ/g,"j").replace(/r/g,"ɹ").replace(/x/g,"k").replace(/ɬ/g,"l").replace(/(?<=[a-zɹː])(?=hˈʌndɹɪd)/g," ").replace(/ z(?=[;:,.!?¡¿—…"«»“” ]|$)/g,"z");return"a"===t&&(g=g.replace(/(?<=nˈaɪn)ti(?!ː)/g,"di")),g.trim()}function U(e,n=!0){return".!?…。?!".includes(e)||n&&"\n"===e}function ee(e,n){let t=n;for(;t<e.length&&!/\s/.test(e[t]);)++t;return e.substring(n,t)}const ne=new Set(["mr","mrs","ms","dr","prof","sr","jr","sgt","col","gen","rep","sen","gov","lt","maj","capt","st","mt","etc","co","inc","ltd","dept","vs","p","pg","jan","feb","mar","apr","jun","jul","aug","sep","sept","oct","nov","dec","sun","mon","tu","tue","tues","wed","th","thu","thur","thurs","fri","sat"]);function te(e){return e=e.replace(/['’]s$/i,"").replace(/\.+$/,""),ne.has(e.toLowerCase())}const ae=new Map([[")","("],["]","["],["}","{"],["》","《"],["〉","〈"],["›","‹"],["»","«"],["〉","〈"],["」","「"],["』","『"],["〕","〔"],["】","【"]]),le=new Set(ae.values());function re(e,n,t,a){if('"'===e||"'"===e){if("'"===e&&t>0&&t<a.length-1&&/[A-Za-z]/.test(a[t-1])&&/[A-Za-z]/.test(a[t+1]))return;return void(n.length&&n.at(-1)===e?n.pop():n.push(e))}if(le.has(e))return void n.push(e);const l=ae.get(e);l&&n.length&&n.at(-1)===l&&n.pop()}class se{constructor(){this._buffer="",this._sentences=[],this._resolver=null,this._closed=!1}push(...e){for(const n of e)this._buffer+=n,this._process()}close(){if(this._closed)throw new Error("Stream is already closed.");this._closed=!0,this.flush()}flush(){const e=this._buffer.trim();e.length>0&&this._sentences.push(e),this._buffer="",this._resolve()}_resolve(){this._resolver&&(this._resolver(),this._resolver=null)}_process(){let e=0;const n=this._buffer,t=n.length;let a=0,l=[];const r=e=>{let a=e;for(;a+1<t&&U(n[a+1],!1);)++a;for(;a+1<t&&(l=n[a+1],"\"')]}」』".includes(l));)++a;var l;let r=a+1;for(;r<t&&/\s/.test(n[r]);)++r;return{end:a,nextNonSpace:r}};for(;a<t;){const s=n[a];if(re(s,l,a,n),0===l.length&&U(s)){const l=n.slice(e,a);if(/(^|\n)\d+$/.test(l)){++a;continue}const{end:g,nextNonSpace:i}=r(a);if(a===i-1&&"\n"!==s){++a;continue}if(i===t)break;let o=a-1;for(;o>=0&&/\S/.test(n[o]);)o--;o=Math.max(e,o+1);const c=ee(n,o);if(!c){++a;continue}if((/https?[,:]\/\//.test(c)||c.includes("@"))&&!U(c.at(-1))){a=o+c.length;continue}if(te(c)){++a;continue}if(/^([A-Za-z]\.)+$/.test(c)&&i<t&&/[A-Z]/.test(n[i])){++a;continue}if("."===s&&i<t&&/[a-z]/.test(n[i])){++a;continue}const u=n.substring(e,g+1).trim();if("..."===u||"…"===u){++a;continue}u&&this._sentences.push(u),a=e=g+1}else++a}this._buffer=n.substring(e),this._sentences.length>0&&this._resolve()}async*[Symbol.asyncIterator](){if(this._resolver)throw new Error("Another iterator is already active.");for(;;)if(this._sentences.length>0)yield this._sentences.shift();else{if(this._closed)break;await new Promise((e=>{this._resolver=e}))}}[Symbol.iterator](){this.flush();const e=this._sentences[Symbol.iterator]();return this._sentences=[],e}get sentences(){return this._sentences}}const ge=Object.freeze({af_maple:{name:"af_maple",language:"en-us",gender:"Female"},af_sol:{name:"af_sol",language:"en-us",gender:"Female"},bf_vale:{name:"bf_vale",language:"en-gb",gender:"Female"},zf_001:{name:"zf_001",language:"zh",gender:"Female"},zf_002:{name:"zf_002",language:"zh",gender:"Female"},zf_003:{name:"zf_003",language:"zh",gender:"Female"},zf_004:{name:"zf_004",language:"zh",gender:"Female"},zf_005:{name:"zf_005",language:"zh",gender:"Female"},zf_006:{name:"zf_006",language:"zh",gender:"Female"},zf_007:{name:"zf_007",language:"zh",gender:"Female"},zf_008:{name:"zf_008",language:"zh",gender:"Female"},zf_017:{name:"zf_017",language:"zh",gender:"Female"},zf_018:{name:"zf_018",language:"zh",gender:"Female"},zf_019:{name:"zf_019",language:"zh",gender:"Female"},zf_021:{name:"zf_021",language:"zh",gender:"Female"},zf_022:{name:"zf_022",language:"zh",gender:"Female"},zf_023:{name:"zf_023",language:"zh",gender:"Female"},zf_024:{name:"zf_024",language:"zh",gender:"Female"},zf_026:{name:"zf_026",language:"zh",gender:"Female"},zf_027:{name:"zf_027",language:"zh",gender:"Female"},zf_028:{name:"zf_028",language:"zh",gender:"Female"},zf_032:{name:"zf_032",language:"zh",gender:"Female"},zf_036:{name:"zf_036",language:"zh",gender:"Female"},zf_038:{name:"zf_038",language:"zh",gender:"Female"},zf_039:{name:"zf_039",language:"zh",gender:"Female"},zf_040:{name:"zf_040",language:"zh",gender:"Female"},zf_042:{name:"zf_042",language:"zh",gender:"Female"},zf_043:{name:"zf_043",language:"zh",gender:"Female"},zf_044:{name:"zf_044",language:"zh",gender:"Female"},zf_046:{name:"zf_046",language:"zh",gender:"Female"},zf_047:{name:"zf_047",language:"zh",gender:"Female"},zf_048:{name:"zf_048",language:"zh",gender:"Female"},zf_049:{name:"zf_049",language:"zh",gender:"Female"},zf_051:{name:"zf_051",language:"zh",gender:"Female"},zf_059:{name:"zf_059",language:"zh",gender:"Female"},zf_060:{name:"zf_060",language:"zh",gender:"Female"},zf_067:{name:"zf_067",language:"zh",gender:"Female"},zf_070:{name:"zf_070",language:"zh",gender:"Female"},zf_071:{name:"zf_071",language:"zh",gender:"Female"},zf_072:{name:"zf_072",language:"zh",gender:"Female"},zf_073:{name:"zf_073",language:"zh",gender:"Female"},zf_074:{name:"zf_074",language:"zh",gender:"Female"},zf_075:{name:"zf_075",language:"zh",gender:"Female"},zf_076:{name:"zf_076",language:"zh",gender:"Female"},zf_077:{name:"zf_077",language:"zh",gender:"Female"},zf_078:{name:"zf_078",language:"zh",gender:"Female"},zf_079:{name:"zf_079",language:"zh",gender:"Female"},zf_083:{name:"zf_083",language:"zh",gender:"Female"},zf_084:{name:"zf_084",language:"zh",gender:"Female"},zf_085:{name:"zf_085",language:"zh",gender:"Female"},zf_086:{name:"zf_086",language:"zh",gender:"Female"},zf_087:{name:"zf_087",language:"zh",gender:"Female"},zf_088:{name:"zf_088",language:"zh",gender:"Female"},zf_090:{name:"zf_090",language:"zh",gender:"Female"},zf_092:{name:"zf_092",language:"zh",gender:"Female"},zf_093:{name:"zf_093",language:"zh",gender:"Female"},zf_094:{name:"zf_094",language:"zh",gender:"Female"},zf_099:{name:"zf_099",language:"zh",gender:"Female"},zm_009:{name:"zm_009",language:"zh",gender:"Male"},zm_010:{name:"zm_010",language:"zh",gender:"Male"},zm_011:{name:"zm_011",language:"zh",gender:"Male"},zm_012:{name:"zm_012",language:"zh",gender:"Male"},zm_013:{name:"zm_013",language:"zh",gender:"Male"},zm_014:{name:"zm_014",language:"zh",gender:"Male"},zm_015:{name:"zm_015",language:"zh",gender:"Male"},zm_016:{name:"zm_016",language:"zh",gender:"Male"},zm_020:{name:"zm_020",language:"zh",gender:"Male"},zm_025:{name:"zm_025",language:"zh",gender:"Male"},zm_029:{name:"zm_029",language:"zh",gender:"Male"},zm_030:{name:"zm_030",language:"zh",gender:"Male"},zm_031:{name:"zm_031",language:"zh",gender:"Male"},zm_033:{name:"zm_033",language:"zh",gender:"Male"},zm_034:{name:"zm_034",language:"zh",gender:"Male"},zm_035:{name:"zm_035",language:"zh",gender:"Male"},zm_037:{name:"zm_037",language:"zh",gender:"Male"},zm_041:{name:"zm_041",language:"zh",gender:"Male"},zm_045:{name:"zm_045",language:"zh",gender:"Male"},zm_050:{name:"zm_050",language:"zh",gender:"Male"},zm_052:{name:"zm_052",language:"zh",gender:"Male"},zm_053:{name:"zm_053",language:"zh",gender:"Male"},zm_054:{name:"zm_054",language:"zh",gender:"Male"},zm_055:{name:"zm_055",language:"zh",gender:"Male"},zm_056:{name:"zm_056",language:"zh",gender:"Male"},zm_057:{name:"zm_057",language:"zh",gender:"Male"},zm_058:{name:"zm_058",language:"zh",gender:"Male"},zm_061:{name:"zm_061",language:"zh",gender:"Male"},zm_062:{name:"zm_062",language:"zh",gender:"Male"},zm_063:{name:"zm_063",language:"zh",gender:"Male"},zm_064:{name:"zm_064",language:"zh",gender:"Male"},zm_065:{name:"zm_065",language:"zh",gender:"Male"},zm_066:{name:"zm_066",language:"zh",gender:"Male"},zm_068:{name:"zm_068",language:"zh",gender:"Male"},zm_069:{name:"zm_069",language:"zh",gender:"Male"},zm_080:{name:"zm_080",language:"zh",gender:"Male"},zm_081:{name:"zm_081",language:"zh",gender:"Male"},zm_082:{name:"zm_082",language:"zh",gender:"Male"},zm_089:{name:"zm_089",language:"zh",gender:"Male"},zm_091:{name:"zm_091",language:"zh",gender:"Male"},zm_095:{name:"zm_095",language:"zh",gender:"Male"},zm_096:{name:"zm_096",language:"zh",gender:"Male"},zm_097:{name:"zm_097",language:"zh",gender:"Male"},zm_098:{name:"zm_098",language:"zh",gender:"Male"},zm_100:{name:"zm_100",language:"zh",gender:"Male"}});let ie="/kokoro/voices";const oe=new Map;async function ce(e){if(oe.has(e))return oe.get(e);const n=await async function(e){if(l&&Object.hasOwn(l,"readFile")){const n=a.resolve(ie,`${e}.bin`),{buffer:t}=await l.readFile(n);return t}const n=`${ie}/${e}.bin`;let t;if("undefined"!=typeof caches)try{t=await caches.open("kokoro-voices");const e=await t.match(n);if(e)return await e.arrayBuffer()}catch{t=null}const r=await fetch(n);if(!r.ok)throw new Error(`Failed to load voice data for "${e}" from ${n}: ${r.status} ${r.statusText}`);const s=await r.arrayBuffer();if(t)try{await t.put(n,new Response(s,{headers:r.headers}))}catch(e){}return s}(e);if(n.byteLength%Float32Array.BYTES_PER_ELEMENT!=0)throw new Error(`Invalid voice data for "${e}": byte length ${n.byteLength} is not a multiple of ${Float32Array.BYTES_PER_ELEMENT}.`);const t=new Float32Array(n);return oe.set(e,t),t}class ue{constructor(e,n){this.model=e,this.tokenizer=n}static async from_pretrained(n,{dtype:t="fp32",device:a=null,model_file_name:l=null,voicePath:r="/kokoro/voices",progress_callback:s=null}={}){!function(e){ie=e}(r);const g=e.StyleTextToSpeech2Model.from_pretrained(n,{progress_callback:s,dtype:t,device:a,model_file_name:l}),i=e.AutoTokenizer.from_pretrained(n,{progress_callback:s}),o=await Promise.all([g,i]);return new ue(...o)}get voices(){return ge}list_voices(){console.table(ge)}_validate_voice(e){if(!ge.hasOwnProperty(e))throw console.error(`Voice "${e}" not found. Available voices:`),console.table(ge),new Error(`Voice "${e}" not found. Should be one of: ${Object.keys(ge).join(", ")}.`);return e.at(0)}async generate(e,{voice:n="zf_001",speed:t=1}={}){const a=this._validate_voice(n),l=await Q(e,a),{input_ids:r}=this.tokenizer(l,{truncation:!0});return this.generate_from_ids(r,{voice:n,speed:t})}async generate_from_ids(n,{voice:t="zf_001",speed:a=1}={}){const l=256*Math.min(Math.max(n.dims.at(-1)-2,0),509),r=(await ce(t)).slice(l,l+256),s={input_ids:n,style:new e.Tensor("float32",r,[1,256]),speed:new e.Tensor("float32",[a],[1])},{waveform:g}=await this.model(s);return new e.RawAudio(g.data,24e3)}_splitLongText(e,n){const t=[];let a=e.trim();for(;a.length>n;){const e=a.slice(0,n+1);let l=Math.max(e.lastIndexOf(","),e.lastIndexOf("、"),e.lastIndexOf(";"),e.lastIndexOf(";"),e.lastIndexOf(","));l<.4*n&&(l=n),t.push(a.slice(0,l+1).trim()),a=a.slice(l+1).trim()}return a&&t.push(a),t}async*stream(e,{voice:n="zf_001",speed:t=1,split_pattern:a=null,maxChunkLength:l=200}={}){const r=this._validate_voice(n);let s;if(e instanceof se)s=e;else{if("string"!=typeof e)throw new Error("Invalid input type. Expected string or TextSplitterStream.");{s=new se;const n=a?e.split(a).map((e=>e.trim())).filter((e=>e.length>0)):[e];s.push(...n),s.close()}}for await(const e of s){const a=e.length>l?this._splitLongText(e,l):[e];for(const e of a){const a=await Q(e,r),{input_ids:l}=this.tokenizer(a,{truncation:!0}),s=await this.generate_from_ids(l,{voice:n,speed:t});yield{text:e,phonemes:a,audio:s}}}}}const he={set cacheDir(n){e.env.cacheDir=n},get cacheDir(){return e.env.cacheDir},set allowLocalModels(n){e.env.allowLocalModels=n},get allowLocalModels(){return e.env.allowLocalModels},set wasmPaths(n){e.env.backends.onnx.wasm.wasmPaths=n},get wasmPaths(){return e.env.backends.onnx.wasm.wasmPaths}};exports.KokoroTTS=ue,exports.TextSplitterStream=se,exports.env=he;
|
package/dist/kokoro.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{StyleTextToSpeech2Model as e,AutoTokenizer as n,Tensor as t,RawAudio as a,env as l}from"@huggingface/transformers";import{phonemize as r}from"phonemizer";import{pinyin as s}from"pinyin-pro";import g from"path";import i from"fs/promises";const o=new Map([[",",","],["。","."],["!","!"],["?","?"],[";",";"],[":",":"],["、",","]]),c=["零","一","二","三","四","五","六","七","八","九"],u=/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+[0-5]$/,h=/^[零一二三四五六七八九十百千万亿两]+$/,m=["千万美元","百万美元","千万块","百万块","千万吨","百万吨","万美元","亿元","万元","美元","千克","毫克","微克","公里","公分","公尺","公寸","公釐","千米","分米","厘米","毫米","微米","小时","分钟","封","艘","把","目","套","段","人","所","朵","匹","张","座","回","场","尾","条","个","首","阙","阵","网","炮","顶","丘","棵","只","支","袭","辆","挑","担","颗","壳","窠","曲","墙","群","腔","砣","客","贯","扎","捆","刀","令","打","手","罗","坡","山","岭","江","溪","钟","队","单","双","对","出","口","头","脚","板","跳","枝","件","贴","针","线","管","名","位","身","堂","课","本","页","家","户","层","丝","毫","厘","分","钱","两","斤","铢","石","钧","锱","忽","克","寸","尺","丈","里","寻","常","铺","程","米","撮","勺","合","升","斗","盘","碗","碟","叠","桶","笼","盆","盒","杯","斛","锅","簋","篮","罐","瓶","壶","卮","盏","箩","箱","煲","啖","袋","钵","年","月","日","季","刻","时","周","天","秒","旬","纪","岁","世","更","夜","春","夏","秋","冬","代","伏","辈","丸","泡","粒","幢","堆","道","面","片","块","元","角","毛","吨","百","千","万","亿"].sort(((e,n)=>n.length-e.length)),f=new Map([["我想去",["我想","去"]],["你的",["你","的"]],["能不能",["能","不能"]],["买了",["买","了"]],["吃了",["吃","了"]],["了两把",["了","两把"]],["吃了一碗",["吃","了","一碗"]],["学不好",["学","不好"]],["做的",["做","的"]],["先去",["先","去"]],["热腾腾的",["热腾腾","的"]]]),z=new Set(["上海","里","你","我们","药品","计算机","喜欢","著名","千古","做"]),d=new Set(["买","来","开","吃"]),_=new Set(["一辈","丈人","丈夫","上司","上头","下巴","下水","不由","世故","东家","东西","两口","丧气","丫头","主意","买卖","事情","云彩","交情","亲家","亲戚","人家","什么","介绍","休息","伙计","似的","位置","体面","作坊","佩服","使唤","便宜","倒腾","兄弟","先生","关系","养活","冒失","冤家","冤枉","冷战","凉快","凑合","凤凰","出息","分析","利害","利索","利落","别人","别扭","刺激","刺猬","前头","力气","功夫","动弹","动静","勤快","匀称","包涵","包袱","千斤","厉害","厚道","口袋","叫唤","吆喝","合同","吉他","名堂","名字","后头","吓唬","含糊","告示","告诉","和尚","咕噜","咖喱","咳嗽","哆嗦","哈欠","哑巴","唾沫","商量","喇叭","喇嘛","喉咙","喜欢","喽啰","嘀咕","嘟囔","嘱咐","嘴巴","困难","在乎","地方","地道","壮实","外甥","多么","多少","大人","大夫","大意","大方","大爷","太阳","头发","女婿","奴才","妖精","妥当","妯娌","姐夫","姑娘","委屈","姥爷","娘家","婆家","媒人","媳妇","嫁妆","字号","学问","官司","实在","客气","家伙","寒碜","寡妇","对付","对头","将军","将就","小伙","小气","少爷","尾巴","屁股","岁数","工夫","差事","巴掌","巴结","师傅","师父","希罕","帐篷","帮手","干事","幸福","庄稼","应酬","开通","弄堂","弟兄","张罗","得罪","心思","志气","忙活","快活","念叨","念头","怎么","思量","怪物","悟性","惦记","意思","意识","懒得","戏弄","戒指","扁担","扎实","扑腾","打发","打听","打扮","打算","打量","扫帚","扫把","折腾","护士","报复","抬举","拖沓","招呼","招牌","拨弄","拳头","拾掇","指头","指甲","挑剔","挖苦","提防","收成","收拾","故事","新鲜","时候","明白","暖和","月亮","月饼","朋友","木匠","木头","本事","机灵","枇杷","枕头","架势","柴火","栅栏","核桃","棉花","棒槌","棺材","槟榔","模糊","欺负","正经","母亲","比方","泥鳅","活泼","浪头","消息","清楚","温和","溜达","滑溜","漂亮","火候","灯笼","炊帚","点心","烂糊","烟筒","烧饼","热闹","照顾","熟悉","爱人","父亲","爽快","牌楼","牙碜","牢骚","牲口","特务","状元","狐狸","玄乎","玫瑰","玻璃","琉璃","琢磨","琵琶","甘蔗","甜头","生意","畜生","疏忽","疙瘩","疟疾","痛快","痢疾","白净","盘算","盘缠","相声","眉毛","眨巴","眯缝","眼睛","知识","石匠","石头","石榴","码头","砚台","祖宗","福气","秀才","秀气","秧歌","称呼","稀罕","稳当","窗户","窝囊","窟窿","笑话","笑语","笤帚","答应","算盘","算计","篱笆","簸箕","粮食","精神","糊涂","糟蹋","糨糊","累赘","红火","结实","编辑","罐头","罗嗦","翻腾","老婆","老实","老爷","耳朵","耷拉","耽搁","耽误","聪明","胡同","胡琴","胡萝","胭脂","胳膊","能耐","脊梁","脑袋","脾气","膏药","自在","舌头","舒坦","舒服","芝麻","苍蝇","苗头","苗条","荒唐","荸荠","菩萨","萝卜","葡萄","葫芦","薄荷","蘑菇","蚂蚱","蛤蟆","蜡烛","行当","行李","街坊","衙门","衣服","衣裳","补丁","裁缝","见识","规矩","计划","认识","记号","记性","讲究","豆腐","财主","费用","趔趄","跟头","跳蚤","踏实","转悠","软和","过去","运气","这个","这么","连累","迷糊","造化","逻辑","道士","邋遢","那个","那么","部分","里头","里脊","钥匙","铁匠","铃铛","铺盖","锄头","门道","闺女","阔气","队伍","难为","风筝","馄饨","馒头","首饰","马虎","骆驼","骨头","高粱","鸳鸯","麻利","麻烦"]),p=new Set(["的","地","得"]),$=new Set(["地标"]),w=new Set(["们","子","上","下"]),b=new Set(["吧","呢","吗","啊","呀","嘛","呗"]),M=new Set(["小院儿","胡同儿","范儿","老汉儿","撒欢儿","寻老礼儿","妥妥儿"]),F=new Set(["虐儿","为儿","护儿","瞒儿","救儿","替儿","有儿","一儿","我儿","俺儿","妻儿","拐儿","聋儿","乞儿","患儿","幼儿","孤儿","婴儿","婴幼儿","连体儿","脑瘫儿","流浪儿","体弱儿","混血儿","蜜雪儿","舫儿","祖儿","美儿","应采儿","可儿","侄儿","孙儿","侄孙儿","女儿","男儿","红孩儿","花儿","虫儿","马儿","鸟儿","猪儿","猫儿","狗儿","少儿","花朵儿"]),y=new Map([["一百二十三个","ㄧ4ㄅㄞ3ㄦ4ㄕ十2/ㄙㄢ1ㄍㄜ5"],["一百二十三","ㄧ4ㄅㄞ3ㄦ4ㄕ十2/ㄙㄢ1"],["价格是十二点五元","ㄐ压4ㄍㄜ2/ㄕ十4/ㄕ十2ㄦ4ㄉ言3/ㄨ3元2"],["完成率是百分之九十五","万2ㄔㄥ2ㄌㄩ4/ㄕ十4/ㄅㄞ3ㄈㄣ1ㄓ十1ㄐ又3ㄕ十2ㄨ3"],["二零二六年","ㄦ4ㄌ应2ㄦ4/ㄌ又4ㄋ言2"],["二零二三年","ㄦ4ㄌ应2/ㄦ4ㄙㄢ1ㄋ言2"],["二零二四年","ㄦ4ㄌ应2ㄦ4/ㄙㄭ4ㄋ言2"],["二零二五年","ㄦ4ㄌ应2ㄦ4/ㄨ3ㄋ言2"],["二零二六年十二月三十一日","ㄦ4ㄌ应2ㄦ4/ㄌ又4ㄋ言2/ㄕ十2ㄦ4月4/ㄙㄢ1ㄕ十2ㄧ2ㄖ十4"],["二零二五年十二月三十一日","ㄦ4ㄌ应2ㄦ4/ㄨ3ㄋ言2/ㄕ十2ㄦ4月4/ㄙㄢ1ㄕ十2ㄧ2ㄖ十4"],["今天是","ㄐ阴1ㄊ言1/ㄕ十4"],["今天是二零二六年六月十六日","ㄐ阴1ㄊ言1/ㄕ十4/ㄦ4ㄌ应2ㄦ4/ㄌ又4ㄋ言2/ㄌ又4月4/ㄕ十2ㄌ又4ㄖ十4"],["百分之十二点五","ㄅㄞ3ㄈㄣ1ㄓ十1ㄕ十2/ㄦ4ㄉ言3ㄨ3"],["十五点半","ㄕ十2ㄨ3ㄉ言3/ㄅㄢ4"],["八点零五分","ㄅㄚ1ㄉ言3/ㄌ应2ㄨ3ㄈㄣ1"],["八点半","ㄅㄚ1ㄉ言3ㄅㄢ4"],["十二点半","ㄕ十2ㄦ4ㄉ言3/ㄅㄢ4"],["这个","ㄓㄜ4ㄍㄜ5"],["一个","ㄧ2ㄍㄜ5"],["今天天气","ㄐ阴1ㄊ言1ㄊ言1ㄑㄧ4"],["今天下午","ㄐ阴1ㄊ言1ㄒ压4ㄨ3"],["三点","ㄙㄢ1ㄉ言3"],["儿化","ㄦ2ㄏ穵4"],["小院儿","ㄒ要3元R4"],["胡同儿","ㄏㄨ2ㄊ中R5"],["媳妇儿","ㄒㄧ2ㄈㄨR5"],["少儿","ㄕㄠ4ㄦ2"],["不怕困难","ㄅㄨ2ㄆㄚ4ㄎ文4ㄋㄢ5"],["两只小狗","ㄌ阳2ㄓ十3/ㄒ要2ㄍㄡ3"],["一点一支持","ㄧ4ㄉ言3/ㄧ4ㄓ十1ㄔ十2"],["长长的路","ㄔㄤ2ㄔㄤ2ㄉㄜ5/ㄌㄨ4"],["发卡行","ㄈㄚ4ㄎㄚ3ㄏㄤ2"],["放款行","ㄈㄤ4ㄎ万3ㄏㄤ2"],["茧行","ㄐ言3ㄏㄤ2"],["各地","ㄍㄜ4ㄉㄧ5"],["色差","ㄙㄜ4ㄔㄚ1"],["借还款","ㄐㄝ4/ㄏ万2ㄎ万3"],["还款","ㄏ万2ㄎ万3"],["还款成功","ㄏ万2ㄎ万3/ㄔㄥ2ㄍ中1"],["时间为准","ㄕ十2ㄐ言1/为2ㄓ文3"],["他的","ㄊㄚ1/ㄉㄜ5"],["好吧","ㄏㄠ3/ㄅㄚ5"],["慢慢地","ㄇㄢ4ㄇㄢ4/ㄉㄜ5"],["听不到","ㄊ应1/ㄅㄨ2ㄉㄠ4"],["试试看","ㄕ十4ㄕ十5ㄎㄢ4"],["早上","ㄗㄠ3ㄕㄤ4"],["树下","ㄕㄨ4ㄒ压5"],["热腾腾","ㄖㄜ4ㄊㄥ2ㄊㄥ2"],["人工智能","ㄖㄣ2ㄍ中1ㄓ十4ㄋㄥ2"],["量子","ㄌ阳4ㄗㄭ3"],["计算机","ㄐㄧ4ㄙ万4ㄐㄧ1"],["这件","ㄓㄜ4ㄐ言4"],["一举两得","ㄧ4ㄐㄩ3ㄌ阳3ㄉㄜ5"],["一分为二儿","ㄧ4ㄈㄣ1为2ㄦ4"],["一分为二地看","ㄧ4ㄈㄣ1为2ㄦ4/ㄉㄜ5/ㄎㄢ4"],["一概而论","ㄧ2ㄍㄞ4ㄦ2ㄌ文4"],["学不好","ㄒ月2/ㄅㄨ4ㄏㄠ3"],["嗲","ㄉㄧㄚ3"],["呗","ㄅㄟ5"],["咗","ㄗㄨㄛ5"],["嘞","ㄌㄟ5"],["个","ㄍㄜ5"],["撒欢儿","ㄙㄚ1ㄏ万R1"],["寻老礼儿","ㄒ云2ㄌㄠ3ㄌㄧR3"],["妥妥儿","ㄊ我3ㄊ我R5"],["老板很好","ㄌㄠ2ㄅㄢ2ㄏㄣ3/ㄏㄠ3"],["一百一十一","ㄧ1ㄅㄞ3ㄧ1ㄕ十2/ㄧ1"],["一点五倍","ㄧ4ㄉ言3/ㄨ3ㄅㄟ4"],["价格为十二点五元","ㄐ压4ㄍㄜ2/为4/ㄕ十2ㄦ4ㄉ言3/ㄨ3元2"],["增长百分之三点五","ㄗㄥ1ㄓㄤ3/ㄅㄞ3ㄈㄣ1ㄓ十1ㄙㄢ1ㄉ言3/ㄨ3"],["四个半小时","ㄙㄭ4ㄍㄜ5/ㄅㄢ4ㄒ要3ㄕ十2"],["需要四个半小时","ㄒㄩ1要4/ㄙㄭ4ㄍㄜ5/ㄅㄢ4ㄒ要3ㄕ十2"],["一九八零年","ㄧ1ㄐ又3ㄅㄚ1/ㄌ应2/ㄋ言2"],["二零零八年八月八日","ㄦ4ㄌ应2ㄌ应2ㄅㄚ1ㄋ言2/ㄅㄚ1月4ㄅㄚ1/ㄖ十4"]]),v=[...y.keys()].sort(((e,n)=>n.length-e.length)),x=new Set(["开户行","行号","掺和","国际化","高楼大厦","热腾腾","牛肉面"]),k=new Map([["b","ㄅ"],["p","ㄆ"],["m","ㄇ"],["f","ㄈ"],["d","ㄉ"],["t","ㄊ"],["n","ㄋ"],["l","ㄌ"],["g","ㄍ"],["k","ㄎ"],["h","ㄏ"],["j","ㄐ"],["q","ㄑ"],["x","ㄒ"],["zh","ㄓ"],["ch","ㄔ"],["sh","ㄕ"],["r","ㄖ"],["z","ㄗ"],["c","ㄘ"],["s","ㄙ"]]),S=new Map([["a","ㄚ"],["o","ㄛ"],["e","ㄜ"],["ai","ㄞ"],["ei","ㄟ"],["ao","ㄠ"],["ou","ㄡ"],["an","ㄢ"],["en","ㄣ"],["ang","ㄤ"],["eng","ㄥ"],["er","ㄦ"],["i","ㄧ"],["ii","ㄭ"],["iii","十"],["ia","压"],["ie","ㄝ"],["iao","要"],["iou","又"],["ian","言"],["in","阴"],["iang","阳"],["ing","应"],["iong","用"],["u","ㄨ"],["ua","穵"],["uo","我"],["uai","外"],["uei","为"],["uan","万"],["uen","文"],["uang","王"],["ueng","瓮"],["ong","中"],["v","ㄩ"],["ve","月"],["van","元"],["vn","云"]]),A="undefined"!=typeof Intl&&Intl.Segmenter?new Intl.Segmenter("zh",{granularity:"word"}):null;function j(e){if(e.includes("."))return e;if(e.includes(":")){let[n,t]=e.split(":").map(Number);return 0===t?`${n} o'clock`:t<10?`${n} oh ${t}`:`${n} ${t}`}let n=parseInt(e.slice(0,4),10);if(n<1100||n%1e3<10)return e;let t=e.slice(0,2),a=parseInt(e.slice(2,4),10),l=e.endsWith("s")?"s":"";if(n%1e3>=100&&n%1e3<=999){if(0===a)return`${t} hundred${l}`;if(a<10)return`${t} oh ${a}${l}`}return`${t} ${a}${l}`}function N(e){const n="$"===e[0]?"dollar":"pound";if(isNaN(Number(e.slice(1))))return`${e.slice(1)} ${n}s`;if(!e.includes(".")){let t="1"===e.slice(1)?"":"s";return`${e.slice(1)} ${n}${t}`}const[t,a]=e.slice(1).split("."),l=parseInt(a.padEnd(2,"0"),10);return`${t} ${n}${"1"===t?"":"s"} and ${l} ${"$"===e[0]?1===l?"cent":"cents":1===l?"penny":"pence"}`}function W(e){let[n,t]=e.split(".");return`${n} point ${t.split("").join(" ")}`}function Z(e){if(e<10)return c[e];if(e<100){const n=Math.floor(e/10),t=e%10;return`${1===n?"":c[n]}十${0===t?"":c[t]}`}if(e<1e3){const n=Math.floor(e/100),t=e%100;return`${c[n]}百${0===t?"":t<10?`零${c[t]}`:Z(t)}`}if(e<1e4){const n=Math.floor(e/1e3),t=e%1e3;return`${c[n]}千${0===t?"":t<100?`零${Z(t)}`:Z(t)}`}return String(e)}function E(e){return Z(e)}function R(e){if(e<1e4)return E(e);const n=Math.floor(e/1e8),t=Math.floor(e%1e8/1e4),a=e%1e4,l=[];return n>0&&l.push(`${R(n)}亿`),t>0&&(n>0&&t<1e3&&l.push("零"),l.push(`${E(t)}万`)),a>0&&((n>0||t>0&&a<1e3)&&l.push("零"),l.push(E(a))),l.join("").replace(/零+/g,"零").replace(/零$/g,"")}function L(e){return[...e].map((e=>c[Number(e)])).join("")}function T(e){return L(e).replace(/一/g,"幺")}function I(e,n=!0){return n?e.replace(/^\+/,"").split(/\s+/).filter(Boolean).map(T).join(","):e.split("-").map(T).join(",")}function P(e){const[n,t=""]=e.split(".");let a=R(Number(n));return t.replace(/0+$/,"")&&(a+=`点${L(t.replace(/0+$/,""))}`),a}const O=new RegExp(`(?<![\\d./A-Za-z])(\\d+)([多余几+])?(${m.join("|")})(?![\\d./A-Za-z])`,"g");function B(e){const n=Z(Number(e));return e.startsWith("0")?`零${n}`:n}function C(e,n,t=""){let a=`${Z(Number(e))}点`;return 0!==Number(n)&&(a+=30===Number(n)?"半":`${B(n)}分`),t&&0!==Number(t)&&(a+=`${B(t)}秒`),a}function D(e){return e.replace(/(\d{4})([- /.])(0[1-9]|1[0-2])\2(0[1-9]|[12]\d|3[01])/g,((e,n,t,a,l)=>`${L(n)}年${Z(Number(a))}月${Z(Number(l))}日`)).replace(/([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?([~-])([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?/g,((e,n,t,a="",l,r,s,g="")=>`${C(n,t,a)}至${C(r,s,g)}`)).replace(/([01]?\d|2[0-3]):([0-5]\d)(?::([0-5]\d))?/g,((e,n,t,a="")=>C(n,t,a))).replace(/(\d{4})年(?:(0?[1-9]|1[0-2])月)?(?:(0?[1-9]|[12]\d|30|31)([日号]))?/g,((e,n,t="",a="",l="")=>{const r=t?`${Z(Number(t))}月`:"",s=a?`${Z(Number(a))}${l}`:"";return`${L(n)}年${r}${s}`})).replace(O,((e,n,t="",a)=>function(e,n="",t){return`${P(e)}${"+"===n?"多":n}${t}`}(n,t,a))).replace(/(?<!\d)((?:\+?86\s?)?1(?:[38]\d|5[0-35-9]|7[678]|9[89])\d{8})(?!\d)/g,(e=>I(e))).replace(/(?<!\d)((?:0(?:10|2[1-3]|[3-9]\d{2})-?)?[1-9]\d{6,7})(?!\d)/g,(e=>I(e,!1))).replace(/(?<!\d)400-?\d{3}-?\d{4}(?!\d)/g,(e=>I(e,!1))).replace(/(电话|号码|热线|客服)(\d{5})(?!\d)/g,((e,n,t)=>`${n}${T(t)}`)).replace(/(?<![\d./A-Za-z])([1-9]\d{0,3})\/([1-9]\d{0,3})(?![\d./A-Za-z])/g,((e,n,t)=>function(e,n){return`${Z(Number(n))}分之${Z(Number(e))}`}(n,t))).replace(/(?<![\d.])([+-]?)(\d+(?:\.\d+)?)%/g,((e,n,t)=>function(e,n){return`${"+"===e?"正":"-"===e?"负":""}百分之${P(n)}`}(n,t))).replace(/(?<![\d./A-Za-z])(\d+(?:\.\d+)?)(℃|°C|kg|cm)(?![\d./A-Za-z])/gi,((e,n,t)=>function(e,n){const t=n.toLowerCase(),a=P(e);return"℃"===t||"°c"===t?`摄氏${a}度`:"kg"===t?`${a}千克`:"cm"===t?`${a}厘米`:`${a}${n}`}(n,t))).replace(/(\bv)(\d+\.\d+)(?![\d./A-Za-z])/gi,((e,n,t)=>`${n}${P(t)}`)).replace(/(?<![\d./A-Za-z])\d+\.\d+(?![\d./A-Za-z])/g,(e=>P(e))).replace(/(?<![\d./A-Za-z])([1-9]\d{0,3})[~-]([1-9]\d{0,3})(?![\d./A-Za-z])/g,((e,n,t)=>function(e,n){return`${Z(Number(e))}到${Z(Number(n))}`}(n,t))).replace(/(?<![\d.])-(\d{1,4})(?![\d.])/g,((e,n)=>`负${Z(Number(n))}`)).replace(/\b\d{1,4}\b/g,(e=>Z(Number(e))))}function V(e){const n=function(e){const n=e.match(/^([a-züv:]+)([0-5])$/i);return n?{base:n[1].toLowerCase().replace(/u:/g,"v").replace(/ü/g,"v"),tone:"0"===n[2]?"5":n[2]}:null}(e);if(!n)return e;let{initial:t,final:a}=function(e){for(const n of["zh","ch","sh"])if(e.startsWith(n))return{initial:n,final:e.slice(n.length)};const n=e.at(0);return k.has(n)?{initial:n,final:e.slice(1)}:e.startsWith("yi")?{initial:"",final:e.replace(/^yi/,"i")}:e.startsWith("yu")?{initial:"",final:e.replace(/^yu/,"v")}:e.startsWith("y")?{initial:"",final:`i${e.slice(1)}`}:e.startsWith("wu")?{initial:"",final:e.replace(/^wu/,"u")}:e.startsWith("w")?{initial:"",final:`u${e.slice(1)}`}:{initial:"",final:e}}(n.base);["j","q","x"].includes(t)&&a.startsWith("u")&&(a=`v${a.slice(1)}`),a=function(e){return"iu"===e?"iou":"ui"===e?"uei":"un"===e?"uen":e}(a),["z","c","s"].includes(t)&&"i"===a?a="ii":["zh","ch","sh","r"].includes(t)&&"i"===a&&(a="iii");const l=k.get(t)??"",r=S.get(a);return r?`${l}${r}${n.tone}`:e}function q(e){if("了"===e)return"ㄌㄜ5";const n=s(e,{type:"array",toneType:"num"}).map(V),t=e.endsWith("元")&&[...e.slice(0,-1)].every((e=>h.test(e)));if(e.length>1&&[...e].every((e=>h.test(e))))for(let t=0;t<n.length;t++)"一"===e[t]&&n[t].endsWith("4")&&(n[t]=n[t].slice(0,-1)+"1");if(e.length>1&&e.endsWith("地")){if("di4"===s(e[e.length-1],{toneType:"num"})){const e=V("de5");u.test(n[n.length-1])&&(n[n.length-1]=e)}}3===n.length&&"一"===e[1]&&e[0]===e[2]&&"ㄧ1"===n[1]&&(n[1]="ㄧ5"),3===n.length&&"不"===e[1]&&"ㄅㄨ4"===n[1]&&(n[1]="ㄅㄨ5");const a=n.map((e=>!!u.test(e)&&e.endsWith("3")));for(let a=0;a<n.length-1;a+=1)e.startsWith("第一")&&1===a&&"ㄧ1"===n[a]||"ㄧ1"===n[a]&&[...e].every(((e,n)=>n===a||h.test(e)))||("ㄧ1"===n[a]&&/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+4$/.test(n[a+1])?n[a]="ㄧ2":"ㄧ1"===n[a]&&/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+[1-3]$/.test(n[a+1])?n[a]="ㄧ4":"ㄅㄨ4"===n[a]&&/^[ㄅ-ㄩ压言阳要阴应用又穵外万王为文瓮我中月元云ㄭ十]+4$/.test(n[a+1])&&(n[a]="ㄅㄨ2"),!t&&u.test(n[a])&&n[a].endsWith("3")&&u.test(n[a+1])&&n[a+1].endsWith("3")&&(n[a]=`${n[a].slice(0,-1)}2`));if(_.has(e)||_.has(e.slice(-2))){const e=n[n.length-1];u.test(e)&&(n[n.length-1]=`${e.slice(0,-1)}5`)}if(3===n.length&&a.every(Boolean)){const t=A?[...A.segment(e)].filter((e=>e.segment.trim().length>0)).map((e=>e.segment)):[e];2===t.length&&1===t[0].length&&2===t[1].length&&(n[0]=n[0].slice(0,-1)+"3")}!t&&4===n.length&&a.every(Boolean)&&n[3].endsWith("3")&&(n[0]=n[0].slice(0,-1)+"2",n[2]=n[2].slice(0,-1)+"2",n[1].endsWith("2")&&(n[1]=n[1].slice(0,-1)+"3")),2===n.length&&e[0]===e[1]&&u.test(n[0])&&u.test(n[1])&&(/^(?:慢慢|刚刚|常|渐渐|万万)$/.test(e)||/^[零一二三四五六七八九]+$/.test(e)||(n[1]=`${n[1].slice(0,-1)}5`));for(let t=1;t<n.length;t+=1){const a=e[t];p.has(a)&&u.test(n[t])&&(n[t]=`${n[t].slice(0,-1)}5`)}if(n.length>1){const t=e[e.length-1];w.has(t)&&u.test(n[n.length-1])&&(n[n.length-1]=`${n[n.length-1].slice(0,-1)}5`)}if(n.length>1){const t=e[e.length-1];b.has(t)&&u.test(n[n.length-1])&&(n[n.length-1]=`${n[n.length-1].slice(0,-1)}5`)}if(n.length>1&&e.endsWith("儿")&&u.test(n[n.length-1])){const t=n[n.length-1].slice(-1);if("2"===t||"5"===t)if(M.has(e)){const e=n.length-2;if(u.test(n[e])){const t=n[e];n[e]=t.slice(0,-1)+"R"+t.slice(-1),n.pop()}}else if(!F.has(e)&&"女儿"!==e&&"花儿"!==e&&"少儿"!==e){const e=n.length-2;if(u.test(n[e])&&!/R/.test(n[e])){const t=n[e];n[e]=t.slice(0,-1)+"R"+t.slice(-1),n.pop()}}}return n.join("").replace(/\s+([,.;:!?,。!?;:、])/g,"$1").replace(/\s+/g," ").trim()}function Y(e,n){if(!n||0===n.size)return e;const t=[];let a=0;for(;a<e.length;){let l=e[a],r=1;for(let t=2;t<=4&&a+t<=e.length;t++){const s=e.slice(a,a+t).join("");n.has(s)&&(l=s,r=t)}t.push(l),a+=r}return t}function G(e){const n=[];for(let t=0;t<e.length;t+=1){let a=e[t];if(h.test(a)){const l=t;for(;t+1<e.length&&h.test(e[t+1]);)a+=e[t+1],t+=1;if(t+1<e.length&&"元"===e[t+1])a+=e[t+1],t+=1;else{if(t+2<e.length&&"个"===e[t+1]&&"半"===e[t+2]){n.push(`${a}个`),n.push("半"),t+=2;continue}t=l,a=e[t]}}"半"===a&&t+1<e.length&&"小时"===e[t+1]?(n.push("半小时"),t+=1):n.push(a)}return n}function H(e){return e.flatMap((e=>f.get(e)??[e]))}function J(e,n){return n>0&&"个"===e[n]&&h.test(e[n-1])&&"半"===e[n+1]}function X(e){return function(e){const n=[];let t=0;for(;t<e.length;){let a=null;for(const n of v)if(e.startsWith(n,t)&&!J(e,t)){a=n;break}if(a){n.push(y.get(a)),t+=a.length;continue}let l=t+1;for(;l<e.length;){let n=!1;for(const t of v)if(e.startsWith(t,l)&&!J(e,l)){n=!0;break}if(n)break;l+=1}const r=e.slice(t,l);let g=A?[...A.segment(r)].filter((({segment:e})=>e.trim().length>0)).map((({segment:e})=>e)):[r];g=H(g),g=Y(g,x),g=G(g);const i=[];for(let e=0;e<g.length;e+=1){let n=g[e];if("儿"===n&&i.length>0)i[i.length-1]+="儿";else{if("一"===n||n.length>1&&"一"===n[0]){if(n.length>1&&i.length>0){const e=n.slice(1),t=i[i.length-1];if(1===t.length&&t===e[0]){i[i.length-1]=t+n;continue}}if("一"===n&&e+1<g.length&&i.length>0){const n=i[i.length-1],t=g[e+1];if(1===n.length&&n===t[0]){i[i.length-1]=n+"一"+t,e+=1;continue}}"一"===n&&e+1<g.length&&(e+=1,n="一"+g[e])}else if(("不"===n||n.length>1&&"不"===n[0])&&!["不太","不能"].includes(n)){if(n.length>1&&i.length>0){const e=i[i.length-1];if(1===e.length){i[i.length-1]=e+n;continue}}if("不"===n&&e+1<g.length&&i.length>0){const n=i[i.length-1];if(1===n.length){i[i.length-1]=n+"不"+g[e+1],e+=1;continue}}"不"===n&&e+1<g.length&&(e+=1,n="不"+g[e])}else{if(["了","着","过"].includes(n)&&i.length>0){if("了"===n&&d.has(i[i.length-1])){i.push(n);continue}i[i.length-1]+=n;continue}if(["日","号"].includes(n)&&i.length>0){i[i.length-1]+=n;continue}if(p.has(n)&&i.length>0&&!("地"===n&&e+1<g.length&&$.has(`${n}${g[e+1]}`))){const e=i[i.length-1];if(z.has(e)){i.push(n);continue}if(e.length>0){i[i.length-1]=e+n;continue}}}if(i.length>0&&"第"===i[i.length-1])i[i.length-1]+=n;else{if(i.length>0){const e=i[i.length-1];if(["了","着","过"].includes(e)||["了","着","过"].includes(n)){i.push(n);continue}const t=e[e.length-1],a=n[0],l=s(t,{toneType:"num"}),r=s(a,{toneType:"num"});if(l.endsWith("3")&&r.endsWith("3")&&e.length+n.length<=3){i[i.length-1]+=n;continue}}if(1===n.length&&i.length>0){const e=i[i.length-1];if(e===n){i[i.length-1]=e+n;continue}if(["了","着","过"].includes(e)||["了","着","过"].includes(n)){i.push(n);continue}const t=e[e.length-1],a=s(t,{toneType:"num"}),l=s(n[0],{toneType:"num"});if(a.endsWith("3")&&l.endsWith("3")){i[i.length-1]+=n;continue}}i.push(n)}}}const o=i.map((e=>q(e))).join("/");o&&n.push(o),t=l}return n.join("/")}(e)}async function K(e){const n=D(function(e){return e.replace(/[,。!?;:、]/g,(e=>o.get(e)??e))}(e)).match(/[\u4E00-\u9FFF]+|[^\u4E00-\u9FFF]+/g)??[];return(await Promise.all(n.map((async e=>/[\u4E00-\u9FFF]/.test(e)?X(e):/[A-Za-z]/.test(e)?te(e,"a"):e)))).join(" ").replace(/\s+([,.;:!?])/g,"$1").replace(/❓\./g,"❓ .").replace(/\s+/g," ").trim()}function Q(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}const U=new RegExp(`(\\s*[${Q(';:,.!?¡¿—…"«»“”(){}[]')}]+\\s*)+`,"g"),ee=new Map([["uzen","jˈuː.zən"]]),ne=new RegExp(`\\b(${[...ee.keys()].map(Q).join("|")})\\b`,"gi");async function te(e,n="a",t=!0){if("z"===n)return K(e);t&&(e=function(e){return e.replace(/[‘’]/g,"'").replace(/«/g,"“").replace(/»/g,"”").replace(/[“”]/g,'"').replace(/\(/g,"«").replace(/\)/g,"»").replace(/、/g,", ").replace(/。/g,". ").replace(/!/g,"! ").replace(/,/g,", ").replace(/:/g,": ").replace(/;/g,"; ").replace(/?/g,"? ").replace(/[^\S \n]/g," ").replace(/ +/," ").replace(/(?<=\n) +(?=\n)/g,"").replace(/\bD[Rr]\.(?= [A-Z])/g,"Doctor").replace(/\b(?:Mr\.|MR\.(?= [A-Z]))/g,"Mister").replace(/\b(?:Ms\.|MS\.(?= [A-Z]))/g,"Miss").replace(/\b(?:Mrs\.|MRS\.(?= [A-Z]))/g,"Mrs").replace(/\betc\.(?! [A-Z])/gi,"etc").replace(/\b(y)eah?\b/gi,"$1e'a").replace(/\d*\.\d+|\b\d{4}s?\b|(?<!:)\b(?:[1-9]|1[0-2]):[0-5]\d\b(?!:)/g,j).replace(/(?<=\d),(?=\d)/g,"").replace(/[$£]\d+(?:\.\d+)?(?: hundred| thousand| (?:[bm]|tr)illion)*\b|[$£]\d+\.\d\d?\b/gi,N).replace(/\d*\.\d+/g,W).replace(/(?<=\d)-(?=\d)/g," to ").replace(/(?<=\d)S/g," S").replace(/(?<=[BCDFGHJ-NP-TV-Z])'?s\b/g,"'S").replace(/(?<=X')S\b/g,"s").replace(/(?:[A-Za-z]\.){2,} [a-z]/g,(e=>e.replace(/\./g,"-"))).replace(/(?<=[A-Z])\.(?=[A-Z])/gi,"-").trim()}(e));const a=function(e,n){const t=[];let a=0;for(const l of e.matchAll(n)){const n=l[0];a<l.index&&t.push({match:!1,text:e.slice(a,l.index)}),n.length>0&&t.push({match:!0,text:n}),a=l.index+n.length}return a<e.length&&t.push({match:!1,text:e.slice(a)}),t}(e,U),l="a"===n?"en-us":"en",s=(await Promise.all(a.map((async({match:e,text:n})=>e?n:async function(e,n){const t=[];let a=0;for(const l of e.matchAll(ne)){const s=e.slice(a,l.index),g=l.index+l[0].length;a<l.index?t.push((await r(s,n)).join(" ")):l.index>0&&/\s/.test(e[l.index-1])&&t.push(" "),t.push(ee.get(l[0].toLowerCase())),g<e.length&&/\s/.test(e[g])&&t.push(" "),a=g}return a<e.length&&t.push((await r(e.slice(a),n)).join(" ")),t.join("")}(n,l))))).join("");let g=s.replace(/kəkˈoːɹoʊ/g,"kˈoʊkəɹoʊ").replace(/kəkˈɔːɹəʊ/g,"kˈəʊkəɹəʊ").replace(/ʲ/g,"j").replace(/r/g,"ɹ").replace(/x/g,"k").replace(/ɬ/g,"l").replace(/(?<=[a-zɹː])(?=hˈʌndɹɪd)/g," ").replace(/ z(?=[;:,.!?¡¿—…"«»“” ]|$)/g,"z");return"a"===n&&(g=g.replace(/(?<=nˈaɪn)ti(?!ː)/g,"di")),g.trim()}function ae(e,n=!0){return".!?…。?!".includes(e)||n&&"\n"===e}function le(e,n){let t=n;for(;t<e.length&&!/\s/.test(e[t]);)++t;return e.substring(n,t)}const re=new Set(["mr","mrs","ms","dr","prof","sr","jr","sgt","col","gen","rep","sen","gov","lt","maj","capt","st","mt","etc","co","inc","ltd","dept","vs","p","pg","jan","feb","mar","apr","jun","jul","aug","sep","sept","oct","nov","dec","sun","mon","tu","tue","tues","wed","th","thu","thur","thurs","fri","sat"]);function se(e){return e=e.replace(/['’]s$/i,"").replace(/\.+$/,""),re.has(e.toLowerCase())}const ge=new Map([[")","("],["]","["],["}","{"],["》","《"],["〉","〈"],["›","‹"],["»","«"],["〉","〈"],["」","「"],["』","『"],["〕","〔"],["】","【"]]),ie=new Set(ge.values());function oe(e,n,t,a){if('"'===e||"'"===e){if("'"===e&&t>0&&t<a.length-1&&/[A-Za-z]/.test(a[t-1])&&/[A-Za-z]/.test(a[t+1]))return;return void(n.length&&n.at(-1)===e?n.pop():n.push(e))}if(ie.has(e))return void n.push(e);const l=ge.get(e);l&&n.length&&n.at(-1)===l&&n.pop()}class ce{constructor(){this._buffer="",this._sentences=[],this._resolver=null,this._closed=!1}push(...e){for(const n of e)this._buffer+=n,this._process()}close(){if(this._closed)throw new Error("Stream is already closed.");this._closed=!0,this.flush()}flush(){const e=this._buffer.trim();e.length>0&&this._sentences.push(e),this._buffer="",this._resolve()}_resolve(){this._resolver&&(this._resolver(),this._resolver=null)}_process(){let e=0;const n=this._buffer,t=n.length;let a=0,l=[];const r=e=>{let a=e;for(;a+1<t&&ae(n[a+1],!1);)++a;for(;a+1<t&&(l=n[a+1],"\"')]}」』".includes(l));)++a;var l;let r=a+1;for(;r<t&&/\s/.test(n[r]);)++r;return{end:a,nextNonSpace:r}};for(;a<t;){const s=n[a];if(oe(s,l,a,n),0===l.length&&ae(s)){const l=n.slice(e,a);if(/(^|\n)\d+$/.test(l)){++a;continue}const{end:g,nextNonSpace:i}=r(a);if(a===i-1&&"\n"!==s){++a;continue}if(i===t)break;let o=a-1;for(;o>=0&&/\S/.test(n[o]);)o--;o=Math.max(e,o+1);const c=le(n,o);if(!c){++a;continue}if((/https?[,:]\/\//.test(c)||c.includes("@"))&&!ae(c.at(-1))){a=o+c.length;continue}if(se(c)){++a;continue}if(/^([A-Za-z]\.)+$/.test(c)&&i<t&&/[A-Z]/.test(n[i])){++a;continue}if("."===s&&i<t&&/[a-z]/.test(n[i])){++a;continue}const u=n.substring(e,g+1).trim();if("..."===u||"…"===u){++a;continue}u&&this._sentences.push(u),a=e=g+1}else++a}this._buffer=n.substring(e),this._sentences.length>0&&this._resolve()}async*[Symbol.asyncIterator](){if(this._resolver)throw new Error("Another iterator is already active.");for(;;)if(this._sentences.length>0)yield this._sentences.shift();else{if(this._closed)break;await new Promise((e=>{this._resolver=e}))}}[Symbol.iterator](){this.flush();const e=this._sentences[Symbol.iterator]();return this._sentences=[],e}get sentences(){return this._sentences}}const ue=Object.freeze({af_maple:{name:"af_maple",language:"en-us",gender:"Female"},af_sol:{name:"af_sol",language:"en-us",gender:"Female"},bf_vale:{name:"bf_vale",language:"en-gb",gender:"Female"},zf_001:{name:"zf_001",language:"zh",gender:"Female"},zf_002:{name:"zf_002",language:"zh",gender:"Female"},zf_003:{name:"zf_003",language:"zh",gender:"Female"},zf_004:{name:"zf_004",language:"zh",gender:"Female"},zf_005:{name:"zf_005",language:"zh",gender:"Female"},zf_006:{name:"zf_006",language:"zh",gender:"Female"},zf_007:{name:"zf_007",language:"zh",gender:"Female"},zf_008:{name:"zf_008",language:"zh",gender:"Female"},zf_017:{name:"zf_017",language:"zh",gender:"Female"},zf_018:{name:"zf_018",language:"zh",gender:"Female"},zf_019:{name:"zf_019",language:"zh",gender:"Female"},zf_021:{name:"zf_021",language:"zh",gender:"Female"},zf_022:{name:"zf_022",language:"zh",gender:"Female"},zf_023:{name:"zf_023",language:"zh",gender:"Female"},zf_024:{name:"zf_024",language:"zh",gender:"Female"},zf_026:{name:"zf_026",language:"zh",gender:"Female"},zf_027:{name:"zf_027",language:"zh",gender:"Female"},zf_028:{name:"zf_028",language:"zh",gender:"Female"},zf_032:{name:"zf_032",language:"zh",gender:"Female"},zf_036:{name:"zf_036",language:"zh",gender:"Female"},zf_038:{name:"zf_038",language:"zh",gender:"Female"},zf_039:{name:"zf_039",language:"zh",gender:"Female"},zf_040:{name:"zf_040",language:"zh",gender:"Female"},zf_042:{name:"zf_042",language:"zh",gender:"Female"},zf_043:{name:"zf_043",language:"zh",gender:"Female"},zf_044:{name:"zf_044",language:"zh",gender:"Female"},zf_046:{name:"zf_046",language:"zh",gender:"Female"},zf_047:{name:"zf_047",language:"zh",gender:"Female"},zf_048:{name:"zf_048",language:"zh",gender:"Female"},zf_049:{name:"zf_049",language:"zh",gender:"Female"},zf_051:{name:"zf_051",language:"zh",gender:"Female"},zf_059:{name:"zf_059",language:"zh",gender:"Female"},zf_060:{name:"zf_060",language:"zh",gender:"Female"},zf_067:{name:"zf_067",language:"zh",gender:"Female"},zf_070:{name:"zf_070",language:"zh",gender:"Female"},zf_071:{name:"zf_071",language:"zh",gender:"Female"},zf_072:{name:"zf_072",language:"zh",gender:"Female"},zf_073:{name:"zf_073",language:"zh",gender:"Female"},zf_074:{name:"zf_074",language:"zh",gender:"Female"},zf_075:{name:"zf_075",language:"zh",gender:"Female"},zf_076:{name:"zf_076",language:"zh",gender:"Female"},zf_077:{name:"zf_077",language:"zh",gender:"Female"},zf_078:{name:"zf_078",language:"zh",gender:"Female"},zf_079:{name:"zf_079",language:"zh",gender:"Female"},zf_083:{name:"zf_083",language:"zh",gender:"Female"},zf_084:{name:"zf_084",language:"zh",gender:"Female"},zf_085:{name:"zf_085",language:"zh",gender:"Female"},zf_086:{name:"zf_086",language:"zh",gender:"Female"},zf_087:{name:"zf_087",language:"zh",gender:"Female"},zf_088:{name:"zf_088",language:"zh",gender:"Female"},zf_090:{name:"zf_090",language:"zh",gender:"Female"},zf_092:{name:"zf_092",language:"zh",gender:"Female"},zf_093:{name:"zf_093",language:"zh",gender:"Female"},zf_094:{name:"zf_094",language:"zh",gender:"Female"},zf_099:{name:"zf_099",language:"zh",gender:"Female"},zm_009:{name:"zm_009",language:"zh",gender:"Male"},zm_010:{name:"zm_010",language:"zh",gender:"Male"},zm_011:{name:"zm_011",language:"zh",gender:"Male"},zm_012:{name:"zm_012",language:"zh",gender:"Male"},zm_013:{name:"zm_013",language:"zh",gender:"Male"},zm_014:{name:"zm_014",language:"zh",gender:"Male"},zm_015:{name:"zm_015",language:"zh",gender:"Male"},zm_016:{name:"zm_016",language:"zh",gender:"Male"},zm_020:{name:"zm_020",language:"zh",gender:"Male"},zm_025:{name:"zm_025",language:"zh",gender:"Male"},zm_029:{name:"zm_029",language:"zh",gender:"Male"},zm_030:{name:"zm_030",language:"zh",gender:"Male"},zm_031:{name:"zm_031",language:"zh",gender:"Male"},zm_033:{name:"zm_033",language:"zh",gender:"Male"},zm_034:{name:"zm_034",language:"zh",gender:"Male"},zm_035:{name:"zm_035",language:"zh",gender:"Male"},zm_037:{name:"zm_037",language:"zh",gender:"Male"},zm_041:{name:"zm_041",language:"zh",gender:"Male"},zm_045:{name:"zm_045",language:"zh",gender:"Male"},zm_050:{name:"zm_050",language:"zh",gender:"Male"},zm_052:{name:"zm_052",language:"zh",gender:"Male"},zm_053:{name:"zm_053",language:"zh",gender:"Male"},zm_054:{name:"zm_054",language:"zh",gender:"Male"},zm_055:{name:"zm_055",language:"zh",gender:"Male"},zm_056:{name:"zm_056",language:"zh",gender:"Male"},zm_057:{name:"zm_057",language:"zh",gender:"Male"},zm_058:{name:"zm_058",language:"zh",gender:"Male"},zm_061:{name:"zm_061",language:"zh",gender:"Male"},zm_062:{name:"zm_062",language:"zh",gender:"Male"},zm_063:{name:"zm_063",language:"zh",gender:"Male"},zm_064:{name:"zm_064",language:"zh",gender:"Male"},zm_065:{name:"zm_065",language:"zh",gender:"Male"},zm_066:{name:"zm_066",language:"zh",gender:"Male"},zm_068:{name:"zm_068",language:"zh",gender:"Male"},zm_069:{name:"zm_069",language:"zh",gender:"Male"},zm_080:{name:"zm_080",language:"zh",gender:"Male"},zm_081:{name:"zm_081",language:"zh",gender:"Male"},zm_082:{name:"zm_082",language:"zh",gender:"Male"},zm_089:{name:"zm_089",language:"zh",gender:"Male"},zm_091:{name:"zm_091",language:"zh",gender:"Male"},zm_095:{name:"zm_095",language:"zh",gender:"Male"},zm_096:{name:"zm_096",language:"zh",gender:"Male"},zm_097:{name:"zm_097",language:"zh",gender:"Male"},zm_098:{name:"zm_098",language:"zh",gender:"Male"},zm_100:{name:"zm_100",language:"zh",gender:"Male"}});let he="/kokoro/voices";const me=new Map;async function fe(e){if(me.has(e))return me.get(e);const n=await async function(e){if(i&&Object.hasOwn(i,"readFile")){const n=g.resolve(he,`${e}.bin`),{buffer:t}=await i.readFile(n);return t}const n=`${he}/${e}.bin`;let t;if("undefined"!=typeof caches)try{t=await caches.open("kokoro-voices");const e=await t.match(n);if(e)return await e.arrayBuffer()}catch{t=null}const a=await fetch(n);if(!a.ok)throw new Error(`Failed to load voice data for "${e}" from ${n}: ${a.status} ${a.statusText}`);const l=await a.arrayBuffer();if(t)try{await t.put(n,new Response(l,{headers:a.headers}))}catch(e){}return l}(e);if(n.byteLength%Float32Array.BYTES_PER_ELEMENT!=0)throw new Error(`Invalid voice data for "${e}": byte length ${n.byteLength} is not a multiple of ${Float32Array.BYTES_PER_ELEMENT}.`);const t=new Float32Array(n);return me.set(e,t),t}class ze{constructor(e,n){this.model=e,this.tokenizer=n}static async from_pretrained(t,{dtype:a="fp32",device:l=null,model_file_name:r=null,voicePath:s="/kokoro/voices",progress_callback:g=null}={}){!function(e){he=e}(s);const i=e.from_pretrained(t,{progress_callback:g,dtype:a,device:l,model_file_name:r}),o=n.from_pretrained(t,{progress_callback:g}),c=await Promise.all([i,o]);return new ze(...c)}get voices(){return ue}list_voices(){console.table(ue)}_validate_voice(e){if(!ue.hasOwnProperty(e))throw console.error(`Voice "${e}" not found. Available voices:`),console.table(ue),new Error(`Voice "${e}" not found. Should be one of: ${Object.keys(ue).join(", ")}.`);return e.at(0)}async generate(e,{voice:n="zf_001",speed:t=1}={}){const a=this._validate_voice(n),l=await te(e,a),{input_ids:r}=this.tokenizer(l,{truncation:!0});return this.generate_from_ids(r,{voice:n,speed:t})}async generate_from_ids(e,{voice:n="zf_001",speed:l=1}={}){const r=256*Math.min(Math.max(e.dims.at(-1)-2,0),509),s=(await fe(n)).slice(r,r+256),g={input_ids:e,style:new t("float32",s,[1,256]),speed:new t("float32",[l],[1])},{waveform:i}=await this.model(g);return new a(i.data,24e3)}_splitLongText(e,n){const t=[];let a=e.trim();for(;a.length>n;){const e=a.slice(0,n+1);let l=Math.max(e.lastIndexOf(","),e.lastIndexOf("、"),e.lastIndexOf(";"),e.lastIndexOf(";"),e.lastIndexOf(","));l<.4*n&&(l=n),t.push(a.slice(0,l+1).trim()),a=a.slice(l+1).trim()}return a&&t.push(a),t}async*stream(e,{voice:n="zf_001",speed:t=1,split_pattern:a=null,maxChunkLength:l=200}={}){const r=this._validate_voice(n);let s;if(e instanceof ce)s=e;else{if("string"!=typeof e)throw new Error("Invalid input type. Expected string or TextSplitterStream.");{s=new ce;const n=a?e.split(a).map((e=>e.trim())).filter((e=>e.length>0)):[e];s.push(...n),s.close()}}for await(const e of s){const a=e.length>l?this._splitLongText(e,l):[e];for(const e of a){const a=await te(e,r),{input_ids:l}=this.tokenizer(a,{truncation:!0}),s=await this.generate_from_ids(l,{voice:n,speed:t});yield{text:e,phonemes:a,audio:s}}}}}const de={set cacheDir(e){l.cacheDir=e},get cacheDir(){return l.cacheDir},set allowLocalModels(e){l.allowLocalModels=e},get allowLocalModels(){return l.allowLocalModels},set wasmPaths(e){l.backends.onnx.wasm.wasmPaths=e},get wasmPaths(){return l.backends.onnx.wasm.wasmPaths}};export{ze as KokoroTTS,ce as TextSplitterStream,de as env};
|