Repository: pytorch/audio

Issue:
Fix docstring of `sliding_window_cmn`
https://github.com/pytorch/audio/blob/ea857940de9e3738166989ad3bf1726741a13f04/torchaudio/functional/functional.py#L947

the input `specgram `shoud be in shape ( ..., time, freq), instead of `(..., freq, time)` as doc says.

Right?


Discussion:
Hi @jackyguo624 

Thanks for the report. I think you are right about it and we should fix it.

CC @jcaw Sorry we missed it in the review process.
@jackyguo624 
Hmm, I think the docstring is right, `(..., freq, time)` means you can drop the batch dimension, directly feed a matrix into it.

https://github.com/pytorch/audio/blob/ea857940de9e3738166989ad3bf1726741a13f04/torchaudio/functional/functional.py#L1022

This line handle when input is a 2-dimensional matrix.
> @jackyguo624
> Hmm, I think the docstring is right, `(..., freq, time)` means you can drop the batch dimension, directly feed a matrix into it.
> 
> https://github.com/pytorch/audio/blob/ea857940de9e3738166989ad3bf1726741a13f04/torchaudio/functional/functional.py#L1022
> 
> This line handle when input is a 2-dimensional matrix.

@yoyololicon 

Well, the batch/channel dimension is fine. I think the issue is about the order of the last two dimensions. The expected order is `(..., time, freq)` whereas the docstring is `(..., freq, time)`
Oh, I see it, nevermind.😅
Spectrograms returned by torchaudio [do have](https://github.com/pytorch/audio/blob/ea857940de9e3738166989ad3bf1726741a13f04/torchaudio/functional/functional.py#L75) the order `(..., freq, time)` though. Should `sliding_window_cmn` be operating on a different order? That seems like a bug.
> Spectrograms returned by torchaudio [do have](https://github.com/pytorch/audio/blob/ea857940de9e3738166989ad3bf1726741a13f04/torchaudio/functional/functional.py#L75) the order `(..., freq, time)` though. Should `sliding_window_cmn` be operating on a different order? That seems like a bug.

This is the inconsistent design principles between the libraries `torchaudio` followed. `sliding_window_cmn` is from Kaldi while `spectrogram` is from another different source. We could think of changing it but it will be a bc-breaking change, so it needs a separate discussion. For now, let's make the docstring of `sliding_window_cmn` accurately reflect the operation.
Hello, can I work on this and fix this issue?

Resolving patch:
diff --git a/torchaudio/functional/functional.py b/torchaudio/functional/functional.py
--- a/torchaudio/functional/functional.py
+++ b/torchaudio/functional/functional.py
@@ -944,7 +944,7 @@ def sliding_window_cmn(
     Apply sliding-window cepstral mean (and optionally variance) normalization per utterance.
 
     Args:
-        specgram (Tensor): Tensor of audio of dimension (..., freq, time)
+        specgram (Tensor): Tensor of audio of dimension (..., time, freq)
         cmn_window (int, optional): Window in frames for running average CMN computation (int, default = 600)
         min_cmn_window (int, optional):  Minimum CMN window used at start of decoding (adds latency only at start).
             Only applicable if center == false, ignored if center==true (int, default = 100)


Test patch: