我想使用librosa读取多个音频文件,然后将其保存到一个空列表中 [英] I want to read multiple audio files with librosa and then save it into an empty list

查看:87
本文介绍了我想使用librosa读取多个音频文件,然后将其保存到一个空列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我的代码.当我追加到数组中时,数组保持为空.请帮助我,错误在哪里.或告诉我其他方法也可以这样做

Here id my code . when I append into the array the array remain empty . Please help me where is the mistake. Or tell me some other way also to do this

A = [] 
# load more files with librosa
pathAudio = "drive/My Drive/dataset/noise/"
files = librosa.util.find_files(pathAudio, ext=['wav']) 
files = np.asarray(files)
for y in files: 
    data, sr = librosa.load(y)
    ps = librosa.feature.melspectrogram(y= data, sr=sr)   
    if ps.shape != (128, 128): continue
    A.append((ps, y.files))

我检查了 ps.shape 的输出是(128,427).我认为它必须保存在该数组中

I checked the ps.shape the output was (128,427). I think it has to save in that array

我还检查了 y.files 输出是*** AttributeError:'numpy.str_'对象没有属性'files'

I also checked y.files the output was *** AttributeError: 'numpy.str_' object has no attribute 'files'

推荐答案

我找出错误所在,这是答案.

I sort out what was the error, Here is the answer.

A = [] 
# load more files with librosa
pathAudio = "drive/My Drive/dataset/noise/"
files = librosa.util.find_files(pathAudio, ext=['wav']) 
files = np.asarray(files)
for y in files: 
    data, sr = librosa.load(y)
    ps = librosa.feature.melspectrogram(y= data, sr=sr)   
    if ps.shape != (128, 128):
      A.append((ps, y))

这篇关于我想使用librosa读取多个音频文件,然后将其保存到一个空列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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