csukuangfj
commited on
Commit
•
046f20b
1
Parent(s):
19a4c88
update model
Browse files- sherpa-onnx-asr.js +51 -6
- sherpa-onnx-wasm-main-asr.js +0 -0
- sherpa-onnx-wasm-main-asr.wasm +2 -2
sherpa-onnx-asr.js
CHANGED
@@ -155,6 +155,14 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
155 |
};
|
156 |
}
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
const transducer =
|
159 |
initSherpaOnnxOnlineTransducerModelConfig(config.transducer, Module);
|
160 |
|
@@ -164,7 +172,7 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
164 |
const ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
165 |
config.zipformer2Ctc, Module);
|
166 |
|
167 |
-
const len = transducer.len + paraformer.len + ctc.len +
|
168 |
const ptr = Module._malloc(len);
|
169 |
|
170 |
let offset = 0;
|
@@ -182,9 +190,10 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
182 |
const modelTypeLen = Module.lengthBytesUTF8(config.modelType || '') + 1;
|
183 |
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
184 |
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
|
|
185 |
|
186 |
-
const bufferLen =
|
187 |
-
|
188 |
const buffer = Module._malloc(bufferLen);
|
189 |
|
190 |
offset = 0;
|
@@ -204,6 +213,9 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
204 |
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
205 |
offset += bpeVocabLen;
|
206 |
|
|
|
|
|
|
|
207 |
offset = transducer.len + paraformer.len + ctc.len;
|
208 |
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
209 |
offset += 4;
|
@@ -232,6 +244,16 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
|
232 |
'i8*'); // bpeVocab
|
233 |
offset += 4;
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
return {
|
236 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
237 |
paraformer: paraformer, ctc: ctc
|
@@ -275,12 +297,20 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
275 |
};
|
276 |
}
|
277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
279 |
const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
|
280 |
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
281 |
config.ctcFstDecoderConfig, Module)
|
282 |
|
283 |
-
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len +
|
284 |
const ptr = Module._malloc(len);
|
285 |
|
286 |
let offset = 0;
|
@@ -295,8 +325,9 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
295 |
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile || '') + 1;
|
296 |
const ruleFstsFileLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
297 |
const ruleFarsFileLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
298 |
-
const
|
299 |
-
|
|
|
300 |
const buffer = Module._malloc(bufferLen);
|
301 |
|
302 |
offset = 0;
|
@@ -314,6 +345,10 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
314 |
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsFileLen);
|
315 |
offset += ruleFarsFileLen;
|
316 |
|
|
|
|
|
|
|
|
|
317 |
offset = feat.len + model.len;
|
318 |
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
319 |
offset += 4;
|
@@ -354,6 +389,16 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
354 |
Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
|
355 |
offset += 4;
|
356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
return {
|
358 |
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
359 |
ctcFstDecoder: ctcFstDecoder
|
|
|
155 |
};
|
156 |
}
|
157 |
|
158 |
+
if (!('tokensBuf' in config)) {
|
159 |
+
config.tokensBuf = '';
|
160 |
+
}
|
161 |
+
|
162 |
+
if (!('tokensBufSize' in config)) {
|
163 |
+
config.tokensBufSize = 0;
|
164 |
+
}
|
165 |
+
|
166 |
const transducer =
|
167 |
initSherpaOnnxOnlineTransducerModelConfig(config.transducer, Module);
|
168 |
|
|
|
172 |
const ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
173 |
config.zipformer2Ctc, Module);
|
174 |
|
175 |
+
const len = transducer.len + paraformer.len + ctc.len + 9 * 4;
|
176 |
const ptr = Module._malloc(len);
|
177 |
|
178 |
let offset = 0;
|
|
|
190 |
const modelTypeLen = Module.lengthBytesUTF8(config.modelType || '') + 1;
|
191 |
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
192 |
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
193 |
+
const tokensBufLen = Module.lengthBytesUTF8(config.tokensBuf || '') + 1;
|
194 |
|
195 |
+
const bufferLen = tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
196 |
+
bpeVocabLen + tokensBufLen;
|
197 |
const buffer = Module._malloc(bufferLen);
|
198 |
|
199 |
offset = 0;
|
|
|
213 |
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
214 |
offset += bpeVocabLen;
|
215 |
|
216 |
+
Module.stringToUTF8(config.tokensBuf || '', buffer + offset, tokensBufLen);
|
217 |
+
offset += tokensBufLen;
|
218 |
+
|
219 |
offset = transducer.len + paraformer.len + ctc.len;
|
220 |
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
221 |
offset += 4;
|
|
|
244 |
'i8*'); // bpeVocab
|
245 |
offset += 4;
|
246 |
|
247 |
+
Module.setValue(
|
248 |
+
ptr + offset,
|
249 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
250 |
+
bpeVocabLen,
|
251 |
+
'i8*'); // tokens_buf
|
252 |
+
offset += 4;
|
253 |
+
|
254 |
+
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
|
255 |
+
offset += 4;
|
256 |
+
|
257 |
return {
|
258 |
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
259 |
paraformer: paraformer, ctc: ctc
|
|
|
297 |
};
|
298 |
}
|
299 |
|
300 |
+
if (!('hotwordsBuf' in config)) {
|
301 |
+
config.hotwordsBuf = '';
|
302 |
+
}
|
303 |
+
|
304 |
+
if (!('hotwordsBufSize' in config)) {
|
305 |
+
config.hotwordsBufSize = 0;
|
306 |
+
}
|
307 |
+
|
308 |
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
309 |
const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
|
310 |
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
311 |
config.ctcFstDecoderConfig, Module)
|
312 |
|
313 |
+
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 5 * 4;
|
314 |
const ptr = Module._malloc(len);
|
315 |
|
316 |
let offset = 0;
|
|
|
325 |
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile || '') + 1;
|
326 |
const ruleFstsFileLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
327 |
const ruleFarsFileLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
328 |
+
const hotwordsBufLen = Module.lengthBytesUTF8(config.hotwordsBuf || '') + 1;
|
329 |
+
const bufferLen = decodingMethodLen + hotwordsFileLen + ruleFstsFileLen +
|
330 |
+
ruleFarsFileLen + hotwordsBufLen;
|
331 |
const buffer = Module._malloc(bufferLen);
|
332 |
|
333 |
offset = 0;
|
|
|
345 |
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsFileLen);
|
346 |
offset += ruleFarsFileLen;
|
347 |
|
348 |
+
Module.stringToUTF8(
|
349 |
+
config.hotwordsBuf || '', buffer + offset, hotwordsBufLen);
|
350 |
+
offset += hotwordsBufLen;
|
351 |
+
|
352 |
offset = feat.len + model.len;
|
353 |
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
354 |
offset += 4;
|
|
|
389 |
Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
|
390 |
offset += 4;
|
391 |
|
392 |
+
Module.setValue(
|
393 |
+
ptr + offset,
|
394 |
+
buffer + decodingMethodLen + hotwordsFileLen + ruleFstsFileLen +
|
395 |
+
ruleFarsFileLen,
|
396 |
+
'i8*');
|
397 |
+
offset += 4;
|
398 |
+
|
399 |
+
Module.setValue(ptr + offset, config.hotwordsBufSize || 0, 'i32');
|
400 |
+
offset += 4;
|
401 |
+
|
402 |
return {
|
403 |
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
404 |
ctcFstDecoder: ctcFstDecoder
|
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:758d3a3094e143da820ec82f4b5859bfb3c851457debfa950aa794339d1461fb
|
3 |
+
size 11435272
|