Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, random
- try:
- import winsound
- except ImportError:
- import os
- def playsound(frequency,duration):
- os.system('beep -f %s -l %s' % (frequency,duration))
- else:
- def playsound(frequency,duration):
- winsound.Beep(frequency,duration)
- major = [523.25,587.33,659.26,698.46,783.99,880.00,978.77,1046.50]
- pent = [554.37,622.25,739.99,830.61,932.33]
- def playSounds(scale, number, length) :
- if scale == 'm' :
- sc = major
- elif scale == 'p' :
- sc = pent
- else :
- sc = major
- for x in range(1, int(number)+1) :
- i = random.randint(1, len(sc))
- playsound(str(sc[i-1]), str(length))
- def playFile(data, times) :
- for i in range(len(dat)) :
- playsound(str(dat[i]),str(times[i]))
- scale = raw_input("Major scale(m), Pentatonic scale(p), File(f)?: ")
- if scale != 'f' :
- number = raw_input("Number of notes: ")
- length = raw_input("Length of each note: ")
- playSounds(scale, number, length)
- else :
- filetoread = raw_input("Location of file: ")
- f = open(filetoread, 'r')
- data = []
- dat = []
- times = []
- time = []
- for line in f:
- data.append(line)
- for i in range(len(data)) :
- data = map(lambda s: s.strip(), data)
- time = data[i].split('- ')
- dat.append(time[0])
- dat = [x.strip(' ') for x in dat]
- for (i, item) in enumerate(dat):
- if item == "c":
- dat[i] = '523.25'
- if item == "d":
- dat[i] = '587.33'
- if item == "e":
- dat[i] = '659.26'
- if item == "f":
- dat[i] = '698.46'
- if item == "g":
- dat[i] = '783.99'
- if item == "a":
- dat[i] = '880.00'
- if item == "b":
- dat[i] = '987.77'
- if item == "c+":
- dat[i] = '1046.50'
- times.append(time[1])
- playFile(dat, times)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement