[Pythonmac-SIG] Mac equivalent of winsound
Todd Koym
TK at EdgertonFoundation.org
Wed Jul 9 13:45:45 EDT 2003
What is the easiest way to play a short sound file (aiff or wav) in
MacPython?
I have an application that requires short sound notifications. Winsound
serves this purpose quite well for Windows, but I'm having trouble
identifying the equivalent module/package to use for the Mac. I'm running
on OS X (Jaguar), but I have to use the Carbon version of MacPython (the
Python interpreter is embedded in a Carbon app). The playing of the sound
file must not open its own user interface/window.
PyGame seems like a lot of work/overkill for my purpose
Snack requires Tkinter - which doesn't run under Carbon
The snippet below (using Carbon.Res and Carbon.Snd) works, but I need to
play sound files, not just snd resources. It seems like I need to use
SndStartFilePlay (from Carbon's Sound Manager), but I can't seem to find
it.
# Show off SndPlay (and some resource manager functions).
# Get a list of all 'snd ' resources in the system and play them all.
from Carbon.Res import *
from Carbon.Snd import *
ch = SndNewChannel(0, 0, None)
print "Channel:", ch
type = 'snd '
for i in range(CountResources(type)):
r = GetIndResource(type, i+1)
print r.GetResInfo(), r.size
if r.GetResInfo()[0] == 1:
print "Skipping simple beep"
continue
ch.SndPlay(r, 0)
More information about the Pythonmac-SIG
mailing list