This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex_bi_series-sherpa-onnx/sherpa-onnx/csrc/silero-vad-model.h

70 lines
1.7 KiB
C
Raw Normal View History

2023-09-17 14:54:38 +08:00
// sherpa-onnx/csrc/silero-vad-model.h
//
// Copyright (c) 2023 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_SILERO_VAD_MODEL_H_
#define SHERPA_ONNX_CSRC_SILERO_VAD_MODEL_H_
#include <memory>
2023-09-23 20:39:13 +08:00
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
2024-11-24 16:29:24 +08:00
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
2023-09-17 14:54:38 +08:00
#include "sherpa-onnx/csrc/vad-model.h"
namespace sherpa_onnx {
class SileroVadModel : public VadModel {
public:
explicit SileroVadModel(const VadModelConfig &config);
2023-09-23 20:39:13 +08:00
#if __ANDROID_API__ >= 9
SileroVadModel(AAssetManager *mgr, const VadModelConfig &config);
2024-11-24 16:29:24 +08:00
#endif
#if __OHOS__
SileroVadModel(NativeResourceManager *mgr, const VadModelConfig &config);
2023-09-23 20:39:13 +08:00
#endif
2023-09-17 14:54:38 +08:00
~SileroVadModel() override;
// reset the internal model states
void Reset() override;
/**
* @param samples Pointer to a 1-d array containing audio samples.
* Each sample should be normalized to the range [-1, 1].
* @param n Number of samples.
*
* @return Return true if speech is detected. Return false otherwise.
*/
bool IsSpeech(const float *samples, int32_t n) override;
// For silero vad V4, it is WindowShift().
// For silero vad V5, it is WindowShift()+64 for 16kHz and
// WindowShift()+32 for 8kHz
2023-09-17 14:54:38 +08:00
int32_t WindowSize() const override;
// 512
2024-06-29 11:45:04 +08:00
int32_t WindowShift() const override;
2023-09-17 14:54:38 +08:00
int32_t MinSilenceDurationSamples() const override;
int32_t MinSpeechDurationSamples() const override;
void SetMinSilenceDuration(float s) override;
void SetThreshold(float threshold) override;
2023-09-17 14:54:38 +08:00
private:
class Impl;
std::unique_ptr<Impl> impl_;
};
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_SILERO_VAD_MODEL_H_