Fix building (#1343)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user