Skip to content

Commit

Permalink
add vad model config
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Sep 15, 2023
1 parent 4dcf224 commit 4767a27
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
1 change: 1 addition & 0 deletions sherpa-onnx/csrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ set(sources
transpose.cc
unbind.cc
utils.cc
vad-model-config.cc
wave-reader.cc
)

Expand Down
6 changes: 3 additions & 3 deletions sherpa-onnx/csrc/silero-vad-model-config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace sherpa_onnx {

void SilerVadModelConfig::Register(ParseOptions *po) {
void SileroVadModelConfig::Register(ParseOptions *po) {
po->Register("silero-vad-model", &model, "Path to silero VAD ONNX model.");

po->Register("silero-vad-prob", &prob,
Expand All @@ -32,7 +32,7 @@ void SilerVadModelConfig::Register(ParseOptions *po) {
"perfomance!");
}

bool SilerVadModelConfig::Validate() const {
bool SileroVadModelConfig::Validate() const {
if (!FileExists(model)) {
SHERPA_ONNX_LOGE("Silero vad model file %s does not exist", model.c_str());
return false;
Expand All @@ -53,7 +53,7 @@ bool SilerVadModelConfig::Validate() const {
return true;
}

std::string SilerVadModelConfig::ToString() const {
std::string SileroVadModelConfig::ToString() const {
std::ostringstream os;

os << "SilerVadModelConfig(";
Expand Down
4 changes: 3 additions & 1 deletion sherpa-onnx/csrc/silero-vad-model-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace sherpa_onnx {

struct SilerVadModelConfig {
struct SileroVadModelConfig {
std::string model;

// threshold to classify a segment as speech
Expand All @@ -25,6 +25,8 @@ struct SilerVadModelConfig {
// 256, 512, 768 samples for 800 Hz
int window_size = 1536; // in samples

SileroVadModelConfig() = default;

void Register(ParseOptions *po);

bool Validate() const;
Expand Down
36 changes: 36 additions & 0 deletions sherpa-onnx/csrc/vad-model-config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// sherpa-onnx/csrc/vad-model-config.cc
//
// Copyright (c) 2023 Xiaomi Corporation

#include "sherpa-onnx/csrc/vad-model-config.h"

#include <sstream>
#include <string>

namespace sherpa_onnx {

void VadModelConfig::Register(ParseOptions *po) {
silero_vad.Register(po);

po->Register("vad-num-threads", &num_threads,
"Number of threads to run the VAD model");

po->Register("vad-provider", &provider,
"Specify a provider to run the VAD model. Supported values: "
"cpu, cuda, coreml");
}

bool VadModelConfig::Validate() const { return silero_vad.Validate(); }

std::string VadModelConfig::ToString() const {
std::ostringstream os;

os << "VadModelConfig(";
os << "silero_vad=" << silero_vad.ToString() << ", ";
os << "num_threads=" << num_threads << ", ";
os << "provider=\"" << provider << "\")";

return os.str();
}

} // namespace sherpa_onnx
34 changes: 34 additions & 0 deletions sherpa-onnx/csrc/vad-model-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// sherpa-onnx/csrc/vad-model-config.h
//
// Copyright (c) 2023 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_VAD_MODEL_CONFIG_H_
#define SHERPA_ONNX_CSRC_VAD_MODEL_CONFIG_H_

#include <string>

#include "sherpa-onnx/csrc/parse-options.h"
#include "sherpa-onnx/csrc/silero-vad-model-config.h"

namespace sherpa_onnx {

struct VadModelConfig {
SileroVadModelConfig silero_vad;

int32_t num_threads = 1;
std::string provider = "cpu";

VadModelConfig() = default;

VadModelConfig(const SileroVadModelConfig &silero_vad, int32_t num_threads,
const std::string &provider)
: silero_vad(silero_vad), num_threads(num_threads), provider(provider) {}

void Register(ParseOptions *po);
bool Validate() const;

std::string ToString() const;
};

} // namespace sherpa_onnx

#endif // SHERPA_ONNX_CSRC_VAD_MODEL_CONFIG_H_

0 comments on commit 4767a27

Please sign in to comment.