I would like to know whether I am correct in my understanding of going from STFT to a spectrogram. My goal is to convert a spectrogram back to a wav file.

If I have my STFT:

audio, _ = librosa.load(f, sr=Fs)
stft = librosa.stft(samples, n_fft=NFFT, hop_length=HOP_LENGTH, win_length=window_length_samples)

and I wish to display a spectogram, I have to do:

spec = librosa.specshow(np.abs(stft))

However, since I have taken the modulus, it must be impossible to go from spec back to audio correct? So does that mean that librosa.istft does NOT convert a spectrogram to a wav file? My confusion arises because I have seen many answers to "spec to wav" questions suggesting the use of librosa.istft.

I am wishing to use a visual representation of audio that can be fed to a convolutional neural network, but still be converted back into audio. As an extension to the question, does anyone have experience using the stft numpy array as the input to a CNN?

  • $\begingroup$ if you don’t change your STFT results, it’s a lot easier to just keep a copy of the wave file and process it the way you want. $\endgroup$ – user28715 Dec 11 '19 at 14:30
  • $\begingroup$ I am actually using generative adversarial networks to try and produce an stft array. So the reason I am wondering about the conversion between STFT and wav is because I’d like the network to generate unique, unseen stft arrays. $\endgroup$ – Harry Stuart Dec 12 '19 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.