-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisualizar.py
94 lines (80 loc) · 2.5 KB
/
visualizar.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# import visualizar
# from importlib import reload
# reload(sys.modules['visualizar'])
#TODO: internacionalizar labels (estilo, contenido, etc)
import numpy as np
import matplotlib.pyplot as plt
import librosa
import librosa.display
#####################
#numpy plot
#####################
def espectrograma(a_content, title, MAX_FREC_BINS=1000):
plt.figure(figsize=(10,5))
plt.subplot(1,2,1)
plt.title(title)
plt.imshow(a_content[:MAX_FREC_BINS,:], origin='lower')
plt.show()
#()
def comparar_2_espectrogramas(a_content, a_style, MAX_FREC_BINS=1000):
plt.figure(figsize=(10,5))
plt.subplot(1,2,1)
plt.title('Contenido')
# plt.title('Content')
plt.imshow(a_content[:MAX_FREC_BINS,:], origin='lower')
plt.subplot(1,2,2)
plt.title('Estilo')
plt.imshow(a_style[:MAX_FREC_BINS,:], origin='lower')
plt.show()
#()
def comparar_3_espectrogramas(a_content, a_style, a, MAX_FREC_BINS=1000):
plt.figure(figsize=(15,5))
plt.subplot(1,3,1)
# plt.title('Content') #TODO: internacionalizar
plt.title('Contenido')
plt.imshow(a_content[:MAX_FREC_BINS,:], origin='lower')
plt.subplot(1,3,2)
# plt.title('Style')
plt.title('Estilo')
plt.imshow(a_style[:MAX_FREC_BINS,:], origin='lower')
plt.subplot(1,3,3)
plt.title('Resultado')
#plt.title('Result')
plt.imshow(a[:MAX_FREC_BINS,:], origin='lower')
plt.show()
#()
##################
# librosa dependecy
#################
def espectrograma_grande(filename, title):
x, sr = librosa.load(filename)
X = librosa.stft(x)
Xdb = librosa.amplitude_to_db(abs(X))
plt.figure(figsize=(14, 5))
plt.title(title)
librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')
#()
def comparar_espectrogramas_grande(filename1, title1, filename2, title2):
x, sr = librosa.load(filename1)
X = librosa.stft(x)
X_content_db = librosa.amplitude_to_db(abs(X))
#plt.figure(figsize=(14, 5))
x, sr = librosa.load(filename2)
X = librosa.stft(x)
X_style_db = librosa.amplitude_to_db(abs(X))
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.title(title1)
librosa.display.specshow(X_content_db, sr=sr, x_axis='time', y_axis='hz')
plt.subplot(1, 2, 2)
plt.title(title2)
librosa.display.specshow(X_style_db, sr=sr, x_axis='time', y_axis='hz')
plt.show()
#()
def plot_time_signal_from_array(x,sr,title):
plt.figure(figsize=(14, 5))
librosa.display.waveplot(x, sr=sr)
plt.title(title)
#()