Commit ·
c418d2b
1
Parent(s): 6f37413
update model
Browse files- sherpa-onnx-tts.js +81 -4
- sherpa-onnx-wasm-main-tts.js +0 -0
sherpa-onnx-tts.js
CHANGED
|
@@ -8,8 +8,12 @@ function freeConfig(config, Module) {
|
|
| 8 |
freeConfig(config.config, Module)
|
| 9 |
}
|
| 10 |
|
| 11 |
-
if ('
|
| 12 |
-
freeConfig(config.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
Module._free(config.ptr);
|
|
@@ -132,6 +136,52 @@ function initSherpaOnnxOfflineTtsMatchaModelConfig(config, Module) {
|
|
| 132 |
}
|
| 133 |
}
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
| 136 |
if (!('offlineTtsVitsModelConfig' in config)) {
|
| 137 |
config.offlineTtsVitsModelConfig = {
|
|
@@ -159,6 +209,16 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
|
| 159 |
};
|
| 160 |
}
|
| 161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
|
| 163 |
const vitsModelConfig = initSherpaOnnxOfflineTtsVitsModelConfig(
|
| 164 |
config.offlineTtsVitsModelConfig, Module);
|
|
@@ -166,7 +226,12 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
|
| 166 |
const matchaModelConfig = initSherpaOnnxOfflineTtsMatchaModelConfig(
|
| 167 |
config.offlineTtsMatchaModelConfig, Module);
|
| 168 |
|
| 169 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
const ptr = Module._malloc(len);
|
| 171 |
|
| 172 |
let offset = 0;
|
|
@@ -188,9 +253,12 @@ function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
|
| 188 |
Module._CopyHeap(matchaModelConfig.ptr, matchaModelConfig.len, ptr + offset);
|
| 189 |
offset += matchaModelConfig.len;
|
| 190 |
|
|
|
|
|
|
|
|
|
|
| 191 |
return {
|
| 192 |
buffer: buffer, ptr: ptr, len: len, config: vitsModelConfig,
|
| 193 |
-
|
| 194 |
}
|
| 195 |
}
|
| 196 |
|
|
@@ -308,9 +376,18 @@ function createOfflineTts(Module, myConfig) {
|
|
| 308 |
lengthScale: 1.0,
|
| 309 |
};
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
const offlineTtsModelConfig = {
|
| 312 |
offlineTtsVitsModelConfig: offlineTtsVitsModelConfig,
|
| 313 |
offlineTtsMatchaModelConfig: offlineTtsMatchaModelConfig,
|
|
|
|
| 314 |
numThreads: 1,
|
| 315 |
debug: 1,
|
| 316 |
provider: 'cpu',
|
|
|
|
| 8 |
freeConfig(config.config, Module)
|
| 9 |
}
|
| 10 |
|
| 11 |
+
if ('matcha' in config) {
|
| 12 |
+
freeConfig(config.matcha, Module)
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
if ('kokoro' in config) {
|
| 16 |
+
freeConfig(config.kokoro, Module)
|
| 17 |
}
|
| 18 |
|
| 19 |
Module._free(config.ptr);
|
|
|
|
| 136 |
}
|
| 137 |
}
|
| 138 |
|
| 139 |
+
function initSherpaOnnxOfflineTtsKokoroModelConfig(config, Module) {
|
| 140 |
+
const modelLen = Module.lengthBytesUTF8(config.model) + 1;
|
| 141 |
+
const voicesLen = Module.lengthBytesUTF8(config.voices) + 1;
|
| 142 |
+
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
| 143 |
+
const dataDirLen = Module.lengthBytesUTF8(config.dataDir || '') + 1;
|
| 144 |
+
|
| 145 |
+
const n = modelLen + voicesLen + tokensLen + dataDirLen;
|
| 146 |
+
|
| 147 |
+
const buffer = Module._malloc(n);
|
| 148 |
+
|
| 149 |
+
const len = 5 * 4;
|
| 150 |
+
const ptr = Module._malloc(len);
|
| 151 |
+
|
| 152 |
+
let offset = 0;
|
| 153 |
+
Module.stringToUTF8(config.model || '', buffer + offset, modelLen);
|
| 154 |
+
offset += modelLen;
|
| 155 |
+
|
| 156 |
+
Module.stringToUTF8(config.voices || '', buffer + offset, voicesLen);
|
| 157 |
+
offset += voicesLen;
|
| 158 |
+
|
| 159 |
+
Module.stringToUTF8(config.tokens || '', buffer + offset, tokensLen);
|
| 160 |
+
offset += tokensLen;
|
| 161 |
+
|
| 162 |
+
Module.stringToUTF8(config.dataDir || '', buffer + offset, dataDirLen);
|
| 163 |
+
offset += dataDirLen;
|
| 164 |
+
|
| 165 |
+
offset = 0;
|
| 166 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
| 167 |
+
offset += modelLen;
|
| 168 |
+
|
| 169 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
| 170 |
+
offset += voicesLen;
|
| 171 |
+
|
| 172 |
+
Module.setValue(ptr + 8, buffer + offset, 'i8*');
|
| 173 |
+
offset += tokensLen;
|
| 174 |
+
|
| 175 |
+
Module.setValue(ptr + 12, buffer + offset, 'i8*');
|
| 176 |
+
offset += dataDirLen;
|
| 177 |
+
|
| 178 |
+
Module.setValue(ptr + 16, config.lengthScale || 1.0, 'float');
|
| 179 |
+
|
| 180 |
+
return {
|
| 181 |
+
buffer: buffer, ptr: ptr, len: len,
|
| 182 |
+
}
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
function initSherpaOnnxOfflineTtsModelConfig(config, Module) {
|
| 186 |
if (!('offlineTtsVitsModelConfig' in config)) {
|
| 187 |
config.offlineTtsVitsModelConfig = {
|
|
|
|
| 209 |
};
|
| 210 |
}
|
| 211 |
|
| 212 |
+
if (!('offlineTtsKokoroModelConfig' in config)) {
|
| 213 |
+
config.offlineTtsKokoroModelConfig = {
|
| 214 |
+
model: '',
|
| 215 |
+
voices: '',
|
| 216 |
+
tokens: '',
|
| 217 |
+
lengthScale: 1.0,
|
| 218 |
+
dataDir: '',
|
| 219 |
+
};
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
|
| 223 |
const vitsModelConfig = initSherpaOnnxOfflineTtsVitsModelConfig(
|
| 224 |
config.offlineTtsVitsModelConfig, Module);
|
|
|
|
| 226 |
const matchaModelConfig = initSherpaOnnxOfflineTtsMatchaModelConfig(
|
| 227 |
config.offlineTtsMatchaModelConfig, Module);
|
| 228 |
|
| 229 |
+
const kokoroModelConfig = initSherpaOnnxOfflineTtsKokoroModelConfig(
|
| 230 |
+
config.offlineTtsKokoroModelConfig, Module);
|
| 231 |
+
|
| 232 |
+
const len = vitsModelConfig.len + matchaModelConfig.len +
|
| 233 |
+
kokoroModelConfig.len + 3 * 4;
|
| 234 |
+
|
| 235 |
const ptr = Module._malloc(len);
|
| 236 |
|
| 237 |
let offset = 0;
|
|
|
|
| 253 |
Module._CopyHeap(matchaModelConfig.ptr, matchaModelConfig.len, ptr + offset);
|
| 254 |
offset += matchaModelConfig.len;
|
| 255 |
|
| 256 |
+
Module._CopyHeap(kokoroModelConfig.ptr, kokoroModelConfig.len, ptr + offset);
|
| 257 |
+
offset += kokoroModelConfig.len;
|
| 258 |
+
|
| 259 |
return {
|
| 260 |
buffer: buffer, ptr: ptr, len: len, config: vitsModelConfig,
|
| 261 |
+
matcha: matchaModelConfig, kokoro: kokoroModelConfig,
|
| 262 |
}
|
| 263 |
}
|
| 264 |
|
|
|
|
| 376 |
lengthScale: 1.0,
|
| 377 |
};
|
| 378 |
|
| 379 |
+
const offlineTtsKokoroModelConfig = {
|
| 380 |
+
model: '',
|
| 381 |
+
voices: '',
|
| 382 |
+
tokens: '',
|
| 383 |
+
dataDir: '',
|
| 384 |
+
lengthScale: 1.0,
|
| 385 |
+
};
|
| 386 |
+
|
| 387 |
const offlineTtsModelConfig = {
|
| 388 |
offlineTtsVitsModelConfig: offlineTtsVitsModelConfig,
|
| 389 |
offlineTtsMatchaModelConfig: offlineTtsMatchaModelConfig,
|
| 390 |
+
offlineTtsKokoroModelConfig: offlineTtsKokoroModelConfig,
|
| 391 |
numThreads: 1,
|
| 392 |
debug: 1,
|
| 393 |
provider: 'cpu',
|
sherpa-onnx-wasm-main-tts.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|