small fixes to wasm kws. (#672)
This commit is contained in:
0
build-wasm-simd-kws.sh
Normal file → Executable file
0
build-wasm-simd-kws.sh
Normal file → Executable file
@@ -4,6 +4,23 @@ function freeConfig(config, Module) {
|
|||||||
if ('buffer' in config) {
|
if ('buffer' in config) {
|
||||||
Module._free(config.buffer);
|
Module._free(config.buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('transducer' in config) {
|
||||||
|
freeConfig(config.transducer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('featConfig' in config) {
|
||||||
|
freeConfig(config.featConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('modelConfig' in config) {
|
||||||
|
freeConfig(config.modelConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('keywordsBuffer' in config) {
|
||||||
|
Module._free(config.keywordsBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
Module._free(config.ptr);
|
Module._free(config.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +106,7 @@ function initModelConfig(config, Module) {
|
|||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
buffer: buffer, ptr: ptr, len: len,
|
buffer: buffer, ptr: ptr, len: len, transducer: transducer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,12 +120,10 @@ function initFeatureExtractorConfig(config, Module) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initKwsConfig(config, Module) {
|
function initKwsConfig(config, Module) {
|
||||||
let featConfig =
|
let featConfig = initFeatureExtractorConfig(config.featConfig, Module);
|
||||||
initFeatureExtractorConfig(config.featConfig, Module);
|
|
||||||
|
|
||||||
let modelConfig = initModelConfig(config.modelConfig, Module);
|
let modelConfig = initModelConfig(config.modelConfig, Module);
|
||||||
let numBytes =
|
let numBytes = featConfig.len + modelConfig.len + 4 * 5;
|
||||||
featConfig.len + modelConfig.len + 4 * 5;
|
|
||||||
|
|
||||||
let ptr = Module._malloc(numBytes);
|
let ptr = Module._malloc(numBytes);
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
@@ -118,7 +133,6 @@ function initKwsConfig(config, Module) {
|
|||||||
Module._CopyHeap(modelConfig.ptr, modelConfig.len, ptr + offset)
|
Module._CopyHeap(modelConfig.ptr, modelConfig.len, ptr + offset)
|
||||||
offset += modelConfig.len;
|
offset += modelConfig.len;
|
||||||
|
|
||||||
|
|
||||||
Module.setValue(ptr + offset, config.maxActivePaths, 'i32');
|
Module.setValue(ptr + offset, config.maxActivePaths, 'i32');
|
||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
@@ -138,7 +152,8 @@ function initKwsConfig(config, Module) {
|
|||||||
offset += 4;
|
offset += 4;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ptr: ptr, len: numBytes, featConfig: featConfig, modelConfig: modelConfig
|
ptr: ptr, len: numBytes, featConfig: featConfig, modelConfig: modelConfig,
|
||||||
|
keywordsBuffer: keywordsBuffer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +193,7 @@ class Stream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
inputFinished() {
|
inputFinished() {
|
||||||
_InputFinished(this.handle);
|
this.Module._InputFinished(this.handle);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -188,9 +203,6 @@ class Kws {
|
|||||||
let config = initKwsConfig(configObj, Module)
|
let config = initKwsConfig(configObj, Module)
|
||||||
let handle = Module._CreateKeywordSpotter(config.ptr);
|
let handle = Module._CreateKeywordSpotter(config.ptr);
|
||||||
|
|
||||||
|
|
||||||
freeConfig(config.featConfig, Module);
|
|
||||||
freeConfig(config.modelConfig, Module);
|
|
||||||
freeConfig(config, Module);
|
freeConfig(config, Module);
|
||||||
|
|
||||||
this.handle = handle;
|
this.handle = handle;
|
||||||
@@ -211,7 +223,6 @@ class Kws {
|
|||||||
return this.Module._IsKeywordStreamReady(this.handle, stream.handle) === 1;
|
return this.Module._IsKeywordStreamReady(this.handle, stream.handle) === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
decode(stream) {
|
decode(stream) {
|
||||||
return this.Module._DecodeKeywordStream(this.handle, stream.handle);
|
return this.Module._DecodeKeywordStream(this.handle, stream.handle);
|
||||||
}
|
}
|
||||||
@@ -230,12 +241,12 @@ function createKws(Module, myConfig) {
|
|||||||
encoder: './encoder-epoch-12-avg-2-chunk-16-left-64.onnx',
|
encoder: './encoder-epoch-12-avg-2-chunk-16-left-64.onnx',
|
||||||
decoder: './decoder-epoch-12-avg-2-chunk-16-left-64.onnx',
|
decoder: './decoder-epoch-12-avg-2-chunk-16-left-64.onnx',
|
||||||
joiner: './joiner-epoch-12-avg-2-chunk-16-left-64.onnx',
|
joiner: './joiner-epoch-12-avg-2-chunk-16-left-64.onnx',
|
||||||
}
|
};
|
||||||
let modelConfig = {
|
let modelConfig = {
|
||||||
transducer: transducerConfig,
|
transducer: transducerConfig,
|
||||||
tokens: './tokens.txt',
|
tokens: './tokens.txt',
|
||||||
provider: 'cpu',
|
provider: 'cpu',
|
||||||
modelType: "",
|
modelType: '',
|
||||||
numThreads: 1,
|
numThreads: 1,
|
||||||
debug: 1
|
debug: 1
|
||||||
};
|
};
|
||||||
@@ -252,8 +263,8 @@ function createKws(Module, myConfig) {
|
|||||||
numTrailingBlanks: 1,
|
numTrailingBlanks: 1,
|
||||||
keywordsScore: 1.0,
|
keywordsScore: 1.0,
|
||||||
keywordsThreshold: 0.25,
|
keywordsThreshold: 0.25,
|
||||||
keywords: "x iǎo ài t óng x ué @小爱同学\n" +
|
keywords: 'x iǎo ài t óng x ué @小爱同学\n' +
|
||||||
"j ūn g ē n iú b ī @军哥牛逼"
|
'j ūn g ē n iú b ī @军哥牛逼'
|
||||||
};
|
};
|
||||||
|
|
||||||
if (myConfig) {
|
if (myConfig) {
|
||||||
|
|||||||
Reference in New Issue
Block a user