csukuangfj
commited on
Commit
•
d78b374
1
Parent(s):
cb4b560
update model
Browse files- app-asr.js +1 -1
- sherpa-onnx-asr.js +40 -13
- sherpa-onnx-wasm-main-asr.js +0 -0
- sherpa-onnx-wasm-main-asr.wasm +2 -2
app-asr.js
CHANGED
@@ -108,7 +108,7 @@ if (navigator.mediaDevices.getUserMedia) {
|
|
108 |
}
|
109 |
|
110 |
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
111 |
-
let result = recognizer.getResult(recognizer_stream);
|
112 |
|
113 |
|
114 |
if (result.length > 0 && lastResult != result) {
|
|
|
108 |
}
|
109 |
|
110 |
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
111 |
+
let result = recognizer.getResult(recognizer_stream).text;
|
112 |
|
113 |
|
114 |
if (result.length > 0 && lastResult != result) {
|
sherpa-onnx-asr.js
CHANGED
@@ -43,6 +43,10 @@ function freeConfig(config, Module) {
|
|
43 |
freeConfig(config.lm, Module)
|
44 |
}
|
45 |
|
|
|
|
|
|
|
|
|
46 |
Module._free(config.ptr);
|
47 |
}
|
48 |
|
@@ -193,11 +197,26 @@ function initSherpaOnnxFeatureConfig(config, Module) {
|
|
193 |
return {ptr: ptr, len: len};
|
194 |
}
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
197 |
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
198 |
const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
|
|
|
|
|
199 |
|
200 |
-
const len = feat.len + model.len + 8 * 4;
|
201 |
const ptr = Module._malloc(len);
|
202 |
|
203 |
let offset = 0;
|
@@ -243,8 +262,11 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
|
243 |
Module.setValue(ptr + offset, config.hotwordsScore, 'float');
|
244 |
offset += 4;
|
245 |
|
|
|
|
|
246 |
return {
|
247 |
-
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model
|
|
|
248 |
}
|
249 |
}
|
250 |
|
@@ -313,6 +335,10 @@ function createOnlineRecognizer(Module, myConfig) {
|
|
313 |
rule3MinUtteranceLength: 20,
|
314 |
hotwordsFile: '',
|
315 |
hotwordsScore: 1.5,
|
|
|
|
|
|
|
|
|
316 |
};
|
317 |
if (myConfig) {
|
318 |
recognizerConfig = myConfig;
|
@@ -635,13 +661,12 @@ class OfflineRecognizer {
|
|
635 |
}
|
636 |
|
637 |
getResult(stream) {
|
638 |
-
const r = this.Module.
|
639 |
-
|
640 |
-
const
|
641 |
-
|
642 |
|
643 |
-
|
644 |
-
return text;
|
645 |
}
|
646 |
};
|
647 |
|
@@ -724,11 +749,13 @@ class OnlineRecognizer {
|
|
724 |
}
|
725 |
|
726 |
getResult(stream) {
|
727 |
-
const r =
|
728 |
-
|
729 |
-
const
|
730 |
-
|
731 |
-
|
|
|
|
|
732 |
}
|
733 |
}
|
734 |
|
|
|
43 |
freeConfig(config.lm, Module)
|
44 |
}
|
45 |
|
46 |
+
if ('ctcFstDecoder' in config) {
|
47 |
+
freeConfig(config.ctcFstDecoder, Module)
|
48 |
+
}
|
49 |
+
|
50 |
Module._free(config.ptr);
|
51 |
}
|
52 |
|
|
|
197 |
return {ptr: ptr, len: len};
|
198 |
}
|
199 |
|
200 |
+
function initSherpaOnnxOnlineCtcFstDecoderConfig(config, Module) {
|
201 |
+
const len = 2 * 4;
|
202 |
+
const ptr = Module._malloc(len);
|
203 |
+
|
204 |
+
const graphLen = Module.lengthBytesUTF8(config.graph) + 1;
|
205 |
+
const buffer = Module._malloc(graphLen);
|
206 |
+
Module.stringToUTF8(config.graph, buffer, graphLen);
|
207 |
+
|
208 |
+
Module.setValue(ptr, buffer, 'i8*');
|
209 |
+
Module.setValue(ptr + 4, config.maxActive, 'i32');
|
210 |
+
return {ptr: ptr, len: len, buffer: buffer};
|
211 |
+
}
|
212 |
+
|
213 |
function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
214 |
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
215 |
const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
|
216 |
+
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
217 |
+
config.ctcFstDecoderConfig, Module)
|
218 |
|
219 |
+
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len;
|
220 |
const ptr = Module._malloc(len);
|
221 |
|
222 |
let offset = 0;
|
|
|
262 |
Module.setValue(ptr + offset, config.hotwordsScore, 'float');
|
263 |
offset += 4;
|
264 |
|
265 |
+
Module._CopyHeap(ctcFstDecoder.ptr, ctcFstDecoder.len, ptr + offset);
|
266 |
+
|
267 |
return {
|
268 |
+
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
269 |
+
ctcFstDecoder: ctcFstDecoder
|
270 |
}
|
271 |
}
|
272 |
|
|
|
335 |
rule3MinUtteranceLength: 20,
|
336 |
hotwordsFile: '',
|
337 |
hotwordsScore: 1.5,
|
338 |
+
ctcFstDecoderConfig: {
|
339 |
+
graph: '',
|
340 |
+
maxActive: 3000,
|
341 |
+
}
|
342 |
};
|
343 |
if (myConfig) {
|
344 |
recognizerConfig = myConfig;
|
|
|
661 |
}
|
662 |
|
663 |
getResult(stream) {
|
664 |
+
const r = this.Module._GetOfflineStreamResultAsJson(stream.handle);
|
665 |
+
const jsonStr = this.Module.UTF8ToString(r);
|
666 |
+
const ans = JSON.parse(jsonStr);
|
667 |
+
this.Module._DestroyOfflineStreamResultJson(r);
|
668 |
|
669 |
+
return ans;
|
|
|
670 |
}
|
671 |
};
|
672 |
|
|
|
749 |
}
|
750 |
|
751 |
getResult(stream) {
|
752 |
+
const r =
|
753 |
+
this.Module._GetOnlineStreamResultAsJson(this.handle, stream.handle);
|
754 |
+
const jsonStr = this.Module.UTF8ToString(r);
|
755 |
+
const ans = JSON.parse(jsonStr);
|
756 |
+
this.Module._DestroyOnlineStreamResultJson(r);
|
757 |
+
|
758 |
+
return ans;
|
759 |
}
|
760 |
}
|
761 |
|
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:8d19732613178ae71a4ba0b1a4d25a583d281677bd37af8e98a37c14ed415f27
|
3 |
+
size 11088141
|