Committed by
GitHub
Release Python GIL in C++ class constructor (#493)
正在显示
4 个修改的文件
包含
8 行增加
和
4 行删除
| @@ -40,7 +40,8 @@ void PybindOfflineRecognizer(py::module *m) { | @@ -40,7 +40,8 @@ void PybindOfflineRecognizer(py::module *m) { | ||
| 40 | 40 | ||
| 41 | using PyClass = OfflineRecognizer; | 41 | using PyClass = OfflineRecognizer; |
| 42 | py::class_<PyClass>(*m, "OfflineRecognizer") | 42 | py::class_<PyClass>(*m, "OfflineRecognizer") |
| 43 | - .def(py::init<const OfflineRecognizerConfig &>(), py::arg("config")) | 43 | + .def(py::init<const OfflineRecognizerConfig &>(), py::arg("config"), |
| 44 | + py::call_guard<py::gil_scoped_release>()) | ||
| 44 | .def( | 45 | .def( |
| 45 | "create_stream", | 46 | "create_stream", |
| 46 | [](const PyClass &self) { return self.CreateStream(); }, | 47 | [](const PyClass &self) { return self.CreateStream(); }, |
| @@ -48,7 +48,8 @@ void PybindOfflineTts(py::module *m) { | @@ -48,7 +48,8 @@ void PybindOfflineTts(py::module *m) { | ||
| 48 | 48 | ||
| 49 | using PyClass = OfflineTts; | 49 | using PyClass = OfflineTts; |
| 50 | py::class_<PyClass>(*m, "OfflineTts") | 50 | py::class_<PyClass>(*m, "OfflineTts") |
| 51 | - .def(py::init<const OfflineTtsConfig &>(), py::arg("config")) | 51 | + .def(py::init<const OfflineTtsConfig &>(), py::arg("config"), |
| 52 | + py::call_guard<py::gil_scoped_release>()) | ||
| 52 | .def_property_readonly("sample_rate", &PyClass::SampleRate) | 53 | .def_property_readonly("sample_rate", &PyClass::SampleRate) |
| 53 | .def( | 54 | .def( |
| 54 | "generate", | 55 | "generate", |
| @@ -53,7 +53,8 @@ void PybindOnlineRecognizer(py::module *m) { | @@ -53,7 +53,8 @@ void PybindOnlineRecognizer(py::module *m) { | ||
| 53 | 53 | ||
| 54 | using PyClass = OnlineRecognizer; | 54 | using PyClass = OnlineRecognizer; |
| 55 | py::class_<PyClass>(*m, "OnlineRecognizer") | 55 | py::class_<PyClass>(*m, "OnlineRecognizer") |
| 56 | - .def(py::init<const OnlineRecognizerConfig &>(), py::arg("config")) | 56 | + .def(py::init<const OnlineRecognizerConfig &>(), py::arg("config"), |
| 57 | + py::call_guard<py::gil_scoped_release>()) | ||
| 57 | .def( | 58 | .def( |
| 58 | "create_stream", | 59 | "create_stream", |
| 59 | [](const PyClass &self) { return self.CreateStream(); }, | 60 | [](const PyClass &self) { return self.CreateStream(); }, |
| @@ -24,7 +24,8 @@ void PybindVoiceActivityDetector(py::module *m) { | @@ -24,7 +24,8 @@ void PybindVoiceActivityDetector(py::module *m) { | ||
| 24 | using PyClass = VoiceActivityDetector; | 24 | using PyClass = VoiceActivityDetector; |
| 25 | py::class_<PyClass>(*m, "VoiceActivityDetector") | 25 | py::class_<PyClass>(*m, "VoiceActivityDetector") |
| 26 | .def(py::init<const VadModelConfig &, float>(), py::arg("config"), | 26 | .def(py::init<const VadModelConfig &, float>(), py::arg("config"), |
| 27 | - py::arg("buffer_size_in_seconds") = 60) | 27 | + py::arg("buffer_size_in_seconds") = 60, |
| 28 | + py::call_guard<py::gil_scoped_release>()) | ||
| 28 | .def( | 29 | .def( |
| 29 | "accept_waveform", | 30 | "accept_waveform", |
| 30 | [](PyClass &self, const std::vector<float> &samples) { | 31 | [](PyClass &self, const std::vector<float> &samples) { |
-
请 注册 或 登录 后发表评论