I have a speech dataset and wanted to extract spectrogram/chromogram images as jpeg in google drive. The code snippet I am saving here saves only the last image. I have seen that librosa library gives only bgr images. Can someone help me in resolving this issue?
import os, glob
from PIL import Image, ImageOps
import matplotlib.pyplot as plt
def load_data():
X,y=[],[]
count = 0
for file in glob.glob("/content/drive/My Drive/rand/data/Actor_*//*.wav"):
file_name=os.path.basename(file)
#src_fname, ext = file_name.splitext(x)
emotion=emotions[file_name.split("-")[2]]
chromagram = feature_chromagram(waveform, sample_rate)
librosa.display.specshow(chromagram, y_axis='chroma', x_axis='time')
fig = plt.Figure()
save_fname = os.path.join(PATH, os.path.basename(emotion)+'.tif')
#im.save(save_fname)
fig.savefig(save_fname)
features = get_features(file)
X.append(features)
#y.append(emotion)
count += 1
# '\r' + end='' results in printing over same line
print('\r' + f' Processed {count}/{1440} audio samples',end=' ')
# Return arrays to plug into sklearn's cross-validation algorithms
return np.array(X), np.array(y) ```
modify this line as
plt.savefig(os.path.join(out_dir,folder,'chroma{:04}.jpg'.format(i)))