from scipy.io import wavfile import numpy as np def main(): samplerate, data = wavfile.read('audio.wav') data = (data.astype(np.float64) - np.min(data)) / (np.max(data) - np.min(data)) data = np.clip(255 * data, 0, 255).astype(np.uint8) data = data[:len(data)//4] with open("audio.h", "w") as f: f.write(f"#define sample_length {len(data)}\n\n") f.write(f"uint8_t samples[{len(data)}] = \n") f.write("{") for d in data[:-1]: f.write(f"0x{d:02x}, ") f.write(f"0x{data[-1]:02x}") f.write("};") if __name__ == "__main__": main()