1

I use the Librosa library to load and resamples the list of audio files. My code -

for folder in os.listdir(dir):
    print(os.path.join(dir, folder))
    for file in os.listdir(os.path.join(dir, folder)):
        if file.endswith("wav"):
            labels.append(str(folder))
            data, sampling_rate = librosa.load(os.path.join(dir, folder, file))
            samples = librosa.core.resample(data, sampling_rate, 15000)
            audio.append(samples)

    else:
        continue

The sampling_rate when load the audio is default = 22050.

When feeding all these audios to machine learning, it throws the "ValueError: setting an array element with a sequence". Then, I found out that some of the audio files are not in the same size. Most of the audio files having the size = 450200. But the rest of them having 455565.

All audios are having the same length of duration.

But, resampling all the audios, does not have the same size of data. Why it happen...

Any suggestion to make all audio files in the same size of data, that machine learning model run successfully...

EDIT:

Using this function -

librosa.util.fix_length(y, 450200, mode='edge')

Makes the audio to delete the last 5365 values, only from the audio's having the size of 455565. But I think 5365 values are use full for machine learning. I already downsampled the audio.

0 Answers0