2021-11-23 00:16:39 +00:00
|
|
|
import librosa
|
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
|
def plot_spectrogram(spec, title=None, ylabel="freq_bin", aspect="auto", xmax=None):
|
|
|
|
fig, axs = plt.subplots(1, 1)
|
|
|
|
axs.set_title(title or "Spectrogram (db)")
|
|
|
|
axs.set_ylabel(ylabel)
|
|
|
|
axs.set_xlabel("frame")
|
|
|
|
im = axs.imshow(librosa.power_to_db(spec), origin="lower", aspect=aspect)
|
|
|
|
if xmax:
|
|
|
|
axs.set_xlim((0, xmax))
|
|
|
|
fig.colorbar(im, ax=axs)
|
2023-03-21 15:39:28 +00:00
|
|
|
plt.show(block=False)
|