fix kws for WebAssembly (#999)
This commit is contained in:
@@ -106,9 +106,9 @@ if (navigator.mediaDevices.getUserMedia) {
|
||||
|
||||
|
||||
let result = recognizer.getResult(recognizer_stream);
|
||||
console.log(result)
|
||||
|
||||
if (result.keyword.length > 0) {
|
||||
console.log(result)
|
||||
lastResult = result;
|
||||
resultList.push(JSON.stringify(result));
|
||||
}
|
||||
@@ -287,4 +287,4 @@ function downsampleBuffer(buffer, exportSampleRate) {
|
||||
offsetBuffer = nextOffsetBuffer;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -67,7 +67,7 @@ function initModelConfig(config, Module) {
|
||||
const paraformer_len = 2 * 4
|
||||
const ctc_len = 1 * 4
|
||||
|
||||
const len = transducer.len + paraformer_len + ctc_len + 5 * 4;
|
||||
const len = transducer.len + paraformer_len + ctc_len + 7 * 4;
|
||||
const ptr = Module._malloc(len);
|
||||
|
||||
let offset = 0;
|
||||
@@ -76,7 +76,10 @@ function initModelConfig(config, Module) {
|
||||
const tokensLen = Module.lengthBytesUTF8(config.tokens) + 1;
|
||||
const providerLen = Module.lengthBytesUTF8(config.provider) + 1;
|
||||
const modelTypeLen = Module.lengthBytesUTF8(config.modelType) + 1;
|
||||
const bufferLen = tokensLen + providerLen + modelTypeLen;
|
||||
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
||||
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
||||
const bufferLen =
|
||||
tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen;
|
||||
const buffer = Module._malloc(bufferLen);
|
||||
|
||||
offset = 0;
|
||||
@@ -87,6 +90,14 @@ function initModelConfig(config, Module) {
|
||||
offset += providerLen;
|
||||
|
||||
Module.stringToUTF8(config.modelType, buffer + offset, modelTypeLen);
|
||||
offset += modelTypeLen;
|
||||
|
||||
Module.stringToUTF8(
|
||||
config.modelingUnit || '', buffer + offset, modelingUnitLen);
|
||||
offset += modelingUnitLen;
|
||||
|
||||
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
||||
offset += bpeVocabLen;
|
||||
|
||||
offset = transducer.len + paraformer_len + ctc_len;
|
||||
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
||||
@@ -105,6 +116,17 @@ function initModelConfig(config, Module) {
|
||||
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(
|
||||
ptr + offset, buffer + tokensLen + providerLen + modelTypeLen,
|
||||
'i8*'); // modelingUnit
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(
|
||||
ptr + offset,
|
||||
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen,
|
||||
'i8*'); // bpeVocab
|
||||
offset += 4;
|
||||
|
||||
return {
|
||||
buffer: buffer, ptr: ptr, len: len, transducer: transducer
|
||||
}
|
||||
@@ -248,7 +270,9 @@ function createKws(Module, myConfig) {
|
||||
provider: 'cpu',
|
||||
modelType: '',
|
||||
numThreads: 1,
|
||||
debug: 1
|
||||
debug: 1,
|
||||
modelingUnit: 'cjkchar',
|
||||
bpeVocab: '',
|
||||
};
|
||||
|
||||
let featConfig = {
|
||||
|
||||
@@ -19,7 +19,7 @@ static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOnlineModelConfig) ==
|
||||
sizeof(SherpaOnnxOnlineTransducerModelConfig) +
|
||||
sizeof(SherpaOnnxOnlineParaformerModelConfig) +
|
||||
sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 5 * 4,
|
||||
sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 7 * 4,
|
||||
"");
|
||||
static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxKeywordSpotterConfig) ==
|
||||
|
||||
Reference in New Issue
Block a user