-
Notifications
You must be signed in to change notification settings - Fork 0
/
pruneSound.py
49 lines (33 loc) · 1.1 KB
/
pruneSound.py
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
40
41
42
43
44
45
46
47
48
49
import aifc
import os
def pruneFile(fileName):
with aifc.open("Piano88KeySounds/{}".format(fileName)) as s:
# print(s.getcompname())
# print(s.getframerate())
# print(s.getnframes())
numOfSeconds = 4
data = s.readframes(numOfSeconds * s.getframerate())
# print(data)
with aifc.open("Piano88KeySoundsCut/{}".format(fileName), mode='wb') as s2:
s2.setparams(s.getparams())
s2.writeframes(data)
print("Pruned file: " + fileName)
def pruneAll(fileNames):
for f in fileNames:
if f[-5:] == ".aiff":
pruneFile(f)
else:
print("Skipping file: " + f)
# print(f[-5:])
def shortenNames(fileNames, path):
# for f in fileNames:
# splitted = f.split(".")
# print(splitted)
# os.rename(path + "/" + f, path + "/" + splitted[2])
for f in fileNames:
os.rename(path + "/" + f, path + "/" + f + ".aiff")
def main():
files = os.listdir("Piano88KeySoundsCut")
# pruneAll(files)
# shortenNames(files, "Piano88KeySoundsCut")
main()