Skip to content

Commit

Permalink
Update compute_cmvn_stats.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mlxu995 authored Jan 26, 2025
1 parent 5a14b35 commit badc510
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tools/compute_cmvn_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import torchaudio.compliance.kaldi as kaldi
from torch.utils.data import Dataset, DataLoader

torchaudio.set_audio_backend("sox_io")


class CollateFunc(object):
''' Collate function for AudioDataset
Expand All @@ -32,18 +30,19 @@ def __call__(self, batch):
value = item[1].strip().split(",")
assert len(value) == 3 or len(value) == 1
wav_path = value[0]
sample_rate = torchaudio.backend.sox_io_backend.info(
wav_path).sample_rate
sample_rate = torchaudio.info(wav_path,
backend='sox').sample_rate
resample_rate = sample_rate
# len(value) == 3 means segmented wav.scp,
# len(value) == 1 means original wav.scp
if len(value) == 3:
start_frame = int(float(value[1]) * sample_rate)
end_frame = int(float(value[2]) * sample_rate)
waveform, sample_rate = torchaudio.backend.sox_io_backend.load(
waveform, sample_rate = torchaudio.load(
filepath=wav_path,
num_frames=end_frame - start_frame,
frame_offset=start_frame)
frame_offset=start_frame,
backend='sox')
else:
waveform, sample_rate = torchaudio.load(item[1])

Expand Down

0 comments on commit badc510

Please sign in to comment.