Commit
·
67c7e25
1
Parent(s):
e8b4808
update model
Browse files- sherpa-onnx-asr.js +46 -5
- sherpa-onnx-wasm-main-asr.js +0 -0
sherpa-onnx-asr.js
CHANGED
|
@@ -239,7 +239,7 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
| 239 |
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
| 240 |
config.ctcFstDecoderConfig, Module)
|
| 241 |
|
| 242 |
-
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len;
|
| 243 |
const ptr = Module._malloc(len);
|
| 244 |
|
| 245 |
let offset = 0;
|
|
@@ -251,7 +251,10 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
| 251 |
|
| 252 |
const decodingMethodLen = Module.lengthBytesUTF8(config.decodingMethod) + 1;
|
| 253 |
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile) + 1;
|
| 254 |
-
const
|
|
|
|
|
|
|
|
|
|
| 255 |
const buffer = Module._malloc(bufferLen);
|
| 256 |
|
| 257 |
offset = 0;
|
|
@@ -259,6 +262,13 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
| 259 |
offset += decodingMethodLen;
|
| 260 |
|
| 261 |
Module.stringToUTF8(config.hotwordsFile, buffer + offset, hotwordsFileLen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
offset = feat.len + model.len;
|
| 264 |
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
|
@@ -286,6 +296,16 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
| 286 |
offset += 4;
|
| 287 |
|
| 288 |
Module._CopyHeap(ctcFstDecoder.ptr, ctcFstDecoder.len, ptr + offset);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
|
| 290 |
return {
|
| 291 |
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
|
@@ -363,7 +383,9 @@ function createOnlineRecognizer(Module, myConfig) {
|
|
| 363 |
ctcFstDecoderConfig: {
|
| 364 |
graph: '',
|
| 365 |
maxActive: 3000,
|
| 366 |
-
}
|
|
|
|
|
|
|
| 367 |
};
|
| 368 |
if (myConfig) {
|
| 369 |
recognizerConfig = myConfig;
|
|
@@ -628,7 +650,7 @@ function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
|
|
| 628 |
const model = initSherpaOnnxOfflineModelConfig(config.modelConfig, Module);
|
| 629 |
const lm = initSherpaOnnxOfflineLMConfig(config.lmConfig, Module);
|
| 630 |
|
| 631 |
-
const len = feat.len + model.len + lm.len +
|
| 632 |
const ptr = Module._malloc(len);
|
| 633 |
|
| 634 |
let offset = 0;
|
|
@@ -643,7 +665,10 @@ function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
|
|
| 643 |
|
| 644 |
const decodingMethodLen = Module.lengthBytesUTF8(config.decodingMethod) + 1;
|
| 645 |
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile) + 1;
|
| 646 |
-
const
|
|
|
|
|
|
|
|
|
|
| 647 |
const buffer = Module._malloc(bufferLen);
|
| 648 |
|
| 649 |
offset = 0;
|
|
@@ -651,6 +676,13 @@ function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
|
|
| 651 |
offset += decodingMethodLen;
|
| 652 |
|
| 653 |
Module.stringToUTF8(config.hotwordsFile, buffer + offset, hotwordsFileLen);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
|
| 655 |
offset = feat.len + model.len + lm.len;
|
| 656 |
|
|
@@ -666,6 +698,15 @@ function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
|
|
| 666 |
Module.setValue(ptr + offset, config.hotwordsScore, 'float');
|
| 667 |
offset += 4;
|
| 668 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
return {
|
| 670 |
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model, lm: lm
|
| 671 |
}
|
|
|
|
| 239 |
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
| 240 |
config.ctcFstDecoderConfig, Module)
|
| 241 |
|
| 242 |
+
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 2 * 4;
|
| 243 |
const ptr = Module._malloc(len);
|
| 244 |
|
| 245 |
let offset = 0;
|
|
|
|
| 251 |
|
| 252 |
const decodingMethodLen = Module.lengthBytesUTF8(config.decodingMethod) + 1;
|
| 253 |
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile) + 1;
|
| 254 |
+
const ruleFstsFileLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
| 255 |
+
const ruleFarsFileLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
| 256 |
+
const bufferLen =
|
| 257 |
+
decodingMethodLen + hotwordsFileLen + ruleFstsFileLen + ruleFarsFileLen;
|
| 258 |
const buffer = Module._malloc(bufferLen);
|
| 259 |
|
| 260 |
offset = 0;
|
|
|
|
| 262 |
offset += decodingMethodLen;
|
| 263 |
|
| 264 |
Module.stringToUTF8(config.hotwordsFile, buffer + offset, hotwordsFileLen);
|
| 265 |
+
offset += hotwordsFileLen;
|
| 266 |
+
|
| 267 |
+
Module.stringToUTF8(config.ruleFsts || '', buffer + offset, ruleFstsFileLen);
|
| 268 |
+
offset += ruleFstsFileLen;
|
| 269 |
+
|
| 270 |
+
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsFileLen);
|
| 271 |
+
offset += ruleFarsFileLen;
|
| 272 |
|
| 273 |
offset = feat.len + model.len;
|
| 274 |
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
|
|
|
| 296 |
offset += 4;
|
| 297 |
|
| 298 |
Module._CopyHeap(ctcFstDecoder.ptr, ctcFstDecoder.len, ptr + offset);
|
| 299 |
+
offset += ctcFstDecoder.len;
|
| 300 |
+
|
| 301 |
+
Module.setValue(
|
| 302 |
+
ptr + offset, buffer + decodingMethodLen + hotwordsFileLen, 'i8*');
|
| 303 |
+
offset += 4;
|
| 304 |
+
|
| 305 |
+
Module.setValue(
|
| 306 |
+
ptr + offset,
|
| 307 |
+
buffer + decodingMethodLen + hotwordsFileLen + ruleFstsFileLen, 'i8*');
|
| 308 |
+
offset += 4;
|
| 309 |
|
| 310 |
return {
|
| 311 |
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
|
|
|
| 383 |
ctcFstDecoderConfig: {
|
| 384 |
graph: '',
|
| 385 |
maxActive: 3000,
|
| 386 |
+
},
|
| 387 |
+
ruleFsts: '',
|
| 388 |
+
ruleFars: '',
|
| 389 |
};
|
| 390 |
if (myConfig) {
|
| 391 |
recognizerConfig = myConfig;
|
|
|
|
| 650 |
const model = initSherpaOnnxOfflineModelConfig(config.modelConfig, Module);
|
| 651 |
const lm = initSherpaOnnxOfflineLMConfig(config.lmConfig, Module);
|
| 652 |
|
| 653 |
+
const len = feat.len + model.len + lm.len + 6 * 4;
|
| 654 |
const ptr = Module._malloc(len);
|
| 655 |
|
| 656 |
let offset = 0;
|
|
|
|
| 665 |
|
| 666 |
const decodingMethodLen = Module.lengthBytesUTF8(config.decodingMethod) + 1;
|
| 667 |
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile) + 1;
|
| 668 |
+
const ruleFstsLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
| 669 |
+
const ruleFarsLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
| 670 |
+
const bufferLen =
|
| 671 |
+
decodingMethodLen + hotwordsFileLen + ruleFstsLen + ruleFarsLen;
|
| 672 |
const buffer = Module._malloc(bufferLen);
|
| 673 |
|
| 674 |
offset = 0;
|
|
|
|
| 676 |
offset += decodingMethodLen;
|
| 677 |
|
| 678 |
Module.stringToUTF8(config.hotwordsFile, buffer + offset, hotwordsFileLen);
|
| 679 |
+
offset += hotwordsFileLen;
|
| 680 |
+
|
| 681 |
+
Module.stringToUTF8(config.ruleFsts || '', buffer + offset, ruleFstsLen);
|
| 682 |
+
offset += ruleFstsLen;
|
| 683 |
+
|
| 684 |
+
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsLen);
|
| 685 |
+
offset += ruleFarsLen;
|
| 686 |
|
| 687 |
offset = feat.len + model.len + lm.len;
|
| 688 |
|
|
|
|
| 698 |
Module.setValue(ptr + offset, config.hotwordsScore, 'float');
|
| 699 |
offset += 4;
|
| 700 |
|
| 701 |
+
Module.setValue(
|
| 702 |
+
ptr + offset, buffer + decodingMethodLen + hotwordsFileLen, 'i8*');
|
| 703 |
+
offset += 4;
|
| 704 |
+
|
| 705 |
+
Module.setValue(
|
| 706 |
+
ptr + offset, buffer + decodingMethodLen + hotwordsFileLen + ruleFstsLen,
|
| 707 |
+
'i8*');
|
| 708 |
+
offset += 4;
|
| 709 |
+
|
| 710 |
return {
|
| 711 |
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model, lm: lm
|
| 712 |
}
|
sherpa-onnx-wasm-main-asr.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|