Spaces:
Configuration error
Configuration error
Commit
·
f4ee1a3
1
Parent(s):
05116d9
update model
Browse files- sherpa-onnx-asr.js +48 -9
- sherpa-onnx-wasm-main-asr.js +0 -0
- sherpa-onnx-wasm-main-asr.wasm +2 -2
sherpa-onnx-asr.js
CHANGED
@@ -15,8 +15,8 @@ function freeConfig(config, Module) {
|
|
15 |
freeConfig(config.paraformer, Module)
|
16 |
}
|
17 |
|
18 |
-
if ('
|
19 |
-
freeConfig(config.
|
20 |
}
|
21 |
|
22 |
if ('feat' in config) {
|
@@ -157,6 +157,22 @@ function initSherpaOnnxOnlineZipformer2CtcModelConfig(config, Module) {
|
|
157 |
}
|
158 |
}
|
159 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
160 |
function initSherpaOnnxOnlineModelConfig(config, Module) {
|
161 |
if (!('transducer' in config)) {
|
162 |
config.transducer = {
|
@@ -179,6 +195,12 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
179 |
};
|
180 |
}
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
if (!('tokensBuf' in config)) {
|
183 |
config.tokensBuf = '';
|
184 |
}
|
@@ -193,10 +215,15 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
193 |
const paraformer =
|
194 |
initSherpaOnnxOnlineParaformerModelConfig(config.paraformer, Module);
|
195 |
|
196 |
-
const
|
197 |
config.zipformer2Ctc, Module);
|
198 |
|
199 |
-
const
|
|
|
|
|
|
|
|
|
|
|
200 |
const ptr = Module._malloc(len);
|
201 |
|
202 |
let offset = 0;
|
@@ -206,8 +233,8 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
206 |
Module._CopyHeap(paraformer.ptr, paraformer.len, ptr + offset);
|
207 |
offset += paraformer.len;
|
208 |
|
209 |
-
Module._CopyHeap(
|
210 |
-
offset +=
|
211 |
|
212 |
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
213 |
const providerLen = Module.lengthBytesUTF8(config.provider || 'cpu') + 1;
|
@@ -240,7 +267,7 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
240 |
Module.stringToUTF8(config.tokensBuf || '', buffer + offset, tokensBufLen);
|
241 |
offset += tokensBufLen;
|
242 |
|
243 |
-
offset = transducer.len + paraformer.len +
|
244 |
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
245 |
offset += 4;
|
246 |
|
@@ -278,9 +305,12 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
278 |
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
|
279 |
offset += 4;
|
280 |
|
|
|
|
|
|
|
281 |
return {
|
282 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
283 |
-
paraformer: paraformer,
|
284 |
}
|
285 |
}
|
286 |
|
@@ -485,6 +515,10 @@ function createOnlineRecognizer(Module, myConfig) {
|
|
485 |
model: '',
|
486 |
};
|
487 |
|
|
|
|
|
|
|
|
|
488 |
let type = 0;
|
489 |
|
490 |
switch (type) {
|
@@ -500,9 +534,13 @@ function createOnlineRecognizer(Module, myConfig) {
|
|
500 |
onlineParaformerModelConfig.decoder = './decoder.onnx';
|
501 |
break;
|
502 |
case 2:
|
503 |
-
//
|
504 |
onlineZipformer2CtcModelConfig.model = './encoder.onnx';
|
505 |
break;
|
|
|
|
|
|
|
|
|
506 |
}
|
507 |
|
508 |
|
@@ -510,6 +548,7 @@ function createOnlineRecognizer(Module, myConfig) {
|
|
510 |
transducer: onlineTransducerModelConfig,
|
511 |
paraformer: onlineParaformerModelConfig,
|
512 |
zipformer2Ctc: onlineZipformer2CtcModelConfig,
|
|
|
513 |
tokens: './tokens.txt',
|
514 |
numThreads: 1,
|
515 |
provider: 'cpu',
|
|
|
15 |
freeConfig(config.paraformer, Module)
|
16 |
}
|
17 |
|
18 |
+
if ('zipformer2Ctc' in config) {
|
19 |
+
freeConfig(config.zipformer2Ctc, Module)
|
20 |
}
|
21 |
|
22 |
if ('feat' in config) {
|
|
|
157 |
}
|
158 |
}
|
159 |
|
160 |
+
function initSherpaOnnxOnlineNemoCtcModelConfig(config, Module) {
|
161 |
+
const n = Module.lengthBytesUTF8(config.model || '') + 1;
|
162 |
+
const buffer = Module._malloc(n);
|
163 |
+
|
164 |
+
const len = 1 * 4; // 1 pointer
|
165 |
+
const ptr = Module._malloc(len);
|
166 |
+
|
167 |
+
Module.stringToUTF8(config.model || '', buffer, n);
|
168 |
+
|
169 |
+
Module.setValue(ptr, buffer, 'i8*');
|
170 |
+
|
171 |
+
return {
|
172 |
+
buffer: buffer, ptr: ptr, len: len,
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
function initSherpaOnnxOnlineModelConfig(config, Module) {
|
177 |
if (!('transducer' in config)) {
|
178 |
config.transducer = {
|
|
|
195 |
};
|
196 |
}
|
197 |
|
198 |
+
if (!('nemoCtc' in config)) {
|
199 |
+
config.nemoCtc = {
|
200 |
+
model: '',
|
201 |
+
};
|
202 |
+
}
|
203 |
+
|
204 |
if (!('tokensBuf' in config)) {
|
205 |
config.tokensBuf = '';
|
206 |
}
|
|
|
215 |
const paraformer =
|
216 |
initSherpaOnnxOnlineParaformerModelConfig(config.paraformer, Module);
|
217 |
|
218 |
+
const zipformer2Ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
219 |
config.zipformer2Ctc, Module);
|
220 |
|
221 |
+
const nemoCtc =
|
222 |
+
initSherpaOnnxOnlineNemoCtcModelConfig(config.nemoCtc, Module);
|
223 |
+
|
224 |
+
const len =
|
225 |
+
transducer.len + paraformer.len + zipformer2Ctc.len + 9 * 4 + nemoCtc.len;
|
226 |
+
|
227 |
const ptr = Module._malloc(len);
|
228 |
|
229 |
let offset = 0;
|
|
|
233 |
Module._CopyHeap(paraformer.ptr, paraformer.len, ptr + offset);
|
234 |
offset += paraformer.len;
|
235 |
|
236 |
+
Module._CopyHeap(zipformer2Ctc.ptr, zipformer2Ctc.len, ptr + offset);
|
237 |
+
offset += zipformer2Ctc.len;
|
238 |
|
239 |
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
240 |
const providerLen = Module.lengthBytesUTF8(config.provider || 'cpu') + 1;
|
|
|
267 |
Module.stringToUTF8(config.tokensBuf || '', buffer + offset, tokensBufLen);
|
268 |
offset += tokensBufLen;
|
269 |
|
270 |
+
offset = transducer.len + paraformer.len + zipformer2Ctc.len;
|
271 |
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
272 |
offset += 4;
|
273 |
|
|
|
305 |
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
|
306 |
offset += 4;
|
307 |
|
308 |
+
Module._CopyHeap(nemoCtc.ptr, nemoCtc.len, ptr + offset);
|
309 |
+
offset += nemoCtc.len;
|
310 |
+
|
311 |
return {
|
312 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
313 |
+
paraformer: paraformer, zipformer2Ctc: zipformer2Ctc, nemoCtc: nemoCtc
|
314 |
}
|
315 |
}
|
316 |
|
|
|
515 |
model: '',
|
516 |
};
|
517 |
|
518 |
+
const onlineNemoCtcModelConfig = {
|
519 |
+
model: '',
|
520 |
+
};
|
521 |
+
|
522 |
let type = 0;
|
523 |
|
524 |
switch (type) {
|
|
|
534 |
onlineParaformerModelConfig.decoder = './decoder.onnx';
|
535 |
break;
|
536 |
case 2:
|
537 |
+
// zipformer2Ctc
|
538 |
onlineZipformer2CtcModelConfig.model = './encoder.onnx';
|
539 |
break;
|
540 |
+
case 3:
|
541 |
+
// nemoCtc
|
542 |
+
onlineNemoCtcModelConfig.model = './nemo-ctc.onnx';
|
543 |
+
break;
|
544 |
}
|
545 |
|
546 |
|
|
|
548 |
transducer: onlineTransducerModelConfig,
|
549 |
paraformer: onlineParaformerModelConfig,
|
550 |
zipformer2Ctc: onlineZipformer2CtcModelConfig,
|
551 |
+
nemoCtc: onlineNemoCtcModelConfig,
|
552 |
tokens: './tokens.txt',
|
553 |
numThreads: 1,
|
554 |
provider: 'cpu',
|
sherpa-onnx-wasm-main-asr.js
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
sherpa-onnx-wasm-main-asr.wasm
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:793f46f5cb9d9645185a44e3b487c5b92ea840cad6840b43595a0d78570f84d5
|
3 |
+
size 11571993
|