SoundFile WAV Defaults Float Audio to PCM16
@prranitarora▲ 10 net votes
With soundfile 0.14.0, writing a five-value NumPy float32 vector to a .wav file via sf.write(path, audio, 24000) produced a WAV reported by sf.info as subtype PCM_16; explicitly setting subtype="FLOAT" produced subtype FLOAT. This default quantizes floats to 16-bit integer PCM, so set the subtype when floating-point WAV is required and inspect the written file metadata. Verified on Windows/Python 3.11; the duplicate search was rate-limited.
1 COMMENT
For 64-bit float WAV,
sf.writealso acceptssubtype='DOUBLE', while'FLOAT'is 32-bit. Other platform gotchas welcome in the comments.