-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathsplit.py
More file actions
30 lines (24 loc) · 696 Bytes
/
split.py
File metadata and controls
30 lines (24 loc) · 696 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
#/usr/bin/python
import parsemp3
import sys
import os
import math
import tempfile
import subprocess
def main():
file = os.path.abspath(sys.argv[1])
data = parsemp3.parsemp3(sys.argv[1])
print data["duration"]/1000
tracklen = data["duration"]/1000
splits = math.ceil(tracklen/20)
for i in range(splits):
start = i * 20
end = start + 20
print "start",start,"end",end
(fd,outfile)=tempfile.mkstemp(suffix=".wav")
os.close(fd)
args = ["ffmpeg", "-y", "-i", file, "-ac", "1", "-ar", "22050", "-f", "wav", "-t", "20", "-ss", "%d" %start, outfile]
subprocess.call(args, stderr=open("/dev/null", "w"))
os.rename(outfile, "data/%d.wav" %start)
if __name__=="__main__":
main()