I have loaded the 1 second audio files in a tensor format and most of them have the [1,22050] tensor size. But several audio files have smaller sizes such as [1,3042] and I want to get rid of them. How to make filter during loading the audio files in a custom dataset?
here is my code:
data_waveform, rate_of_sample = torchaudio.load(audio_file)
if data_waveform.shape ==[1,22050]:
sound_data = data_waveform
else:
pass
sample = {'audio_file': sound_data, 'labels': label}
if self.transform:
sample = self.transform(sample)
return sample
But I am getting the error message such as "UnboundLocalError: local variable 'sound_data' referenced before assignment". How to create tensor size checker for loading only correct sized tensors?