1

I am doing some audio pre-processing to train a ML model.
All the audio files of the dataset are:

RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 16000 Hz.

I am using the following snippet of code to resample the dataset to 8000 Hz:

samples, sample_rate = librosa.load(filename, sr = 16000)
samples = librosa.resample(samples, sample_rate, 8000)

then I use the following snippet to reshape the new samples:

samples.reshape(1,8000,1)

but for some reason, I keep getting the following error: ValueError: cannot reshape array of size 4000 into shape (1,8000,1) but the size differs from a file to another, but it's always less than 8000 HZ (the desired sample rate).

I doubled checked the original sample rate and it was 16000 Hz, I also tried to load the files with a sample rate of 8000, but I had no luck.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Zaid Afaneh
  • 114
  • 1
  • 10
  • 1
    Why do you reshape like that? If your input files are not always 16000 samples long then this code is quite wrong – Jon Nordby Jun 07 '21 at 20:46
  • @JonNordby You are totally right, I was using a Dataset I found online and a code written specifically for this Dataset, I found out in the original code the author filtered the files that are not 16000 samples long, you can say its a beginners mistake I didn't filter them. Thank you. – Zaid Afaneh Jul 06 '21 at 10:49

0 Answers0