1
$\begingroup$

Close to this question but different : Wav To Spectrogram, Back To Wav

I already posted this on StackOverflow(https://stackoverflow.com/questions/54743968/how-to-go-from-wav-file-to-spectrogram-back-to-wav-file-in-python), but I figured this question might be more suited to be here :

Here's my problem. I have some wav files. I want to create their spectrogram. Then I want to do some stuff with the spectrogram and then I want to recreate a wav file associated to the new spectrogram. I am aware that the spectrogram doesn't have the phase information, however, since I have an original file, I can (theoretically) extract the phase from the original wav file.

I want to do that in Python (if possible), do you know a good library that would allow me to do that?

$\endgroup$
6
  • $\begingroup$ I'm not sure what you want to do here? How would the original phase information still mean anything sensible after you modified magnitudes? $\endgroup$ Feb 19, 2019 at 14:09
  • $\begingroup$ The idea is that the modified spectrogram would represent a a "close" version of the original sound. As a result, using the original phase to recompute the sound seems a better approximation that just forgetting the phase of the original file. $\endgroup$ Feb 19, 2019 at 14:23
  • 2
    $\begingroup$ Why do you want to modify the spectrogram? How is that different from regular filtering? Maybe what you want is a time-variant filter? $\endgroup$
    – MBaz
    Feb 19, 2019 at 14:31
  • $\begingroup$ Spectrogram is an image, and as such a lot of deep learning techniques are very effective on spectrograms. I want to perform spectrogram reconstruction using deep learning. The end goal is still to go back to actual sound, so I need to understand how to go from an 'updated' spectrogram and an original wav file to a new wav file. The first thing I want to test there is to use the phase from the original file, but every idea is welcomed :) $\endgroup$ Feb 19, 2019 at 14:39
  • $\begingroup$ yeah, but modification of a time amplitude signal inherently has phase effects, so you can't "de-intertwine" things that easily. $\endgroup$ Feb 19, 2019 at 17:01

1 Answer 1

2
$\begingroup$

You need to keep the phase information, which isn't included in a spectrogram. "Spectrogram" is just the magnitude of the STFT output.

So this is conceptually the same as STFT ↔ ISTFT, which is supported in Python now:

The Examples section in the ISTFT link does exactly what you want, modifying a STFT and inverse transforming to reduce noise.

$\endgroup$
2
  • 1
    $\begingroup$ Thank you, I'll check that this week, and i'll come back to validate your answer if it works for me :) $\endgroup$ Feb 19, 2019 at 16:13
  • 1
    $\begingroup$ Sorry for taking so much time to come back, I finally tried your suggestion, and it was what I needed. Thank you very much. $\endgroup$ Mar 7, 2019 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.