From a57e5e3f097d57be66bc048ca08b754a62c9a45c Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Fri, 26 Jul 2024 18:01:19 +0800 Subject: [PATCH] fix wasm --- wasm/asr/sherpa-onnx-asr.js | 45 ++++++++++++++++++++----------------- wasm/kws/sherpa-onnx-kws.js | 22 +++++++++--------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/wasm/asr/sherpa-onnx-asr.js b/wasm/asr/sherpa-onnx-asr.js index 1a70ba952..704a7b10c 100644 --- a/wasm/asr/sherpa-onnx-asr.js +++ b/wasm/asr/sherpa-onnx-asr.js @@ -869,7 +869,7 @@ class OfflineStream { free() { if (this.handle) { - this.Module._DestroyOfflineStream(this.handle); + this.Module._SherpaOnnxDestroyOfflineStream(this.handle); this.handle = null; } } @@ -882,7 +882,7 @@ class OfflineStream { const pointer = this.Module._malloc(samples.length * samples.BYTES_PER_ELEMENT); this.Module.HEAPF32.set(samples, pointer / samples.BYTES_PER_ELEMENT); - this.Module._AcceptWaveformOffline( + this.Module._SherpaOnnxAcceptWaveformOffline( this.handle, sampleRate, pointer, samples.length); this.Module._free(pointer); } @@ -892,7 +892,7 @@ class OfflineRecognizer { constructor(configObj, Module) { this.config = configObj; const config = initSherpaOnnxOfflineRecognizerConfig(configObj, Module); - const handle = Module._CreateOfflineRecognizer(config.ptr); + const handle = Module._SherpaOnnxCreateOfflineRecognizer(config.ptr); freeConfig(config, Module); this.handle = handle; @@ -900,24 +900,25 @@ class OfflineRecognizer { } free() { - this.Module._DestroyOfflineRecognizer(this.handle); + this.Module._SherpaOnnxDestroyOfflineRecognizer(this.handle); this.handle = 0 } createStream() { - const handle = this.Module._CreateOfflineStream(this.handle); + const handle = this.Module._SherpaOnnxCreateOfflineStream(this.handle); return new OfflineStream(handle, this.Module); } decode(stream) { - this.Module._DecodeOfflineStream(this.handle, stream.handle); + this.Module._SherpaOnnxDecodeOfflineStream(this.handle, stream.handle); } getResult(stream) { - const r = this.Module._GetOfflineStreamResultAsJson(stream.handle); + const r = + this.Module._SherpaOnnxGetOfflineStreamResultAsJson(stream.handle); const jsonStr = this.Module.UTF8ToString(r); const ans = JSON.parse(jsonStr); - this.Module._DestroyOfflineStreamResultJson(r); + this.Module._SherpaOnnxDestroyOfflineStreamResultJson(r); return ans; } @@ -933,7 +934,7 @@ class OnlineStream { free() { if (this.handle) { - this.Module._DestroyOnlineStream(this.handle); + this.Module._SherpaOnnxDestroyOnlineStream(this.handle); this.handle = null; this.Module._free(this.pointer); this.pointer = null; @@ -954,12 +955,12 @@ class OnlineStream { } this.Module.HEAPF32.set(samples, this.pointer / samples.BYTES_PER_ELEMENT); - this.Module._AcceptWaveform( + this.Module._SherpaOnnxOnlineStreamAcceptWaveform( this.handle, sampleRate, this.pointer, samples.length); } inputFinished() { - this.Module._InputFinished(this.handle); + this.Module._SherpaOnnxOnlineStreamInputFinished(this.handle); } }; @@ -967,7 +968,7 @@ class OnlineRecognizer { constructor(configObj, Module) { this.config = configObj; const config = initSherpaOnnxOnlineRecognizerConfig(configObj, Module) - const handle = Module._CreateOnlineRecognizer(config.ptr); + const handle = Module._SherpaOnnxCreateOnlineRecognizer(config.ptr); freeConfig(config, Module); @@ -976,37 +977,39 @@ class OnlineRecognizer { } free() { - this.Module._DestroyOnlineRecognizer(this.handle); + this.Module._SherpaOnnxDestroyOnlineRecognizer(this.handle); this.handle = 0 } createStream() { - const handle = this.Module._CreateOnlineStream(this.handle); + const handle = this.Module._SherpaOnnxCreateOnlineStream(this.handle); return new OnlineStream(handle, this.Module); } isReady(stream) { - return this.Module._IsOnlineStreamReady(this.handle, stream.handle) == 1; + return this.Module._SherpaOnnxIsOnlineStreamReady( + this.handle, stream.handle) == 1; } decode(stream) { - this.Module._DecodeOnlineStream(this.handle, stream.handle); + this.Module._SherpaOnnxDecodeOnlineStream(this.handle, stream.handle); } isEndpoint(stream) { - return this.Module._IsEndpoint(this.handle, stream.handle) == 1; + return this.Module._SherpaOnnxOnlineStreamIsEndpoint( + this.handle, stream.handle) == 1; } reset(stream) { - this.Module._Reset(this.handle, stream.handle); + this.Module._SherpaOnnxOnlineStreamReset(this.handle, stream.handle); } getResult(stream) { - const r = - this.Module._GetOnlineStreamResultAsJson(this.handle, stream.handle); + const r = this.Module._SherpaOnnxGetOnlineStreamResultAsJson( + this.handle, stream.handle); const jsonStr = this.Module.UTF8ToString(r); const ans = JSON.parse(jsonStr); - this.Module._DestroyOnlineStreamResultJson(r); + this.Module._SherpaOnnxDestroyOnlineStreamResultJson(r); return ans; } diff --git a/wasm/kws/sherpa-onnx-kws.js b/wasm/kws/sherpa-onnx-kws.js index cb9d5ac7a..23d2bb361 100644 --- a/wasm/kws/sherpa-onnx-kws.js +++ b/wasm/kws/sherpa-onnx-kws.js @@ -189,7 +189,7 @@ class Stream { free() { if (this.handle) { - this.Module._DestroyOnlineKwsStream(this.handle); + this.Module._SherpaOnnxDestroyOnlineStream(this.handle); this.handle = null; this.Module._free(this.pointer); this.pointer = null; @@ -210,12 +210,12 @@ class Stream { } this.Module.HEAPF32.set(samples, this.pointer / samples.BYTES_PER_ELEMENT); - this.Module._AcceptWaveform( + this.Module._SherpaOnnxOnlineStreamAcceptWaveform( this.handle, sampleRate, this.pointer, samples.length); } inputFinished() { - this.Module._InputFinished(this.handle); + this.Module._SherpaOnnxOnlineStreamInputFinished(this.handle); } }; @@ -223,7 +223,7 @@ class Kws { constructor(configObj, Module) { this.config = configObj; let config = initKwsConfig(configObj, Module) - let handle = Module._CreateKeywordSpotter(config.ptr); + let handle = Module._SherpaOnnxCreateKeywordSpotter(config.ptr); freeConfig(config, Module); @@ -232,28 +232,30 @@ class Kws { } free() { - this.Module._DestroyKeywordSpotter(this.handle); + this.Module._SherpaOnnxDestroyKeywordSpotter(this.handle); this.handle = 0 } createStream() { - let handle = this.Module._CreateKeywordStream(this.handle); + let handle = this.Module._SherpaOnnxCreateKeywordStream(this.handle); return new Stream(handle, this.Module); } isReady(stream) { - return this.Module._IsKeywordStreamReady(this.handle, stream.handle) === 1; + return this.Module._SherpaOnnxIsKeywordStreamReady( + this.handle, stream.handle) == 1; } decode(stream) { - return this.Module._DecodeKeywordStream(this.handle, stream.handle); + return this.Module._SherpaOnnxDecodeKeywordStream( + this.handle, stream.handle); } getResult(stream) { - let r = this.Module._GetKeywordResult(this.handle, stream.handle); + let r = this.Module._SherpaOnnxGetKeywordResult(this.handle, stream.handle); let jsonPtr = this.Module.getValue(r + 24, 'i8*'); let json = this.Module.UTF8ToString(jsonPtr); - this.Module._DestroyKeywordResult(r); + this.Module._SherpaOnnxDestroyKeywordResult(r); return JSON.parse(json); } }