sound-cnn icon indicating copy to clipboard operation
sound-cnn copied to clipboard

error

Open b4zz4 opened this issue 7 years ago • 4 comments

python train.py 240 44100 audio/ 1000 150

Traceback (most recent call last): File "train.py", line 20, in classes,trainX,trainYa,valX,valY,testX,testY = util.processAudio(bpm,samplingRate,mypath) File "/home/fuquo/src/sound-cnn/utilities.py", line 22, in processAudio seconds = audData[1][:,1].shape[0]/samplingRate IndexError: too many indices for array

b4zz4 avatar Mar 19 '17 04:03 b4zz4

Were you able to fix it? @b4zz4

StanSilas avatar Dec 15 '17 07:12 StanSilas

no

b4zz4 avatar Dec 15 '17 15:12 b4zz4

Toying with the code a little, I had some similar issues. I managed to fix this yet I don't really get what you did.

Maybe you gave 'audio/' as an input option when you actually have to give a directory with the audio files like 'instruments/guitar/'. I suppose this is what you did since apparently audData[1] seems empty (maybe no audio file was found?).

I also preferred to separate the tuple output of scipy.io.wavfile.read into two variables:

rate, audData = scipy.io.wavfile.read(mypath+audiofile)

then I get the recording rate (44100hz) and the audio data in separate variables and I could rewrite:

seconds = audData[:,1].shape[0]/samplingRate

Don't forget to use // operator instead of / in python3 to get integer outputs from divisions.

Bibobu avatar Feb 06 '18 11:02 Bibobu

audData[1][:,1] implies that the data read is at least 2-dimensional. When I try and see what's going on in there I see a 1D array as the actual audio data. How did this code ever work?

>>> audData
(16000, array([-257, -275, -254, ...,  162,  135,  165], dtype=int16))
>>> rate = audData[0]
>>> audData[1].shape
(20696,)

When I try and remove this "unknown dimension" by replacing audData[1][:,1] with audData[1], I still get the following error:

Traceback (most recent call last):
  File "train.py", line 20, in <module>
    classes,trainX,trainYa,valX,valY,testX,testY = util.processAudio(bpm,samplingRate,mypath)
  File "/mnt/4ADE1465DE144C17/Programming/python/sound-cnn/utilities.py", line 26, in processAudio
    audData = np.reshape(audData[1][0:samples*((seconds*samplingRate)/samples)],[samples,(seconds*samplingRate)/samples])
TypeError: slice indices must be integers or None or have an __index__ method

Because...

>>> samples = audData[1].shape[0]/samplingRate
>>> samples
0
>>> audData = np.reshape(audData[1][0:samples*((seconds*samplingRate)/samples)],[samples,(seconds*samplingRate)/samples])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ZeroDivisionError: integer division or modulo by zero

Which I just don't get how to fix.

mvrozanti avatar Nov 08 '18 14:11 mvrozanti