Skip to content

Fix: Resolve "IndexError: invalid index to scalar variable" issue #9

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions AudioLib/AudioProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,16 @@ def set_bandpass(self, cutoff_low, cutoff_high, order=5):

@staticmethod
def convert_to_mono_audio(input_audio):
'''Returns a numpy array that represents the mono version of a stereo input'''
output_audio = []
temp_audio = input_audio.astype(float)

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

return np.array(output_audio, dtype = 'int16')
'''Returns a numpy array that represents the mono version of input audio'''
if input_audio.ndim == 1 or input_audio.shape[1] == 1:
# If the input is already mono, return it as is
output_audio = np.array(input_audio, dtype='float32')
elif input_audio.shape[1] == 2:
# If the input is stereo, convert it to mono (average both channels)
output_audio = np.mean(input_audio, axis=1)
else:
# For more than two channels, choose a strategy to handle multi-channel audio
# Here, simply take the first channel and discard the rest
output_audio = input_audio[:, 0]

return output_audio
3 changes: 3 additions & 0 deletions tests/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
Note : Please change the code below to fit your needs.
'''

import sys
sys.path.append('<path>/PythonAudioEffects')
# EXAMPLE: In my case it was, sys.path.append('/home/pixel22/Projects/PythonAudioEffects')
from AudioLib import AudioEffect

input_file_path = 'input.wav'
Expand Down
4 changes: 4 additions & 0 deletions tests/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
Note : Please change the code below to fit your needs.
'''

import sys
sys.path.append('<path>/PythonAudioEffects')
# EXAMPLE: In my case it was, sys.path.append('/home/pixel22/Projects/PythonAudioEffects')
from AudioLib import AudioEffect
from AudioLib.AudioProcessing import AudioProcessing

sound1 = AudioProcessing('input.wav')
Expand Down