![]() |
|
|
|
#1 |
|
I posted a message ("Help with my 1st Tkinter program") a few days ago
complaining that Python did not have any built in basic cross platform sound capability. I was wrong (at least partly). Python comes with some sound playing ability for some platforms. Since no one responded to my post, I assume the capability is not well known so I will post a code snippet from my practice program that demonstrates how I play a sound file with Python on both Windows and Linux. It may save someone else some time. The winsound module lets you play .wav files under windows. The ossaudiodev module in combination with the wave module lets you play ..wav files under Linux (and some other nix's as well). =========================== file='tada.wav' if platform.startswith('win'): from winsound import PlaySound, SND_FILENAME, SND_ASYNC PlaySound(file, SND_FILENAME|SND_ASYNC) elif platform.find('linux')>-1: from wave import open as waveOpen from ossaudiodev import open as ossOpen s = waveOpen('tada.wav','rb') (nc,sw,fr,nf,comptype, compname) = s.getparams( ) dsp = ossOpen('/dev/dsp','w') try: from ossaudiodev import AFMT_S16_NE except ImportError: if byteorder == "little": AFMT_S16_NE = ossaudiodev.AFMT_S16_LE else: AFMT_S16_NE = ossaudiodev.AFMT_S16_BE dsp.setparameters(AFMT_S16_NE, nc, fr) data = s.readframes(nf) s.close() dsp.write(data) dsp.close() =============================== Bill Bill Dandreta |
|
|
|
|
#2 |
|
Posts: n/a
|
"Bill Dandreta" <> wrote in message
news:Msved.21689$... > I posted a message ("Help with my 1st Tkinter program") a few days ago > complaining that Python did not have any built in basic cross platform > sound capability. I was wrong (at least partly). Python comes with some > sound playing ability for some platforms. Take a look: http://pymedia.org/ Dmitry/ Dmitry Borisov |
|
|
|
#3 |
|
Posts: n/a
|
Bill Dandreta:
>The winsound module lets you play .wav files under windows. Thank you. You can also create "on the fly" memory-mapped wav files (with wave and mmap modules, I think), and play them. How to use the flag SND_PURGE for WAVs loaded from filename or memory mapped? Bear hugs, Bearophile bearophile |
|
|
|
#4 |
|
Posts: n/a
|
just a quick note.... Bill Dandreta <> writes: > I posted a message ("Help with my 1st Tkinter program") a few days ago > complaining that Python did not have any built in basic cross platform > sound capability. I was wrong (at least partly). Python comes with > some sound playing ability for some platforms. I remember that somebody has implemented Python bindings for the portaudio library, which is a cross-platform library for real-time audio. Johannes Johannes Nix |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DolbyD 5.1 gives very weak sound | def456 | DVD Video | 29 | 04-29-2007 06:10 PM |
| SFX Sound Effects Libraries - Cheap!! | Barbara | DVD Video | 1 | 11-11-2006 12:23 PM |
| Sound Driver Problem | tasted | Hardware | 2 | 07-14-2006 01:41 PM |
| *$600 FREE At FULL-TILT POKER, Sign-Up with no C.C. to play on our free tables 24-7! | bigpokerjackpotsonlyatpartypoker | DVD Video | 0 | 01-07-2006 05:00 AM |
| terminator dvd 5.1 - 2.0 sound problems? | rolling | DVD Video | 1 | 02-18-2005 04:30 AM |