librosa 解决No Backends 问题

问题的原因:librosa不能直接读mp3文件,需要用audioread

解决过程:

1.找到问题 显示异常类型

try:
        [id, audio_file, audio_repr_file] = files[index]
        if not os.path.exists(audio_repr_file[:audio_repr_file.rfind('/') + 1]):
            path = Path(audio_repr_file[:audio_repr_file.rfind('/') + 1])
            path.mkdir(parents=True, exist_ok=True)
        # compute audio representation (pre-processing)
        length = compute_audio_repr(audio_file, audio_repr_file)
        # index.tsv writing
        fw = open(config_file.DATA_FOLDER + config['audio_representation_folder'] + "index_" + str(config['machine_i']) + ".tsv", "a")
        fw.write("%s\t%s\t%s\n" % (id, audio_repr_file[len(config_file.DATA_FOLDER):], audio_file[len(config_file.DATA_FOLDER):]))
        fw.close()
        print(str(index) + '/' + str(len(files)) + ' Computed: %s' % audio_file)

    except Exception as e:
        ferrors = open(config_file.DATA_FOLDER + config['audio_representation_folder'] + "errors" + str(config['machine_i']) + ".txt", "a")
        ferrors.write(audio_file + "\n")
        ferrors.write(str(e))
        ferrors.close()
        print('Error computing audio representation: ', audio_file)
        print(str(e))
        print(e.__class__.__name__) #显示异常类型

2.报出No Backends错误

3.解决

3.1 librosa读取mp3文件需要借助ffmpeg

先直接直接输入:

ffmpeg

看是否正常运行或者存在什么问题

出现下面的代码,说明安装成功;如果没有的话,说明安装错误

 3.2 重新安装

conda install ffmpeg -c conda-forge

安装成功后,还需要添加路径

3.3 添加路径

which ffmpeg找到安装的位置
 

ffmpeg: /home/yourlocation/anaconda3/bin/ffmpeg

cd进入audioread的文件夹,一般在你的虚拟环境里
 

cd /home/ubuntu/miniconda3/envs/pytorch_cpu/lib/python3.5/site-packages/audioread

找到ffdec.py文件, 发现在ffdec.py 33行

COMMANDS = ('ffmpeg', 'avconv')

33行改成:换成ffmpeg的安装位置

COMMANDS = ('/home/yourlocation/anaconda3/bin/ffmpeg', 'avconv')

再运行代码,就成功了!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值