Bhavay_Malhotra:

I want to convert each spectrogram into a file and add into my directory for train and test and further create a ImageDataGenerator to load the images inside my model. Any ideas how can I convert my spectrogram to an Image file to store it in a directory ?


Assuming you don’t mind using Librosa and matplotlib, which can be awesome for audio pipelines, maybe you could try what this user (a researcher) did here https://github.com/librosa/librosa/issues/1313#issuecomment-833521645 4. First, it appears that they encode the audio waveforms into (mel) spectrograms (before using them as inputs for the network), which can be done with Librosa, for example with librosa.feature.melspectrogram . Then, it looks like they use librosa.display.specshow (API doc) and matplotlib.pyplot.savefig (API doc 2) to display and save each figure.
Alternatively, check out these answers on StackOverflow: audio - Store the Spectrogram as Image in Python - Stack Overflow 4 (with Librosa, matplotlib) and python - How can I save a Librosa spectrogram plot as a specific sized image? - Stack Overflow 4 (with Librosa,  skimage.io).
Finally, there are a couple of proposals on Kaggle that you may find useful: Converting sounds into images: a general guide | Kaggle 3. The 1st one uses Librosa, while the 2nd one utilizes the fastai library.
Other potentially useful resources:

SpecAugment, with the LibriSpeech dataset: Google AI Blog: SpecAugment: A New Data Augmentation Method for Automatic Speech Recognition 2.
How to Extract Spectrograms from Audio with Python - YouTube 2
https://github.com/musikalkemist/DeepLearningForAudioWithPython
https://github.com/musikalkemist/AudioSignalProcessingForML
And more:


  
    
    
    Deep Learning for signal processing problem Research & Models
  
  
    For learning about waveform/signal processing, you could start with the Sound of AI channel that teaches signal processing with Python and deep learning for audio with TensorFlow and Librosa. Some hands-on examples (in separate playlists): 


16- How to Implement a CNN for Music Genre Classification - YouTube 


How to Implement Autoencoders in Python and Keras || The Encoder - YouTube 


How to Extract Spectrograms from Audio with Python - YouTube 


GitHub repos by the same person: 


GitHub -…