diff --git a/CMakeLists.txt b/CMakeLists.txt index e340954..fac3f11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/kaldifeat/csrc/feature-fbank.h b/kaldifeat/csrc/feature-fbank.h index 05a467f..a30ff66 100644 --- a/kaldifeat/csrc/feature-fbank.h +++ b/kaldifeat/csrc/feature-fbank.h @@ -44,20 +44,18 @@ struct FbankOptions { std::string ToString() const { std::ostringstream os; - os << "frame_opts: \n"; - os << frame_opts << "\n"; - os << "\n"; + os << "FbankOptions("; - os << "mel_opts: \n"; - os << mel_opts << "\n"; + os << "frame_opts=" << frame_opts.ToString() << ", "; + os << "mel_opts=" << mel_opts.ToString() << ", "; - 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 << "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(); } }; diff --git a/kaldifeat/csrc/feature-mfcc.h b/kaldifeat/csrc/feature-mfcc.h index 2c00b7f..2d45b2c 100644 --- a/kaldifeat/csrc/feature-mfcc.h +++ b/kaldifeat/csrc/feature-mfcc.h @@ -53,20 +53,18 @@ struct MfccOptions { std::string ToString() const { std::ostringstream os; - os << "frame_opts: \n"; - os << frame_opts << "\n"; - os << "\n"; + os << "MfccOptions("; + os << "frame_opts=" << frame_opts.ToString() << ", "; + os << "mel_opts=" << mel_opts.ToString() << ", "; - os << "mel_opts: \n"; - os << mel_opts << "\n"; + 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 << "\")"; - 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"; return os.str(); } }; diff --git a/kaldifeat/csrc/feature-plp.h b/kaldifeat/csrc/feature-plp.h index dd5247c..0c39595 100644 --- a/kaldifeat/csrc/feature-plp.h +++ b/kaldifeat/csrc/feature-plp.h @@ -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(); } }; diff --git a/kaldifeat/csrc/feature-spectrogram.h b/kaldifeat/csrc/feature-spectrogram.h index c4febe6..3665f4a 100644 --- a/kaldifeat/csrc/feature-spectrogram.h +++ b/kaldifeat/csrc/feature-spectrogram.h @@ -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(); } }; 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/csrc/mel-computations.h b/kaldifeat/csrc/mel-computations.h index 0abfabd..9aa8d9c 100644 --- a/kaldifeat/csrc/mel-computations.h +++ b/kaldifeat/csrc/mel-computations.h @@ -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(); } }; diff --git a/kaldifeat/python/csrc/feature-fbank.cc b/kaldifeat/python/csrc/feature-fbank.cc index 6e52f0c..a7ed09a 100644 --- a/kaldifeat/python/csrc/feature-fbank.cc +++ b/kaldifeat/python/csrc/feature-fbank.cc @@ -16,6 +16,35 @@ static void PybindFbankOptions(py::module &m) { using PyClass = FbankOptions; py::class_(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 { + auto opts = std::make_unique(); + 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(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) diff --git a/kaldifeat/python/csrc/feature-mfcc.cc b/kaldifeat/python/csrc/feature-mfcc.cc index fe893cb..44c200d 100644 --- a/kaldifeat/python/csrc/feature-mfcc.cc +++ b/kaldifeat/python/csrc/feature-mfcc.cc @@ -16,6 +16,35 @@ void PybindMfccOptions(py::module &m) { using PyClass = MfccOptions; py::class_(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 { + auto opts = std::make_unique(); + 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(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) diff --git a/kaldifeat/python/csrc/feature-plp.cc b/kaldifeat/python/csrc/feature-plp.cc index 364ef93..7553f3a 100644 --- a/kaldifeat/python/csrc/feature-plp.cc +++ b/kaldifeat/python/csrc/feature-plp.cc @@ -16,6 +16,41 @@ void PybindPlpOptions(py::module &m) { using PyClass = PlpOptions; py::class_(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 { + auto opts = std::make_unique(); + 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(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) diff --git a/kaldifeat/python/csrc/feature-spectrogram.cc b/kaldifeat/python/csrc/feature-spectrogram.cc index 24b156b..aaf3d78 100644 --- a/kaldifeat/python/csrc/feature-spectrogram.cc +++ b/kaldifeat/python/csrc/feature-spectrogram.cc @@ -15,7 +15,27 @@ namespace kaldifeat { static void PybindSpectrogramOptions(py::module &m) { using PyClass = SpectrogramOptions; py::class_(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 { + auto opts = std::make_unique(); + 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(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) diff --git a/kaldifeat/python/csrc/feature-window.cc b/kaldifeat/python/csrc/feature-window.cc index 5abaf36..116f82a 100644 --- a/kaldifeat/python/csrc/feature-window.cc +++ b/kaldifeat/python/csrc/feature-window.cc @@ -4,6 +4,7 @@ #include "kaldifeat/python/csrc/feature-window.h" +#include #include #include "kaldifeat/csrc/feature-window.h" @@ -14,7 +15,38 @@ namespace kaldifeat { static void PybindFrameExtractionOptions(py::module &m) { using PyClass = FrameExtractionOptions; py::class_(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 { + auto opts = std::make_unique(); + + 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) diff --git a/kaldifeat/python/csrc/mel-computations.cc b/kaldifeat/python/csrc/mel-computations.cc index e8f1c31..fa9544f 100644 --- a/kaldifeat/python/csrc/mel-computations.cc +++ b/kaldifeat/python/csrc/mel-computations.cc @@ -4,6 +4,7 @@ #include "kaldifeat/python/csrc/mel-computations.h" +#include #include #include "kaldifeat/csrc/mel-computations.h" @@ -14,7 +15,24 @@ namespace kaldifeat { static void PybindMelBanksOptions(py::module &m) { using PyClass = MelBanksOptions; py::class_(m, "MelBanksOptions") - .def(py::init<>()) + .def(py::init( + [](int32_t num_bins = 25, float low_freq = 20, + float high_freq = 0, float vtln_low = 100, + float vtln_high = -500, + bool debug_mel = false) -> std::unique_ptr { + auto opts = std::make_unique(); + + opts->num_bins = num_bins; + opts->low_freq = low_freq; + opts->high_freq = high_freq; + opts->vtln_low = vtln_low; + opts->vtln_high = vtln_high; + + return opts; + }), + py::arg("num_bins") = 25, py::arg("low_freq") = 20, + py::arg("high_freq") = 0, py::arg("vtln_low") = 100, + py::arg("vtln_high") = -500, py::arg("debug_mel") = false) .def_readwrite("num_bins", &PyClass::num_bins) .def_readwrite("low_freq", &PyClass::low_freq) .def_readwrite("high_freq", &PyClass::high_freq) diff --git a/kaldifeat/python/kaldifeat/__init__.py b/kaldifeat/python/kaldifeat/__init__.py index d32c46c..92e7980 100644 --- a/kaldifeat/python/kaldifeat/__init__.py +++ b/kaldifeat/python/kaldifeat/__init__.py @@ -8,6 +8,8 @@ if torch.__version__.split("+")[0] != kaldifeat_torch_version.split("+")[0]: f"But you are using PyTorch {torch.__version__} to run it" ) +from pathlib import Path as _Path + from _kaldifeat import ( FbankOptions, FrameExtractionOptions, @@ -15,6 +17,7 @@ from _kaldifeat import ( MfccOptions, PlpOptions, SpectrogramOptions, + num_frames, ) from .fbank import Fbank, OnlineFbank @@ -24,7 +27,5 @@ from .online_feature import OnlineFeature from .plp import OnlinePlp, Plp from .spectrogram import Spectrogram -from pathlib import Path as _Path - cmake_prefix_path = _Path(__file__).parent / "share" / "cmake" del _Path diff --git a/kaldifeat/python/tests/test_fbank_options.py b/kaldifeat/python/tests/test_fbank_options.py index f2fffdc..6f822b1 100755 --- a/kaldifeat/python/tests/test_fbank_options.py +++ b/kaldifeat/python/tests/test_fbank_options.py @@ -12,6 +12,7 @@ import kaldifeat def test_default(): opts = kaldifeat.FbankOptions() + 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 diff --git a/kaldifeat/python/tests/test_frame_extraction_options.py b/kaldifeat/python/tests/test_frame_extraction_options.py index 511d0a7..c4a2e73 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 @@ -22,7 +23,9 @@ def test_default(): def test_set_get(): - opts = kaldifeat.FrameExtractionOptions() + opts = kaldifeat.FrameExtractionOptions(samp_freq=22150) + assert opts.samp_freq == 22150 + opts.samp_freq = 44100 assert opts.samp_freq == 44100 diff --git a/kaldifeat/python/tests/test_mel_bank_options.py b/kaldifeat/python/tests/test_mel_bank_options.py index 70624a1..c064980 100755 --- a/kaldifeat/python/tests/test_mel_bank_options.py +++ b/kaldifeat/python/tests/test_mel_bank_options.py @@ -9,6 +9,7 @@ import kaldifeat def test_default(): opts = kaldifeat.MelBanksOptions() + print(opts) assert opts.num_bins == 25 assert opts.low_freq == 20 assert opts.high_freq == 0 @@ -19,10 +20,12 @@ def test_default(): def test_set_get(): - opts = kaldifeat.MelBanksOptions() - opts.num_bins = 100 + opts = kaldifeat.MelBanksOptions(num_bins=100) assert opts.num_bins == 100 + opts.num_bins = 200 + assert opts.num_bins == 200 + opts.low_freq = 22 assert opts.low_freq == 22 diff --git a/kaldifeat/python/tests/test_mfcc_options.py b/kaldifeat/python/tests/test_mfcc_options.py index cef03ab..c650f46 100755 --- a/kaldifeat/python/tests/test_mfcc_options.py +++ b/kaldifeat/python/tests/test_mfcc_options.py @@ -12,6 +12,7 @@ import kaldifeat def test_default(): opts = kaldifeat.MfccOptions() + print(opts) assert opts.frame_opts.samp_freq == 16000 assert opts.frame_opts.frame_shift_ms == 10.0 diff --git a/kaldifeat/python/tests/test_plp_options.py b/kaldifeat/python/tests/test_plp_options.py index c30dd64..fc81111 100755 --- a/kaldifeat/python/tests/test_plp_options.py +++ b/kaldifeat/python/tests/test_plp_options.py @@ -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 diff --git a/kaldifeat/python/tests/test_spectrogram_options.py b/kaldifeat/python/tests/test_spectrogram_options.py index 34c8849..7a4fd1a 100755 --- a/kaldifeat/python/tests/test_spectrogram_options.py +++ b/kaldifeat/python/tests/test_spectrogram_options.py @@ -12,6 +12,7 @@ import kaldifeat def test_default(): opts = kaldifeat.SpectrogramOptions() + print(opts) assert opts.frame_opts.samp_freq == 16000 assert opts.frame_opts.frame_shift_ms == 10.0 @@ -30,7 +31,8 @@ def test_default(): def test_set_get(): - opts = kaldifeat.SpectrogramOptions() + opts = kaldifeat.SpectrogramOptions(energy_floor=10) + assert opts.energy_floor == 10 opts.energy_floor = 1 assert opts.energy_floor == 1 @@ -138,6 +140,30 @@ def test_pickle(): assert str(opts) == str(opts2) +def test_device(): + opts = kaldifeat.SpectrogramOptions(device="cpu") + assert opts.device == torch.device("cpu") + + opts = kaldifeat.SpectrogramOptions(device="cuda") + assert opts.device == torch.device("cuda") + + opts = kaldifeat.SpectrogramOptions(device="cuda:1") + assert opts.device == torch.device("cuda:1") + print(opts) + + opts = kaldifeat.SpectrogramOptions(device=torch.device("cpu")) + assert opts.device == torch.device("cpu") + + opts = kaldifeat.SpectrogramOptions(device=torch.device("cuda")) + assert opts.device == torch.device("cuda") + + opts = kaldifeat.SpectrogramOptions(device=torch.device("cuda:3")) + assert opts.device == torch.device("cuda:3") + + opts = kaldifeat.SpectrogramOptions(device=torch.device("cuda", 2)) + assert opts.device == torch.device("cuda", 2) + + def main(): test_default() test_set_get() @@ -146,6 +172,7 @@ def main(): test_from_dict_partial() test_from_dict_full_and_as_dict() test_pickle() + test_device() if __name__ == "__main__": diff --git a/scripts/conda-cpu/kaldifeat/meta.yaml b/scripts/conda-cpu/kaldifeat/meta.yaml index b95bd78..005d8df 100644 --- a/scripts/conda-cpu/kaldifeat/meta.yaml +++ b/scripts/conda-cpu/kaldifeat/meta.yaml @@ -1,6 +1,6 @@ package: name: kaldifeat - version: "1.21" + version: "1.22" source: path: "{{ environ.get('KALDIFEAT_ROOT_DIR') }}" diff --git a/scripts/conda/kaldifeat/meta.yaml b/scripts/conda/kaldifeat/meta.yaml index 4589373..0de720d 100644 --- a/scripts/conda/kaldifeat/meta.yaml +++ b/scripts/conda/kaldifeat/meta.yaml @@ -1,6 +1,6 @@ package: name: kaldifeat - version: "1.21" + version: "1.22" source: path: "{{ environ.get('KALDIFEAT_ROOT_DIR') }}"