Getting: Input signal length=0 is too small to resample from 8000->22050

4,080 views
Skip to first unread message

Eugene Gordon

unread,
Aug 12, 2020, 1:12:17 AM8/12/20
to librosa
Hi All,

We have small (5 sec) 8000hz sample rate wav files. librosa loads files using default value for sr. For some files load happens without error, but for some files 
we get:
librosa/core/audio.py", line 547, in resample y_hat = resampy.resample(y, orig_sr, target_sr, filter=res_type, axis=-1) 
 File resampy/core.py, line 98, in resample 'resample from {}->{}'.format(x.shape[axis], sr_orig, sr_new)) 
ValueError: Input signal length=0 is too small to resample from 8000->22050

For those problematic files we tried to load them using sr=8000 to avoid resampling but
we getting: 
 can't extend empty axis 0 using modes other than 'constant' or 'empty'
looks like message is coming from numpy used by librosa.

Any hints what could be wrong with wav files?

Thank you,
Eugene

tob...@gmail.com

unread,
Aug 12, 2020, 3:29:49 PM8/12/20
to librosa
Hey, out of curiosity, do you mind uploading one of the files that it's failing on? :-)

I guess you're sure that the audio file in question is actually 5 sec? What happens if you put sr=None? (Remember, default sr is 22050 I believe, so if you wanna force no resampling, set sr to None).
I have no experience with this, to back the ideas up, I'm just curious as to whether it might work :-)

Eugene Gordon

unread,
Aug 13, 2020, 9:46:38 PM8/13/20
to librosa
Changing sr=None doesn't help.
Sure - I attached the sample trouble file.

Thanks
test-5sec.wav

tob...@gmail.com

unread,
Aug 14, 2020, 11:41:02 AM8/14/20
to librosa
Okay, so here's what I did.

I started by trying to play the file. Sure enough, it played and I could hear the voice.

I then opened it in audacity, a lightweight but powerful open source (I believe) audio editor. Now here things got strange. There was no sound waves! And I couldn't play any audio.

So I thought the info in the file must be corrupt somehow. But doing an internet search, I found the answer.

It's because the audio file in question is actually not a wav file (my theory). If I changed the extension to .mp3 and opened it in audacity again, suddenly there was a sound wave!

So.. if you REALLY want those samples included.. I would maybe do a try, except when loading the files -- and if the problem occurs.. You'd have to rename the extension through python and then open it again.

Maybe there's another way to do it, but then someone else has to chip in.

:-)

tob...@gmail.com

unread,
Aug 14, 2020, 12:09:18 PM8/14/20
to librosa
Okay, so it's not that simple I see.

I just tried to rename the file and then open it in Librosa but the error still comes. In the metadata of the file, it still says that it's a wav file, made with wav codecs etc.

If I re-export it in Audacity AS a mp3, then I can load it in Librosa.

So... Yeah, either skip them or if you really need to include them, find out how it loads the data without looking at the metadata for file format or whatever... Or maybe there's nothing you can do because the file format is just screwed.

:-)

tob...@gmail.com

unread,
Aug 14, 2020, 12:32:37 PM8/14/20
to librosa

I couldn't get pydub to work, even with ffmpeg and I haven't tried the lame option they're mentioning although I'm sure it works, but if you have ffmpeg installed you could also do (as an example):

input = '/path/myfile.wav'
output ='path/myfile.mp3'
sr = ???
bitrate = ???
cmd = 'ffmpeg -i {} -vn -ar {} -ac 2 -b:a {}k {}'.format(input, sr, bitrate, output)
subprocess.call(cmd, shell=True)


.. and then load it. But you'd have to make sure that the subprocess was done, before trying to load. Maybe a for loop checking for the existence of the mp3 file or something?

Of course, it would be nicer if we could force librosa (or audiofile, or any other audio loader) to load the wav file as if it was an mp3 file (if that is really the case).



Hope all this helps! Back to writing project on genre classification :D

Evgueni Gordienko

unread,
Aug 14, 2020, 3:57:31 PM8/14/20
to librosa
Thanks for the recoding/reformatting hint - will try it out.
Reply all
Reply to author
Forward
0 new messages