Skip to content

Commit

Permalink
Fix js
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Mar 20, 2024
1 parent 13dcc0d commit 050aa75
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions nodejs-examples/test-offline-nemo-ctc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function createOfflineRecognizer() {
whisper: {
encoder: '',
decoder: '',
language: '',
task: '',
},
tdnn: {
model: '',
Expand Down
2 changes: 2 additions & 0 deletions nodejs-examples/test-offline-paraformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function createOfflineRecognizer() {
whisper: {
encoder: '',
decoder: '',
language: '',
task: '',
},
tdnn: {
model: '',
Expand Down
2 changes: 2 additions & 0 deletions nodejs-examples/test-offline-transducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function createOfflineRecognizer() {
whisper: {
encoder: '',
decoder: '',
language: '',
task: '',
},
tdnn: {
model: '',
Expand Down
2 changes: 2 additions & 0 deletions nodejs-examples/test-offline-whisper.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function createOfflineRecognizer() {
whisper: {
encoder: './sherpa-onnx-whisper-tiny.en/tiny.en-encoder.int8.onnx',
decoder: './sherpa-onnx-whisper-tiny.en/tiny.en-decoder.int8.onnx',
language: '',
task: 'transcribe',
},
tdnn: {
model: '',
Expand Down
19 changes: 17 additions & 2 deletions wasm/asr/sherpa-onnx-asr.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,24 +393,39 @@ function initSherpaOnnxOfflineNemoEncDecCtcModelConfig(config, Module) {
function initSherpaOnnxOfflineWhisperModelConfig(config, Module) {
const encoderLen = Module.lengthBytesUTF8(config.encoder) + 1;
const decoderLen = Module.lengthBytesUTF8(config.decoder) + 1;
const languageLen = Module.lengthBytesUTF8(config.language) + 1;
const taskLen = Module.lengthBytesUTF8(config.task) + 1;

const n = encoderLen + decoderLen;
const n = encoderLen + decoderLen + languageLen + taskLen;
const buffer = Module._malloc(n);

const len = 2 * 4; // 2 pointers
const len = 4 * 4; // 4 pointers
const ptr = Module._malloc(len);

let offset = 0;
Module.stringToUTF8(config.encoder, buffer + offset, encoderLen);
offset += encoderLen;

Module.stringToUTF8(config.decoder, buffer + offset, decoderLen);
offset += decoderLen;

Module.stringToUTF8(config.language, buffer + offset, languageLen);
offset += languageLen;

Module.stringToUTF8(config.task, buffer + offset, taskLen);

offset = 0;
Module.setValue(ptr, buffer + offset, 'i8*');
offset += encoderLen;

Module.setValue(ptr + 4, buffer + offset, 'i8*');
offset += decoderLen;

Module.setValue(ptr + 8, buffer + offset, 'i8*');
offset += languageLen;

Module.setValue(ptr + 12, buffer + offset, 'i8*');
offset += taskLen;

return {
buffer: buffer, ptr: ptr, len: len,
Expand Down
4 changes: 3 additions & 1 deletion wasm/nodejs/sherpa-onnx-wasm-nodejs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static_assert(sizeof(SherpaOnnxOfflineTransducerModelConfig) == 3 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineParaformerModelConfig) == 4, "");

static_assert(sizeof(SherpaOnnxOfflineNemoEncDecCtcModelConfig) == 4, "");
static_assert(sizeof(SherpaOnnxOfflineWhisperModelConfig) == 2 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineWhisperModelConfig) == 4 * 4, "");
static_assert(sizeof(SherpaOnnxOfflineTdnnModelConfig) == 4, "");
static_assert(sizeof(SherpaOnnxOfflineLMConfig) == 2 * 4, "");

Expand Down Expand Up @@ -77,6 +77,8 @@ void PrintOfflineRecognizerConfig(SherpaOnnxOfflineRecognizerConfig *config) {
fprintf(stdout, "----------offline whisper model config----------\n");
fprintf(stdout, "encoder: %s\n", whisper->encoder);
fprintf(stdout, "decoder: %s\n", whisper->decoder);
fprintf(stdout, "language: %s\n", whisper->language);
fprintf(stdout, "task: %s\n", whisper->task);

fprintf(stdout, "----------offline tdnn model config----------\n");
fprintf(stdout, "model: %s\n", tdnn->model);
Expand Down

0 comments on commit 050aa75

Please sign in to comment.