-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplicer.py
More file actions
56 lines (47 loc) · 1.27 KB
/
splicer.py
File metadata and controls
56 lines (47 loc) · 1.27 KB
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
50
51
52
53
54
55
56
#!/usr/bin/env python
# encoding: utf=8
import numpy
import time
import os, sys, os.path
import re
import echonest.audio as audio
from echonest.sorting import duration
from echonest.selection import have_pitch_max, overlap_ends_of, overlap_starts_of, fall_on_the
def keysig(audiofile):
return audiofile.analysis.loudness
def main(username):
auds=[]
p = re.compile("mix")
files = os.listdir("f")
for file in files:
m = p.findall(file)
if m:
print "processing f/"+file
try:
auds.append(audio.LocalAudioFile("f/"+file))
except:
print "failed to include "+file
auds.sort(key=keysig)
mixed = []
end = None
previous = None
for aud in auds:
bars = aud.analysis.bars
try:
if end != None and previous != None:
mix = audio.mix(audio.getpieces(previous, [end]), audio.getpieces(aud, [bars[0]]), 0.5)
mixed.append(mix)
else:
mixed.append(audio.getpieces(aud, [bars[0]]))
except:
print "failed to create mix bar"
try:
mixed.append(audio.getpieces(aud, bars[1:-5]))
end = bars[-5]
previous = aud
except:
print "unable to append bars"
out = audio.assemble(mixed, numChannels=2)
out.encode(username+".mp3")
if __name__=='__main__':
main(sys.argv[1])