diff --git a/kaldifeat/python/tests/test_data/run.sh b/kaldifeat/python/tests/test_data/run.sh index 361b657..f081640 100755 --- a/kaldifeat/python/tests/test_data/run.sh +++ b/kaldifeat/python/tests/test_data/run.sh @@ -41,3 +41,9 @@ if [ ! -f test-40-no-snip-edges.txt ]; then compute-fbank-feats --dither=0 --num-mel-bins=40 --snip-edges=0 \ scp:test.scp ark,t:test-40-no-snip-edges.txt fi + +if [ ! -f test-1hour.wav ]; then + # generate a wav of one hour, containing a sine-wave + # swept from 300 Hz to 3300 Hz + sox -n -r 16000 -b 16 test-1hour.wav synth 3600 sine 300-3300 +fi diff --git a/kaldifeat/python/tests/test_fbank.py b/kaldifeat/python/tests/test_fbank.py index 0282230..e18e95d 100755 --- a/kaldifeat/python/tests/test_fbank.py +++ b/kaldifeat/python/tests/test_fbank.py @@ -68,5 +68,41 @@ def test_fbank(): assert torch.allclose(features0[10], feature_frame_10) +def test_benchmark(): + # You have to run ./test_data/run.sh to generate test_data/test-1hour.wav + device = torch.device("cpu") + # device = torch.device('cuda:0') + wave = read_wave("test_data/test-1hour.wav").to(device) + opts = kaldifeat.FbankOptions() + opts.frame_opts.dither = 0 + opts.device = device + opts.mel_opts.num_bins = 80 + + fbank = kaldifeat.Fbank(opts) + + # 1 seconds has 100 frames + chunk_size = 100 * 10 # 10 seconds + audio_frames = fbank.convert_samples_to_frames(wave) + num_chunks = audio_frames.size(0) // chunk_size + + features = [] + for i in range(num_chunks): + start = i * chunk_size + end = start + chunk_size + this_chunk = fbank.compute(audio_frames[start:end]) + features.append(this_chunk) + + if end < audio_frames.size(0): + last_chunk = fbank.compute(audio_frames[end:]) + features.append(last_chunk) + + features = torch.cat(features, dim=0) + + # watch -n 0.2 free -m + # features2 = fbank(wave) + # assert torch.allclose(features, features2) + + if __name__ == "__main__": test_fbank() + # test_benchmark()