Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: invalid index to scalar variable. #5

Open
AlexMnatsakanian opened this issue Mar 24, 2021 · 1 comment · May be fixed by #9
Open

IndexError: invalid index to scalar variable. #5

AlexMnatsakanian opened this issue Mar 24, 2021 · 1 comment · May be fixed by #9

Comments

@AlexMnatsakanian
Copy link

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

@yoyoberenguer
Copy link

yoyoberenguer commented Mar 26, 2021

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants