%pylab inline
Populating the interactive namespace from numpy and matplotlib
img = imread('sonos.jpg')
imshow(img)
<matplotlib.image.AxesImage at 0x10cc56590>
img.shape
(1133, 1510, 3)
red_only = img.copy()
red_only[:,:,1] = 0
red_only[:,:,2] = 0
imshow(red_only)
<matplotlib.image.AxesImage at 0x10ce92090>
sig = img[550,:, 1].astype(int16)
plot(sig)
[<matplotlib.lines.Line2D at 0x10dae20d0>]
sigout = list((img[0,:, 1].astype(int16) - 100) * 100)
for y in range(1, 500):
sigout = sigout + list((img[y,:, 1].astype(int16) - 100) * 200 )
++y
plot(sigout)
[<matplotlib.lines.Line2D at 0x10e4dfe90>]
plot(sigout[350000:355000])
[<matplotlib.lines.Line2D at 0x10f59d350>]
from scipy.io import wavfile
wavfile.write('outsig.wav', 44100, array(sigout, dtype=int16))
from IPython.display import Audio
sound_file = './outsig.wav'
from IPython.display import HTML
from base64 import b64encode
path_to_audio = "./outsig.wav"
audio_type = "wav"
sound = open(path_to_audio, "rb").read()
sound_encoded = b64encode(sound)
sound_tag = """
<audio id="beep" controls src="data:audio/{1};base64,{0}">
</audio>""".format(sound_encoded, audio_type)
play_beep = """
<script type="text/javascript">
var audio = document.getElementById("beep");
audio.play();
</script>
"""
HTML(sound_tag)
HTML(play_beep)