feature-window.cc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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-window.h"
  19. #include <string>
  20. #include "feature-window.h"
  21. #include "kaldi-native-fbank/python/csrc/utils.h"
  22. namespace knf {
  23. static void PybindFrameExtractionOptions(py::module &m) { // NOLINT
  24. using PyClass = FrameExtractionOptions;
  25. py::class_<PyClass>(m, "FrameExtractionOptions")
  26. .def(py::init<>())
  27. .def_readwrite("samp_freq", &PyClass::samp_freq)
  28. .def_readwrite("frame_shift_ms", &PyClass::frame_shift_ms)
  29. .def_readwrite("frame_length_ms", &PyClass::frame_length_ms)
  30. .def_readwrite("dither", &PyClass::dither)
  31. .def_readwrite("preemph_coeff", &PyClass::preemph_coeff)
  32. .def_readwrite("remove_dc_offset", &PyClass::remove_dc_offset)
  33. .def_readwrite("window_type", &PyClass::window_type)
  34. .def_readwrite("round_to_power_of_two", &PyClass::round_to_power_of_two)
  35. .def_readwrite("blackman_coeff", &PyClass::blackman_coeff)
  36. .def_readwrite("snip_edges", &PyClass::snip_edges)
  37. .def("as_dict",
  38. [](const PyClass &self) -> py::dict { return AsDict(self); })
  39. .def_static("from_dict",
  40. [](py::dict dict) -> PyClass {
  41. return FrameExtractionOptionsFromDict(dict);
  42. })
  43. #if 0
  44. .def_readwrite("allow_downsample",
  45. &PyClass::allow_downsample)
  46. .def_readwrite("allow_upsample", &PyClass::allow_upsample)
  47. #endif
  48. .def("__str__",
  49. [](const PyClass &self) -> std::string { return self.ToString(); })
  50. .def(py::pickle(
  51. [](const PyClass &self) -> py::dict { return AsDict(self); },
  52. [](py::dict dict) -> PyClass {
  53. return FrameExtractionOptionsFromDict(dict);
  54. }));
  55. }
  56. void PybindFeatureWindow(py::module &m) { // NOLINT
  57. PybindFrameExtractionOptions(m);
  58. }
  59. } // namespace knf