Ability to save Spectrogram as image
See original GitHub issueIs your feature request related to a problem? Please describe. I am currently working with spectrograms of streaming 2-second clips to perform sound event detection. I am working on an embedded device, and have to be able to process those 2 second files in a short time.
Currently I am bottlenecked by plt.savefig()
as a way of saving the spectrogram after using librosa.display.specshow()
. This operation alone takes ~0.8 seconds, which is around 75% of the end-to-end process (audio loading to detection).
This is the gist of what I’m doing after recording the windows.
Describe the solution you’d like
It would be great if librosa.display.specshow()
or another function return the raw spectrogram as an image, which can then be saved via cv2/skimage/etc.
Describe alternatives you’ve considered I tried saving the raw data , but the visualization is not as rich and wouldn’t be useful.
I can also increase the window size to be 5 seconds, but that would be detrimental to the accuracy of the detections.
Additional context Related issue which has been closed
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
I’m going to close this issue out, as there’s nothing to be done on the librosa side. Our spectrogram code already produces raw matrix data, and if you want to convert that to an image without going through matplotlib, it’s possible but not something we would add as core functionality.
I wrote some code for this recently for a paper I was publishing. Here’s the relevant code snippet, you can futz around with it. For example I wanted a gray colormap (for color blind readers) but you can change any of the options. I include a larger code sample so you see how you can adjust things: