Commit
·
ca0e49b
1
Parent(s):
5ac1876
update model
Browse files- sherpa-onnx-asr.js +76 -5
- sherpa-onnx-wasm-main-vad-asr.js +0 -0
- sherpa-onnx-wasm-main-vad-asr.wasm +2 -2
sherpa-onnx-asr.js
CHANGED
|
@@ -59,6 +59,10 @@ function freeConfig(config, Module) {
|
|
| 59 |
freeConfig(config.senseVoice, Module)
|
| 60 |
}
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
if ('lm' in config) {
|
| 63 |
freeConfig(config.lm, Module)
|
| 64 |
}
|
|
@@ -246,7 +250,7 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
| 246 |
Module.setValue(ptr + offset, buffer + tokensLen, 'i8*'); // provider
|
| 247 |
offset += 4;
|
| 248 |
|
| 249 |
-
Module.setValue(ptr + offset, config.debug
|
| 250 |
offset += 4;
|
| 251 |
|
| 252 |
Module.setValue(
|
|
@@ -692,6 +696,51 @@ function initSherpaOnnxOfflineWhisperModelConfig(config, Module) {
|
|
| 692 |
}
|
| 693 |
}
|
| 694 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 695 |
function initSherpaOnnxOfflineMoonshineModelConfig(config, Module) {
|
| 696 |
const preprocessorLen = Module.lengthBytesUTF8(config.preprocessor || '') + 1;
|
| 697 |
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
|
@@ -811,7 +860,7 @@ function initSherpaOnnxOfflineSenseVoiceModelConfig(config, Module) {
|
|
| 811 |
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
| 812 |
offset += languageLen;
|
| 813 |
|
| 814 |
-
Module.setValue(ptr + 8, config.useInverseTextNormalization
|
| 815 |
|
| 816 |
return {
|
| 817 |
buffer: buffer, ptr: ptr, len: len,
|
|
@@ -907,6 +956,16 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 907 |
};
|
| 908 |
}
|
| 909 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 910 |
const transducer =
|
| 911 |
initSherpaOnnxOfflineTransducerModelConfig(config.transducer, Module);
|
| 912 |
|
|
@@ -936,9 +995,11 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 936 |
const zipformerCtc =
|
| 937 |
initSherpaOnnxOfflineZipformerCtcModelConfig(config.zipformerCtc, Module);
|
| 938 |
|
|
|
|
|
|
|
| 939 |
const len = transducer.len + paraformer.len + nemoCtc.len + whisper.len +
|
| 940 |
tdnn.len + 8 * 4 + senseVoice.len + moonshine.len + fireRedAsr.len +
|
| 941 |
-
dolphin.len + zipformerCtc.len;
|
| 942 |
|
| 943 |
const ptr = Module._malloc(len);
|
| 944 |
|
|
@@ -1000,7 +1061,7 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 1000 |
Module.setValue(ptr + offset, config.numThreads || 1, 'i32');
|
| 1001 |
offset += 4;
|
| 1002 |
|
| 1003 |
-
Module.setValue(ptr + offset, config.debug
|
| 1004 |
offset += 4;
|
| 1005 |
|
| 1006 |
Module.setValue(ptr + offset, buffer + tokensLen, 'i8*'); // provider
|
|
@@ -1043,11 +1104,14 @@ function initSherpaOnnxOfflineModelConfig(config, Module) {
|
|
| 1043 |
Module._CopyHeap(zipformerCtc.ptr, zipformerCtc.len, ptr + offset);
|
| 1044 |
offset += zipformerCtc.len;
|
| 1045 |
|
|
|
|
|
|
|
|
|
|
| 1046 |
return {
|
| 1047 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
| 1048 |
paraformer: paraformer, nemoCtc: nemoCtc, whisper: whisper, tdnn: tdnn,
|
| 1049 |
senseVoice: senseVoice, moonshine: moonshine, fireRedAsr: fireRedAsr,
|
| 1050 |
-
dolphin: dolphin, zipformerCtc: zipformerCtc
|
| 1051 |
}
|
| 1052 |
}
|
| 1053 |
|
|
@@ -1189,6 +1253,13 @@ class OfflineRecognizer {
|
|
| 1189 |
this.Module = Module;
|
| 1190 |
}
|
| 1191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1192 |
free() {
|
| 1193 |
this.Module._SherpaOnnxDestroyOfflineRecognizer(this.handle);
|
| 1194 |
this.handle = 0
|
|
|
|
| 59 |
freeConfig(config.senseVoice, Module)
|
| 60 |
}
|
| 61 |
|
| 62 |
+
if ('canary' in config) {
|
| 63 |
+
freeConfig(config.canary, Module)
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
if ('lm' in config) {
|
| 67 |
freeConfig(config.lm, Module)
|
| 68 |
}
|
|
|
|
| 250 |
Module.setValue(ptr + offset, buffer + tokensLen, 'i8*'); // provider
|
| 251 |
offset += 4;
|
| 252 |
|
| 253 |
+
Module.setValue(ptr + offset, config.debug ?? 1, 'i32');
|
| 254 |
offset += 4;
|
| 255 |
|
| 256 |
Module.setValue(
|
|
|
|
| 696 |
}
|
| 697 |
}
|
| 698 |
|
| 699 |
+
function initSherpaOnnxOfflineCanaryModelConfig(config, Module) {
|
| 700 |
+
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
| 701 |
+
const decoderLen = Module.lengthBytesUTF8(config.decoder || '') + 1;
|
| 702 |
+
const srcLangLen = Module.lengthBytesUTF8(config.srcLang || '') + 1;
|
| 703 |
+
const tgtLangLen = Module.lengthBytesUTF8(config.tgtLang || '') + 1;
|
| 704 |
+
|
| 705 |
+
const n = encoderLen + decoderLen + srcLangLen + tgtLangLen;
|
| 706 |
+
const buffer = Module._malloc(n);
|
| 707 |
+
|
| 708 |
+
const len = 5 * 4; // 4 pointers + 1 int32
|
| 709 |
+
const ptr = Module._malloc(len);
|
| 710 |
+
|
| 711 |
+
let offset = 0;
|
| 712 |
+
Module.stringToUTF8(config.encoder || '', buffer + offset, encoderLen);
|
| 713 |
+
offset += encoderLen;
|
| 714 |
+
|
| 715 |
+
Module.stringToUTF8(config.decoder || '', buffer + offset, decoderLen);
|
| 716 |
+
offset += decoderLen;
|
| 717 |
+
|
| 718 |
+
Module.stringToUTF8(config.srcLang || '', buffer + offset, srcLangLen);
|
| 719 |
+
offset += srcLangLen;
|
| 720 |
+
|
| 721 |
+
Module.stringToUTF8(config.tgtLang || '', buffer + offset, tgtLangLen);
|
| 722 |
+
offset += tgtLangLen;
|
| 723 |
+
|
| 724 |
+
offset = 0;
|
| 725 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
| 726 |
+
offset += encoderLen;
|
| 727 |
+
|
| 728 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
| 729 |
+
offset += decoderLen;
|
| 730 |
+
|
| 731 |
+
Module.setValue(ptr + 8, buffer + offset, 'i8*');
|
| 732 |
+
offset += srcLangLen;
|
| 733 |
+
|
| 734 |
+
Module.setValue(ptr + 12, buffer + offset, 'i8*');
|
| 735 |
+
offset += tgtLangLen;
|
| 736 |
+
|
| 737 |
+
Module.setValue(ptr + 16, config.usePnc ?? 1, 'i32');
|
| 738 |
+
|
| 739 |
+
return {
|
| 740 |
+
buffer: buffer, ptr: ptr, len: len,
|
| 741 |
+
}
|
| 742 |
+
}
|
| 743 |
+
|
| 744 |
function initSherpaOnnxOfflineMoonshineModelConfig(config, Module) {
|
| 745 |
const preprocessorLen = Module.lengthBytesUTF8(config.preprocessor || '') + 1;
|
| 746 |
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
|
|
|
| 860 |
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
| 861 |
offset += languageLen;
|
| 862 |
|
| 863 |
+
Module.setValue(ptr + 8, config.useInverseTextNormalization ?? 0, 'i32');
|
| 864 |
|
| 865 |
return {
|
| 866 |
buffer: buffer, ptr: ptr, len: len,
|
|
|
|
| 956 |
};
|
| 957 |
}
|
| 958 |
|
| 959 |
+
if (!('canary' in config)) {
|
| 960 |
+
config.canary = {
|
| 961 |
+
encoder: '',
|
| 962 |
+
decoder: '',
|
| 963 |
+
srcLang: '',
|
| 964 |
+
tgtLang: '',
|
| 965 |
+
usePnc: 1,
|
| 966 |
+
};
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
const transducer =
|
| 970 |
initSherpaOnnxOfflineTransducerModelConfig(config.transducer, Module);
|
| 971 |
|
|
|
|
| 995 |
const zipformerCtc =
|
| 996 |
initSherpaOnnxOfflineZipformerCtcModelConfig(config.zipformerCtc, Module);
|
| 997 |
|
| 998 |
+
const canary = initSherpaOnnxOfflineCanaryModelConfig(config.canary, Module);
|
| 999 |
+
|
| 1000 |
const len = transducer.len + paraformer.len + nemoCtc.len + whisper.len +
|
| 1001 |
tdnn.len + 8 * 4 + senseVoice.len + moonshine.len + fireRedAsr.len +
|
| 1002 |
+
dolphin.len + zipformerCtc.len + canary.len;
|
| 1003 |
|
| 1004 |
const ptr = Module._malloc(len);
|
| 1005 |
|
|
|
|
| 1061 |
Module.setValue(ptr + offset, config.numThreads || 1, 'i32');
|
| 1062 |
offset += 4;
|
| 1063 |
|
| 1064 |
+
Module.setValue(ptr + offset, config.debug ?? 1, 'i32');
|
| 1065 |
offset += 4;
|
| 1066 |
|
| 1067 |
Module.setValue(ptr + offset, buffer + tokensLen, 'i8*'); // provider
|
|
|
|
| 1104 |
Module._CopyHeap(zipformerCtc.ptr, zipformerCtc.len, ptr + offset);
|
| 1105 |
offset += zipformerCtc.len;
|
| 1106 |
|
| 1107 |
+
Module._CopyHeap(canary.ptr, canary.len, ptr + offset);
|
| 1108 |
+
offset += canary.len;
|
| 1109 |
+
|
| 1110 |
return {
|
| 1111 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
| 1112 |
paraformer: paraformer, nemoCtc: nemoCtc, whisper: whisper, tdnn: tdnn,
|
| 1113 |
senseVoice: senseVoice, moonshine: moonshine, fireRedAsr: fireRedAsr,
|
| 1114 |
+
dolphin: dolphin, zipformerCtc: zipformerCtc, canary: canary,
|
| 1115 |
}
|
| 1116 |
}
|
| 1117 |
|
|
|
|
| 1253 |
this.Module = Module;
|
| 1254 |
}
|
| 1255 |
|
| 1256 |
+
setConfig(configObj) {
|
| 1257 |
+
const config =
|
| 1258 |
+
initSherpaOnnxOfflineRecognizerConfig(configObj, this.Module);
|
| 1259 |
+
this.Module._SherpaOnnxOfflineRecognizerSetConfig(this.handle, config.ptr);
|
| 1260 |
+
freeConfig(config, this.Module);
|
| 1261 |
+
}
|
| 1262 |
+
|
| 1263 |
free() {
|
| 1264 |
this.Module._SherpaOnnxDestroyOfflineRecognizer(this.handle);
|
| 1265 |
this.handle = 0
|
sherpa-onnx-wasm-main-vad-asr.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
sherpa-onnx-wasm-main-vad-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:f7463e83e9a1aa4b88e9446bf74e71b8cd83fdbe4a68c4f243de15f7c61c4e8b
|
| 3 |
+
size 11541908
|