[Edu-sig] Python sound.
Tue, 18 Dec 2001 12:57:04 -0800 (PST)
Hey folks, after some late night oil, I wrote these
wrappers to Snack, to simplify the interface (my
students haven't yet reached GUI or event driven
programming). I hope this helps someone.
(You will need Snack for Python here:
Basically, there are 3 functions:
SoundStart, SoundStop, and Beep. SoundStart wraps the
initialization for Snack and Tkinter, and hides the
tk window. SoundStop tries to clean-up after the
initialization. Beep is exactly analogous to the
winsound.Beep call, except that the duration is
seconds rather than milliseconds.
compsci.SoundStart(50) #volume gain set to 50%
compsci.Beep(261.63, 10) #plays Middle-C for 10
compsci.SoundStop() #clean up
"""Initialize the Sound System"""
global root, filt
root = Tkinter.Tk()
if volume > 100:
volume = 100
elif volume < 0:
volume = 0
def Beep(freq, duration):
"""Play a note of freq hertz for duration
s = tkSnack.Sound()
filt = tkSnack.Filter('generator', freq, 30000,
0.0, 'sine', int(11500*duration))
"""Turn off the Sound System"""
root = root.destroy()
filt = None
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com