Why does `transforms.TimeStretch` return `complex64`?

kuraga: <p>Good day!</p>
<p>torchaudio 2.1.1</p>
<p><a href="https://pytorch.org/audio/2.1.0/generated/torchaudio.transforms.TimeStretch.html#torchaudio.transforms.TimeStretch.forward" class="inline-onebox" rel="noopener nofollow ugc">TimeStretch — Torchaudio 2.1.0 documentation</a> :</p>
<blockquote>
<p>Stretched spectrogram. The resulting tensor is of the same dtype as the input spectrogram, but the number of frames is changed to <code>ceil(num_frame / rate)</code>.</p>
</blockquote>
<pre><code class="lang-auto">s = torchaudio.transforms.Spectrogram()(x)
s.dtype  # =&gt; torch.float32

t = torchaudio.transforms.TimeStretch(fixed_rate=0.9)(s)
t.dtype  # =&gt;  torch.complex64
</code></pre>
<p>Why?</p>

kuraga: <aside class="onebox githubissue" data-onebox-src="https://github.com/pytorch/audio/issues/3688">
  <header class="source">

      <a href="https://github.com/pytorch/audio/issues/3688" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/audio</a>
  </header>

  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/audio/issues/3688" target="_blank" rel="noopener nofollow ugc">Why does `transforms.TimeStretch` return  of type `complex64`?</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2023-11-05" data-time="12:02:57" data-timezone="UTC">12:02PM - 05 Nov 23 UTC</span>
      </div>


      <div class="user">
        <a href="https://github.com/kuraga" target="_blank" rel="noopener nofollow ugc">
          <img alt="kuraga" src="https://avatars.githubusercontent.com/u/1063219?v=4" class="onebox-avatar-inline" width="20" height="20">
          kuraga
        </a>
      </div>
    </div>

    <div class="labels">
    </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">### 🐛 Describe the bug

Good day!

https://pytorch.org/audio/2.1.0/generated/t<span class="show-more-container"><a href="" rel="noopener" class="show-more">…</a></span><span class="excerpt hidden">orchaudio.transforms.TimeStretch.html#torchaudio.transforms.TimeStretch.forward:

&gt; Stretched spectrogram. The resulting tensor is of the same dtype as the input spectrogram, but the number of frames is changed to `ceil(num_frame / rate)`.

But:
```
s = torchaudio.transforms.Spectrogram()(x)
s.dtype  # =&gt; torch.float32

t = torchaudio.transforms.TimeStretch(fixed_rate=0.9)(s)
t.dtype  # =&gt;  torch.complex64
```

Should I collect a bug report or don't I understand time stretching?

(previously posted [at the forum](https://discuss.pytorch.org/t/why-does-transforms-timestretch-return-complex64/191208))

### Versions

torchaudio 2.1.1 from Google Colab</span></p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


Greg_Shay: <p>If you haven’t figured this out already…<br>
A complex spectrum contains the phase as well as amplitude of the audio spectral energies.</p>
<p>If your application results are ok with ignoring phase, convert complex to real by using a magnitude function.</p>
<p>If you don’t want to lose the phase information, you will have to keep (and use) the complex spectrum results. Each frequency bin in the spectrum will have a phase according to the ratio of the real vs imaginary value of that bin.</p>