import numpy as np from scipy.io import wavfile sample_rate = 8000 seconds = 0.02 time = np.arange(int(sample_rate * seconds)) / sample_rate left = 0.4 * np.sin(2 * np.pi * 440 * time) right = 0.4 * np.sin(2 * np.pi * 660 * time) stereo = np.column_stack((left, right)) pcm = np.round(stereo * np.iinfo(np.int16).max).astype(np.int16) wavfile.write("source.wav", sample_rate, pcm) rate, data = wavfile.read("source.wav") quiet = (data.astype(np.int32) // 2).astype(np.int16) wavfile.write("quiet.wav", rate, quiet) check_rate, check = wavfile.read("quiet.wav") print(f"source rate: {rate}") print(f"source dtype: {data.dtype}") print(f"source shape: {data.shape}") print(f"source sample row 1: {data[1].tolist()}") print(f"written rate: {check_rate}") print(f"written dtype: {check.dtype}") print(f"written shape: {check.shape}") print(f"written sample row 1: {check[1].tolist()}") print(f"amplitude reduced: {np.max(np.abs(check)) < np.max(np.abs(data))}") print(f"round trip exact: {np.array_equal(check, quiet)}")