convert numpy int16 audio array to float32 convert numpy int16 audio array to float32 numpy numpy

convert numpy int16 audio array to float32


By convention, floating point audio data is normalized to the range of [-1.0,1.0] which you can do by scaling:

audio = audio.astype(np.float32, order='C') / 32768.0

This may fix the problem for you but you need to make sure that soundfile.write writes a wav header that indicates float32. It may do that automatically based on the dtype of the array.