%pylab inline
from __future__ import print_function
from __future__ import division
img = imread('4.jpg');
imshow(img)
Populating the interactive namespace from numpy and matplotlib
<matplotlib.image.AxesImage at 0x11166fc50>
mag_spec = img[0,:1023,0]
phs_spec = img[0,:1023,1]
X = [np.complex(cos(phs)* mag, -sin(phs)* mag) for mag, phs in zip(mag_spec, phs_spec)]
sig= list(fft.irfft(X)*6000)
for i in range(1,img.shape[1]-1):
# the red channel of the image serves to be the magtitude specturm
mag_spec = img[:,i,0]
# the green channel of the image serves to be the phase specturm
phs_spec = img[:,i,1]
X = [np.complex(cos(phs)* mag, -sin(phs)* mag) for mag, phs in zip(mag_spec, phs_spec)]
x= fft.irfft(X)
sig = sig + list(x*6000)
plot(sig)
[<matplotlib.lines.Line2D at 0x1148cfed0>]
img.shape[1]
1280
from scipy.io import wavfile
wavfile.write('test.wav', 44100, array(sig, dtype=int16))
from IPython.display import Audio
Audio(sig,rate=44100)