csukuangfj commited on
Commit
ffc29f9
·
1 Parent(s): 87d69d0

update model

Browse files
sherpa-onnx-asr.js CHANGED
@@ -63,6 +63,10 @@ function freeConfig(config, Module) {
63
  freeConfig(config.ctcFstDecoder, Module)
64
  }
65
 
 
 
 
 
66
  Module._free(config.ptr);
67
  }
68
 
@@ -281,6 +285,34 @@ function initSherpaOnnxFeatureConfig(config, Module) {
281
  return {ptr: ptr, len: len};
282
  }
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  function initSherpaOnnxOnlineCtcFstDecoderConfig(config, Module) {
285
  const len = 2 * 4;
286
  const ptr = Module._malloc(len);
@@ -317,12 +349,21 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
317
  config.hotwordsBufSize = 0;
318
  }
319
 
 
 
 
 
 
 
 
 
320
  const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
321
  const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
322
  const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
323
  config.ctcFstDecoderConfig, Module)
 
324
 
325
- const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 5 * 4;
326
  const ptr = Module._malloc(len);
327
 
328
  let offset = 0;
@@ -411,9 +452,12 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
411
  Module.setValue(ptr + offset, config.hotwordsBufSize || 0, 'i32');
412
  offset += 4;
413
 
 
 
 
414
  return {
415
  buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
416
- ctcFstDecoder: ctcFstDecoder
417
  }
418
  }
419
 
@@ -989,11 +1033,20 @@ function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
989
  };
990
  }
991
 
 
 
 
 
 
 
 
 
992
  const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
993
  const model = initSherpaOnnxOfflineModelConfig(config.modelConfig, Module);
994
  const lm = initSherpaOnnxOfflineLMConfig(config.lmConfig, Module);
 
995
 
996
- const len = feat.len + model.len + lm.len + 7 * 4;
997
  const ptr = Module._malloc(len);
998
 
999
  let offset = 0;
@@ -1056,8 +1109,12 @@ function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
1056
  Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
1057
  offset += 4;
1058
 
 
 
 
1059
  return {
1060
- buffer: buffer, ptr: ptr, len: len, feat: feat, model: model, lm: lm
 
1061
  }
1062
  }
1063
 
 
63
  freeConfig(config.ctcFstDecoder, Module)
64
  }
65
 
66
+ if ('hr' in config) {
67
+ freeConfig(config.hr, Module)
68
+ }
69
+
70
  Module._free(config.ptr);
71
  }
72
 
 
285
  return {ptr: ptr, len: len};
286
  }
287
 
288
+ function initSherpaOnnxHomophoneReplacerConfig(config, Module) {
289
+ const len = 3 * 4;
290
+ const ptr = Module._malloc(len);
291
+
292
+ const dictDirLen = Module.lengthBytesUTF8(config.dictDir || '') + 1;
293
+ const lexiconLen = Module.lengthBytesUTF8(config.lexicon || '') + 1;
294
+ const ruleFstsLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
295
+
296
+ const bufferLen = dictDirLen + lexiconLen + ruleFstsLen;
297
+
298
+ const buffer = Module._malloc(bufferLen);
299
+ let offset = 0
300
+ Module.stringToUTF8(config.dictDir || '', buffer + offset, dictDirLen);
301
+ offset += dictDirLen;
302
+
303
+ Module.stringToUTF8(config.lexicon || '', buffer + offset, lexiconLen);
304
+ offset += lexiconLen;
305
+
306
+ Module.stringToUTF8(config.ruleFsts || '', buffer + offset, ruleFstsLen);
307
+ offset += ruleFstsLen;
308
+
309
+ Module.setValue(ptr, buffer, 'i8*');
310
+ Module.setValue(ptr + 4, buffer + dictDirLen, 'i8*');
311
+ Module.setValue(ptr + 8, buffer + dictDirLen + lexiconLen, 'i8*');
312
+
313
+ return {ptr: ptr, len: len, buffer: buffer};
314
+ }
315
+
316
  function initSherpaOnnxOnlineCtcFstDecoderConfig(config, Module) {
317
  const len = 2 * 4;
318
  const ptr = Module._malloc(len);
 
349
  config.hotwordsBufSize = 0;
350
  }
351
 
352
+ if (!('hr' in config)) {
353
+ config.hr = {
354
+ dictDir: '',
355
+ lexicon: '',
356
+ ruleFsts: '',
357
+ };
358
+ }
359
+
360
  const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
361
  const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
362
  const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
363
  config.ctcFstDecoderConfig, Module)
364
+ const hr = initSherpaOnnxHomophoneReplacerConfig(config.hr, Module);
365
 
366
+ const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 5 * 4 + hr.len;
367
  const ptr = Module._malloc(len);
368
 
369
  let offset = 0;
 
452
  Module.setValue(ptr + offset, config.hotwordsBufSize || 0, 'i32');
453
  offset += 4;
454
 
455
+ Module._CopyHeap(hr.ptr, hr.len, ptr + offset);
456
+ offset += hr.len;
457
+
458
  return {
459
  buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
460
+ ctcFstDecoder: ctcFstDecoder, hr: hr,
461
  }
462
  }
463
 
 
1033
  };
1034
  }
1035
 
1036
+ if (!('hr' in config)) {
1037
+ config.hr = {
1038
+ dictDir: '',
1039
+ lexicon: '',
1040
+ ruleFsts: '',
1041
+ };
1042
+ }
1043
+
1044
  const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
1045
  const model = initSherpaOnnxOfflineModelConfig(config.modelConfig, Module);
1046
  const lm = initSherpaOnnxOfflineLMConfig(config.lmConfig, Module);
1047
+ const hr = initSherpaOnnxHomophoneReplacerConfig(config.hr, Module);
1048
 
1049
+ const len = feat.len + model.len + lm.len + 7 * 4 + hr.len;
1050
  const ptr = Module._malloc(len);
1051
 
1052
  let offset = 0;
 
1109
  Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
1110
  offset += 4;
1111
 
1112
+ Module._CopyHeap(hr.ptr, hr.len, ptr + offset);
1113
+ offset += hr.len;
1114
+
1115
  return {
1116
+ buffer: buffer, ptr: ptr, len: len, feat: feat, model: model, lm: lm,
1117
+ hr: hr,
1118
  }
1119
  }
1120
 
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:7de0a408867bb4ee9ba03c63fb0a5b50f30facf9d962a27a651fb41b1c83cbfe
3
- size 11465949
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74c8d3601d5c98fd34063595e059995267b762e005ec68820a5f8c45e79923ec
3
+ size 11532373