From f28857495d282863f33c3ed58abf11771798c957 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Sat, 3 Dec 2022 12:05:45 +0800 Subject: [PATCH] small fixes --- kaldifeat/csrc/feature-window.h | 29 +++++++++---------- kaldifeat/python/csrc/feature-window.cc | 21 +------------- .../tests/test_frame_extraction_options.py | 1 + 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/kaldifeat/csrc/feature-window.h b/kaldifeat/csrc/feature-window.h index 26d743a..16046f1 100644 --- a/kaldifeat/csrc/feature-window.h +++ b/kaldifeat/csrc/feature-window.h @@ -62,21 +62,20 @@ struct FrameExtractionOptions { } std::string ToString() const { std::ostringstream os; -#define KALDIFEAT_PRINT(x) os << #x << ": " << x << "\n" - KALDIFEAT_PRINT(samp_freq); - KALDIFEAT_PRINT(frame_shift_ms); - KALDIFEAT_PRINT(frame_length_ms); - KALDIFEAT_PRINT(dither); - KALDIFEAT_PRINT(preemph_coeff); - KALDIFEAT_PRINT(remove_dc_offset); - KALDIFEAT_PRINT(window_type); - KALDIFEAT_PRINT(round_to_power_of_two); - KALDIFEAT_PRINT(blackman_coeff); - KALDIFEAT_PRINT(snip_edges); - // KALDIFEAT_PRINT(allow_downsample); - // KALDIFEAT_PRINT(allow_upsample); - KALDIFEAT_PRINT(max_feature_vectors); -#undef KALDIFEAT_PRINT + os << "FrameExtractionOptions("; + os << "samp_freq=" << samp_freq << ", "; + os << "frame_shift_ms=" << frame_shift_ms << ", "; + os << "frame_length_ms=" << frame_length_ms << ", "; + os << "dither=" << dither << ", "; + os << "preemph_coeff=" << preemph_coeff << ", "; + os << "remove_dc_offset=" << (remove_dc_offset ? "True" : "False") << ", "; + os << "window_type=" << '"' << window_type << '"' << ", "; + os << "round_to_power_of_two=" << (round_to_power_of_two ? "True" : "False") + << ", "; + os << "blackman_coeff=" << blackman_coeff << ", "; + os << "snip_edges=" << (snip_edges ? "True" : "False") << ", "; + os << "max_feature_vectors=" << max_feature_vectors << ")"; + return os.str(); } }; diff --git a/kaldifeat/python/csrc/feature-window.cc b/kaldifeat/python/csrc/feature-window.cc index dc80c50..116f82a 100644 --- a/kaldifeat/python/csrc/feature-window.cc +++ b/kaldifeat/python/csrc/feature-window.cc @@ -70,26 +70,7 @@ static void PybindFrameExtractionOptions(py::module &m) { .def_readwrite("allow_upsample", &PyClass::allow_upsample) #endif .def("__str__", - [](const PyClass &self) -> std::string { - std::ostringstream os; - os << "FrameExtractionOptions("; - os << "samp_freq=" << self.samp_freq << ", "; - os << "frame_shift_ms=" << self.frame_shift_ms << ", "; - os << "frame_length_ms=" << self.frame_length_ms << ", "; - os << "dither=" << self.dither << ", "; - os << "preemph_coeff=" << self.preemph_coeff << ", "; - os << "remove_dc_offset=" - << (self.remove_dc_offset ? "True" : "False") << ", "; - os << "window_type=" << '"' << self.window_type << '"' << ", "; - os << "round_to_power_of_two=" - << (self.round_to_power_of_two ? "True" : "False") << ", "; - os << "blackman_coeff=" << self.blackman_coeff << ", "; - os << "snip_edges=" << (self.snip_edges ? "True" : "False") - << ", "; - os << "max_feature_vectors=" << self.max_feature_vectors << ")"; - - return os.str(); - }) + [](const PyClass &self) -> std::string { return self.ToString(); }) .def(py::pickle( [](const PyClass &self) -> py::dict { return AsDict(self); }, [](py::dict dict) -> PyClass { diff --git a/kaldifeat/python/tests/test_frame_extraction_options.py b/kaldifeat/python/tests/test_frame_extraction_options.py index 511d0a7..27e5405 100755 --- a/kaldifeat/python/tests/test_frame_extraction_options.py +++ b/kaldifeat/python/tests/test_frame_extraction_options.py @@ -9,6 +9,7 @@ import kaldifeat def test_default(): opts = kaldifeat.FrameExtractionOptions() + print(opts) assert opts.samp_freq == 16000 assert opts.frame_shift_ms == 10.0 assert opts.frame_length_ms == 25.0