How to play a .wav sound?
Erlend J. Leiknes
nookieNO_SP_AM at online.no
Fri May 31 23:01:52 EDT 2002
Think this should work... not tested.
import os
def get_os():
if (os.name == "nt" or os.name == "dos" or os.name == "cw"):
return "ms"
else:
return "posix"
def playsound(file):
if get_os() == "ms":
import winsound
winsound.PlaySound(file,winsound.SND_FILENAME)
else:
f = open(file,'r')
sound_device = "/dev/dsp"
d = open(sound_device,'w')
sdata = f.read(1024)
while sdata:
d.write(sdata)
f.close()
d.close()
"Bruno Bellamy" <bellamy at neverland.net> wrote in message
news:ad8jo7$ohl$1 at wanadoo.fr...
> I guess the question has probably been asked many times, sorry for
> bothering...
> But I searched here and there, and I couldn't find how to do that, simply
> play a .wav sound from a python program using Tkinter.
>
> Moreover, I need to do that in a program that would run similarly under
> Linux and Windows.
>
> I saw there's a python module called wave, but it seems it can only read
> .wav files. I coulnd't find a way to actually play the sound. Maybe it's
> hidden somewhere?
>
> If anybody can help me, that would be cool. :)
>
> --
> Bruno Bellamy: bellamy at neverland.net
> Web perso: http://neverland.net/bellamy
> ShowerGate, le croquis de la semaine: http://showergate.net
More information about the Python-list
mailing list