Fix building (#1343)
This commit is contained in:
@@ -155,6 +155,14 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!('tokensBuf' in config)) {
|
||||
config.tokensBuf = '';
|
||||
}
|
||||
|
||||
if (!('tokensBufSize' in config)) {
|
||||
config.tokensBufSize = 0;
|
||||
}
|
||||
|
||||
const transducer =
|
||||
initSherpaOnnxOnlineTransducerModelConfig(config.transducer, Module);
|
||||
|
||||
@@ -164,7 +172,7 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
||||
const ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
||||
config.zipformer2Ctc, Module);
|
||||
|
||||
const len = transducer.len + paraformer.len + ctc.len + 7 * 4;
|
||||
const len = transducer.len + paraformer.len + ctc.len + 9 * 4;
|
||||
const ptr = Module._malloc(len);
|
||||
|
||||
let offset = 0;
|
||||
@@ -182,9 +190,10 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
||||
const modelTypeLen = Module.lengthBytesUTF8(config.modelType || '') + 1;
|
||||
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
||||
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
||||
const tokensBufLen = Module.lengthBytesUTF8(config.tokensBuf || '') + 1;
|
||||
|
||||
const bufferLen =
|
||||
tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen;
|
||||
const bufferLen = tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
||||
bpeVocabLen + tokensBufLen;
|
||||
const buffer = Module._malloc(bufferLen);
|
||||
|
||||
offset = 0;
|
||||
@@ -204,6 +213,9 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
||||
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
||||
offset += bpeVocabLen;
|
||||
|
||||
Module.stringToUTF8(config.tokensBuf || '', buffer + offset, tokensBufLen);
|
||||
offset += tokensBufLen;
|
||||
|
||||
offset = transducer.len + paraformer.len + ctc.len;
|
||||
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
||||
offset += 4;
|
||||
@@ -232,6 +244,16 @@ function initSherpaOnnxOnlineModelConfig(config, Module) {
|
||||
'i8*'); // bpeVocab
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(
|
||||
ptr + offset,
|
||||
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
||||
bpeVocabLen,
|
||||
'i8*'); // tokens_buf
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
|
||||
offset += 4;
|
||||
|
||||
return {
|
||||
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
||||
paraformer: paraformer, ctc: ctc
|
||||
@@ -275,12 +297,20 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
||||
};
|
||||
}
|
||||
|
||||
if (!('hotwordsBuf' in config)) {
|
||||
config.hotwordsBuf = '';
|
||||
}
|
||||
|
||||
if (!('hotwordsBufSize' in config)) {
|
||||
config.hotwordsBufSize = 0;
|
||||
}
|
||||
|
||||
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
||||
const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
|
||||
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
||||
config.ctcFstDecoderConfig, Module)
|
||||
|
||||
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 3 * 4;
|
||||
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 5 * 4;
|
||||
const ptr = Module._malloc(len);
|
||||
|
||||
let offset = 0;
|
||||
@@ -295,8 +325,9 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
||||
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile || '') + 1;
|
||||
const ruleFstsFileLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
||||
const ruleFarsFileLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
||||
const bufferLen =
|
||||
decodingMethodLen + hotwordsFileLen + ruleFstsFileLen + ruleFarsFileLen;
|
||||
const hotwordsBufLen = Module.lengthBytesUTF8(config.hotwordsBuf || '') + 1;
|
||||
const bufferLen = decodingMethodLen + hotwordsFileLen + ruleFstsFileLen +
|
||||
ruleFarsFileLen + hotwordsBufLen;
|
||||
const buffer = Module._malloc(bufferLen);
|
||||
|
||||
offset = 0;
|
||||
@@ -314,6 +345,10 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
||||
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsFileLen);
|
||||
offset += ruleFarsFileLen;
|
||||
|
||||
Module.stringToUTF8(
|
||||
config.hotwordsBuf || '', buffer + offset, hotwordsBufLen);
|
||||
offset += hotwordsBufLen;
|
||||
|
||||
offset = feat.len + model.len;
|
||||
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
||||
offset += 4;
|
||||
@@ -354,6 +389,16 @@ function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
||||
Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(
|
||||
ptr + offset,
|
||||
buffer + decodingMethodLen + hotwordsFileLen + ruleFstsFileLen +
|
||||
ruleFarsFileLen,
|
||||
'i8*');
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(ptr + offset, config.hotwordsBufSize || 0, 'i32');
|
||||
offset += 4;
|
||||
|
||||
return {
|
||||
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
||||
ctcFstDecoder: ctcFstDecoder
|
||||
|
||||
@@ -19,14 +19,14 @@ static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOnlineModelConfig) ==
|
||||
sizeof(SherpaOnnxOnlineTransducerModelConfig) +
|
||||
sizeof(SherpaOnnxOnlineParaformerModelConfig) +
|
||||
sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 7 * 4,
|
||||
sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 9 * 4,
|
||||
"");
|
||||
static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOnlineCtcFstDecoderConfig) == 2 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOnlineRecognizerConfig) ==
|
||||
sizeof(SherpaOnnxFeatureConfig) +
|
||||
sizeof(SherpaOnnxOnlineModelConfig) + 8 * 4 +
|
||||
sizeof(SherpaOnnxOnlineCtcFstDecoderConfig) + 3 * 4,
|
||||
sizeof(SherpaOnnxOnlineCtcFstDecoderConfig) + 5 * 4,
|
||||
"");
|
||||
|
||||
void MyPrint(SherpaOnnxOnlineRecognizerConfig *config) {
|
||||
@@ -54,6 +54,9 @@ void MyPrint(SherpaOnnxOnlineRecognizerConfig *config) {
|
||||
fprintf(stdout, "model type: %s\n", model_config->model_type);
|
||||
fprintf(stdout, "modeling unit: %s\n", model_config->modeling_unit);
|
||||
fprintf(stdout, "bpe vocab: %s\n", model_config->bpe_vocab);
|
||||
fprintf(stdout, "tokens_buf: %s\n",
|
||||
model_config->tokens_buf ? model_config->tokens_buf : "");
|
||||
fprintf(stdout, "tokens_buf_size: %d\n", model_config->tokens_buf_size);
|
||||
|
||||
fprintf(stdout, "----------feat config----------\n");
|
||||
fprintf(stdout, "sample rate: %d\n", feat->sample_rate);
|
||||
|
||||
@@ -62,12 +62,20 @@ function initSherpaOnnxOnlineTransducerModelConfig(config, Module) {
|
||||
|
||||
// The user should free the returned pointers
|
||||
function initModelConfig(config, Module) {
|
||||
if (!('tokensBuf' in config)) {
|
||||
config.tokensBuf = '';
|
||||
}
|
||||
|
||||
if (!('tokensBufSize' in config)) {
|
||||
config.tokensBufSize = 0;
|
||||
}
|
||||
|
||||
const transducer =
|
||||
initSherpaOnnxOnlineTransducerModelConfig(config.transducer, Module);
|
||||
const paraformer_len = 2 * 4
|
||||
const ctc_len = 1 * 4
|
||||
|
||||
const len = transducer.len + paraformer_len + ctc_len + 7 * 4;
|
||||
const len = transducer.len + paraformer_len + ctc_len + 9 * 4;
|
||||
const ptr = Module._malloc(len);
|
||||
Module.HEAPU8.fill(0, ptr, ptr + len);
|
||||
|
||||
@@ -79,8 +87,9 @@ function initModelConfig(config, Module) {
|
||||
const modelTypeLen = Module.lengthBytesUTF8(config.modelType || '') + 1;
|
||||
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
||||
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
||||
const bufferLen =
|
||||
tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen;
|
||||
const tokensBufLen = Module.lengthBytesUTF8(config.tokensBuf || '') + 1;
|
||||
const bufferLen = tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
||||
bpeVocabLen + tokensBufLen;
|
||||
const buffer = Module._malloc(bufferLen);
|
||||
|
||||
offset = 0;
|
||||
@@ -100,6 +109,9 @@ function initModelConfig(config, Module) {
|
||||
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
||||
offset += bpeVocabLen;
|
||||
|
||||
Module.stringToUTF8(config.tokensBuf || '', buffer + offset, tokensBufLen);
|
||||
offset += tokensBufLen;
|
||||
|
||||
offset = transducer.len + paraformer_len + ctc_len;
|
||||
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
||||
offset += 4;
|
||||
@@ -128,6 +140,16 @@ function initModelConfig(config, Module) {
|
||||
'i8*'); // bpeVocab
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(
|
||||
ptr + offset,
|
||||
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
||||
bpeVocabLen,
|
||||
'i8*'); // tokens_buf
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(ptr + offset, config.tokensBufSize || 0, 'i32');
|
||||
offset += 4;
|
||||
|
||||
return {
|
||||
buffer: buffer, ptr: ptr, len: len, transducer: transducer
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ static_assert(sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) == 1 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxOnlineModelConfig) ==
|
||||
sizeof(SherpaOnnxOnlineTransducerModelConfig) +
|
||||
sizeof(SherpaOnnxOnlineParaformerModelConfig) +
|
||||
sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 7 * 4,
|
||||
sizeof(SherpaOnnxOnlineZipformer2CtcModelConfig) + 9 * 4,
|
||||
"");
|
||||
static_assert(sizeof(SherpaOnnxFeatureConfig) == 2 * 4, "");
|
||||
static_assert(sizeof(SherpaOnnxKeywordSpotterConfig) ==
|
||||
|
||||
Reference in New Issue
Block a user