Add Python ASR examples with alsa (#646)

This commit is contained in:
Fangjun Kuang
2024-03-08 11:34:48 +08:00
committed by GitHub
parent e9e8d755d9
commit d3287f9494
12 changed files with 326 additions and 10 deletions

View File

@@ -0,0 +1,30 @@
// sherpa-onnx/python/csrc/alsa.cc
//
// Copyright (c) 2024 Xiaomi Corporation
#include "sherpa-onnx/python/csrc/alsa.h"
#include <vector>
#include "sherpa-onnx/csrc/alsa.h"
namespace sherpa_onnx {
void PybindAlsa(py::module *m) {
using PyClass = Alsa;
py::class_<PyClass>(*m, "Alsa")
.def(py::init<const char *>(), py::arg("device_name"),
py::call_guard<py::gil_scoped_release>())
.def(
"read",
[](PyClass &self, int32_t num_samples) -> std::vector<float> {
return self.Read(num_samples);
},
py::arg("num_samples"), py::call_guard<py::gil_scoped_release>())
.def_property_readonly("expected_sample_rate",
&PyClass::GetExpectedSampleRate)
.def_property_readonly("actual_sample_rate",
&PyClass::GetActualSampleRate);
}
} // namespace sherpa_onnx