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, sys

def beep(sound):
    winsound.PlaySound('%s.wav' % sound, winsound.SND_FILENAME)

if __name__ == '__main__':

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

JQuery UI Button Loaded On Ajax Not Styled

jquery ajax jquery-ui styling

So I have an ajax call that populates my dom with a button that I want to have the styling and functionality of JQuery UI's button elements, but when I call $("button").button() on my page being re...

Getting the last n elements of a vector. Is there a better way than using the length() function?

r indexing

If, for argument's sake, I want the last five elements of a 10-length vector in Python, I can use the "-" operator in the range index so:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.