-2

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'

Faiza
  • 1
  • 5
  • Have you tried to debug your code? [There appears to have been no effort to debug the code.](http://idownvotedbecau.se/nodebugging/) Please [edit] your question to include the details of what you’ve found. You should also answer the [questions given by Xxxo](https://stackoverflow.com/a/62383765/711006). – Melebius Jun 15 '20 at 08:01
  • I debug the code and the problem in last line `y.files` giving error _'numpy.str' object has no attribute 'files'_ – Faiza Jun 15 '20 at 08:39
  • 1
    @Faiza, no, you did not debug the code. You just run the code and you report the error. You should check what debugging is. – Xxxo Jun 15 '20 at 11:26

2 Answers2

0

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?

Xxxo
  • 1,784
  • 1
  • 15
  • 24
0

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))
Faiza
  • 1
  • 5