Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

multi-library, cross-platform audio decoding

Project description


.. image::

Decode audio files using whichever backend is available. The library
currently supports:

- `Gstreamer`_ via `PyGObject`_.
- `Core Audio`_ on Mac OS X via `ctypes`_. (PyObjC not required.)
- `MAD`_ via the `pymad`_ bindings.
- `FFmpeg`_ or `Libav`_ via its command-line interface.
- The standard library `wave`_, `aifc`_, and `sunau`_ modules (for
uncompressed audio formats).

.. _Gstreamer:
.. _gst-python:
.. _Core Audio:
.. _ctypes:
.. _MAD:
.. _pymad:
.. _FFmpeg:
.. _Libav:
.. _wave:
.. _aifc:
.. _aifc:
.. _PyGObject:

Use the library like so::

with audioread.audio_open(filename) as f:
print(f.channels, f.samplerate, f.duration)
for buf in f:

Buffers in the file can be accessed by iterating over the object returned from
``audio_open``. Each buffer is a ``buffer`` or ``str`` object containing raw
**16-bit little-endian signed integer PCM data**. (Currently, these PCM format
parameters are not configurable, but this could be added to most of the

Additional values are available as fields on the audio file object:

- ``channels`` is the number of audio channels (an integer).
- ``samplerate`` is given in Hz (an integer).
- ``duration`` is the length of the audio in seconds (a float).

The ``audio_open`` function transparently selects a backend that can read the
file. (Each backend is implemented in a module inside the ``audioread``
package.) If no backends succeed in opening the file, a ``DecodeError``
exception is raised. This exception is only used when the file type is
unsupported by the backends; if the file doesn't exist, a standard ``IOError``
will be raised.

Audioread is "universal" and supports both Python 2 (2.6+) and Python 3


The included ```` script demonstrates using this package to
convert compressed audio files to WAV files.

Version History

The FFmpeg backend can now also use Libav's ``avconv`` command.
Fix a warning by requiring GStreamer >= 1.0.
Fix some Python 3 crashes with the new GStreamer backend (thanks to

The GStreamer backend now uses GStreamer 1.x via the new
gobject-introspection API (and is compatible with Python 3).

When running FFmpeg on Windows, disable its crash dialog. Thanks to

Fix an unhandled exception when opening non-raw audio files (thanks to
Fix Python 3 compatibility for the raw-file backend.

Add support for FFmpeg on Windows (thanks to Jean-Christophe Saad-Dupuy).

Add support for Sun/NeXT `Au files`_ via the standard-library ``sunau``
module (thanks to Dan Ellis).

Use the rawread (standard-library) backend for .wav files.

Send SIGKILL, not SIGTERM, to ffmpeg processes to avoid occasional hangs.

When GStreamer fails to report a duration, raise an exception instead of
silently setting the duration field to None.

Catch GStreamer's exception when necessary components, such as
``uridecodebin``, are missing.
The GStreamer backend now accepts relative paths.
Fix a hang in GStreamer when the stream finishes before it begins (when
reading broken files).
Initial support for Python 3.

All decoding errors are now subclasses of ``DecodeError``.

Fix opening WAV and AIFF files via Unicode filenames.

Make FFmpeg timeout more robust.
Dump FFmpeg output on timeout.
Fix a nondeterministic hang in the Gstreamer backend.
Fix a file descriptor leak in the MAD backend.

Fix crash when FFmpeg fails to report a duration.
Fix a hang when FFmpeg fills up its stderr output buffer.
Add a timeout to ``ffmpeg`` tool execution (currently 10 seconds for each
4096-byte read); a ``ReadTimeoutError`` exception is raised if the tool times

Fix channel count detection for FFmpeg backend.

Fix a problem with the Gstreamer backend where audio files could be left open
even after the ``GstAudioFile`` was "closed".

Fix a hang in the GStreamer backend that occurs occasionally on some

Initial release.

.. _Au files:

Et Cetera

``audioread`` is by Adrian Sampson. It is made available under `the MIT
license`_. An alternative to this module is ``_.

.. _the MIT license:

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
audioread-2.1.0.tar.gz (14.6 kB) Copy SHA256 hash SHA256 Source None

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