Building on JoeKington's comment, I have downloaded this file, and tried the following
>>> import scipy.io.wavfile
>>> rate, data = scipy.io.wavfile.read('wahoo.wav')
>>> data
array([134, 134, 134, ..., 124, 124, 124], dtype=uint8)
>>> data_bis = np.fft.ifft(np.fft.fft(data))
>>> data_bis
array([ 134. +6.68519934e-14j, 134. -4.57982480e-14j,
134. -1.78967708e-14j, ..., 124. -2.09835513e-14j,
124. -1.61750469e-14j, 124. -2.14867343e-14j])
>>> data_bis = data_bis.astype('uint8')
C:\Users\Jaime y Eva\Desktop\stack_exchange.py:1: ComplexWarning: Casting complex values to real discards the imaginary part
# -*- coding: utf-8 -*-
>>> data_bis
array([134, 133, 133, ..., 123, 123, 123], dtype=uint8)
>>> scipy.io.wavfile.write('wahoo_bis.wav', rate, data_bis)
And the resulting file plays exactly the same as the original one.
So turning the return complex values into reals is only half the problem (and you may want to go with np.abs
rather than data.real
, as the code above implicitly does), and you then also need to recast your floating point numbers to uint
s of the apropriate bit-depth.