-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_with_librosa.py
71 lines (53 loc) · 1.62 KB
/
plot_with_librosa.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
Display sound signals with librosa
"""
import matplotlib.pyplot as plt
import librosa
import librosa.display as disp
# shift the pitch
y_sh = librosa.effects.pitch_shift(y, sr, n_steps=-6)
def plotWave(y, sr, y_shifted):
gray = '#57506D'
yellow = "#FFC726"
plt.figure()
plt.subplot(2, 1, 1)
disp.waveplot(y, sr=sr, color=gray)
plt.title('Monophonic waveplot')
plt.subplot(2, 1, 2)
disp.waveplot(y, sr=sr)
disp.waveplot(y_shifted, sr=sr, color=yellow)
plt.title('Stereo')
plt.show()
def plotHarmPers(y, sr, y_shifted):
y_harm, y_perc = librosa.effects.hpss(y)
plt.subplot(2, 1, 1)
disp.waveplot(y_harm, sr=sr, alpha=0.25)
disp.waveplot(y_perc, sr=sr, color='r', alpha=0.5)
plt.title('Harmonic + Percussive')
plt.subplot(2, 1, 2)
y_harm_sh, y_perc_sh = librosa.effects.hpss(y)
disp.waveplot(y_harm_sh, sr=sr, alpha=0.25)
disp.waveplot(y_perc_sh, sr=sr, color='r', alpha=0.5)
plt.title('Harmonic + Percussive (shifted)')
plt.tight_layout()
plt.show()
def plotSpec(y, sr):
plt.figure()
yD = librosa.stft(y, n_fft=sr)
disp.specshow(librosa.amplitude_to_db(yD), y_axis='log', x_axis='time')
plt.title('Power Spectrogram')
plt.show()
def plotChroma(y, sr):
plt.figure()
cD = librosa.feature.chroma_stft(y, n_fft=sr)
disp.specshow(cD, y_axis='chroma', x_axis='time')
plt.title('Chromatograph')
plt.show()
def main():
y, sr = librosa.load("input_records/Iza10.wav")
plotWave(y, sr, y_sh)
# plotHarmPers(y, sr, y_sh)
# plotSpec(y, sr)
# plotChroma(y, sr)
if __name__ == "__main__":
main()