small fixes

This commit is contained in:
Fangjun Kuang 2022-12-03 12:05:45 +08:00
parent 68c0414bde
commit f28857495d
3 changed files with 16 additions and 35 deletions

View File

@ -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();
}
};

View File

@ -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 {

View File

@ -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