From ef2e3cfd3bf3c6d3226fb285b9a8597f0fe63463 Mon Sep 17 00:00:00 2001 From: git-pixel22 Date: Thu, 16 Nov 2023 22:17:45 +0530 Subject: [PATCH 1/2] Fix: Resolve 'ModuleNotFoundError: No module named 'AudioLib'' issue --- tests/effects.py | 3 +++ tests/processing.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/tests/effects.py b/tests/effects.py index 7808d6a..1e2726a 100644 --- a/tests/effects.py +++ b/tests/effects.py @@ -7,6 +7,9 @@ Note : Please change the code below to fit your needs. ''' +import sys +sys.path.append('/PythonAudioEffects') +# EXAMPLE: In my case it was, sys.path.append('/home/pixel22/Projects/PythonAudioEffects') from AudioLib import AudioEffect input_file_path = 'input.wav' diff --git a/tests/processing.py b/tests/processing.py index 6a48685..1127ab0 100644 --- a/tests/processing.py +++ b/tests/processing.py @@ -7,6 +7,10 @@ Note : Please change the code below to fit your needs. ''' +import sys +sys.path.append('/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') From d7cd8f079320187b9561bb9b9363102eaa333dee Mon Sep 17 00:00:00 2001 From: git-pixel22 Date: Thu, 16 Nov 2023 22:23:44 +0530 Subject: [PATCH 2/2] Fix IndexError: Resolved invalid index assignment causing scalar variable error --- AudioLib/AudioProcessing.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/AudioLib/AudioProcessing.py b/AudioLib/AudioProcessing.py index 87d2c25..00fb82c 100644 --- a/AudioLib/AudioProcessing.py +++ b/AudioLib/AudioProcessing.py @@ -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