forked from kaldi-asr/kaldi
-
Notifications
You must be signed in to change notification settings - Fork 14
add WaveReader and WaveInfoReader #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // pybind/feat/wave_reader_pybind.cc | ||
|
|
||
| // Copyright 2019 Microsoft Corporation (author: Xingyu Na) | ||
|
|
||
| // See ../../../COPYING for clarification regarding multiple authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| // MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| // See the Apache 2 License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #include "feat/wave_reader_pybind.h" | ||
| #include "feat/wave-reader.h" | ||
| #include "util/table-types.h" | ||
|
|
||
| using namespace kaldi; | ||
|
|
||
| void pybind_wave_reader(py::module& m) { | ||
| m.attr("kWaveSampleMax") = py::cast(kWaveSampleMax); | ||
|
|
||
| py::class_<WaveInfo>(m, "WaveInfo") | ||
| .def(py::init<>()) | ||
| .def("IsStreamed", &WaveInfo::IsStreamed, | ||
| "Is stream size unknown? Duration and SampleCount not valid if true.") | ||
| .def("SampFreq", &WaveInfo::SampFreq, | ||
| "Sample frequency, Hz.") | ||
| .def("SampleCount", &WaveInfo::SampleCount, | ||
| "Number of samples in stream. Invalid if IsStreamed() is true.") | ||
| .def("Duration", &WaveInfo::Duration, | ||
| "Approximate duration, seconds. Invalid if IsStreamed() is true.") | ||
| .def("NumChannels", &WaveInfo::NumChannels, | ||
| "Number of channels, 1 to 16.") | ||
| .def("BlockAlign", &WaveInfo::BlockAlign, | ||
| "Bytes per sample.") | ||
| .def("DataBytes", &WaveInfo::DataBytes, | ||
| "Wave data bytes. Invalid if IsStreamed() is true.") | ||
| .def("ReverseBytes", &WaveInfo::ReverseBytes, | ||
| "Is data file byte order different from machine byte order?"); | ||
|
|
||
| py::class_<WaveData>(m, "WaveData") | ||
naxingyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .def(py::init<>()) | ||
| .def(py::init<const float, const Matrix<float>>(), | ||
| py::arg("samp_freq"), py::arg("data")) | ||
| .def("Duration", &WaveData::Duration, | ||
| "Returns the duration in seconds") | ||
| .def("Data", &WaveData::Data, py::return_value_policy::reference) | ||
| .def("SampFreq", &WaveData::SampFreq) | ||
| .def("Clear", &WaveData::Clear) | ||
| .def("CopyFrom", &WaveData::CopyFrom) | ||
| .def("Swap", &WaveData::Swap); | ||
|
|
||
| py::class_<SequentialTableReader<WaveHolder>>(m, "SequentialWaveReader") | ||
| .def(py::init<>()) | ||
| .def(py::init<const std::string&>(), py::arg("rspecifier")) | ||
| .def("Open", &SequentialTableReader<WaveHolder>::Open, py::arg("rspecifier")) | ||
| .def("Done", &SequentialTableReader<WaveHolder>::Done) | ||
| .def("Key", &SequentialTableReader<WaveHolder>::Key) | ||
| .def("FreeCurrent", &SequentialTableReader<WaveHolder>::FreeCurrent) | ||
| .def("Value", &SequentialTableReader<WaveHolder>::Value, | ||
| py::return_value_policy::reference) | ||
| .def("Next", &SequentialTableReader<WaveHolder>::Next) | ||
| .def("IsOpen", &SequentialTableReader<WaveHolder>::IsOpen) | ||
| .def("Close", &SequentialTableReader<WaveHolder>::Close); | ||
|
|
||
| py::class_<RandomAccessTableReader<WaveHolder>>(m, "RandomAccessWaveReader") | ||
| .def(py::init<>()) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should the copy constructor also be wrapped? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I see |
||
| .def(py::init<const std::string&>(), py::arg("rspecifier")) | ||
| .def("Open", &RandomAccessTableReader<WaveHolder>::Open, py::arg("rspecifier")) | ||
| .def("IsOpen", &RandomAccessTableReader<WaveHolder>::IsOpen) | ||
| .def("Close", &RandomAccessTableReader<WaveHolder>::Close) | ||
| .def("HasKey", &RandomAccessTableReader<WaveHolder>::HasKey, py::arg("key")) | ||
| .def("Value", &RandomAccessTableReader<WaveHolder>::Value, | ||
| py::return_value_policy::reference); | ||
|
|
||
| py::class_<SequentialTableReader<WaveInfoHolder>>(m, "SequentialWaveInfoReader") | ||
| .def(py::init<>()) | ||
| .def(py::init<const std::string&>(), py::arg("rspecifier")) | ||
| .def("Open", &SequentialTableReader<WaveInfoHolder>::Open, py::arg("rspecifier")) | ||
| .def("Done", &SequentialTableReader<WaveInfoHolder>::Done) | ||
| .def("Key", &SequentialTableReader<WaveInfoHolder>::Key) | ||
| .def("FreeCurrent", &SequentialTableReader<WaveInfoHolder>::FreeCurrent) | ||
| .def("Value", &SequentialTableReader<WaveInfoHolder>::Value, | ||
| py::return_value_policy::reference) | ||
| .def("Next", &SequentialTableReader<WaveInfoHolder>::Next) | ||
| .def("IsOpen", &SequentialTableReader<WaveInfoHolder>::IsOpen) | ||
| .def("Close", &SequentialTableReader<WaveInfoHolder>::Close); | ||
|
|
||
| py::class_<RandomAccessTableReader<WaveInfoHolder>>(m, "RandomAccessWaveInfoReader") | ||
| .def(py::init<>()) | ||
| .def(py::init<const std::string&>(), py::arg("rspecifier")) | ||
| .def("Open", &RandomAccessTableReader<WaveInfoHolder>::Open, py::arg("rspecifier")) | ||
| .def("IsOpen", &RandomAccessTableReader<WaveInfoHolder>::IsOpen) | ||
| .def("Close", &RandomAccessTableReader<WaveInfoHolder>::Close) | ||
| .def("HasKey", &RandomAccessTableReader<WaveInfoHolder>::HasKey, py::arg("key")) | ||
| .def("Value", &RandomAccessTableReader<WaveInfoHolder>::Value, | ||
| py::return_value_policy::reference); | ||
|
|
||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // pybind/feat/wave_reader_pybind.h | ||
|
|
||
| // Copyright 2019 Microsoft Corporation (author: Xingyu Na) | ||
|
|
||
| // See ../../../COPYING for clarification regarding multiple authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
| // WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
| // MERCHANTABLITY OR NON-INFRINGEMENT. | ||
| // See the Apache 2 License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| #ifndef KALDI_PYBIND_FEAT_WAVE_READER_PYBIND_H_ | ||
| #define KALDI_PYBIND_FEAT_WAVE_READER_PYBIND_H_ | ||
|
|
||
| #include "pybind/kaldi_pybind.h" | ||
|
|
||
| void pybind_wave_reader(py::module& m); | ||
|
|
||
| #endif // KALDI_PYBIND_FEAT_WAVE_READER_PYBIND_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
naxingyu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Copyright 2019 Microsoft Corporation (author: Xingyu Na) | ||
| # Apache 2.0 | ||
|
|
||
| import os | ||
| import sys | ||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir)) | ||
|
|
||
| import unittest | ||
|
|
||
| import numpy as np | ||
|
|
||
| import kaldi | ||
|
|
||
| class TestWaveData(unittest.TestCase): | ||
|
|
||
| def test_duration(self): | ||
| waveform = kaldi.FloatMatrix(1, 16000) | ||
| wave_data = kaldi.WaveData(samp_freq=16000, data=waveform) | ||
| self.assertEqual(1, wave_data.Duration()) | ||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.