Refactor C API to prefix each API with SherpaOnnx. (#1171)

This commit is contained in:
Fangjun Kuang
2024-07-26 18:47:02 +08:00
committed by GitHub
parent 994c3e7c96
commit 4e6aeff07e
47 changed files with 667 additions and 618 deletions

View File

@@ -141,7 +141,7 @@ AudioTaggingCreateOfflineStreamWrapper(const Napi::CallbackInfo &info) {
return Napi::External<SherpaOnnxOfflineStream>::New(
env, const_cast<SherpaOnnxOfflineStream *>(stream),
[](Napi::Env env, SherpaOnnxOfflineStream *stream) {
DestroyOfflineStream(stream);
SherpaOnnxDestroyOfflineStream(stream);
});
}

View File

@@ -44,7 +44,7 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
SHERPA_ONNX_ASSIGN_ATTR_FLOAT(keywords_threshold, keywordsThreshold);
SHERPA_ONNX_ASSIGN_ATTR_STR(keywords_file, keywordsFile);
SherpaOnnxKeywordSpotter *kws = CreateKeywordSpotter(&c);
SherpaOnnxKeywordSpotter *kws = SherpaOnnxCreateKeywordSpotter(&c);
if (c.model_config.transducer.encoder) {
delete[] c.model_config.transducer.encoder;
@@ -95,7 +95,7 @@ static Napi::External<SherpaOnnxKeywordSpotter> CreateKeywordSpotterWrapper(
return Napi::External<SherpaOnnxKeywordSpotter>::New(
env, kws, [](Napi::Env env, SherpaOnnxKeywordSpotter *kws) {
DestroyKeywordSpotter(kws);
SherpaOnnxDestroyKeywordSpotter(kws);
});
}
@@ -122,11 +122,11 @@ static Napi::External<SherpaOnnxOnlineStream> CreateKeywordStreamWrapper(
SherpaOnnxKeywordSpotter *kws =
info[0].As<Napi::External<SherpaOnnxKeywordSpotter>>().Data();
SherpaOnnxOnlineStream *stream = CreateKeywordStream(kws);
SherpaOnnxOnlineStream *stream = SherpaOnnxCreateKeywordStream(kws);
return Napi::External<SherpaOnnxOnlineStream>::New(
env, stream, [](Napi::Env env, SherpaOnnxOnlineStream *stream) {
DestroyOnlineStream(stream);
SherpaOnnxDestroyOnlineStream(stream);
});
}
@@ -162,7 +162,7 @@ static Napi::Boolean IsKeywordStreamReadyWrapper(
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
int32_t is_ready = IsKeywordStreamReady(kws, stream);
int32_t is_ready = SherpaOnnxIsKeywordStreamReady(kws, stream);
return Napi::Boolean::New(env, is_ready);
}
@@ -198,7 +198,7 @@ static void DecodeKeywordStreamWrapper(const Napi::CallbackInfo &info) {
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
DecodeKeywordStream(kws, stream);
SherpaOnnxDecodeKeywordStream(kws, stream);
}
static Napi::String GetKeywordResultAsJsonWrapper(
@@ -233,11 +233,11 @@ static Napi::String GetKeywordResultAsJsonWrapper(
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
const char *json = GetKeywordResultAsJson(kws, stream);
const char *json = SherpaOnnxGetKeywordResultAsJson(kws, stream);
Napi::String s = Napi::String::New(env, json);
FreeKeywordResultJson(json);
SherpaOnnxFreeKeywordResultJson(json);
return s;
}

View File

@@ -202,7 +202,8 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fsts, ruleFsts);
SHERPA_ONNX_ASSIGN_ATTR_STR(rule_fars, ruleFars);
SherpaOnnxOfflineRecognizer *recognizer = CreateOfflineRecognizer(&c);
SherpaOnnxOfflineRecognizer *recognizer =
SherpaOnnxCreateOfflineRecognizer(&c);
if (c.model_config.transducer.encoder) {
delete[] c.model_config.transducer.encoder;
@@ -306,7 +307,7 @@ CreateOfflineRecognizerWrapper(const Napi::CallbackInfo &info) {
return Napi::External<SherpaOnnxOfflineRecognizer>::New(
env, recognizer,
[](Napi::Env env, SherpaOnnxOfflineRecognizer *recognizer) {
DestroyOfflineRecognizer(recognizer);
SherpaOnnxDestroyOfflineRecognizer(recognizer);
});
}
@@ -334,11 +335,11 @@ static Napi::External<SherpaOnnxOfflineStream> CreateOfflineStreamWrapper(
SherpaOnnxOfflineRecognizer *recognizer =
info[0].As<Napi::External<SherpaOnnxOfflineRecognizer>>().Data();
SherpaOnnxOfflineStream *stream = CreateOfflineStream(recognizer);
SherpaOnnxOfflineStream *stream = SherpaOnnxCreateOfflineStream(recognizer);
return Napi::External<SherpaOnnxOfflineStream>::New(
env, stream, [](Napi::Env env, SherpaOnnxOfflineStream *stream) {
DestroyOfflineStream(stream);
SherpaOnnxDestroyOfflineStream(stream);
});
}
@@ -405,8 +406,8 @@ static void AcceptWaveformOfflineWrapper(const Napi::CallbackInfo &info) {
Napi::Float32Array samples = obj.Get("samples").As<Napi::Float32Array>();
int32_t sample_rate = obj.Get("sampleRate").As<Napi::Number>().Int32Value();
AcceptWaveformOffline(stream, sample_rate, samples.Data(),
samples.ElementLength());
SherpaOnnxAcceptWaveformOffline(stream, sample_rate, samples.Data(),
samples.ElementLength());
}
static void DecodeOfflineStreamWrapper(const Napi::CallbackInfo &info) {
@@ -441,7 +442,7 @@ static void DecodeOfflineStreamWrapper(const Napi::CallbackInfo &info) {
SherpaOnnxOfflineStream *stream =
info[1].As<Napi::External<SherpaOnnxOfflineStream>>().Data();
DecodeOfflineStream(recognizer, stream);
SherpaOnnxDecodeOfflineStream(recognizer, stream);
}
static Napi::String GetOfflineStreamResultAsJsonWrapper(
@@ -466,10 +467,10 @@ static Napi::String GetOfflineStreamResultAsJsonWrapper(
SherpaOnnxOfflineStream *stream =
info[0].As<Napi::External<SherpaOnnxOfflineStream>>().Data();
const char *json = GetOfflineStreamResultAsJson(stream);
const char *json = SherpaOnnxGetOfflineStreamResultAsJson(stream);
Napi::String s = Napi::String::New(env, json);
DestroyOfflineStreamResultJson(json);
SherpaOnnxDestroyOfflineStreamResultJson(json);
return s;
}

View File

@@ -130,7 +130,7 @@ SpeakerEmbeddingExtractorCreateStreamWrapper(const Napi::CallbackInfo &info) {
return Napi::External<SherpaOnnxOnlineStream>::New(
env, const_cast<SherpaOnnxOnlineStream *>(stream),
[](Napi::Env env, SherpaOnnxOnlineStream *stream) {
DestroyOnlineStream(stream);
SherpaOnnxDestroyOnlineStream(stream);
});
}

View File

@@ -124,7 +124,7 @@ SpokenLanguageIdentificationCreateOfflineStreamWrapper(
return Napi::External<SherpaOnnxOfflineStream>::New(
env, stream, [](Napi::Env env, SherpaOnnxOfflineStream *stream) {
DestroyOfflineStream(stream);
SherpaOnnxDestroyOfflineStream(stream);
});
}

View File

@@ -194,7 +194,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
c.ctc_fst_decoder_config = GetCtcFstDecoderConfig(o);
SherpaOnnxOnlineRecognizer *recognizer = CreateOnlineRecognizer(&c);
SherpaOnnxOnlineRecognizer *recognizer = SherpaOnnxCreateOnlineRecognizer(&c);
if (c.model_config.transducer.encoder) {
delete[] c.model_config.transducer.encoder;
@@ -270,7 +270,7 @@ static Napi::External<SherpaOnnxOnlineRecognizer> CreateOnlineRecognizerWrapper(
return Napi::External<SherpaOnnxOnlineRecognizer>::New(
env, recognizer,
[](Napi::Env env, SherpaOnnxOnlineRecognizer *recognizer) {
DestroyOnlineRecognizer(recognizer);
SherpaOnnxDestroyOnlineRecognizer(recognizer);
});
}
@@ -298,11 +298,11 @@ static Napi::External<SherpaOnnxOnlineStream> CreateOnlineStreamWrapper(
SherpaOnnxOnlineRecognizer *recognizer =
info[0].As<Napi::External<SherpaOnnxOnlineRecognizer>>().Data();
SherpaOnnxOnlineStream *stream = CreateOnlineStream(recognizer);
SherpaOnnxOnlineStream *stream = SherpaOnnxCreateOnlineStream(recognizer);
return Napi::External<SherpaOnnxOnlineStream>::New(
env, stream, [](Napi::Env env, SherpaOnnxOnlineStream *stream) {
DestroyOnlineStream(stream);
SherpaOnnxDestroyOnlineStream(stream);
});
}
@@ -369,7 +369,8 @@ static void AcceptWaveformWrapper(const Napi::CallbackInfo &info) {
Napi::Float32Array samples = obj.Get("samples").As<Napi::Float32Array>();
int32_t sample_rate = obj.Get("sampleRate").As<Napi::Number>().Int32Value();
AcceptWaveform(stream, sample_rate, samples.Data(), samples.ElementLength());
SherpaOnnxOnlineStreamAcceptWaveform(stream, sample_rate, samples.Data(),
samples.ElementLength());
}
static Napi::Boolean IsOnlineStreamReadyWrapper(
@@ -405,7 +406,7 @@ static Napi::Boolean IsOnlineStreamReadyWrapper(
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
int32_t is_ready = IsOnlineStreamReady(recognizer, stream);
int32_t is_ready = SherpaOnnxIsOnlineStreamReady(recognizer, stream);
return Napi::Boolean::New(env, is_ready);
}
@@ -442,7 +443,7 @@ static void DecodeOnlineStreamWrapper(const Napi::CallbackInfo &info) {
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
DecodeOnlineStream(recognizer, stream);
SherpaOnnxDecodeOnlineStream(recognizer, stream);
}
static Napi::String GetOnlineStreamResultAsJsonWrapper(
@@ -478,10 +479,10 @@ static Napi::String GetOnlineStreamResultAsJsonWrapper(
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
const char *json = GetOnlineStreamResultAsJson(recognizer, stream);
const char *json = SherpaOnnxGetOnlineStreamResultAsJson(recognizer, stream);
Napi::String s = Napi::String::New(env, json);
DestroyOnlineStreamResultJson(json);
SherpaOnnxDestroyOnlineStreamResultJson(json);
return s;
}
@@ -508,7 +509,7 @@ static void InputFinishedWrapper(const Napi::CallbackInfo &info) {
SherpaOnnxOnlineStream *stream =
info[0].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
InputFinished(stream);
SherpaOnnxOnlineStreamInputFinished(stream);
}
static void ResetOnlineStreamWrapper(const Napi::CallbackInfo &info) {
@@ -543,7 +544,7 @@ static void ResetOnlineStreamWrapper(const Napi::CallbackInfo &info) {
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
Reset(recognizer, stream);
SherpaOnnxOnlineStreamReset(recognizer, stream);
}
static Napi::Boolean IsEndpointWrapper(const Napi::CallbackInfo &info) {
@@ -578,7 +579,7 @@ static Napi::Boolean IsEndpointWrapper(const Napi::CallbackInfo &info) {
SherpaOnnxOnlineStream *stream =
info[1].As<Napi::External<SherpaOnnxOnlineStream>>().Data();
int32_t is_endpoint = IsEndpoint(recognizer, stream);
int32_t is_endpoint = SherpaOnnxOnlineStreamIsEndpoint(recognizer, stream);
return Napi::Boolean::New(env, is_endpoint);
}
@@ -603,12 +604,12 @@ static Napi::External<SherpaOnnxDisplay> CreateDisplayWrapper(
}
int32_t max_word_per_line = info[0].As<Napi::Number>().Int32Value();
const SherpaOnnxDisplay *display = CreateDisplay(max_word_per_line);
const SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(max_word_per_line);
return Napi::External<SherpaOnnxDisplay>::New(
env, const_cast<SherpaOnnxDisplay *>(display),
[](Napi::Env env, SherpaOnnxDisplay *display) {
DestroyDisplay(display);
SherpaOnnxDestroyDisplay(display);
});
}