multi-library, cross-platform audio decoding
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).
Use the library like so:
with audioread.audio_open(filename) as f: print(f.channels, f.samplerate, f.duration) for buf in f: do_something(buf)
Buffers in the file can be accessed by iterating over the object returned from audio_open. Each buffer is a bytes-like object (buffer, bytes, or bytearray) 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 backends.)
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.
A second optional parameter to audio_open specifies which backends to try (instead of trying them all, which is the default). You can use the available_backends function to get a list backends that are usable on the current system.
Audioread is “universal” and supports both Python 2 (2.6+) and Python 3 (3.2+).
The included decode.py script demonstrates using this package to convert compressed audio files to WAV files.
- Fix an unhandled OSError when FFmpeg is not installed.
- Properly close some filehandles in the FFmpeg backend (thanks to @RyanMarcus and @ssssam). The maddec backend now always produces bytes objects, like the other backends (thanks to @ssssam). Resolve an audio data memory leak in the GStreamer backend (thanks again to @ssssam). You can now optionally specify which specific backends audio_open should try (thanks once again to @ssssam). On Windows, avoid opening a console window to run FFmpeg (thanks to @flokX).
- Fix a “no such process” crash in the FFmpeg backend on Windows Subsystem for Linux (thanks to @llamasoft). Avoid suppressing SIGINT in the GStreamer backend on older versions of PyGObject (thanks to @lazka).
- Properly clean up the file handle when a backend fails to decode a file. Fix parsing of “N.M” channel counts in the FFmpeg backend (thanks to @piem). Avoid a crash in the raw backend when a file uses an unsupported number of bits per sample (namely, 24-bit samples in Python < 3.4). Add a __version__ value to the package.
- Fix a bug in the FFmpeg backend where, after closing a file, the program’s standard input stream would be “broken” and wouldn’t receive any input.
- Avoid some warnings in the GStreamer backend when using modern versions of GLib. We now require at least GLib 2.32.
- Fix a file descriptor leak when opening and closing many files using GStreamer.
- Just fix ReST formatting in the README.
- 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 @xix-xeaon).
- 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 jcsaaddupuy.
- Fix an unhandled exception when opening non-raw audio files (thanks to aostanin). 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 out.
- 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 platforms.
- Initial release.
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size audioread-2.1.8.tar.gz (21.2 kB)||File type Source||Python version None||Upload date||Hashes View|