An error occurred, when librosa.resample() with the return value of the sf.read().
See original GitHub issueDescription
An error occurred, when resamping with the return value of the sf.read() function. what’s different, between librosa.load() and sf.read(). how can i get it work, when read RAW file.
Steps/Code to Reproduce
I have two sound documents with similar parameters,Need to re-sampling. One is in wav format and the other is in pure raw format.
The raw format cannot be loaded using librosa.load(). Then changed to soundfile.read () read, but when call librosa.resample(), got an error.
I have attached the relevant attachments and documentation. Please help with the science… I check the pcm file ,it can be replayed in AdobeAudition.
Here are the relevant documents. HaveException.zip
Content
import librosa #librosa 0.6.3
import librosa.display
import matplotlib.pyplot as plt #matplotlib 3.1.0
import numpy as np #numpy 1.16.2
import soundfile as sf #PySoundFile 0.9.0.post1
showPictures=True
sourceFileName ="chineseRecord2Stereo.wav"
destFileName="16bitMono16K.wav"
DATA, SR = librosa.load(sourceFileName,sr=48000,mono=False,dtype=np.float32)
# work fine.
sourceFileName = 'Call_streamout.pcm.0.AudioALSAStreamOut.pid400.tid8131_48K2Stero32PCM.pcm'
destFileName="16bitMono16K.wav"
DATA,SR = sf.read(sourceFileName, channels=2, samplerate=48000,dtype=np.float32,
subtype='PCM_32',format="RAW",endian='LITTLE')
# work failed
DATA_16k = librosa.resample(DATA,SR,16000)
DATA_16k_mono=librosa.to_mono(DATA_16k)
sf.write(destFileName, DATA_16k_mono, 16000, subtype='PCM_16')
Expected Results
No Error
Actual Results
Error ValueError: Input signal length=2 is too small to resample from 48000->16000
Versions
import platform; print(platform.platform()) Windows-10-10.0.18362-SP0 import sys; print(“Python”, sys.version) Python 3.6.8 (tags/v3.6.8:3c6b436a57, Dec 24 2018, 00:16:47) [MSC v.1916 64 bit (AMD64)] import numpy; print(“NumPy”, numpy.version) NumPy 1.16.2 import scipy; print(“SciPy”, scipy.version) SciPy 1.3.0 import librosa; print(“librosa”, librosa.version) librosa 0.6.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
Hello @Vladislav2018, from your screenshots it sounds like your array is a 409600x1 matrix and needs to be raveled into a vector https://numpy.org/doc/stable/reference/generated/numpy.ravel.html
Yes probably. Consult the soundfile documentation to see what exactly it expects.