Add JavaScript API (node-addon) for FireRedAsr (#1873)

This commit is contained in:
Fangjun Kuang
2025-02-17 12:24:52 +08:00
committed by GitHub
parent 1d49dd2fb0
commit 050df2a357
27 changed files with 134 additions and 46 deletions

View File

@@ -80,6 +80,23 @@ static SherpaOnnxOfflineWhisperModelConfig GetOfflineWhisperModelConfig(
return c;
}
static SherpaOnnxOfflineFireRedAsrModelConfig GetOfflineFireRedAsrModelConfig(
Napi::Object obj) {
SherpaOnnxOfflineFireRedAsrModelConfig c;
memset(&c, 0, sizeof(c));
if (!obj.Has("fireRedAsr") || !obj.Get("fireRedAsr").IsObject()) {
return c;
}
Napi::Object o = obj.Get("fireRedAsr").As<Napi::Object>();
SHERPA_ONNX_ASSIGN_ATTR_STR(encoder, encoder);
SHERPA_ONNX_ASSIGN_ATTR_STR(decoder, decoder);
return c;
}
static SherpaOnnxOfflineMoonshineModelConfig GetOfflineMoonshineModelConfig(
Napi::Object obj) {
SherpaOnnxOfflineMoonshineModelConfig c;
@@ -150,6 +167,7 @@ static SherpaOnnxOfflineModelConfig GetOfflineModelConfig(Napi::Object obj) {
c.tdnn = GetOfflineTdnnModelConfig(o);
c.sense_voice = GetOfflineSenseVoiceModelConfig(o);
c.moonshine = GetOfflineMoonshineModelConfig(o);
c.fire_red_asr = GetOfflineFireRedAsrModelConfig(o);
SHERPA_ONNX_ASSIGN_ATTR_STR(tokens, tokens);
SHERPA_ONNX_ASSIGN_ATTR_INT32(num_threads, numThreads);
@@ -271,6 +289,9 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
SHERPA_ONNX_DELETE_C_STR(c.model_config.moonshine.uncached_decoder);
SHERPA_ONNX_DELETE_C_STR(c.model_config.moonshine.cached_decoder);
SHERPA_ONNX_DELETE_C_STR(c.model_config.fire_red_asr.encoder);
SHERPA_ONNX_DELETE_C_STR(c.model_config.fire_red_asr.decoder);
SHERPA_ONNX_DELETE_C_STR(c.model_config.tokens);
SHERPA_ONNX_DELETE_C_STR(c.model_config.provider);
SHERPA_ONNX_DELETE_C_STR(c.model_config.model_type);