PythonAudioEffects icon indicating copy to clipboard operation
PythonAudioEffects copied to clipboard

IndexError: invalid index to scalar variable.

Open AlexMnatsakanian opened this issue 3 years ago • 1 comments

output_audio.append((e[0] / 2) + (e[1] / 2)) Im not sure what this does? ii keep getting this error

AlexMnatsakanian avatar Mar 24 '21 04:03 AlexMnatsakanian

Hi, The code you are referencing comes from the method convert_to_mono_audio(input_audio) This method is used by the class Processing to normalized data sample when instantiating the sound objects, please have a look at the source code and

__init__() 

The method discuss above is used to convert stereophonic sound (2 channels) into a monophonic sound Also it will divide every sound samples by 2 such as

for e in temp_audio:
    output_audio.append((e[0] / 2) + (e[1] / 2))

The error you are getting mean that the object e is not what is supposed to be. In the example above "e" must be a python list a buffer or a numpy.array containing the data samples, if this is not the case an exception will be raised (IndexError: invalid index to scalar variable), scalar means that the value is most likely to be an integer or a float. Now, to explain your issue, I would suggest to check what is e in your scenario by adding an extra line to the source code such as

for e in temp_audio:
    print(type(e))
    output_audio.append((e[0] / 2) + (e[1] / 2))

I am strongly suspecting that the object input_audio passed to the method convert_to_mono_audio(input_audio) is not a numpy.array or a python list or any sort of data samples. for reference :

    scipy.io.wavfile.read(filename, mmap=False)[source]
    # Return the sample rate (in samples/sec) and data from a WAV file
    # Returns: | rate : intSample rate of wav filedata : numpy arrayData read from wav file

Your file is most likely to be invalid (try a WAV file instead)

yoyoberenguer avatar Mar 26 '21 09:03 yoyoberenguer