0

I need to produce a number of consistent music samples. Having 1 second long wave with sample rate 44100, I should be able to get an array of exactly 44100 samples. Unfortunatelly, this is not true.

My approach is the following:

1) Produce output.wav, which is 1 second long with sample rate 44100

avconv -i input.mp3 -ss 00:01:00 -t 00:00:01 -ar 44100 -ac 1 output.wav

2) I read the file and print the number of samples

meta,song  = scipy.io.wavfile.read(path + "/" +file)
assert meta == 44100
print(len(song))

For different choices of input.mp3 and starting position I get different numbers: 43776, 43776, 44928, 43776, 43776, 44928

My question is, why is that the case? and how can I change the step 1, to produce consistent data samples?

1 Answers1

0

The avconv is not very precize. The song fragment which is supposed to have one sec, acctually has 0.983991 sec.

To solve the problem we might use sox:

sox input.mp3 -r 44100 -c 1 output.wav  --show-progress trim 0 00:01

sox does not support mp3 in default, so I had to install

sudo apt-get install libsox-fmt-mp3