// sherpa-onnx/python/csrc/voice-activity-detector.cc // // Copyright (c) 2023 Xiaomi Corporation #include "sherpa-onnx/python/csrc/voice-activity-detector.h" #include #include "sherpa-onnx/csrc/voice-activity-detector.h" namespace sherpa_onnx { void PybindSpeechSegment(py::module *m) { using PyClass = SpeechSegment; py::class_(*m, "SpeechSegment") .def_property_readonly("start", [](const PyClass &self) { return self.start; }) .def_property_readonly("samples", [](const PyClass &self) { return self.samples; }); } void PybindVoiceActivityDetector(py::module *m) { PybindSpeechSegment(m); using PyClass = VoiceActivityDetector; py::class_(*m, "VoiceActivityDetector") .def(py::init(), py::arg("config"), py::arg("buffer_size_in_seconds") = 60, py::call_guard()) .def( "accept_waveform", [](PyClass &self, const std::vector &samples) { self.AcceptWaveform(samples.data(), samples.size()); }, py::arg("samples"), py::call_guard()) .def_property_readonly("config", &PyClass::GetConfig) .def("empty", &PyClass::Empty, py::call_guard()) .def("pop", &PyClass::Pop, py::call_guard()) .def("is_speech_detected", &PyClass::IsSpeechDetected, py::call_guard()) .def("reset", &PyClass::Reset, py::call_guard()) .def_property_readonly("front", &PyClass::Front); } } // namespace sherpa_onnx