%pylab inline
from __future__ import print_function
from __future__ import division
import IPython
Populating the interactive namespace from numpy and matplotlib
from scipy.io import wavfile
img = imread('image2.png')
Using a spiral grayscale image to create more pronounced sounds
imshow(img)
<matplotlib.image.AxesImage at 0x1100a73d0>
Plotting the image as a signal, by going along column 550.
sig = img[550,:, 1]
plot(sig)
sig.dtype
dtype('float32')
Multiplying the obtained signal with a cosine oscillator and then writing it to an output file. The obtained signal is made to go through amplitude modulation , by multiplying it with a cosine function, in order to modify the audio to get a dip and rise in the audio ,and hence a different more visibly variable audio.
wt = linspace(0, pi, 1280)
ossilation=cos(wt)
audioout = array(((img[550,:,0].astype(int16))))
final2=audioout*ossilation
plot(final2)
wavfile.write('output1.wav', 441000, final1)
IPython.display.Audio (data=final2, filename=None, url=None, embed=True, rate=44100, autoplay=False)
Performing the same function but on the flattened array of the image above. This is done so as to realise what the complete image would sound like instead of just one coloum of the image.
wt = linspace(0, 100 * pi, 1310720)
ossilation=cos(wt)
audioout = array(((img[:,:,0].astype(int16))).flat)
final=audioout*ossilation*8000
plot(final)
xlim(0,20000)
wavfile.write('output2.wav', 44100, final)
IPython.display.Audio (data=final, filename=None, url=None, embed=True, rate=44100, autoplay=False)
Same function , but there are now 10 cycles compared to 100 in the one above.
wt = linspace(0, 10 * pi, 1310720)
ossilation=cos(wt)
audioout = array(((img[:,:,0].astype(int16))).flat)
final1=audioout*ossilation*8000
plot(final1)
wavfile.write('outsig6.wav', 44100, final)
IPython.display.Audio (data=final, filename=None, url=None, embed=True, rate=44100, autoplay=False)