-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch19.py
More file actions
40 lines (28 loc) · 862 Bytes
/
ch19.py
File metadata and controls
40 lines (28 loc) · 862 Bytes
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
31
32
33
34
35
36
37
38
39
import email
import wave, struct
from pprint import pprint
if __name__ == '__main__':
# f = open('email.dat', 'r')
# email_txt = f.read()
# f.close()
# msg = email.message_from_string(email_txt)
# attach = msg.get_payload()[0]
# f= open(attach.get_filename(), 'wb')
# f.write(attach.get_payload(decode=True))
# f.close()
inp = wave.open('indian.wav', 'r')
out = wave.open('indian-inv.wav', 'w')
length = inp.getnframes()
channels = inp.getnchannels()
print 'length:', length
print 'channels:', channels
out.setnchannels(channels)
out.setnframes(length)
out.setsampwidth(inp.getsampwidth())
out.setframerate(inp.getframerate())
for i in range(0,length):
wavData = inp.readframes(channels)
newdata = struct.pack('>h', *struct.unpack('<h', wavData))
out.writeframes(newdata)
inp.close()
out.close()