Play, Record, Process live sounds to/from Numpy arrays in Python

PyGame and PyAudio are two of the best currently maintained packages for playing audio from Python, including from Numpy arrays or streaming sources.

PyGame

PyGame is for building games and does much more than audio. I find PyGame to be very robust across a wide variety of systems (including embedded systems) to play audio from Python.

Setup PyGame

Example PyGame program

PyAudio

PyAudio uses PortAudio on Windows, Mac, and Linux to allow easy playback of Numpy arrays. If you find that you’re not able to install PortAudio, consider using PyGame instead of PyAudio.

Example PyAudio program

Linux PyAudio setup

apt install portaudio19-dev
pip install pyaudio

Mac PyAudio setup

brew install portaudio
pip install pyaudio

Windows PyAudio setup

The Windows PyAudio wheels are currently for Python 2.7, 3.4, 3.5, and 3.6 and include PortAudio.

pip install pyaudio

Leave a Comment