librosa can't open .wav created by librosa?

2020-07-18 06:42发布

i'm trying to use librosa to generate some data by cutting 1s pieces from some .wav file with a duration of 60s.

This part works, i create all my files and i can also listen to them via any player, but if i try to open them with librosa.load i receive this error:

>>> librosa.load('.\\train\\audio\\silence\\0doing_the_dishes.wav', sr=None)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "C:\Users\gionata\AppData\Local\Programs\Python\Python36\lib\site\packages\librosa\core\audio.py", line 107, in load
with audioread.audio_open(os.path.realpath(path)) as input_file: File "C:\Users\gionata\AppData\Local\Programs\Python\Python36\lib\site-packages\audioread\__init__.py", line 116, in audio_open 
raise NoBackendError()
audioread.NoBackendError

Do you have any suggestion? I create the file.wav with this function:

def create_silence():
    path=DB+"_background_noise_/"
    sounds = [x[len(DB):] for x in glob.glob(path+ '*.wav')]
    for elem in enumerate(sounds):
       sound=elem.split('\\')[1]
       print(sound)
       for j,i in enumerate(np.arange(0.0, 59.0, 0.3)):
           y, sr=librosa.load(DB+elem, sr=None, offset=i, duration=1.0)
           librosa.output.write_wav(DB+'silence/'+str(j)+sound, y, sr=sr, norm=False)

The problem only presents itself with file created by librosa, librosa.load has worked with other files with no problems at all.

5条回答
对你真心纯属浪费
2楼-- · 2020-07-18 07:19

It's about ffmpeg, if you use windows, you can solve this according to here and if you use linux, if can try:

sudo apt-get install libav-tools
查看更多
Explosion°爆炸
3楼-- · 2020-07-18 07:20

I couldn't get 吴连伟's or Gionata's solution to work, however this did the trick:

from scipy.io import wavfile
import scipy
maxv = np.iinfo(np.int16).max
scipy.io.wavfile.write(path, sr, (y*maxv).astype(np.int16))

(Where path is the path and file name, y is the first output from librosa.load, and sr the second output from librosa.load)

This wav-file I could load with librosa in a later stage, so it solved the problem!

查看更多
Anthone
4楼-- · 2020-07-18 07:21
import librosa
audio_path='C:/Users/hp/name.wav' #location 
(xf, sr) = librosa.load(audio_path)

It have worked for me xf=array of sound file,sr=frequency

查看更多
等我变得足够好
5楼-- · 2020-07-18 07:26

libav-tools is deprecated in ubuntu, so

sudo apt-get install ffmpeg 

did the trick

查看更多
倾城 Initia
6楼-- · 2020-07-18 07:34

I solvede this, Librosa outputs the values as they are, in my case the np.array where float32 but the standard is 16 bit for each value, so changing the type does the trick:

def create_silence():
path=DB+"_background_noise_/"
maxv = np.iinfo(np.int16).max
sounds = [x[len(DB):] for x in glob.glob(path+ '*.wav')]
for elem in sounds:
    sound=elem.split('\\')[1]
    print(sound)
    for j,i in enumerate(np.arange(0.0, 59.0, 0.3)):
        y, fs=librosa.load(DB+elem, sr=None, offset=i, duration=1.0, mono=False)
        librosa.output.write_wav(DB+'silence/'+str(j)+sound, y=(y*maxv).astype(np.int16), sr=fs, norm=False)
查看更多
登录 后发表回答