feature-mfcc.cc (2207B)
1 /** 2 * Copyright (c) 2024 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 19 #include "kaldi-native-fbank/csrc/feature-mfcc.h" 20 21 #include <string> 22 23 #include "kaldi-native-fbank/csrc/feature-window.h" 24 #include "kaldi-native-fbank/csrc/mel-computations.h" 25 #include "kaldi-native-fbank/python/csrc/feature-mfcc.h" 26 #include "kaldi-native-fbank/python/csrc/utils.h" 27 28 namespace knf { 29 30 static void PybindMfccOptions(py::module &m) { // NOLINT 31 using PyClass = MfccOptions; 32 py::class_<PyClass>(m, "MfccOptions") 33 .def(py::init<>()) 34 .def_readwrite("frame_opts", &PyClass::frame_opts) 35 .def_readwrite("mel_opts", &PyClass::mel_opts) 36 .def_readwrite("num_ceps", &PyClass::num_ceps) 37 .def_readwrite("use_energy", &PyClass::use_energy) 38 .def_readwrite("energy_floor", &PyClass::energy_floor) 39 .def_readwrite("raw_energy", &PyClass::raw_energy) 40 .def_readwrite("cepstral_lifter", &PyClass::cepstral_lifter) 41 .def_readwrite("htk_compat", &PyClass::htk_compat) 42 .def("__str__", 43 [](const PyClass &self) -> std::string { return self.ToString(); }) 44 .def("as_dict", 45 [](const PyClass &self) -> py::dict { return AsDict(self); }) 46 .def_static( 47 "from_dict", 48 [](py::dict dict) -> PyClass { return MfccOptionsFromDict(dict); }) 49 .def(py::pickle( 50 [](const PyClass &self) -> py::dict { return AsDict(self); }, 51 [](py::dict dict) -> PyClass { return MfccOptionsFromDict(dict); })); 52 } 53 54 void PybindFeatureMfcc(py::module &m) { // NOLINT 55 PybindMfccOptions(m); 56 } 57 58 } // namespace knf