mirror of
https://github.com/index-tts/index-tts.git
synced 2026-08-28 14:56:25 +08:00
ee40fa7d6c
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