Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #you have to install the pip library for reading images
- import wave, struct, math, random
- from PIL import Image
- def addsample(S):
- data = struct.pack('<h', S)
- obj.writeframesraw(data)
- img = Image.open("Silhouette-image-here.png")
- img_BW = img.convert("L")
- pixel_data_bw = img_BW.load()
- width, height = img_BW.size
- sampleRate = 44100.0 # hertz
- duration = 1.0 # seconds, this does nothing
- frequency = 1000 # hertz, this will change the frequency
- wavehight = 65534
- pixel2wave = wavehight / height
- obj = wave.open('sound.wav','w')
- obj.setnchannels(1) # mono
- obj.setsampwidth(2)
- obj.setframerate(sampleRate)
- for x in range(width):
- for i in range(-1,2,2):
- rawheight = 0
- for y in range(height):
- if img_BW.getpixel((x, y*i)) < 250:
- rawheight = (height/2-y)*i
- break
- for place_holder in range(int(sampleRate/frequency)):
- addsample(int(rawheight * pixel2wave))
- obj.close()
- #this was created by DEVIXLER/Scar32
Add Comment
Please, Sign In to add comment