Skip to content

Commit

Permalink
Change how options are displayed (#62)
Browse files Browse the repository at this point in the history
* Change the way how FrameExtractionOptions is displayed

* small fixes

* Change the way how MelBankOptions is displayed

* Change the way how SpectrogramOptions is displayed

* Change the way how FbankOptions is displayed

* Change the way how MfccOptions is displayed

* Change the way how PlpOptions is displayed

* Export num_frames

* release v1.22
  • Loading branch information
csukuangfj authored Dec 3, 2022
1 parent 8ee0c34 commit 94a567c
Show file tree
Hide file tree
Showing 22 changed files with 279 additions and 86 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(kaldifeat)
# remember to change the version in
# scripts/conda/kaldifeat/meta.yaml
# scripts/conda-cpu/kaldifeat/meta.yaml
set(kaldifeat_VERSION "1.21")
set(kaldifeat_VERSION "1.22")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
Expand Down
26 changes: 12 additions & 14 deletions kaldifeat/csrc/feature-fbank.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,18 @@ struct FbankOptions {

std::string ToString() const {
std::ostringstream os;
os << "frame_opts: \n";
os << frame_opts << "\n";
os << "\n";

os << "mel_opts: \n";
os << mel_opts << "\n";

os << "use_energy: " << use_energy << "\n";
os << "energy_floor: " << energy_floor << "\n";
os << "raw_energy: " << raw_energy << "\n";
os << "htk_compat: " << htk_compat << "\n";
os << "use_log_fbank: " << use_log_fbank << "\n";
os << "use_power: " << use_power << "\n";
os << "device: " << device << "\n";
os << "FbankOptions(";

os << "frame_opts=" << frame_opts.ToString() << ", ";
os << "mel_opts=" << mel_opts.ToString() << ", ";

os << "use_energy=" << (use_energy ? "True" : "False") << ", ";
os << "energy_floor=" << energy_floor << ", ";
os << "raw_energy=" << (raw_energy ? "True" : "False") << ", ";
os << "htk_compat=" << (htk_compat ? "True" : "False") << ", ";
os << "use_log_fbank=" << (use_log_fbank ? "True" : "False") << ", ";
os << "use_power=" << (use_power ? "True" : "False") << ", ";
os << "device=\"" << device << "\")";
return os.str();
}
};
Expand Down
26 changes: 12 additions & 14 deletions kaldifeat/csrc/feature-mfcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,18 @@ struct MfccOptions {

std::string ToString() const {
std::ostringstream os;
os << "frame_opts: \n";
os << frame_opts << "\n";
os << "\n";

os << "mel_opts: \n";
os << mel_opts << "\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 << "cepstral_lifter: " << cepstral_lifter << "\n";
os << "htk_compat: " << htk_compat << "\n";
os << "device: " << device << "\n";
os << "MfccOptions(";
os << "frame_opts=" << frame_opts.ToString() << ", ";
os << "mel_opts=" << mel_opts.ToString() << ", ";

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 << "cepstral_lifter=" << cepstral_lifter << ", ";
os << "htk_compat=" << (htk_compat ? "True" : "False") << ", ";
os << "device=\"" << device << "\")";

return os.str();
}
};
Expand Down
32 changes: 15 additions & 17 deletions kaldifeat/csrc/feature-plp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,21 @@ struct PlpOptions {

std::string ToString() const {
std::ostringstream os;
os << "frame_opts: \n";
os << frame_opts << "\n";
os << "\n";

os << "mel_opts: \n";
os << mel_opts << "\n";

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 << "PlpOptions(";

os << "frame_opts=" << frame_opts.ToString() << ", ";
os << "mel_opts=" << mel_opts.ToString() << ", ";

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();
}
};
Expand Down
13 changes: 6 additions & 7 deletions kaldifeat/csrc/feature-spectrogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ struct SpectrogramOptions {

std::string ToString() const {
std::ostringstream os;
os << "frame_opts: \n";
os << frame_opts << "\n";

os << "energy_floor: " << energy_floor << "\n";
os << "raw_energy: " << raw_energy << "\n";
// os << "return_raw_fft: " << return_raw_fft << "\n";
os << "device: " << device << "\n";
os << "SpectrogramOptions(";
os << "frame_opts=" << frame_opts.ToString() << ", ";
os << "energy_floor=" << energy_floor << ", ";
os << "raw_energy=" << (raw_energy ? "True" : "False") << ", ";
os << "return_raw_fft=" << (return_raw_fft ? "True" : "False") << ", ";
os << "device=\"" << device << "\")";
return os.str();
}
};
Expand Down
29 changes: 14 additions & 15 deletions kaldifeat/csrc/feature-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
};
Expand Down
15 changes: 8 additions & 7 deletions kaldifeat/csrc/mel-computations.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ struct MelBanksOptions {

std::string ToString() const {
std::ostringstream os;
os << "num_bins: " << num_bins << "\n";
os << "low_freq: " << low_freq << "\n";
os << "high_freq: " << high_freq << "\n";
os << "vtln_low: " << vtln_low << "\n";
os << "vtln_high: " << vtln_high << "\n";
os << "debug_mel: " << debug_mel << "\n";
os << "htk_mode: " << htk_mode << "\n";
os << "MelBanksOptions(";
os << "num_bins=" << num_bins << ", ";
os << "low_freq=" << low_freq << ", ";
os << "high_freq=" << high_freq << ", ";
os << "vtln_low=" << vtln_low << ", ";
os << "vtln_high=" << vtln_high << ", ";
os << "debug_mel=" << (debug_mel ? "True" : "False") << ", ";
os << "htk_mode=" << (htk_mode ? "True" : "False") << ")";
return os.str();
}
};
Expand Down
29 changes: 29 additions & 0 deletions kaldifeat/python/csrc/feature-fbank.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ static void PybindFbankOptions(py::module &m) {
using PyClass = FbankOptions;
py::class_<PyClass>(m, "FbankOptions")
.def(py::init<>())
.def(py::init([](const MelBanksOptions &mel_opts,
const FrameExtractionOptions &frame_opts =
FrameExtractionOptions(),
bool use_energy = false, float energy_floor = 0.0f,
bool raw_energy = true, bool htk_compat = false,
bool use_log_fbank = true, bool use_power = true,
py::object device =
py::str("cpu")) -> std::unique_ptr<FbankOptions> {
auto opts = std::make_unique<FbankOptions>();
opts->frame_opts = frame_opts;
opts->mel_opts = mel_opts;
opts->use_energy = use_energy;
opts->energy_floor = energy_floor;
opts->raw_energy = raw_energy;
opts->htk_compat = htk_compat;
opts->use_log_fbank = use_log_fbank;
opts->use_power = use_power;

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("use_energy") = false, py::arg("energy_floor") = 0.0f,
py::arg("raw_energy") = true, py::arg("htk_compat") = false,
py::arg("use_log_fbank") = true, py::arg("use_power") = true,
py::arg("device") = py::str("cpu"))
.def_readwrite("frame_opts", &PyClass::frame_opts)
.def_readwrite("mel_opts", &PyClass::mel_opts)
.def_readwrite("use_energy", &PyClass::use_energy)
Expand Down
29 changes: 29 additions & 0 deletions kaldifeat/python/csrc/feature-mfcc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,35 @@ void PybindMfccOptions(py::module &m) {
using PyClass = MfccOptions;
py::class_<PyClass>(m, "MfccOptions")
.def(py::init<>())
.def(py::init([](const MelBanksOptions &mel_opts,
const FrameExtractionOptions &frame_opts =
FrameExtractionOptions(),
int32_t num_ceps = 13, bool use_energy = true,
float energy_floor = 0.0, bool raw_energy = true,
float cepstral_lifter = 22.0, bool htk_compat = false,
py::object device =
py::str("cpu")) -> std::unique_ptr<MfccOptions> {
auto opts = std::make_unique<MfccOptions>();
opts->frame_opts = frame_opts;
opts->mel_opts = mel_opts;
opts->num_ceps = num_ceps;
opts->use_energy = use_energy;
opts->energy_floor = energy_floor;
opts->raw_energy = raw_energy;
opts->cepstral_lifter = cepstral_lifter;
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("num_ceps") = 13, py::arg("use_energy") = true,
py::arg("energy_floor") = 0.0f, py::arg("raw_energy") = true,
py::arg("cepstral_lifter") = 22.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("num_ceps", &PyClass::num_ceps)
Expand Down
35 changes: 35 additions & 0 deletions kaldifeat/python/csrc/feature-plp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion kaldifeat/python/csrc/feature-spectrogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@ namespace kaldifeat {
static void PybindSpectrogramOptions(py::module &m) {
using PyClass = SpectrogramOptions;
py::class_<PyClass>(m, "SpectrogramOptions")
.def(py::init<>())
.def(py::init([](const FrameExtractionOptions &frame_opts =
FrameExtractionOptions(),
float energy_floor = 0.0, bool raw_energy = true,
bool return_raw_fft = false,
py::object device = py::str(
"cpu")) -> std::unique_ptr<SpectrogramOptions> {
auto opts = std::make_unique<SpectrogramOptions>();
opts->frame_opts = frame_opts;
opts->energy_floor = energy_floor;
opts->raw_energy = raw_energy;
opts->return_raw_fft = return_raw_fft;

std::string s = static_cast<py::str>(device);
opts->device = torch::Device(s);

return opts;
}),
py::arg("frame_opts") = FrameExtractionOptions(),
py::arg("energy_floor") = 0.0, py::arg("raw_energy") = true,
py::arg("return_raw_fft") = false,
py::arg("device") = py::str("cpu"))
.def_readwrite("frame_opts", &PyClass::frame_opts)
.def_readwrite("energy_floor", &PyClass::energy_floor)
.def_readwrite("raw_energy", &PyClass::raw_energy)
Expand Down
34 changes: 33 additions & 1 deletion kaldifeat/python/csrc/feature-window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "kaldifeat/python/csrc/feature-window.h"

#include <memory>
#include <string>

#include "kaldifeat/csrc/feature-window.h"
Expand All @@ -14,7 +15,38 @@ namespace kaldifeat {
static void PybindFrameExtractionOptions(py::module &m) {
using PyClass = FrameExtractionOptions;
py::class_<PyClass>(m, "FrameExtractionOptions")
.def(py::init<>())
.def(
py::init([](float samp_freq = 16000, float frame_shift_ms = 10.0f,
float frame_length_ms = 25.0f, float dither = 1.0f,
float preemph_coeff = 0.97f, bool remove_dc_offset = true,
const std::string &window_type = "povey",
bool round_to_power_of_two = true,
float blackman_coeff = 0.42f, bool snip_edges = true,
int32_t max_feature_vectors =
-1) -> std::unique_ptr<FrameExtractionOptions> {
auto opts = std::make_unique<FrameExtractionOptions>();

opts->samp_freq = samp_freq;
opts->frame_shift_ms = frame_shift_ms;
opts->frame_length_ms = frame_length_ms;
opts->dither = dither;
opts->preemph_coeff = preemph_coeff;
opts->remove_dc_offset = remove_dc_offset;
opts->window_type = window_type;
opts->round_to_power_of_two = round_to_power_of_two;
opts->blackman_coeff = blackman_coeff;
opts->snip_edges = snip_edges;
opts->max_feature_vectors = max_feature_vectors;

return opts;
}),
py::arg("samp_freq") = 16000, py::arg("frame_shift_ms") = 10.0f,
py::arg("frame_length_ms") = 25.0f, py::arg("dither") = 1.0f,
py::arg("preemph_coeff") = 0.97f, py::arg("remove_dc_offset") = true,
py::arg("window_type") = "povey",
py::arg("round_to_power_of_two") = true,
py::arg("blackman_coeff") = 0.42f, py::arg("snip_edges") = true,
py::arg("max_feature_vectors") = -1)
.def_readwrite("samp_freq", &PyClass::samp_freq)
.def_readwrite("frame_shift_ms", &PyClass::frame_shift_ms)
.def_readwrite("frame_length_ms", &PyClass::frame_length_ms)
Expand Down
Loading

0 comments on commit 94a567c

Please sign in to comment.