feature-fbank.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Copyright (c) 2022 Xiaomi Corporation (authors: Fangjun Kuang)
  3. *
  4. * See LICENSE for clarification regarding multiple authors
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "kaldi-native-fbank/python/csrc/feature-fbank.h"
  19. #include <memory>
  20. #include <string>
  21. #include "feature-fbank.h"
  22. #include "kaldi-native-fbank/python/csrc/utils.h"
  23. namespace knf {
  24. static void PybindFbankOptions(py::module &m) { // NOLINT
  25. using PyClass = FbankOptions;
  26. py::class_<PyClass>(m, "FbankOptions")
  27. .def(py::init<>())
  28. .def_readwrite("frame_opts", &PyClass::frame_opts)
  29. .def_readwrite("mel_opts", &PyClass::mel_opts)
  30. .def_readwrite("use_energy", &PyClass::use_energy)
  31. .def_readwrite("energy_floor", &PyClass::energy_floor)
  32. .def_readwrite("raw_energy", &PyClass::raw_energy)
  33. .def_readwrite("htk_compat", &PyClass::htk_compat)
  34. .def_readwrite("use_log_fbank", &PyClass::use_log_fbank)
  35. .def_readwrite("use_power", &PyClass::use_power)
  36. .def("__str__",
  37. [](const PyClass &self) -> std::string { return self.ToString(); })
  38. .def("as_dict",
  39. [](const PyClass &self) -> py::dict { return AsDict(self); })
  40. .def_static(
  41. "from_dict",
  42. [](py::dict dict) -> PyClass { return FbankOptionsFromDict(dict); })
  43. .def(py::pickle(
  44. [](const PyClass &self) -> py::dict { return AsDict(self); },
  45. [](py::dict dict) -> PyClass { return FbankOptionsFromDict(dict); }));
  46. }
  47. void PybindFeatureFbank(py::module &m) { // NOLINT
  48. PybindFbankOptions(m);
  49. }
  50. } // namespace knf