Add keyword spotter C API for HarmonyOS (#1769)

This commit is contained in:
Fangjun Kuang
2025-01-26 14:12:30 +08:00
committed by GitHub
parent 73c3695287
commit f178e96bf0
8 changed files with 135 additions and 42 deletions

View File

@@ -678,7 +678,7 @@ struct SherpaOnnxKeywordSpotter {
std::unique_ptr<sherpa_onnx::KeywordSpotter> impl;
};
const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
static sherpa_onnx::KeywordSpotterConfig GetKeywordSpotterConfig(
const SherpaOnnxKeywordSpotterConfig *config) {
sherpa_onnx::KeywordSpotterConfig spotter_config;
@@ -739,10 +739,20 @@ const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
std::string(config->keywords_buf, config->keywords_buf_size);
}
if (config->model_config.debug) {
if (spotter_config.model_config.debug) {
#if OHOS
SHERPA_ONNX_LOGE("%{public}s\n", spotter_config.ToString().c_str());
#else
SHERPA_ONNX_LOGE("%s\n", spotter_config.ToString().c_str());
#endif
}
return spotter_config;
}
const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotter(
const SherpaOnnxKeywordSpotterConfig *config) {
auto spotter_config = GetKeywordSpotterConfig(config);
if (!spotter_config.Validate()) {
SHERPA_ONNX_LOGE("Errors in config!");
return nullptr;
@@ -2272,6 +2282,22 @@ SherpaOnnxCreateSpeakerEmbeddingExtractorOHOS(
return p;
}
const SherpaOnnxKeywordSpotter *SherpaOnnxCreateKeywordSpotterOHOS(
const SherpaOnnxKeywordSpotterConfig *config, NativeResourceManager *mgr) {
if (!mgr) {
return SherpaOnnxCreateKeywordSpotter(config);
}
auto spotter_config = GetKeywordSpotterConfig(config);
SherpaOnnxKeywordSpotter *spotter = new SherpaOnnxKeywordSpotter;
spotter->impl =
std::make_unique<sherpa_onnx::KeywordSpotter>(mgr, spotter_config);
return spotter;
}
#if SHERPA_ONNX_ENABLE_TTS == 1
const SherpaOnnxOfflineTts *SherpaOnnxCreateOfflineTtsOHOS(
const SherpaOnnxOfflineTtsConfig *config, NativeResourceManager *mgr) {