vad-model.h
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// sherpa-onnx/csrc/vad-model.h
//
// Copyright (c) 2023 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_VAD_MODEL_H_
#define SHERPA_ONNX_CSRC_VAD_MODEL_H_
#include <memory>
#if __ANDROID_API__ >= 9
#include "android/asset_manager.h"
#include "android/asset_manager_jni.h"
#endif
#if __OHOS__
#include "rawfile/raw_file_manager.h"
#endif
#include "sherpa-onnx/csrc/vad-model-config.h"
namespace sherpa_onnx {
class VadModel {
public:
virtual ~VadModel() = default;
static std::unique_ptr<VadModel> Create(const VadModelConfig &config);
#if __ANDROID_API__ >= 9
static std::unique_ptr<VadModel> Create(AAssetManager *mgr,
const VadModelConfig &config);
#endif
#if __OHOS__
static std::unique_ptr<VadModel> Create(NativeResourceManager *mgr,
const VadModelConfig &config);
#endif
// reset the internal model states
virtual void Reset() = 0;
/**
* @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. Should be equal to WindowSize()
*
* @return Return true if speech is detected. Return false otherwise.
*/
virtual bool IsSpeech(const float *samples, int32_t n) = 0;
virtual int32_t WindowSize() const = 0;
virtual int32_t WindowShift() const = 0;
virtual int32_t MinSilenceDurationSamples() const = 0;
virtual int32_t MinSpeechDurationSamples() const = 0;
virtual void SetMinSilenceDuration(float s) = 0;
virtual void SetThreshold(float threshold) = 0;
};
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_VAD_MODEL_H_