Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Reliable low-latency audio playback and recording

Project description

Warning

This is work in progress!

Goal: Reliable low-latency audio playback and recording with Python, using PortAudio via the sounddevice module.

The audio callback is implemented in C (and compiled with the help of CFFI) and doesn’t invoke the Python interpreter, therefore avoiding waiting for things like garbage collection and the GIL.

All PortAudio platforms and host APIs are supported. Runs on any Python version where CFFI is available.

Features:

  • playback of multiple signals at the same time (that’s why it’s called “mixer”)
  • play from buffer, play from ringbuffer
  • record into buffer, record into ringbuffer
  • multichannel support
  • NumPy arrays with data type 'float32' can be easily used (via the buffer protocol) as long as they are C-contiguous
  • fixed latency playback, (close to) no jitter (optional)
    • to be verified …
  • sample-accurate playback/recording (with known offset)
    • to be verified …
  • non-blocking callback function, using PortAudio ringbuffers
  • all memory allocations/deallocations happen outside the audio callback

Planned features:

  • meticulous reporting of overruns/underruns
  • loopback tests to verify correct operation and accurate latency values
  • fade in/out?
  • loop?
  • playlist/queue?

Out of scope:

  • reading from/writing to files (use e.g. the soundfile module)
  • realtime signal processing (inside the audio callback)
  • signal generators
  • multiple mixer instances (some PortAudio host APIs only support one stream at a time)
  • resampling (apart from what PortAudio does)
  • fast forward/rewind
  • panning/balance
  • audio/video synchronization

Somewhat similar projects:

Installation

On Windows, macOS, and Linux you can install a precompiled wheel with:

python3 -m pip install rtmixer

This will install rtmixer and its dependencies, including sounddevice.

Note

On Linux, to use sounddevice and rtmixer you will need to have PortAudio installed, e.g. via sudo apt install libportaudio2. On other platforms, PortAudio comes bundled with sounddevice.

Developers can install in editable mode with some variant of:

git clone https://github.com/spatialaudio/python-rtmixer
cd python-rtmixer
git submodule update --init
python3 -m pip install -e .

Usage

See the list of examples on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for rtmixer, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size rtmixer-0.1.0-cp35-cp35m-macosx_10_6_intel.whl (23.1 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp35-cp35m-manylinux1_i686.whl (28.0 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp35-cp35m-manylinux1_x86_64.whl (30.3 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp35-cp35m-win32.whl (15.7 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp35-cp35m-win_amd64.whl (17.6 kB) File type Wheel Python version cp35 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp36-cp36m-macosx_10_6_intel.whl (23.1 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp36-cp36m-manylinux1_i686.whl (28.0 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp36-cp36m-manylinux1_x86_64.whl (30.3 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp36-cp36m-win32.whl (15.7 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp36-cp36m-win_amd64.whl (17.5 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp37-cp37m-macosx_10_6_intel.whl (23.1 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp37-cp37m-manylinux1_i686.whl (28.0 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp37-cp37m-manylinux1_x86_64.whl (30.3 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp37-cp37m-win32.whl (15.7 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0-cp37-cp37m-win_amd64.whl (17.5 kB) File type Wheel Python version cp37 Upload date Hashes View hashes
Filename, size rtmixer-0.1.0.tar.gz (24.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page