title: Invertible STFT and ISTFT in Python
body: <p>Is there any general-purpose form of <a href="https://en.wikipedia.org/wiki/Short-time_Fourier_transform" rel="noreferrer">short-time Fourier transform</a> with corresponding inverse transform built into SciPy or NumPy or whatever?</p>
  
  <p>There's the pyplot <code>specgram</code> function in matplotlib, which calls <code>ax.specgram()</code>, which calls <code>mlab.specgram()</code>, which calls <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/mlab.py#L206" rel="noreferrer"><code>_spectral_helper()</code></a>:</p>
  
  <blockquote>
  <pre><code>#The checks for if y is x are so that we can use the same function to
  #implement the core of psd(), csd(), and spectrogram() without doing
  #extra calculations.  We return the unaveraged Pxy, freqs, and t.
  </code></pre>
  </blockquote>
  
  <p>but</p>
  
  <blockquote>
    <p>This is a helper function that implements the commonality between the
    204   #psd, csd, and spectrogram. It is
    <em>NOT</em> meant to be used outside of mlab</p>
  </blockquote>
  
  <p>I'm not sure if this can be used to do an STFT and ISTFT, though.  Is there anything else, or should I translate something like <a href="http://labrosa.ee.columbia.edu/matlab/pvoc/" rel="noreferrer">these MATLAB functions</a>?</p>
  
  <p>I know how to write my own ad-hoc implementation; I'm just looking for something full-featured, which can handle different windowing functions (but has a sane default), is fully invertible with COLA windows (<code>istft(stft(x))==x</code>), tested by multiple people, no off-by-one errors, handles the ends and zero padding well, fast RFFT implementation for real input, etc.</p>