```
import os
import argparse
import soundfile as sf
import numpy as np
if __name__ == '__main__':
P = argparse.ArgumentParser()
P.add_argument('-p', action='store', type=float, default=1e-3, help='bit-flip probability')
P.add_argument('track', action='store', help='path to flac|wav file')
args = P.parse_args()
track = args.track
d, fs = sf.read(track, dtype='int16')
# grab 30s of samples, starting from 60s into the song
d = d[fs*60:fs*60 + fs*30:]
p = args.p # probability of a bit-flip
r = np.random.random(d.shape[0]*16)
b = (r <= p).astype('uint8') # array of bit-flip choices for probability p
# sanity chk - should be approximately 'p'
print(f'Sanity check: {p} ~= {np.sum(b) / b.size}')
# work with left channel only, convert signed 16-bit integer array to bit array
lch = d[:, 0]
lch_bits = np.unpackbits(lch.astype('>i2').view('uint8'))
# operate over input bits flipping bits as indicated by 'b'
lch_bf = np.where(b==0, lch_bits, lch_bits ^ 1).astype('uint8')
# check bit patterns - only useful for p >= 0.01
#print(lch_bits[:128], b[:128], lch_bf[:128])
# convert the randomly flipped bit-array back to 16-bit integer values
x = np.packbits(lch_bf).astype('uint16')
z = ((x[0::2] << 8) | x[1::2]).astype('int16')
track_base = ''.join(os.path.basename(track).split('.')[:-1])
suffix = os.path.basename(track).split('.')[-1]
sf.write(f'{track_base}_mono.{suffix}', lch, fs, 'PCM_16')
sf.write(f'{track_base}_mono_{p}.{suffix}', z, fs, 'PCM_16')
```