Add speaker identification APIs for HarmonyOS (#1607)
* Add speaker embedding extractor API for HarmonyOS * Add ArkTS API for speaker identification
This commit is contained in:
@@ -22,11 +22,10 @@ class SpeakerEmbeddingExtractorGeneralImpl
|
||||
const SpeakerEmbeddingExtractorConfig &config)
|
||||
: model_(config) {}
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
template <typename Manager>
|
||||
SpeakerEmbeddingExtractorGeneralImpl(
|
||||
AAssetManager *mgr, const SpeakerEmbeddingExtractorConfig &config)
|
||||
Manager *mgr, const SpeakerEmbeddingExtractorConfig &config)
|
||||
: model_(mgr, config) {}
|
||||
#endif
|
||||
|
||||
int32_t Dim() const override { return model_.GetMetaData().output_dim; }
|
||||
|
||||
@@ -46,9 +45,15 @@ class SpeakerEmbeddingExtractorGeneralImpl
|
||||
std::vector<float> Compute(OnlineStream *s) const override {
|
||||
int32_t num_frames = s->NumFramesReady() - s->GetNumProcessedFrames();
|
||||
if (num_frames <= 0) {
|
||||
#if __OHOS__
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Please make sure IsReady(s) returns true. num_frames: %{public}d",
|
||||
num_frames);
|
||||
#else
|
||||
SHERPA_ONNX_LOGE(
|
||||
"Please make sure IsReady(s) returns true. num_frames: %d",
|
||||
num_frames);
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -64,8 +69,13 @@ class SpeakerEmbeddingExtractorGeneralImpl
|
||||
if (meta_data.feature_normalize_type == "global-mean") {
|
||||
SubtractGlobalMean(features.data(), num_frames, feat_dim);
|
||||
} else {
|
||||
#if __OHOS__
|
||||
SHERPA_ONNX_LOGE("Unsupported feature_normalize_type: %{public}s",
|
||||
meta_data.feature_normalize_type.c_str());
|
||||
#else
|
||||
SHERPA_ONNX_LOGE("Unsupported feature_normalize_type: %s",
|
||||
meta_data.feature_normalize_type.c_str());
|
||||
#endif
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user