Play a Sound with Python


This question already has an answer here:


The Snack Sound Toolkit can play wav, au and mp3 files.

s = Sound()'sound.wav')

For Windows, you can use winsound. It's built in

import winsound

winsound.PlaySound('sound.wav', winsound.SND_FILENAME)

You should be able to use ossaudiodev for linux:

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')
  from ossaudiodev import AFMT_S16_NE
except ImportError:
  from sys import byteorder
  if byteorder == "little":
    AFMT_S16_NE = ossaudiodev.AFMT_S16_LE
    AFMT_S16_NE = ossaudiodev.AFMT_S16_BE
dsp.setparameters(AFMT_S16_NE, nc, fr)
data = s.readframes(nf)

(Credit for ossaudiodev: Bill Dandreta

Need Your Help

Android Java XML : how to find tag like "abc:tag" with unknown "abc" part with getElementsByTagName()

java android xml tags getelementsbytagname

My Android app reads a XML file and searches for a tag that can be found in different forms, like "tag" or "abc:tag" for example. My code is able to find just the "tag" form. How to find other form...

Add a map in Django Admin

python django

I want to add a js-map in Django admin (when you creating object).