-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShapeMarch.py
54 lines (41 loc) · 2.27 KB
/
ShapeMarch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from Image2Sound import *
#####################################
# Converts multiple images to sounds using qualative locations
####################################
# Audio Settings
sampleRate = 44101 # This can stay the same
audioLength = 1 # Length of audio in seconds
sampleLength = sampleRate * audioLength
# The highest and lowest frequencies available. Numbers are pretty much arbitrary, but at both edges of human hearing/my headphone's capabilities
highFreq = 8192 # 2^13
lowFreq = 128 # 2^7
# Image Settings
resolution = 64 # resolution of square image (must be a power of 2)
shape = 'Circle' # Change to 'Circle' or 'Square'
position = "" # See notes on position below
# Input/Output Settings
generateImage = False # True = generate Image. False = use existing image
writeImage = False # True = save generated Image to file. False = don't save (only applies if generateImage = True)
writeAudio = False # True = save audio as file. False = play the audio without saving
invertImage = False # True = invert colors. False = do not invert colors
posXs = ["Left", "Center", "Right"]
posYs = ["Top", "Center", "Bottom"]
for y in posYs:
for x in posXs:
if x == y:
position = "Center"
else:
position = y+"_"+x
name = getName(shape, position, resolution) # Gets the name of the image/audio file without the extension (i.e. .png and .wav). It automatically looks for images inside the ./Pictures folder and writes audio to ./Sounds folder, so neither are included here.
print(name)
# Stuff to Ignore and Leave as Is
img = getImage(shape, position, resolution, generateImage, writeImage, name) # name is only necessary when using custom images not following standard pattenr, but it doesn't hurt to include it here
cv2.imshow("Test", img)
cv2.waitKey(10)
samples = image2Sound(img, audioLength, sampleRate, resolution, lowFreq, highFreq, invertImage) # turns the image into an list of audio samples.
playSound(samples, sampleRate) # plays the sound
# Save the audio file is desired
if writeAudio:
if invertImage: name = getName(shape, position, resolution, True)
writeSound(name, sampleRate, samples)
cv2.destroyAllWindows()