mirror of
https://github.com/csukuangfj/kaldifeat.git
synced 2025-08-09 18:12:17 +00:00
Add benchmark code for a 1-hour sound file.
This commit is contained in:
parent
5471c6a1f3
commit
dc5ea15084
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user