Omar
Omar

Reputation: 375

ValueError: Input signal length=2 is too small to resample from 44100->16000

I am trying to read some audio wav files and everything was perfect until I added some more audio files I faced an error. The reading audio files and resampling it to 16KHz using the following code

def speech_file_to_array_fn(batch):
    start = 0 
    stop = 20 
    srate = 16_000
    speech_array, sampling_rate = sf.read(batch["file"], start = start * srate , stop = stop * srate)
    batch["speech"] = librosa.resample(np.asarray(speech_array), sampling_rate, srate)
    batch["sampling_rate"] = srate
    batch["parent"] = batch["label"]
    return batch

I am receiving this error:

ValueError: Input signal length=2 is too small to resample from 44100->16000

I tried transposing the audio file after reading it but didn't work

Thanks

Upvotes: 1

Views: 4354

Answers (1)

Rolv Apneseth
Rolv Apneseth

Reputation: 2118

I believe this is discussed in this issue over on the GitHub for librosa.

I've never used the library before but it looks like, from this comment, that in your case you could just do the following:

def speech_file_to_array_fn(batch):
    start = 0 
    stop = 20 
    srate = 16_000
    speech_array, sampling_rate = sf.read(batch["file"], start = start * srate , stop = stop * srate)
    speech_array = speech_array.T
    batch["speech"] = librosa.resample(np.asarray(speech_array), sampling_rate, srate)
    batch["sampling_rate"] = srate
    batch["parent"] = batch["label"]
    return batch

Let me know if this works as I have no way to test it.

Upvotes: 1

Related Questions