Upload env/soundfile-0.13.1.dist-info/METADATA
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438Metadata-Version: 2.1Name: soundfileVersion: 0.13.1Summary: An audio library based on libsndfile, CFFI and NumPyHome-page: https://github.com/bastibe/python-soundfileAuthor: Bastian BechtoldAuthor-email: basti@bastibe.deLicense: BSD 3-Clause LicenseKeywords: audio,libsndfilePlatform: anyClassifier: Development Status :: 5 - Production/StableClassifier: Intended Audience :: DevelopersClassifier: Intended Audience :: Science/ResearchClassifier: License :: OSI Approved :: BSD LicenseClassifier: Natural Language :: EnglishClassifier: Operating System :: OS IndependentClassifier: Programming Language :: PythonClassifier: Programming Language :: Python :: 3Classifier: Programming Language :: Python :: 2Classifier: Programming Language :: Python :: Implementation :: PyPyClassifier: Programming Language :: Python :: Implementation :: CPythonClassifier: Topic :: Multimedia :: Sound/AudioDescription-Content-Type: text/x-rstLicense-File: LICENSERequires-Dist: cffi >=1.0Requires-Dist: numpyProvides-Extra: numpy
python-soundfile================
|version| |python| |status| |license|
|contributors| |downloads|
The `soundfile <https://github.com/bastibe/python-soundfile>`__ module is an audiolibrary based on libsndfile, CFFI and NumPy. Full documentation isavailable on https://python-soundfile.readthedocs.io/.
The ``soundfile`` module can read and write sound files. File reading/writing issupported through `libsndfile <http://www.mega-nerd.com/libsndfile/>`__,which is a free, cross-platform, open-source (LGPL) library for readingand writing many different sampled sound file formats that runs on manyplatforms including Windows, OS X, and Unix. It is accessed through`CFFI <https://cffi.readthedocs.io/>`__, which is a foreign functioninterface for Python calling C code. CFFI is supported for CPython 2.6+,3.x and PyPy 2.0+. The ``soundfile`` module represents audio data as NumPy arrays.
| python-soundfile is BSD licensed (BSD 3-Clause License).| (c) 2013, Bastian Bechtold
|open-issues| |closed-issues| |open-prs| |closed-prs|
.. |contributors| image:: https://img.shields.io/github/contributors/bastibe/python-soundfile.svg.. |version| image:: https://img.shields.io/pypi/v/soundfile.svg.. |python| image:: https://img.shields.io/pypi/pyversions/soundfile.svg.. |license| image:: https://img.shields.io/github/license/bastibe/python-soundfile.svg.. |downloads| image:: https://img.shields.io/pypi/dm/soundfile.svg.. |open-issues| image:: https://img.shields.io/github/issues/bastibe/python-soundfile.svg.. |closed-issues| image:: https://img.shields.io/github/issues-closed/bastibe/python-soundfile.svg.. |open-prs| image:: https://img.shields.io/github/issues-pr/bastibe/python-soundfile.svg.. |closed-prs| image:: https://img.shields.io/github/issues-pr-closed/bastibe/python-soundfile.svg.. |status| image:: https://img.shields.io/pypi/status/soundfile.svg
Breaking Changes----------------
The ``soundfile`` module has evolved rapidly in the past. Mostnotably, we changed the import name from ``import pysoundfile`` to``import soundfile`` in 0.7. In 0.6, we cleaned up many smallinconsistencies, particularly in the the ordering and naming offunction arguments and the removal of the indexing interface.
In 0.8.0, we changed the default value of ``always_2d`` from ``True``to ``False``. Also, the order of arguments of the ``write`` functionchanged from ``write(data, file, ...)`` to ``write(file, data, ...)``.
In 0.9.0, we changed the ``ctype`` arguments of the ``buffer_*``methods to ``dtype``, using the Numpy ``dtype`` notation. The old``ctype`` arguments still work, but are now officially deprecated.
In 0.12.0, we changed the load order of the libsndfile library. Now,the packaged libsndfile in the platform-specific wheels is triedbefore falling back to any system-provided libsndfile. If you wouldprefer using the system-provided libsndfile, install the sourcepackage or source wheel instead of the platform-specific wheels.
Installation------------
The ``soundfile`` module depends on the Python packages CFFI and NumPy, and thelibrary libsndfile.
In a modern Python, you can use ``pip install soundfile`` to downloadand install the latest release of the ``soundfile`` module and itsdependencies. On Windows (64/32) and OS X (Intel/ARM) and Linux 64,this will also install a current version of the library libsndfile. Ifyou install the source module, you need to install libsndfile usingyour distribution's package manager, for example ``sudo apt installlibsndfile1``.
If you are running on an unusual platform or if you are using an olderversion of Python, you might need to install NumPy and CFFI separately,for example using the Anaconda_ package manager.
.. _Anaconda: https://www.continuum.io/downloads
Building--------
``Soundfile`` itself does not contain any compiled code and can bebundled into a wheel with the usual ``python setup.py bdist_wheel``.However, ``soundfile`` relies on libsndfile, and optionally ships itsown copy of libsndfile in the wheel.
To build a binary wheel that contains libsndfile, make sure tocheckout and update the ``_soundfile_data`` submodule, then run``python setup.py bdist_wheel`` as usual. If the resulting file sizeof the wheel is around one megabyte, a matching libsndfile has beenbundled (without libsndfile, it's around 25 KB).
To build binary wheels for all supported platforms, run ``pythonbuild_wheels.py``, which will ``python setup.py bdist_wheel`` for eachof the platforms we have precompiled libsndfiles for.
Error Reporting---------------
In case of API usage errors the ``soundfile`` module raises the usual `ValueError` or `TypeError`.
For other errors `SoundFileError` is raised (used to be `RuntimeError`).Particularly, a `LibsndfileError` subclass of this exception is raised onerrors reported by the libsndfile library. In that case the exception objectprovides the libsndfile internal error code in the `LibsndfileError.code` attribute and the rawlibsndfile error message in the `LibsndfileError.error_string` attribute.
Read/Write Functions--------------------
Data can be written to the file using `soundfile.write()`, or read fromthe file using `soundfile.read()`. The ``soundfile`` module can open all file formatsthat `libsndfile supports<http://www.mega-nerd.com/libsndfile/#Features>`__, for example WAV,FLAC, OGG and MAT files (see `Known Issues <https://github.com/bastibe/python-soundfile#known-issues>`__ below about writing OGG files).
Here is an example for a program that reads a wave file and copies itinto an FLAC file:
.. code:: python
import soundfile as sf
data, samplerate = sf.read('existing_file.wav') sf.write('new_file.flac', data, samplerate)
Block Processing----------------
Sound files can also be read in short, optionally overlapping blockswith `soundfile.blocks()`.For example, this calculates the signal level for each block of a longfile:
.. code:: python
import numpy as np import soundfile as sf
rms = [np.sqrt(np.mean(block**2)) for block in sf.blocks('myfile.wav', blocksize=1024, overlap=512)]
``SoundFile`` Objects---------------------
Sound files can also be opened as `SoundFile` objects. Every`SoundFile` has a specific sample rate, data format and a set number ofchannels.
If a file is opened, it is kept open for as long as the `SoundFile`object exists. The file closes when the object is garbage collected,but you should use the `SoundFile.close()` method or thecontext manager to close the file explicitly:
.. code:: python
import soundfile as sf
with sf.SoundFile('myfile.wav', 'r+') as f: while f.tell() < f.frames: pos = f.tell() data = f.read(1024) f.seek(pos) f.write(data*2)
All data access uses frames as index. A frame is one discrete time-stepin the sound file. Every frame contains as many samples as there arechannels in the file.
RAW Files---------
`soundfile.read()` can usually auto-detect the file type of sound files. Thisis not possible for RAW files, though:
.. code:: python
import soundfile as sf
data, samplerate = sf.read('myfile.raw', channels=1, samplerate=44100, subtype='FLOAT')
Note that on x86, this defaults to ``endian='LITTLE'``. If you arereading big endian data (mostly old PowerPC/6800-based files), youhave to set ``endian='BIG'`` accordingly.
You can write RAW files in a similar way, but be advised that in mostcases, a more expressive format is better and should be used instead.
Virtual IO----------
If you have an open file-like object, `soundfile.read()` can open it just likeregular files:
.. code:: python
import soundfile as sf with open('filename.flac', 'rb') as f: data, samplerate = sf.read(f)
Here is an example using an HTTP request:
.. code:: python
import io import soundfile as sf from urllib.request import urlopen
url = "http://tinyurl.com/shepard-risset" data, samplerate = sf.read(io.BytesIO(urlopen(url).read()))
Note that the above example only works with Python 3.x.For Python 2.x support, replace the third line with:
.. code:: python
from urllib2 import urlopen
In-memory files^^^^^^^^^^^^^^^
Chunks of audio, i.e. `bytes`, can also be read and written without touching the filesystem.In the following example OGG is converted to WAV entirely in memory (without writing files to the disk):
.. code:: python
import io import soundfile as sf
def ogg2wav(ogg: bytes): ogg_buf = io.BytesIO(ogg) ogg_buf.name = 'file.ogg' data, samplerate = sf.read(ogg_buf) wav_buf = io.BytesIO() wav_buf.name = 'file.wav' sf.write(wav_buf, data, samplerate) wav_buf.seek(0) # Necessary for `.read()` to return all bytes return wav_buf.read()
Controlling bitrate mode and compression level^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^For some audio formats, you can control the bitrate and compression level.
`compression_level` is a float between 0 and 1, with 1 being the highest compression, and `bitrate_mode` is 'VARIABLE', 'CONSTANT', or 'AVERAGE'.
.. code:: python
import soundfile as sf # for example, this uncompressed 5 minute wav file with 32 kHz sample rate is 18 Mb data, samplerate = sf.read('5min_32kHz.wav') # maximum mp3 compression results in 1.1 Mb file, with either CONSTANT or VARIABLE bit rate sf.write('max_compression_vbr.mp3', data, samplerate, bitrate_mode='VARIABLE', compression_level=.99) sf.write('max_compression_cbr.mp3', data, samplerate, bitrate_mode='CONSTANT', compression_level=.99) # minimum mp3 compression results in 3.5 Mb file sf.write('min_compression_vbr.mp3', data, samplerate, bitrate_mode='VARIABLE', compression_level=0)
Known Issues------------
Writing to OGG files can result in empty files with certain versions of libsndfile. See `#130 <https://github.com/bastibe/python-soundfile/issues/130>`__ for news on this issue.
If using a Buildroot style system, Python has trouble locating ``libsndfile.so`` file, which causes python-soundfile to not be loaded. This is apparently a bug in `python <https://bugs.python.org/issue13508>`__. For the time being, in ``soundfile.py``, you can remove the call to ``_find_library`` and hardcode the location of the ``libsndfile.so`` in ``_ffi.dlopen``. See `#258 <https://github.com/bastibe/python-soundfile/issues/258>`__ for discussion on this issue.
News----
2013-08-27 V0.1.0 Bastian Bechtold: Initial prototype. A simple wrapper for libsndfile in Python
2013-08-30 V0.2.0 Bastian Bechtold: Bugfixes and more consistency with PySoundCard
2013-08-30 V0.2.1 Bastian Bechtold: Bugfixes
2013-09-27 V0.3.0 Bastian Bechtold: Added binary installer for Windows, and context manager
2013-11-06 V0.3.1 Bastian Bechtold: Switched from distutils to setuptools for easier installation
2013-11-29 V0.4.0 Bastian Bechtold: Thanks to David Blewett, now with Virtual IO!
2013-12-08 V0.4.1 Bastian Bechtold: Thanks to Xidorn Quan, FLAC files are not float32 any more.
2014-02-26 V0.5.0 Bastian Bechtold: Thanks to Matthias Geier, improved seeking and a flush() method.
2015-01-19 V0.6.0 Bastian Bechtold: A big, big thank you to Matthias Geier, who did most of the work!
- Switched to ``float64`` as default data type. - Function arguments changed for consistency. - Added unit tests. - Added global `read()`, `write()`, `blocks()` convenience functions. - Documentation overhaul and hosting on readthedocs. - Added ``'x'`` open mode. - Added `tell()` method. - Added ``__repr__()`` method.
2015-04-12 V0.7.0 Bastian Bechtold: Again, thanks to Matthias Geier for all of his hard work, but also Nils Werner and Whistler7 for their many suggestions and help.
- Renamed ``import pysoundfile`` to ``import soundfile``. - Installation through pip wheels that contain the necessary libraries for OS X and Windows. - Removed ``exclusive_creation`` argument to `write()`. - Added `truncate()` method.
2015-10-20 V0.8.0 Bastian Bechtold: Again, Matthias Geier contributed a whole lot of hard work to this release.
- Changed the default value of ``always_2d`` from ``True`` to ``False``. - Numpy is now optional, and only loaded for ``read`` and ``write``. - Added `SoundFile.buffer_read()` and `SoundFile.buffer_read_into()` and `SoundFile.buffer_write()`, which read/write raw data without involving Numpy. - Added `info()` function that returns metadata of a sound file. - Changed the argument order of the `write()` function from ``write(data, file, ...)`` to ``write(file, data, ...)``
And many more minor bug fixes.
2017-02-02 V0.9.0 Bastian Bechtold: Thank you, Matthias Geier, Tomas Garcia, and Todd, for contributions for this release.
- Adds support for ALAC files. - Adds new member ``__libsndfile_version__`` - Adds number of frames to ``info`` class - Adds ``dtype`` argument to ``buffer_*`` methods - Deprecates ``ctype`` argument to ``buffer_*`` methods - Adds official support for Python 3.6
And some minor bug fixes.
2017-11-12 V0.10.0 Bastian Bechtold: Thank you, Matthias Geier, Toni Barth, Jon Peirce, Till Hoffmann, and Tomas Garcia, for contributions to this release.
- Should now work with cx_freeze. - Several documentation fixes in the README. - Removes deprecated ``ctype`` argument in favor of ``dtype`` in ``buffer_*()``. - Adds `SoundFile.frames` in favor of now-deprecated ``__len__()``. - Improves performance of `blocks()` and `SoundFile.blocks()`. - Improves import time by using CFFI's out of line mode. - Adds a build script for building distributions.
2022-06-02 V0.11.0 Bastian Bechtold: Thank you, tennies, Hannes Helmholz, Christoph Boeddeker, Matt Vollrath, Matthias Geier, Jacek Konieczny, Boris Verkhovskiy, Jonas Haag, Eduardo Moguillansky, Panos Laganakos, Jarvy Jarvison, Domingo Ramirez, Tim Chagnon, Kyle Benesch, Fabian-Robert Stöter, Joe Todd
- MP3 support - Adds binary wheels for macOS M1 - Improves compatibility with macOS, specifically for M1 machines - Fixes file descriptor open for binary wheels on Windows and Python 3.5+ - Updates libsndfile to v1.1.0 - Adds get_strings method for retrieving all metadata at once - Improves documentation, error messages and tests - Displays length of very short files in samples - Supports the file system path protocol (pathlib et al)
2023-02-02 V0.12.0 Bastian Bechtold Thank you, Barabazs, Andrew Murray, Jon Peirce, for contributions to this release.
- Updated libsndfile to v1.2.0 - Improves precompiled library location, especially with py2app or cx-freeze. - Now provide binary wheels for Linux x86_64 - Now prefers packaged libsndfile over system-installed libsndfile
2023-02-15 V0.12.1 Bastian Bechtold Thank you, funnypig, for the bug report
- Fixed typo on library location detection if no packaged lib and no system lib was found
2025-01-02 V0.13.0 Bastian Bechtold Thank you, Zhong Jianxin, mcclure, jneuendorf-i4h, aoirint, endolith, Guy Illes, ytya, Sam Lapp, Benjamin Moody
- Updated libsndfile to v1.2.2 - Linux arm64 builds added - Numpy is now a dependency - Fixed error in blocks, if file is very short - Compression level and bitrate controls added for compressed files - Various README improvements - Various build system improvements - Various improvements to error messages
2025-01-25 V0.13.1 Bastian Bechtold Thank you, Brian McFee and Guy Illes
- Fixed regression in blocksenv/soundfile-0.13.1.dist-info/METADATAAdded+438