<p>A suitably constructed STFT spectrogram containing both magnitude and phase can be converted back to a time-domain waveform using the <a href="https://ccrma.stanford.edu/~jos/sasp/Overlap_Add_OLA_STFT_Processing.html" rel="nofollow noreferrer">Overlap Add method</a>. Important thing is that the spectrogram construction must have the <a href="https://ccrma.stanford.edu/~jos/sasp/Mathematical_Definition_STFT.html#19930" rel="nofollow noreferrer">constant-overlap-add</a> property.</p>

<p>It can be challenging to have your modifications correctly manipulate both magnitude and phase of a spectrogram. So sometimes the phase is discarded, and magnitude manipulated independently. In order to convert this back into a waveform one must then <em>estimate</em> phase information during reconstruction (phase reconstruction). This is a lossy process, and usually pretty computationally intensive. Established approaches use an iterative algorithm, usually a variation on Griffin-Lim. But there are now also <a href="https://arxiv.org/abs/1808.06719" rel="nofollow noreferrer">new methods</a> using Convolutional Neural Networks.</p>

<h2>Waveform from mel-spectrogram or MFCC using librosa</h2>

<p><a href="http://librosa.github.io/librosa/changelog.html#v0-7-0" rel="nofollow noreferrer">librosa version 0.7.0</a> contains a fast Griffin-Lim implementation as well as helper functions to invert a mel-spectrogram of MFCC.</p>

<p>Below is a code example. The input test file is found at <a href="https://github.com/jonnor/machinehearing/blob/ab7fe72807e9519af0151ec4f7ebfd890f432c83/handson/spectrogram-inversion/436951__arnaud-coutancier__old-ladies-pets-and-train-02.flac" rel="nofollow noreferrer">https://github.com/jonnor/machinehearing/blob/ab7fe72807e9519af0151ec4f7ebfd890f432c83/handson/spectrogram-inversion/436951__arnaud-coutancier__old-ladies-pets-and-train-02.flac</a></p>

<pre class="lang-py prettyprint-override"><code>import numpy
import librosa
import soundfile

# parameters
sr = 22050
n_mels = 128
hop_length = 512
n_iter = 32
n_mfcc = None # can try n_mfcc=20

# load audio and create Mel-spectrogram
path = '436951__arnaud-coutancier__old-ladies-pets-and-train-02.flac'
y, _ = librosa.load(path, sr=sr)
S = numpy.abs(librosa.stft(y, hop_length=hop_length, n_fft=hop_length*2))
mel_spec = librosa.feature.melspectrogram(S=S, sr=sr, n_mels=n_mels, hop_length=hop_length)

# optional, compute MFCCs in addition
if n_mfcc is not None:
    mfcc = librosa.feature.mfcc(S=librosa.power_to_db(S), sr=sr, n_mfcc=n_mfcc)
    mel_spec = librosa.feature.inverse.mfcc_to_mel(mfcc, n_mels=n_mels)

# Invert mel-spectrogram
S_inv = librosa.feature.inverse.mel_to_stft(mel_spec, sr=sr, n_fft=hop_length*4)
y_inv = librosa.griffinlim(S_inv, n_iter=n_iter,
                            hop_length=hop_length)

soundfile.write('orig.wav', y, samplerate=sr)
soundfile.write('inv.wav', y_inv, samplerate=sr)
</code></pre>

<h2>Results</h2>

<p>The reconstructed waveform will have some artifacts.</p>

<p>The above example got a lot of repetitive noise, more than I expected. It was possible to reduce it quite a lot using the standard Noise Reduction algorithm in Audacity. </p>

<p><a href="https://i.stack.imgur.com/orlyg.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/orlyg.jpg" alt="Spectrograms of original audio, reconstructed audio and reconstructed audio with noise removed"></a></p>
Creating wave data from FFT data?
<p>As you might notice, i am really new to python and sound processing. I (hopefully) extracted FFT data from a wave file using python and the logfbank and mfcc function. (The logfbank seems to give the most promising data, mfcc output looked a bit weird for me).</p>

<p>In my program i want to change the logfbank/mfcc data and then create wave data from it (and write them into a file). I didn't really find any information about the process of creating wave data from FFT data. Does anyone of you have an idea how to solve this? I would appreciate it a lot :)</p>

<p>This is my code so far:</p>

<pre><code>from scipy.io import wavfile 
import numpy as np
from python_speech_features import mfcc, logfbank

rate, signal = wavfile.read('orig.wav')
fbank = logfbank(signal, rate, nfilt=100, nfft=1400).T
mfcc = mfcc(signal, rate, numcep=13, nfilt=26, nfft=1103).T 

#magic data processing of fbank or mfcc here

#creating wave data and writing it back to a .wav file here
</code></pre>