I'm working on machine learning model and tried to downsample WAV files with Python script, but it didn't work, so I made the simple version - script "resamples" WAV file from 44100Hz to the same 44100Hz sample rate. Original and output files seems identical while listening to, they are both 16-bit depth, 44100Hz sample rate, output has 1 channel, but I did it for testing purposes and I think shouldn't matter.
However, plot shows minimal differences original vs "resampled" signal:
There is my whole code:
def calculate_differences_between_arrays(arr1, arr2):
differences = []
for val1, val2 in zip(arr1, arr2):
diff = val1 - val2
differences.append(diff)
return differences
def show_plot_for_list(list, header):
plt.plot(list)
plt.title(header)
plt.show()
if __name__ == "__main__":
# audio read
origin_sample_rate, origin_audio = wavfile.read('org.wav')
wavfile.write('out_org.wav', origin_sample_rate, origin_audio[:,0])
origin_num_samples, origin_num_channels = origin_audio.shape
# resampling
target_audio_scipy = scipy.signal.resample(origin_audio[:,0], origin_num_samples).astype(int)
target_audio_scipy = np.array(target_audio_scipy, np.int16)
# show differences
diffArray = calculate_differences_between_arrays(origin_audio[:,0], target_audio_scipy)
show_plot_for_list(diffArray, 'Differences')
# write modified audio to WAV file
wavfile.write('out.wav', origin_sample_rate, target_audio_scipy)
Is my script wrong, or it is normal behavior and it won't be problem while downsampling for example to 16000Hz?