15 lines
448 B
Python
15 lines
448 B
Python
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)
|
|
plt.show(block=False)
|