mirror of
https://github.com/csukuangfj/kaldifeat.git
synced 2025-08-19 23:06:18 +00:00
Change the way how PlpOptions is displayed
This commit is contained in:
parent
335b4d855a
commit
0baa34cc5e
@ -61,23 +61,21 @@ struct PlpOptions {
|
||||
|
||||
std::string ToString() const {
|
||||
std::ostringstream os;
|
||||
os << "frame_opts: \n";
|
||||
os << frame_opts << "\n";
|
||||
os << "\n";
|
||||
os << "PlpOptions(";
|
||||
|
||||
os << "mel_opts: \n";
|
||||
os << mel_opts << "\n";
|
||||
os << "frame_opts=" << frame_opts.ToString() << ", ";
|
||||
os << "mel_opts=" << mel_opts.ToString() << ", ";
|
||||
|
||||
os << "lpc_order: " << lpc_order << "\n";
|
||||
os << "num_ceps: " << num_ceps << "\n";
|
||||
os << "use_energy: " << use_energy << "\n";
|
||||
os << "energy_floor: " << energy_floor << "\n";
|
||||
os << "raw_energy: " << raw_energy << "\n";
|
||||
os << "compress_factor: " << compress_factor << "\n";
|
||||
os << "cepstral_lifter: " << cepstral_lifter << "\n";
|
||||
os << "cepstral_scale: " << cepstral_scale << "\n";
|
||||
os << "htk_compat: " << htk_compat << "\n";
|
||||
os << "device: " << device << "\n";
|
||||
os << "lpc_order=" << lpc_order << ", ";
|
||||
os << "num_ceps=" << num_ceps << ", ";
|
||||
os << "use_energy=" << (use_energy ? "True" : "False") << ", ";
|
||||
os << "energy_floor=" << energy_floor << ", ";
|
||||
os << "raw_energy=" << (raw_energy ? "True" : "False") << ", ";
|
||||
os << "compress_factor=" << compress_factor << ", ";
|
||||
os << "cepstral_lifter=" << cepstral_lifter << ", ";
|
||||
os << "cepstral_scale=" << cepstral_scale << ", ";
|
||||
os << "htk_compat=" << (htk_compat ? "True" : "False") << ", ";
|
||||
os << "device=\"" << device << "\")";
|
||||
return os.str();
|
||||
}
|
||||
};
|
||||
|
@ -16,6 +16,41 @@ void PybindPlpOptions(py::module &m) {
|
||||
using PyClass = PlpOptions;
|
||||
py::class_<PyClass>(m, "PlpOptions")
|
||||
.def(py::init<>())
|
||||
.def(py::init([](const MelBanksOptions &mel_opts,
|
||||
const FrameExtractionOptions &frame_opts =
|
||||
FrameExtractionOptions(),
|
||||
int32_t lpc_order = 12, int32_t num_ceps = 13,
|
||||
bool use_energy = true, float energy_floor = 0.0,
|
||||
bool raw_energy = true, float compress_factor = 0.33333,
|
||||
int32_t cepstral_lifter = 22, float cepstral_scale = 1.0,
|
||||
bool htk_compat = false,
|
||||
py::object device =
|
||||
py::str("cpu")) -> std::unique_ptr<PlpOptions> {
|
||||
auto opts = std::make_unique<PlpOptions>();
|
||||
opts->frame_opts = frame_opts;
|
||||
opts->mel_opts = mel_opts;
|
||||
opts->lpc_order = lpc_order;
|
||||
opts->num_ceps = num_ceps;
|
||||
opts->use_energy = use_energy;
|
||||
opts->energy_floor = energy_floor;
|
||||
opts->raw_energy = raw_energy;
|
||||
opts->compress_factor = compress_factor;
|
||||
opts->cepstral_lifter = cepstral_lifter;
|
||||
opts->cepstral_scale = cepstral_scale;
|
||||
opts->htk_compat = htk_compat;
|
||||
|
||||
std::string s = static_cast<py::str>(device);
|
||||
opts->device = torch::Device(s);
|
||||
|
||||
return opts;
|
||||
}),
|
||||
py::arg("mel_opts"),
|
||||
py::arg("frame_opts") = FrameExtractionOptions(),
|
||||
py::arg("lpc_order") = 12, py::arg("num_ceps") = 13,
|
||||
py::arg("use_energy") = true, py::arg("energy_floor") = 0.0,
|
||||
py::arg("raw_energy") = true, py::arg("compress_factor") = 0.33333,
|
||||
py::arg("cepstral_lifter") = 22, py::arg("cepstral_scale") = 1.0,
|
||||
py::arg("htk_compat") = false, py::arg("device") = py::str("cpu"))
|
||||
.def_readwrite("frame_opts", &PyClass::frame_opts)
|
||||
.def_readwrite("mel_opts", &PyClass::mel_opts)
|
||||
.def_readwrite("lpc_order", &PyClass::lpc_order)
|
||||
|
@ -12,6 +12,7 @@ import kaldifeat
|
||||
|
||||
def test_default():
|
||||
opts = kaldifeat.PlpOptions()
|
||||
print(opts)
|
||||
assert opts.frame_opts.samp_freq == 16000
|
||||
assert opts.frame_opts.frame_shift_ms == 10.0
|
||||
assert opts.frame_opts.frame_length_ms == 25.0
|
||||
|
Loading…
x
Reference in New Issue
Block a user