In [1]:
import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
import librosa
import librosa.display

x, sr = librosa.load("Billy.wav")
S = librosa.stft(x)
fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(np.abs(S),ref=np.max), y_axis='linear', x_axis='time', ax=ax)
ax.set_title('Power spectrogram')
fig.colorbar(img, ax=ax, format="%+2.0f dB")
ipd.Audio(x, rate=sr)
Out[1]:
In [2]:
f = np.arange(S.shape[0])
t = np.arange(S.shape[1])
A = np.exp(-t[None, :]*f[:, None]/(100*S.shape[1]))
librosa.display.specshow(A, y_axis='linear', x_axis='time')
Out[2]:
<matplotlib.collections.QuadMesh at 0x7ff0aa608d90>
In [3]:
SNew = S*A
fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(np.abs(SNew),ref=np.max), y_axis='linear', x_axis='time', ax=ax)
ax.set_title('Power spectrogram')
fig.colorbar(img, ax=ax, format="%+2.0f dB")
Out[3]:
<matplotlib.colorbar.Colorbar at 0x7ff0ab2ce7d0>
In [4]:
y = librosa.istft(SNew)
ipd.Audio(y, rate=sr)
Out[4]:
In [ ]: