Spaces:
Configuration error
Configuration error
Commit
·
478c894
1
Parent(s):
869bed1
update model
Browse files- sherpa-onnx-asr.js +65 -4
- sherpa-onnx-wasm-main-asr.js +0 -0
sherpa-onnx-asr.js
CHANGED
|
@@ -137,7 +137,7 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
| 137 |
const ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
| 138 |
config.zipformer2Ctc, Module);
|
| 139 |
|
| 140 |
-
const len = transducer.len + paraformer.len + ctc.len +
|
| 141 |
const ptr = Module._malloc(len);
|
| 142 |
|
| 143 |
let offset = 0;
|
|
@@ -153,7 +153,11 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
| 153 |
const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1;
|
| 154 |
const providerLen = Module.lengthBytesUTF8(config.provider) + 1;
|
| 155 |
const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1;
|
| 156 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
const buffer = Module._malloc(bufferLen);
|
| 158 |
|
| 159 |
offset = 0;
|
|
@@ -164,6 +168,14 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
| 164 |
offset += providerLen;
|
| 165 |
|
| 166 |
Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
offset = transducer.len + paraformer.len + ctc.len;
|
| 169 |
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
|
@@ -182,6 +194,17 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
| 182 |
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
| 183 |
offset += 4;
|
| 184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
return {
|
| 186 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
| 187 |
paraformer: paraformer, ctc: ctc
|
|
@@ -317,6 +340,8 @@ function createOnlineRecognizer(Module, myConfig) {
|
|
| 317 |
provider: 'cpu',
|
| 318 |
debug: 1,
|
| 319 |
modelType: '',
|
|
|
|
|
|
|
| 320 |
};
|
| 321 |
|
| 322 |
const featureConfig = {
|
|
@@ -504,7 +529,7 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 504 |
const tdnn = initSherpaOnnxOfflineTdnnModelConfig(config.tdnn, Module);
|
| 505 |
|
| 506 |
const len = transducer.len + paraformer.len + nemoCtc.len + whisper.len +
|
| 507 |
-
tdnn.len +
|
| 508 |
const ptr = Module._malloc(len);
|
| 509 |
|
| 510 |
let offset = 0;
|
|
@@ -526,7 +551,13 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 526 |
const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1;
|
| 527 |
const providerLen = Module.lengthBytesUTF8(config.provider) + 1;
|
| 528 |
const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1;
|
| 529 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
const buffer = Module._malloc(bufferLen);
|
| 531 |
|
| 532 |
offset = 0;
|
|
@@ -537,6 +568,18 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 537 |
offset += providerLen;
|
| 538 |
|
| 539 |
Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
|
| 541 |
offset =
|
| 542 |
transducer.len + paraformer.len + nemoCtc.len + whisper.len + tdnn.len;
|
|
@@ -556,6 +599,24 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 556 |
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
| 557 |
offset += 4;
|
| 558 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
return {
|
| 560 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
| 561 |
paraformer: paraformer, nemoCtc: nemoCtc, whisper: whisper, tdnn: tdnn
|
|
|
|
| 137 |
const ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
| 138 |
config.zipformer2Ctc, Module);
|
| 139 |
|
| 140 |
+
const len = transducer.len + paraformer.len + ctc.len + 7 * 4;
|
| 141 |
const ptr = Module._malloc(len);
|
| 142 |
|
| 143 |
let offset = 0;
|
|
|
|
| 153 |
const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1;
|
| 154 |
const providerLen = Module.lengthBytesUTF8(config.provider) + 1;
|
| 155 |
const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1;
|
| 156 |
+
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
| 157 |
+
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
| 158 |
+
|
| 159 |
+
const bufferLen =
|
| 160 |
+
tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen;
|
| 161 |
const buffer = Module._malloc(bufferLen);
|
| 162 |
|
| 163 |
offset = 0;
|
|
|
|
| 168 |
offset += providerLen;
|
| 169 |
|
| 170 |
Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen);
|
| 171 |
+
offset += modelTypeLen;
|
| 172 |
+
|
| 173 |
+
Module.stringToUTF8(
|
| 174 |
+
config.modelingUnit || '', buffer + offset, modelingUnitLen);
|
| 175 |
+
offset += modelingUnitLen;
|
| 176 |
+
|
| 177 |
+
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
| 178 |
+
offset += bpeVocabLen;
|
| 179 |
|
| 180 |
offset = transducer.len + paraformer.len + ctc.len;
|
| 181 |
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
|
|
|
| 194 |
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
| 195 |
offset += 4;
|
| 196 |
|
| 197 |
+
Module.setValue(
|
| 198 |
+
ptr + offset, buffer + tokensLen + providerLen + modelTypeLen,
|
| 199 |
+
'i8*'); // modelingUnit
|
| 200 |
+
offset += 4;
|
| 201 |
+
|
| 202 |
+
Module.setValue(
|
| 203 |
+
ptr + offset,
|
| 204 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen,
|
| 205 |
+
'i8*'); // bpeVocab
|
| 206 |
+
offset += 4;
|
| 207 |
+
|
| 208 |
return {
|
| 209 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
| 210 |
paraformer: paraformer, ctc: ctc
|
|
|
|
| 340 |
provider: 'cpu',
|
| 341 |
debug: 1,
|
| 342 |
modelType: '',
|
| 343 |
+
modelingUnit: 'cjkchar',
|
| 344 |
+
bpeVocab: '',
|
| 345 |
};
|
| 346 |
|
| 347 |
const featureConfig = {
|
|
|
|
| 529 |
const tdnn = initSherpaOnnxOfflineTdnnModelConfig(config.tdnn, Module);
|
| 530 |
|
| 531 |
const len = transducer.len + paraformer.len + nemoCtc.len + whisper.len +
|
| 532 |
+
tdnn.len + 8 * 4;
|
| 533 |
const ptr = Module._malloc(len);
|
| 534 |
|
| 535 |
let offset = 0;
|
|
|
|
| 551 |
const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1;
|
| 552 |
const providerLen = Module.lengthBytesUTF8(config.provider) + 1;
|
| 553 |
const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1;
|
| 554 |
+
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
| 555 |
+
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
| 556 |
+
const teleSpeechCtcLen =
|
| 557 |
+
Module.lengthBytesUTF8(config.teleSpeechCtc || '') + 1;
|
| 558 |
+
|
| 559 |
+
const bufferLen = tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
| 560 |
+
bpeVocabLen + teleSpeechCtcLen;
|
| 561 |
const buffer = Module._malloc(bufferLen);
|
| 562 |
|
| 563 |
offset = 0;
|
|
|
|
| 568 |
offset += providerLen;
|
| 569 |
|
| 570 |
Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen);
|
| 571 |
+
offset += modelTypeLen;
|
| 572 |
+
|
| 573 |
+
Module.stringToUTF8(
|
| 574 |
+
config.modelingUnit || '', buffer + offset, modelingUnitLen);
|
| 575 |
+
offset += modelingUnitLen;
|
| 576 |
+
|
| 577 |
+
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
| 578 |
+
offset += bpeVocabLen;
|
| 579 |
+
|
| 580 |
+
Module.stringToUTF8(
|
| 581 |
+
config.teleSpeechCtc || '', buffer + offset, teleSpeechCtcLen);
|
| 582 |
+
offset += teleSpeechCtcLen;
|
| 583 |
|
| 584 |
offset =
|
| 585 |
transducer.len + paraformer.len + nemoCtc.len + whisper.len + tdnn.len;
|
|
|
|
| 599 |
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
| 600 |
offset += 4;
|
| 601 |
|
| 602 |
+
Module.setValue(
|
| 603 |
+
ptr + offset, buffer + tokensLen + providerLen + modelTypeLen,
|
| 604 |
+
'i8*'); // modelingUnit
|
| 605 |
+
offset += 4;
|
| 606 |
+
|
| 607 |
+
Module.setValue(
|
| 608 |
+
ptr + offset,
|
| 609 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen,
|
| 610 |
+
'i8*'); // bpeVocab
|
| 611 |
+
offset += 4;
|
| 612 |
+
|
| 613 |
+
Module.setValue(
|
| 614 |
+
ptr + offset,
|
| 615 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
| 616 |
+
bpeVocabLen,
|
| 617 |
+
'i8*'); // teleSpeechCtc
|
| 618 |
+
offset += 4;
|
| 619 |
+
|
| 620 |
return {
|
| 621 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
| 622 |
paraformer: paraformer, nemoCtc: nemoCtc, whisper: whisper, tdnn: tdnn
|
sherpa-onnx-wasm-main-asr.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|