Files
Souptik Chakraborty ee40fa7d6c fix: normalize waveforms before torchaudio.save to avoid saturated WAVs (#773)
torchaudio 2.9 moved save() onto TorchCodec, whose compatibility shim
converts non-float32 input with a bare src.float() and no rescaling, then
treats the result as [-1, 1] audio. Every save site passed a PCM-scale
int16 tensor, so on 2.9+ roughly 99.99% of frames clipped to full scale
with no exception and no warning.

Add save_pcm_wav() in indextts/utils/common.py, which normalizes PCM-scale
input to float32 [-1, 1] and pins encoding="PCM_S"/bits_per_sample=16 on
the torchaudio versions that still honour them. Pinning matters: below 2.9
the WAV subtype is derived from the input dtype, so normalizing alone would
silently switch output from 16-bit PCM to 32-bit float. Above 2.9 the two
arguments are ignored and warn, so they are omitted there.

Route all six save sites in indextts/ and backends/trt/ through it.

Verified on torchaudio 2.7.1, 2.8.0, 2.9.0 and 2.11.0: identical 16-bit
PCM output, 0% clipped frames. Before the change 2.9.0 and 2.11.0 produced
only 3 distinct sample values with 99.9875% of frames at full scale.

Fixes #724
2026-08-18 14:52:28 +08:00
..
2025-09-08 17:36:39 +08:00
2026-08-11 15:08:26 +08:00
2025-03-25 12:52:52 +08:00
2025-03-25 14:03:29 -04:00