944,054 Members | Top Members by Rank

Ad:
  • Python Code Snippet
  • Views: 13143
  • Python RSS
1

Play those cute little Wave files (Python)

by on Feb 8th, 2005
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.
Python Code Snippet (Toggle Plain Text)
  1. # play a wave sound on a Windows Box
  2. # Python23 tested vegaseat 2/8/2005
  3.  
  4. import winsound
  5. import time
  6.  
  7. # pick a wave file supplied by Windows XP or one of your own ...
  8. # soundfile = "c:\\Windows\\Media\\chimes.wav"
  9. # Python also accepts the forward slash
  10. soundfile = "c:/Windows/Media/chimes.wav"
  11. winsound.PlaySound(soundfile, winsound.SND_FILENAME|winsound.SND_ASYNC)
  12.  
  13. # wait one and a half seconds
  14. time.sleep(1.5)
  15. # play the system exit sound if set
  16. winsound.PlaySound("SystemExit", winsound.SND_ALIAS)
  17.  
Comments on this Code Snippet
Jun 20th, 2006
0

Re: Play those cute little Wave files (Python)

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.
Newbie Poster
tspyv is offline Offline
1 posts
since Jun 2006
Jul 28th, 2010
0

Re: Play those cute little Wave files (Python)

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
Newbie Poster
jbronen is offline Offline
5 posts
since Jul 2010
Message:
Previous Thread in Python Forum Timeline: pyGTK + py2exe -- Setted GTK theme not being used
Next Thread in Python Forum Timeline: Python GUI Programming





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC