Add VAD examples using ALSA for recording (#739)

This commit is contained in:
Fangjun Kuang
2024-04-08 16:41:01 +08:00
committed by GitHub
parent a5f8fbc83f
commit 6fb8ceda57
17 changed files with 601 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ set(srcs
vad-model-config.cc
vad-model.cc
voice-activity-detector.cc
wave-writer.cc
)
if(SHERPA_ONNX_HAS_ALSA)
list(APPEND srcs ${CMAKE_SOURCE_DIR}/sherpa-onnx/csrc/alsa.cc alsa.cc)

View File

@@ -26,6 +26,7 @@
#include "sherpa-onnx/python/csrc/vad-model-config.h"
#include "sherpa-onnx/python/csrc/vad-model.h"
#include "sherpa-onnx/python/csrc/voice-activity-detector.h"
#include "sherpa-onnx/python/csrc/wave-writer.h"
#if SHERPA_ONNX_ENABLE_TTS == 1
#include "sherpa-onnx/python/csrc/offline-tts.h"
@@ -36,6 +37,8 @@ namespace sherpa_onnx {
PYBIND11_MODULE(_sherpa_onnx, m) {
m.doc() = "pybind11 binding of sherpa-onnx";
PybindWaveWriter(&m);
PybindFeatures(&m);
PybindOnlineCtcFstDecoderConfig(&m);
PybindOnlineModelConfig(&m);

View File

@@ -0,0 +1,27 @@
// sherpa-onnx/python/csrc/wave-writer.cc
//
// Copyright (c) 2024 Xiaomi Corporation
#include "sherpa-onnx/python/csrc/wave-writer.h"
#include <string>
#include <vector>
#include "sherpa-onnx/csrc/wave-writer.h"
namespace sherpa_onnx {
void PybindWaveWriter(py::module *m) {
m->def(
"write_wave",
[](const std::string &filename, const std::vector<float> &samples,
int32_t sample_rate) -> bool {
bool ok =
WriteWave(filename, sample_rate, samples.data(), samples.size());
return ok;
},
py::arg("filename"), py::arg("samples"), py::arg("sample_rate"));
}
} // namespace sherpa_onnx

View File

@@ -0,0 +1,16 @@
// sherpa-onnx/python/csrc/wave-writer.h
//
// Copyright (c) 2024 Xiaomi Corporation
#ifndef SHERPA_ONNX_PYTHON_CSRC_WAVE_WRITER_H_
#define SHERPA_ONNX_PYTHON_CSRC_WAVE_WRITER_H_
#include "sherpa-onnx/python/csrc/sherpa-onnx.h"
namespace sherpa_onnx {
void PybindWaveWriter(py::module *m);
}
#endif // SHERPA_ONNX_PYTHON_CSRC_WAVE_WRITER_H_