Skip to content

Commit a92babf

Browse files
authored
[src] Issue error if file sample rate differs from feature .conf (#4648)
Change rolled to all feature extractors.
1 parent 5cd9c1e commit a92babf

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

src/cudafeatbin/compute-fbank-feats-cuda.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "feat/wave-reader.h"
2323
#include "cudamatrix/cu-matrix.h"
2424
#include "cudamatrix/cu-vector.h"
25+
26+
2527
int main(int argc, char *argv[]) {
2628
try {
2729
using namespace kaldi;
@@ -66,7 +68,7 @@ int main(int argc, char *argv[]) {
6668
po.PrintUsage();
6769
exit(1);
6870
}
69-
71+
7072
g_cuda_allocator.SetOptions(g_allocator_options);
7173
CuDevice::Instantiate().SelectGpuId("yes");
7274
CuDevice::Instantiate().AllowMultithreading();
@@ -76,7 +78,7 @@ int main(int argc, char *argv[]) {
7678

7779
std::string output_wspecifier = po.GetArg(2);
7880

79-
// Fbank is implemented via the MFCC code path
81+
// Fbank is implemented via the MFCC code path.
8082
CudaSpectralFeatures fbank(fbank_opts);
8183

8284
SequentialTableReader<WaveHolder> reader(wav_rspecifier);
@@ -88,7 +90,7 @@ int main(int argc, char *argv[]) {
8890
"needed if the vtln-map option is used.");
8991
RandomAccessBaseFloatReaderMapped vtln_map_reader(vtln_map_rspecifier,
9092
utt2spk_rspecifier);
91-
93+
9294
if (output_format == "kaldi") {
9395
if (!kaldi_writer.Open(output_wspecifier))
9496
KALDI_ERR << "Could not initialize output with wspecifier "
@@ -106,6 +108,11 @@ int main(int argc, char *argv[]) {
106108
num_utts++;
107109
std::string utt = reader.Key();
108110
const WaveData &wave_data = reader.Value();
111+
if (wave_data.SampFreq() != fbank_opts.frame_opts.samp_freq) {
112+
KALDI_ERR << "File: " << utt << " has an mismatched sampling "
113+
<< "rate (config= " << fbank_opts.frame_opts.samp_freq
114+
<< " vs file=" << wave_data.SampFreq() << ".";
115+
}
109116
if (wave_data.Duration() < min_duration) {
110117
KALDI_WARN << "File: " << utt << " is too short ("
111118
<< wave_data.Duration() << " sec): producing no output.";

src/cudafeatbin/compute-fbank-online-batched-cuda.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using namespace kaldi;
3434

3535
// This class stores data for input and output for this binary.
3636
// We will read/write slices of this input/output in an online
37-
// fasion.
37+
// fashion.
3838
struct UtteranceDataHandle {
3939
std::string utt;
4040
WaveData wave_data_in;
@@ -186,6 +186,12 @@ int main(int argc, char *argv[]) {
186186
for (; !reader.Done(); reader.Next()) {
187187
std::string utt = reader.Key();
188188
WaveData &wave_data = reader.Value();
189+
if (wave_data.SampFreq() != feature_opts.frame_opts.samp_freq) {
190+
KALDI_ERR << "File: " << utt << " has an mismatched sampling "
191+
<< "rate (config= " << feature_opts.frame_opts.samp_freq
192+
<< " vs file=" << wave_data.SampFreq() << ".";
193+
}
194+
189195
duration += wave_data.Duration();
190196
data_handles.emplace_back(utt, wave_data, frame_opts, feat_dim);
191197
}

src/cudafeatbin/compute-mfcc-feats-cuda.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "feat/wave-reader.h"
2323
#include "cudamatrix/cu-matrix.h"
2424
#include "cudamatrix/cu-vector.h"
25+
26+
2527
int main(int argc, char *argv[]) {
2628
try {
2729
using namespace kaldi;
@@ -66,7 +68,7 @@ int main(int argc, char *argv[]) {
6668
po.PrintUsage();
6769
exit(1);
6870
}
69-
71+
7072
g_cuda_allocator.SetOptions(g_allocator_options);
7173
CuDevice::Instantiate().SelectGpuId("yes");
7274
CuDevice::Instantiate().AllowMultithreading();
@@ -87,7 +89,7 @@ int main(int argc, char *argv[]) {
8789
"needed if the vtln-map option is used.");
8890
RandomAccessBaseFloatReaderMapped vtln_map_reader(vtln_map_rspecifier,
8991
utt2spk_rspecifier);
90-
92+
9193
if (output_format == "kaldi") {
9294
if (!kaldi_writer.Open(output_wspecifier))
9395
KALDI_ERR << "Could not initialize output with wspecifier "
@@ -105,6 +107,11 @@ int main(int argc, char *argv[]) {
105107
num_utts++;
106108
std::string utt = reader.Key();
107109
const WaveData &wave_data = reader.Value();
110+
if (wave_data.SampFreq() != mfcc_opts.frame_opts.samp_freq) {
111+
KALDI_ERR << "File: " << utt << " has an mismatched sampling "
112+
<< "rate (config= " << mfcc_opts.frame_opts.samp_freq
113+
<< " vs file=" << wave_data.SampFreq() << ".";
114+
}
108115
if (wave_data.Duration() < min_duration) {
109116
KALDI_WARN << "File: " << utt << " is too short ("
110117
<< wave_data.Duration() << " sec): producing no output.";

src/cudafeatbin/compute-mfcc-online-batched-cuda.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using namespace kaldi;
3434

3535
// This class stores data for input and output for this binary.
3636
// We will read/write slices of this input/output in an online
37-
// fasion.
37+
// fashion.
3838
struct UtteranceDataHandle {
3939
std::string utt;
4040
WaveData wave_data_in;
@@ -186,6 +186,12 @@ int main(int argc, char *argv[]) {
186186
for (; !reader.Done(); reader.Next()) {
187187
std::string utt = reader.Key();
188188
WaveData &wave_data = reader.Value();
189+
if (wave_data.SampFreq() != feature_opts.frame_opts.samp_freq) {
190+
KALDI_ERR << "File: " << utt << " has an mismatched sampling "
191+
<< "rate (config= " << feature_opts.frame_opts.samp_freq
192+
<< " vs file=" << wave_data.SampFreq() << ".";
193+
}
194+
189195
duration += wave_data.Duration();
190196
data_handles.emplace_back(utt, wave_data, frame_opts, feat_dim);
191197
}
@@ -373,6 +379,7 @@ int main(int argc, char *argv[]) {
373379
#if HAVE_CUDA == 1
374380
cudaProfilerStop();
375381
#endif
382+
376383
return 0;
377384
} catch (const std::exception &e) {
378385
std::cerr << e.what();

src/cudafeatbin/compute-online-feats-batched-cuda.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ using namespace kaldi;
3434

3535
// This class stores data for input and output for this binary.
3636
// We will read/write slices of this input/output in an online
37-
// fasion.
37+
// fashion.
3838
struct UtteranceDataHandle {
3939
std::string utt;
4040
WaveData wave_data_in;
@@ -205,7 +205,7 @@ int main(int argc, char *argv[]) {
205205

206206
// This binary is pipelined to allow concurrent memory copies and compute.
207207
// State exists for each pipeline and successive chunks go to different
208-
// pipelines in a modular fasion. The calling thread will synchronize with
208+
// pipelines in a modular fashion. The calling thread will synchronize with
209209
// a pipeline prior to launching work in that pipeline. 2 should be enough
210210
// to get concurrency on current hardware.
211211
const int num_pipelines = 3;

0 commit comments

Comments
 (0)