1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| import struct import array
with open('snake.wav', 'rb') as fr, open('snake_copy.wav', 'wb') as fw: info = fr.read(44) print(struct.unpack('h', info[22:24])) print(struct.unpack('i', info[24:28])) fr.seek(0, 2) loc = fr.tell() n = int((loc - 44) / 2) buf = array.array('h', (0 for _ in range(n))) fr.seek(44) fr.readinto(buf) for i in range(n): buf[i] = int(buf[i] / 8)
fw.write(info) buf.tofile(fw)
|