简体   繁体   English

使用 librosa 时出现“无后端错误”

[英]“No Backend Error ” while working with librosa

    file = open('data.csv', 'w', newline='')
with file:
    writer = csv.writer(file)
    writer.writerow(header)
genres = 'blues classical country disco hiphop jazz metal pop reggae rock'.split()
for g in genres:
    for filename in os.listdir(f'./genres/{g}'):
        songname = f'./genres/{g}/{filename}'
        y, sr = librosa.load(songname, mono=True, duration=30)
        chroma_stft = librosa.feature.chroma_stft(y=y, sr=sr)
        rmse = librosa.feature.rmse(y=y)
        spec_cent = librosa.feature.spectral_centroid(y=y, sr=sr)
        spec_bw = librosa.feature.spectral_bandwidth(y=y, sr=sr)
        rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)
        zcr = librosa.feature.zero_crossing_rate(y)
        mfcc = librosa.feature.mfcc(y=y, sr=sr)
        to_append = f'{filename} {np.mean(chroma_stft)} {np.mean(rmse)} {np.mean(spec_cent)} {np.mean(spec_bw)} {np.mean(rolloff)} {np.mean(zcr)}'    
        for e in mfcc:
            to_append += f' {np.mean(e)}'
        to_append += f' {g}'
        file = open('data.csv', 'a', newline='')
        with file:
            writer = csv.writer(file)
            writer.writerow(to_append.split())

By excuting this code gives me no backend error.通过执行此代码没有给我后端错误。 I have tried installing ffmpeg.我试过安装 ffmpeg。 But it was not solved and the error is as follows但是没有解决,报错如下

NoBackendError                            Traceback (most recent call last)
<ipython-input-14-0137cee5a3ad> in <module>
      7     for filename in os.listdir(f'./genres/{g}'):
      8         songname = f'./genres/{g}/{filename}'
----> 9         y, sr = librosa.load(songname, mono=True, duration=30)
     10         chroma_stft = librosa.feature.chroma_stft(y=y, sr=sr)
     11         rmse = librosa.feature.rmse(y=y)

~\anaconda3\envs\tensorflow\lib\site-packages\librosa\core\audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    110 
    111     y = []
--> 112     with audioread.audio_open(os.path.realpath(path)) as input_file:
    113         sr_native = input_file.samplerate
    114         n_channels = input_file.channels

~\anaconda3\envs\tensorflow\lib\site-packages\audioread\__init__.py in audio_open(path, backends)
    114 
    115     # All backends failed!
--> 116     raise NoBackendError()

NoBackendError: 

How to solve this error?如何解决这个错误? I have even tried installing ffmeg but the issue is not solved.我什至尝试安装ffmeg,但问题没有解决。 Is there any additional packages to install?是否有任何额外的软件包要安装?

I'm facing the same error too.我也面临同样的错误。 Just for importing the audio files, you can use:仅用于导入音频文件,您可以使用:

import scipy.io as sio

samplerate, data = sio.wavfile.read(location_of_file)

Then you can use librosa for feature extraction然后你可以使用 librosa 进行特征提取

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM