Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

python - I want to read multiple audio files with librosa and then save it into an empty list

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))

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The initial guess is that the shape of the MEL weighted spectrogram is not (128,128).

But the question is really really really really not giving any relevant information in order for someone to understand what is happening. For example, are all files of same duration? Then, what is the duration of the files?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...