fernozzle

Monday Left Me Broken

Oct 26th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #you have to install the pip library for reading images
  2. import wave, struct, math, random
  3. from PIL import Image
  4. def addsample(S):
  5. data = struct.pack('<h', S)
  6. obj.writeframesraw(data)
  7. img = Image.open("Silhouette-image-here.png")
  8. img_BW = img.convert("L")
  9. pixel_data_bw = img_BW.load()
  10. width, height = img_BW.size
  11. sampleRate = 44100.0 # hertz
  12. duration = 1.0 # seconds, this does nothing
  13. frequency = 1000 # hertz, this will change the frequency
  14. wavehight = 65534
  15. pixel2wave = wavehight / height
  16. obj = wave.open('sound.wav','w')
  17. obj.setnchannels(1) # mono
  18. obj.setsampwidth(2)
  19. obj.setframerate(sampleRate)
  20. for x in range(width):
  21. for i in range(-1,2,2):
  22. rawheight = 0
  23. for y in range(height):
  24. if img_BW.getpixel((x, y*i)) < 250:
  25. rawheight = (height/2-y)*i
  26. break
  27. for place_holder in range(int(sampleRate/frequency)):
  28. addsample(int(rawheight * pixel2wave))
  29. obj.close()
  30. #this was created by DEVIXLER/Scar32
Add Comment
Please, Sign In to add comment