Debian Codegraph @

README.rst

raw
1 audioread
2 =========
3
4 Decode audio files using whichever backend is available. The library
5 currently supports:
6
7 - `Gstreamer`_ via `PyGObject`_.
8 - `Core Audio`_ on Mac OS X via `ctypes`_. (PyObjC not required.)
9 - `MAD`_ via the `pymad`_ bindings.
10 - `FFmpeg`_ or `Libav`_ via its command-line interface.
11 - The standard library `wave`_, `aifc`_, and `sunau`_ modules (for
12 uncompressed audio formats).
13
14 .. _Gstreamer: http://gstreamer.freedesktop.org/
15 .. _gst-python: http://gstreamer.freedesktop.org/modules/gst-python.html
16 .. _Core Audio: http://developer.apple.com/technologies/mac/audio-and-video.html
17 .. _ctypes: http://docs.python.org/library/ctypes.html
18 .. _MAD: http://www.underbit.com/products/mad/
19 .. _pymad: http://spacepants.org/src/pymad/
20 .. _FFmpeg: http://ffmpeg.org/
21 .. _Libav: https://www.libav.org/
22 .. _wave: http://docs.python.org/library/wave.html
23 .. _aifc: http://docs.python.org/library/aifc.html
24 .. _sunau: http://docs.python.org/library/sunau.html
25 .. _PyGObject: https://pygobject.readthedocs.io/
26
27 Use the library like so::
28
29 with audioread.audio_open(filename) as f:
30 print(f.channels, f.samplerate, f.duration)
31 for buf in f:
32 do_something(buf)
33
34 Buffers in the file can be accessed by iterating over the object returned from
35 ``audio_open``. Each buffer is a bytes-like object (``buffer``, ``bytes``, or
36 ``bytearray``) containing raw **16-bit little-endian signed integer PCM
37 data**. (Currently, these PCM format parameters are not configurable, but this
38 could be added to most of the backends.)
39
40 Additional values are available as fields on the audio file object:
41
42 - ``channels`` is the number of audio channels (an integer).
43 - ``samplerate`` is given in Hz (an integer).
44 - ``duration`` is the length of the audio in seconds (a float).
45
46 The ``audio_open`` function transparently selects a backend that can read the
47 file. (Each backend is implemented in a module inside the ``audioread``
48 package.) If no backends succeed in opening the file, a ``DecodeError``
49 exception is raised. This exception is only used when the file type is
50 unsupported by the backends; if the file doesn't exist, a standard ``IOError``
51 will be raised.
52
53 A second optional parameter to ``audio_open`` specifies which backends to try
54 (instead of trying them all, which is the default). You can use the
55 ``available_backends`` function to get a list backends that are usable on the
56 current system.
57
58 Audioread supports Python 3 (3.9+).
59
60 Example
61 -------
62
63 The included ``decode.py`` script demonstrates using this package to
64 convert compressed audio files to WAV files.
65
66 Troubleshooting
67 ---------------
68
69 A ``NoBackendError`` exception means that the library could not find one of
70 the libraries or tools it needs to decode audio. This could mean, for example,
71 that you have a broken installation of `FFmpeg`_. To check, try typing
72 ``ffmpeg -version`` in your shell. If that gives you an error, try installing
73 FFmpeg with your OS's package manager (e.g., apt or yum) or `using Conda
74 <https://anaconda.org/conda-forge/ffmpeg>`_.
75
76 Version History
77 ---------------
78
79 3.0.2
80 Support path-like objects (not just strings) in the Core Audio backend.
81
82 3.0.1
83 Fix a possible deadlock when FFmpeg's version output produces too much data.
84
85 3.0.0
86 Drop support for Python 2 and older versions of Python 3. The library now
87 requires Python 3.6+.
88 Increase default block size in FFmpegAudioFile to get slightly faster file reading.
89 Cache backends for faster lookup (thanks to @bmcfee).
90 Audio file classes now inherit from a common base ``AudioFile`` class.
91
92 2.1.9
93 Work correctly with GStreamer 1.18 and later (thanks to @ssssam).
94
95 2.1.8
96 Fix an unhandled ``OSError`` when FFmpeg is not installed.
97
98 2.1.7
99 Properly close some filehandles in the FFmpeg backend (thanks to
100 @RyanMarcus and @ssssam).
101 The maddec backend now always produces bytes objects, like the other
102 backends (thanks to @ssssam).
103 Resolve an audio data memory leak in the GStreamer backend (thanks again to
104 @ssssam).
105 You can now optionally specify which specific backends ``audio_open`` should
106 try (thanks once again to @ssssam).
107 On Windows, avoid opening a console window to run FFmpeg (thanks to @flokX).
108
109 2.1.6
110 Fix a "no such process" crash in the FFmpeg backend on Windows Subsystem for
111 Linux (thanks to @llamasoft).
112 Avoid suppressing SIGINT in the GStreamer backend on older versions of
113 PyGObject (thanks to @lazka).
114
115 2.1.5
116 Properly clean up the file handle when a backend fails to decode a file.
117 Fix parsing of "N.M" channel counts in the FFmpeg backend (thanks to @piem).
118 Avoid a crash in the raw backend when a file uses an unsupported number of
119 bits per sample (namely, 24-bit samples in Python < 3.4).
120 Add a ``__version__`` value to the package.
121
122 2.1.4
123 Fix a bug in the FFmpeg backend where, after closing a file, the program's
124 standard input stream would be "broken" and wouldn't receive any input.
125
126 2.1.3
127 Avoid some warnings in the GStreamer backend when using modern versions of
128 GLib. We now require at least GLib 2.32.
129
130 2.1.2
131 Fix a file descriptor leak when opening and closing many files using
132 GStreamer.
133
134 2.1.1
135 Just fix ReST formatting in the README.
136
137 2.1.0
138 The FFmpeg backend can now also use Libav's ``avconv`` command.
139 Fix a warning by requiring GStreamer >= 1.0.
140 Fix some Python 3 crashes with the new GStreamer backend (thanks to
141 @xix-xeaon).
142
143 2.0.0
144 The GStreamer backend now uses GStreamer 1.x via the new
145 gobject-introspection API (and is compatible with Python 3).
146
147 1.2.2
148 When running FFmpeg on Windows, disable its crash dialog. Thanks to
149 jcsaaddupuy.
150
151 1.2.1
152 Fix an unhandled exception when opening non-raw audio files (thanks to
153 aostanin).
154 Fix Python 3 compatibility for the raw-file backend.
155
156 1.2.0
157 Add support for FFmpeg on Windows (thanks to Jean-Christophe Saad-Dupuy).
158
159 1.1.0
160 Add support for Sun/NeXT `Au files`_ via the standard-library ``sunau``
161 module (thanks to Dan Ellis).
162
163 1.0.3
164 Use the rawread (standard-library) backend for .wav files.
165
166 1.0.2
167 Send SIGKILL, not SIGTERM, to ffmpeg processes to avoid occasional hangs.
168
169 1.0.1
170 When GStreamer fails to report a duration, raise an exception instead of
171 silently setting the duration field to None.
172
173 1.0.0
174 Catch GStreamer's exception when necessary components, such as
175 ``uridecodebin``, are missing.
176 The GStreamer backend now accepts relative paths.
177 Fix a hang in GStreamer when the stream finishes before it begins (when
178 reading broken files).
179 Initial support for Python 3.
180
181 0.8
182 All decoding errors are now subclasses of ``DecodeError``.
183
184 0.7
185 Fix opening WAV and AIFF files via Unicode filenames.
186
187 0.6
188 Make FFmpeg timeout more robust.
189 Dump FFmpeg output on timeout.
190 Fix a nondeterministic hang in the Gstreamer backend.
191 Fix a file descriptor leak in the MAD backend.
192
193 0.5
194 Fix crash when FFmpeg fails to report a duration.
195 Fix a hang when FFmpeg fills up its stderr output buffer.
196 Add a timeout to ``ffmpeg`` tool execution (currently 10 seconds for each
197 4096-byte read); a ``ReadTimeoutError`` exception is raised if the tool times
198 out.
199
200 0.4
201 Fix channel count detection for FFmpeg backend.
202
203 0.3
204 Fix a problem with the Gstreamer backend where audio files could be left open
205 even after the ``GstAudioFile`` was "closed".
206
207 0.2
208 Fix a hang in the GStreamer backend that occurs occasionally on some
209 platforms.
210
211 0.1
212 Initial release.
213
214 .. _Au files: http://en.wikipedia.org/wiki/Au_file_format
215
216 Et Cetera
217 ---------
218
219 ``audioread`` is by Adrian Sampson. It is made available under `the MIT
220 license`_. An alternative to this module is `decoder.py`_.
221
222 .. _the MIT license: http://www.opensource.org/licenses/mit-license.php
223 .. _decoder.py: http://www.brailleweb.com/cgi-bin/python.py