Play audio with Python


How can I play audio (it would be like a 1 second sound) from a Python script?

It would be best if it was platform independent, but firstly it needs to work on a Mac.

I know I could just execute the afplay file.mp3 command from within Python, but is it possible to do it in raw Python? I would also be better if it didn't rely on external libraries.

8/27/2015 11:23:30 PM

Accepted Answer

You can find information about Python audio here:

It doesn't look like it can play .mp3 files without external libraries. You could either convert your .mp3 file to a .wav or other format, or use a library like PyMedia.

11/4/2008 3:27:13 AM

Your best bet is probably to use pygame/SDL. It's an external library, but it has great support across platforms.


You can find more specific documentation about the audio mixer support in the documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow