0

I have around 5000 audio samples and have make spectrogram of each and save as image. I already know how to make spectrogram with librosa, dispaly it and save in proper image. But every time before save image it despayes. Make this with all 5000 samples is not a good idea. Is it possible to save image without displaing it?

import numpy as np
import librosa
import librosa.display
import matplotlib.pyplot as plt

f_name = # path to current file
path = # path where to save result

X, s_rate = librosa.load(f_name, res_type='kaiser_fast', duration=4.0)

mfc = librosa.feature.melspectrogram(y=X, sr=s_rate)
ch = librosa.feature.chroma_stft(y=X, sr=s_rate)
sc = librosa.feature.spectral_contrast(y=X, sr=s_rate)
tz = librosa.feature.tonnetz(y=X, sr=s_rate)

small_MFCC = np.concatenate([mfc, ch, sc, tz], axis=0)
librosa.display.specshow(small_MFCC)
plt.savefig(path, bbox_inches="tight", pad_inches=0.0)

2 Answers2

0

The best is to not use plotting just to save a spectrogram/cepstrum as an image. For that, see this post: How can I save a Librosa spectrogram plot as a specific sized image?

Jon Nordby
  • 5,494
  • 1
  • 21
  • 50
0

Define an out_dir and use this command to save file.

      plt.savefig(os.path.join(out_dir,folder,'spec{:04}.jpg'.format(i)))```
poorna
  • 61
  • 1
  • 9
  • https://stackoverflow.com/questions/71525231/saving-generated-spectrogram-image-data-into-a-directory-as-jpeg-files-in-google this link may help – poorna Mar 22 '22 at 05:51