-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4767a27
commit 9a2394c
Showing
6 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// sherpa-onnx/csrc/silero-vad-model.h | ||
// | ||
// Copyright (c) 2023 Xiaomi Corporation | ||
|
||
#include "sherpa-onnx/csrc/silero-vad-model.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
class SileroVadModel::Impl { | ||
public: | ||
Impl(const VadModelConfig &config) : config_(config) {} | ||
|
||
void Reset() {} | ||
|
||
bool IsSpeech(const float *samples, int32_t n) { return true; } | ||
|
||
private: | ||
VadModelConfig config_; | ||
}; | ||
|
||
SileroVadModel::SileroVadModel(const VadModelConfig &config) | ||
: impl_(std::make_unique<Impl>(config)) {} | ||
|
||
SileroVadModel::~SileroVadModel() = default; | ||
|
||
void SileroVadModel::Reset() { return impl_->Reset(); } | ||
|
||
bool SileroVadModel::IsSpeech(const float *samples, int32_t n) { | ||
return impl_->IsSpeech(samples, n); | ||
} | ||
|
||
} // namespace sherpa_onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// 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> | ||
|
||
#include "sherpa-onnx/csrc/vad-model.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
class SileroVadModel : public VadModel { | ||
public: | ||
SileroVadModel(const VadModelConfig &config); | ||
~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; | ||
|
||
private: | ||
class Impl; | ||
std::unique_ptr<Impl> impl_; | ||
}; | ||
|
||
} // namespace sherpa_onnx | ||
|
||
#endif // SHERPA_ONNX_CSRC_SILERO_VAD_MODEL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// sherpa-onnx/csrc/vad-model.cc | ||
// | ||
// Copyright (c) 2023 Xiaomi Corporation | ||
|
||
#include "sherpa-onnx/csrc/vad-model.h" | ||
|
||
#include "sherpa-onnx/csrc/silero-vad-model.h" | ||
|
||
namespace sherpa_onnx { | ||
|
||
std::unique_ptr<VadModel> VadModel::Create(const VadModelConfig &config) { | ||
// TODO(fangjun): Support other VAD models. | ||
return std::make_unique<SileroVadModel>(config); | ||
} | ||
|
||
} // namespace sherpa_onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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> | ||
|
||
#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); | ||
|
||
// 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. | ||
* | ||
* @return Return true if speech is detected. Return false otherwise. | ||
*/ | ||
virtual bool IsSpeech(const float *samples, int32_t n) = 0; | ||
}; | ||
|
||
} // namespace sherpa_onnx | ||
|
||
#endif // SHERPA_ONNX_CSRC_VAD_MODEL_H_ |