This is pretty straightforward using wave
, actually.
import wave
data = [128 for i in range(100)] # zeroes
data[50] = 255 # except for one spike
data = bytes(data) # convert to bytes
with open(r'D:\foo.wav', 'wb') as file:
f = wave.open(file)
f.setnchannels(1) # mono
f.setsampwidth(1)
f.setframerate(44100) # standard sample rate
f.writeframes(data)
Here's what the resulting .wav
file looks like in Audacity: image.