Can I convert spectrograms generated with librosa back to audio?

Yes, it is possible to recover most of the signal and estimate the phase with e.g. Griffin-Lim Algorithm (GLA). Its “fast” implementation for Python can be found in librosa. Here’s how you can use it: import numpy as np import librosa y, sr = librosa.load(librosa.util.example_audio_file(), duration=10) S = np.abs(librosa.stft(y)) y_inv = librosa.griffinlim(S) And that’s how … Read more

How to convert a .wav file to a spectrogram in python3

Use scipy.signal.spectrogram. import matplotlib.pyplot as plt from scipy import signal from scipy.io import wavfile sample_rate, samples = wavfile.read(‘path-to-mono-audio-file.wav’) frequencies, times, spectrogram = signal.spectrogram(samples, sample_rate) plt.pcolormesh(times, frequencies, spectrogram) plt.imshow(spectrogram) plt.ylabel(‘Frequency [Hz]’) plt.xlabel(‘Time [sec]’) plt.show() Be sure that your wav file is mono (single channel) and not stereo (dual channel) before trying to do this. I highly … Read more