Play those cute little Wave files (Python)

vegaseat 3 Tallied Votes 1K Views Share

The code is shamefully short, but here it is. Now you can listen to the many sound files in wave (.wav) format and boing, chirp, chime, bark, booh, laugh and mooh at the people around you.

# play a wave sound on a Windows Box
# Python23 tested   vegaseat   2/8/2005

import winsound
import time

# pick a wave file supplied by Windows XP or one of your own ...
# soundfile = "c:\\Windows\\Media\\chimes.wav"
# Python also accepts the forward slash
soundfile = "c:/Windows/Media/chimes.wav"
winsound.PlaySound(soundfile, winsound.SND_FILENAME|winsound.SND_ASYNC)

# wait one and a half seconds
time.sleep(1.5)
# play the system exit sound if set
winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
tspyv 0 Newbie Poster

Its so short that it doesn't exist? At least in my browser (Firefox), the box where the code should be is coming up as empty, and looking at the html source doesn't seem to yield the snippet.

jbronen 0 Newbie Poster

Hey, thanks a lot for this code; it's been a huge help. I have one question though: is there any way to determine/modify the volume of the .wav files being played? Do you know of any way to make the program I wrote using your code louder?
Thanks,
jbronen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.