forked from aleksapirot/voiceSeparation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepet.py
More file actions
71 lines (51 loc) · 1.67 KB
/
repet.py
File metadata and controls
71 lines (51 loc) · 1.67 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from common import *
from repet_speedup import *
def autocor(spect):
m = spect.shape[0]
return signal.correlate(spect ** 2, spect ** 2)[m - 1:] / np.arange(m, 0, -1)
# racuna beat spectrum
# moglo bi se prebaciti u cython
def beat(spect):
n = spect.shape[0] // 2 + 1
m = spect.shape[1]
B = np.ndarray((n, m))
for i in range(n):
B[i] = autocor(spect[i])
return bspectrum(B)
# deli spektrogram na periode
def split(spect, period, last=True):
split = np.split(spect, period * np.arange(1, spect.shape[1] // period + 1), axis=1)
if last:
return split
else:
return split[:-1]
# racuna ponavljajuci segment
def segment(spect, period):
return np.median(split(spect, period, last=False), axis=0)
# racuna repeating spectrogram
def repspect(spect, seg):
period = seg.shape[1]
splt = split(spect, period)
W = np.zeros(spect.shape)
for i in range(0, len(splt) - 1):
W[:, i * period:(i + 1) * period] = np.min([spect[:, i * period:(i + 1) * period], seg], axis=0)
x = (len(splt) - 1) * period
W[:, x:] = np.min([spect[:, x:], seg[:, :W.shape[1] - x]], axis=0)
return W
def repet(audio, rate, highpass):
winlen = 1024
f, t, cspect, spect = magspect(audio, rate, winlen=winlen)
#plotspect((f, t, spect))
bt = beat(spect)
#plt.plot(t, bt)
#plt.show()
per = period(bt)
#print(t[per])
#print(per)
seg = segment(spect, per)
# plotspect((f, t[0:per], seg))
rep = repspect(spect, seg)
# plotspect((f, t, rep))
mask = rep / clip(spect)
# plotspect((f, t, msk), maxcoef=1)
return applymask(audio, cspect, 1-mask, winlen, None, highpass, rate)