Sorry for the late reply, but I think this is a good place to advertise my library ...
AFAIK, the standard library has only one module for playing audio: ossaudiodev . Unfortunately, this only works on Linux and FreeBSD.
UPDATE: there is also winsound , but obviously it also depends on the platform.
For something more platform independent, you will need to use an external library.
My recommendation is the sounddevice module (but beware, I'm the author).
The package includes the pre-compiled PortAudio library for Mac OS X and Windows and can be easily installed using
pip install sounddevice
It can play sound from NumPy arrays, but it can also use simple Python buffers (if NumPy is not available).
To play a NumPy array, all you need (assuming the audio data has a sampling frequency of 44100 Hz):
import sounddevice as sd sd.play(myarray, 44100)
See the documentation for more details.
It cannot read / write sound files, for this you need a separate library.
Matthias Dec 09 '15 at 12:37 2015-12-09 12:37
source share