I need to plot a spectrogram fast as possible. The spectrogram is calculated with librosa and then ploted with matplotlib. This needs now around 50ms, is it possible to do this faster?
I'm very new to matplotlib and librosa.
This is my code:
mel_spec = lb.melspectrogram(y=samples, sr=44100, fmax=8000, n_mels=256)
plt.figure()
plt.subplots(figsize=(0.5, 5))
librosa.display.specshow(librosa.power_to_db(mel_spec, ref=np.max), fmax=8000)
plt.axis('off')
plt.subplots_adjust(top=1, bottom=0, right=1, left=0, hspace=0, wspace=0)
plt.margins(0, 0)
predict_img = io.BytesIO()
plt.savefig(predict_img, format="jpeg")
predict_img.seek(0)
UPDATE:
More details about the use case.
This images are created with 100ms audio snippets and returned as base64 encoded string, this string is forwarded to a ML model for prediction. I need this setup with the lowest possible latency. I'm fine with the latency of the prediction but the latency of the image creation is a little bit slow.