25
25
26
26
import librosa
27
27
import matplotlib .pyplot as plt
28
+ from IPython .display import Audio
28
29
from torchaudio .utils import download_asset
29
30
30
31
######################################################################
@@ -69,11 +70,6 @@ def get_spectrogram(
69
70
return spectrogram (waveform )
70
71
71
72
72
- def plot_spec (ax , spec , title , ylabel = "freq_bin" ):
73
- ax .set_title (title )
74
- ax .imshow (librosa .power_to_db (spec ), origin = "lower" , aspect = "auto" )
75
-
76
-
77
73
######################################################################
78
74
# SpecAugment
79
75
# -----------
@@ -98,11 +94,15 @@ def plot_spec(ax, spec, title, ylabel="freq_bin"):
98
94
spec_12 = stretch (spec , overriding_rate = 1.2 )
99
95
spec_09 = stretch (spec , overriding_rate = 0.9 )
100
96
101
- ######################################################################
102
- #
103
-
104
97
98
+ ######################################################################
99
+ # Visualization
100
+ # ~~~~~~~~~~~~~
105
101
def plot ():
102
+ def plot_spec (ax , spec , title ):
103
+ ax .set_title (title )
104
+ ax .imshow (librosa .amplitude_to_db (spec ), origin = "lower" , aspect = "auto" )
105
+
106
106
fig , axes = plt .subplots (3 , 1 , sharex = True , sharey = True )
107
107
plot_spec (axes [0 ], torch .abs (spec_12 [0 ]), title = "Stretched x1.2" )
108
108
plot_spec (axes [1 ], torch .abs (spec [0 ]), title = "Original" )
@@ -112,6 +112,30 @@ def plot():
112
112
113
113
plot ()
114
114
115
+
116
+ ######################################################################
117
+ # Audio Samples
118
+ # ~~~~~~~~~~~~~
119
+ def preview (spec , rate = 16000 ):
120
+ ispec = T .InverseSpectrogram ()
121
+ waveform = ispec (spec )
122
+
123
+ return Audio (waveform [0 ].numpy ().T , rate = rate )
124
+
125
+
126
+ preview (spec )
127
+
128
+
129
+ ######################################################################
130
+ #
131
+ preview (spec_12 )
132
+
133
+
134
+ ######################################################################
135
+ #
136
+ preview (spec_09 )
137
+
138
+
115
139
######################################################################
116
140
# Time and Frequency Masking
117
141
# --------------------------
@@ -131,6 +155,10 @@ def plot():
131
155
132
156
133
157
def plot ():
158
+ def plot_spec (ax , spec , title ):
159
+ ax .set_title (title )
160
+ ax .imshow (librosa .power_to_db (spec ), origin = "lower" , aspect = "auto" )
161
+
134
162
fig , axes = plt .subplots (3 , 1 , sharex = True , sharey = True )
135
163
plot_spec (axes [0 ], spec [0 ], title = "Original" )
136
164
plot_spec (axes [1 ], time_masked [0 ], title = "Masked along time axis" )
0 commit comments