librosa无法打开librosa创建的.wav? [英] librosa can't open .wav created by librosa?

查看:562
本文介绍了librosa无法打开librosa创建的.wav?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用librosa通过从60秒持续时间的某些.wav文件中剪切1s片段来生成一些数据.

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

这部分有效,我创建了所有文件,也可以通过任何播放器收听它们,但是如果我尝试使用librosa.load打开它们,则会收到此错误:

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

您有什么建议吗?我使用以下功能创建file.wav:

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)

问题仅在librosa创建的文件中出现,librosa.load已与其他文件一起使用,完全没有问题.

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

推荐答案

我解决了这个问题,Librosa按原样输出值,在我的例子中是np.array,其中float32但每个值的标准是16位,因此更改该类型可以解决问题:

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)

这篇关于librosa无法打开librosa创建的.wav?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆