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 SpeakerEmbeddingExtractorNeMoImpl : public SpeakerEmbeddingExtractorImpl {
|
||||
const SpeakerEmbeddingExtractorConfig &config)
|
||||
: model_(config) {}
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
template <typename Manager>
|
||||
SpeakerEmbeddingExtractorNeMoImpl(
|
||||
AAssetManager *mgr, const SpeakerEmbeddingExtractorConfig &config)
|
||||
Manager *mgr, const SpeakerEmbeddingExtractorConfig &config)
|
||||
: model_(mgr, config) {}
|
||||
#endif
|
||||
|
||||
int32_t Dim() const override { return model_.GetMetaData().output_dim; }
|
||||
|
||||
@@ -54,9 +53,15 @@ class SpeakerEmbeddingExtractorNeMoImpl : public SpeakerEmbeddingExtractorImpl {
|
||||
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 {};
|
||||
}
|
||||
|
||||
@@ -72,8 +77,14 @@ class SpeakerEmbeddingExtractorNeMoImpl : public SpeakerEmbeddingExtractorImpl {
|
||||
if (meta_data.feature_normalize_type == "per_feature") {
|
||||
NormalizePerFeature(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