Fix ASR pipeline mono conversion for channels-last audio (fixes #47886) (#47888)
* Fix ASR pipeline mono conversion for channels-last audio
The pipeline averaged multi-channel input over a hardcoded axis 0, which
assumes channels-first. soundfile.read, librosa.load(mono=False) and
scipy.io.wavfile.read all return channels-last, so a stereo waveform was
averaged across time and collapsed to one value per channel: 48000 samples
became 2, were padded back to silence, and transcribed as " you" with only
a warning saying the conversion had succeeded.
Infer the channel axis from the shorter dimension instead, and report the
actual shape rather than ndim, which always printed 2 for any 2-D input.
* Reject ambiguous channel layouts instead of inferring the channel axis
Per review: inferring the channel axis with argmin is unsafe. It picks an
arbitrary axis for ndim >= 3, and it silently downmixes 5.1 audio where the
weighting should be the caller's choice.
Keep the documented (channels, samples) layout, which is what torchcodec
returns, and raise when the input does not conform. A channels-last array gets
an error naming the transpose, rather than a transcription of two samples.
Also move the conversion ahead of F.resample. The resampler operates on the last
axis, so a multi-channel array had to be reduced first, and the stride
arithmetic reads shape[0] as samples.
* Correct the comment on why the downmix runs before resampling
* Apply suggestion from @Rocketknight1
---------
Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>