Chromaprint and Acoustid for Python
===================================
`Chromaprint`_ and its associated `Acoustid`_ Web service make up a
high-quality, open-source acoustic fingerprinting system. This package provides
Python bindings for both the fingerprinting algorithm library, which is written
in C but portable, and the Web service, which provides fingerprint lookups.
.. _Chromaprint: http://acoustid.org/chromaprint
.. _Acoustid: http://acoustid.org/
Installation
------------
This library works with Python 2 (2.7+, possibly also 2.6) and Python 3
(3.3+).
First, install the `Chromaprint`_ fingerprinting library by `Lukas Lalinsky`__.
(The library itself depends on an FFT library, but it's smart enough to use an
algorithm from software you probably already have installed; see the Chromaprint
page for details.) This module can use either the Chromaprint dynamic library or
the ``fpcalc`` command-line tool, which itself depends on `libavcodec`_. If you
use ``fpcalc``, either ensure that it is on your ``$PATH`` or set the ``FPCALC``
environment variable to its location.
__ lukas_
.. _lukas: https://oxygene.sk/about/
.. _libavcodec: http://ffmpeg.org/
Then you can install this library from `PyPI`_ using `pip`_::
$ pip install pyacoustid
This library uses `audioread`_ to do audio decoding when not using ``fpcalc``
and `requests`_ to talk to the HTTP API (pip should automatically install
these dependencies).
.. _pip: http://www.pip-installer.org/
.. _PyPI: http://pypi.python.org/
.. _audioread: https://github.com/sampsyo/audioread
.. _requests: http://python-requests.org
Running
-------
You can run the included demonstration script, ``aidmatch.py``, to test your
installation::
$ python aidmatch.py mysterious_music.mp3
This will show the top metadata match from Acoustid's database. The script uses
`audioread`_ to decode music, so it should transparently use a media library
available on your system (GStreamer, FFmpeg, MAD, or Core Audio).
Using in Your Code
------------------
The simplest way to use pyacoustid to identify audio files is to call the
``match`` function::
>>> import acoustid
>>> for score, recording_id, title, artist in acoustid.match(apikey, path):
>>> ...
This convenience function uses `audioread`_ to decode audio and parses the
response for you, pulling out the most important track metadata. It returns in
iterable over tuples of relevant information. Everything happens in one fell
swoop. There are also a number of "smaller" functions you can use to perform
parts of the process:
- ``fingerprint(samplerate, channels, pcmiter)``: Generate a fingerprint for raw
audio data. Specify the audio parameters and give an iterable containing
blocks of PCM data.
- ``fingerprint_file(path)``: Using either the Chromaprint dynamic library or
the ``fpcalc`` command-line tool, fingerprint an audio file. (You can use
``force_fpcalc`` to use only the latter.) Returns a pair consisting of the
file's duration and its fingerprint.
- ``lookup(apikey, fingerprint, duration)``: Make a request to the `Acoustid`_
API to look up the fingerprint returned by the previous function. An API key
is required, as is the length, in seconds, of the source audio. Returns a
parsed JSON response.
- ``parse_lookup_result(data)``: Given a parsed JSON response, return an
iterator over tuples containing the match score (a float between 0 and 1), the
MusicBrainz recording ID, title, and artist name for each match.
- ``compare_fingerprints(a, b)``: Compare two fingerprints produced by
`fingerprint_file`, returning a similarity score.
The module internally performs thread-safe API rate limiting to 3 queries per
second whenever the Web API is called, in accordance with the `Web service
documentation`_.
If you're running your own Acoustid database server, you can set the base URL
for all API calls with the ``set_base_url`` function.
Calls to the library can raise ``AcoustidError`` exceptions of two subtypes:
``FingerprintGenerationError`` and ``WebServiceError``. Catch these exceptions
if you want to proceed when audio can't be decoded or no match is found on the
server. ``NoBackendError``, a subclass of ``FingerprintGenerationError``, is
used when the Chromaprint library or fpcalc command-line tool cannot be found.
.. _Web service documentation: http://acoustid.org/webservice
Version History
---------------
1.3.0
Multiple artists are joined by join phrases, as displayed on the web page.
A new (pure-Python) function compares two Chromaprint fingerprints for
similarity.
Search more shared-library locations for the Chromaprint library on Windows.
1.2.3
Fix the signedness of numbers returned from
`chromaprint_decode_fingerprint`.
1.2.2
Fix a regression in the previous version that caused a `KeyError` crash when
calling `submit`.
1.2.1
The `meta` parameter to some API functions can now be a list (instead of
just a single string).
1.2.0
Add a `force_fpcalc` option to `fingerprint_file` and `match`.
Avoid leaving a dangling socket after communicating with the server.
Fix a crash when passing a `memoryview` object to the fingerprinter.
API requests can now optionally time out.
More reliably find the library on Windows on Python 3.8.
Add a `hash_fingerprint` function to the low-level library.
1.1.7
Include a LICENSE file.
1.1.6
In submission, avoid an error on non-integer durations.
A new function, `get_submission_status`, abstracts the API endpoint for
monitoring submissions using the (new) result from the `submit` function.
1.1.5
Fix compatibility with Python 3 in the `submit` function.
Errors in `submit` are now also handled correctly (i.e., they raise an
informative `WebServiceError` instead of a `TypeError`).
1.1.4
Fix an error on versions of the `fpcalc` tool that report the duration as a
fractional number.
1.1.3
Accept `bytearray` objects in addition to other bytes-like types.
1.1.2
Fix a possible crash on Unicode text in Python 2 in a non-Unicode locale.
Look for version "1" of the Chromaprint shared library file.
1.1.1
Fix a possible setup error on Python 3 (thanks to Simon Chopin).
1.1.0
Include ``fpcalc.py`` script in source distributions.
Add Python 3 support (thanks to Igor Tsarev).
1.0.0
Include ``fpcalc.py``, a script mimicking the ``fpcalc`` program from the
Chromaprint package.
Handle a ``UnicodeDecodeError`` raised when using the ``fpcalc`` backend on
Windows with Unicode filenames.
Standard error output from ``fpcalc`` is suppressed.
0.7
Properly encode Unicode parameters (resolves a ``UnicodeEncodeError``
in fingerprint submission).
Parse all recordings for each Acoustid lookup result.
0.6
Add a new function, ``fingerprint_file``, that automatically selects a
backend for fingerprinting a single file.
0.5
Fix response parsing when recording has no artists or title.
Fix compatibility with Python < 2.7.
Add specific ``NoBackendError`` exception.
0.4
Fingerprinting can now fall back to using the ``fpcalc`` command-line tool
instead of the Chromaprint dynamic library so the library can be used with
the binary distributions (thanks to Lukas Lalinsky).
Fingerprint submission (thanks to Alastair Porter).
Data chunks can now be buffers as well as bytestrings (fixes compatibility
with pymad).
0.3
Configurable API base URL.
Result parser now generates all results instead of returning just one.
Find the chromaprint library on Cygwin.
New module names: ``chromaprint`` and ``acoustid`` (no package).
0.2
Compress HTTP requests and responses.
Limit audio decoding to 120 seconds.
Return score from convenience function.
0.1
Initial release.
Credits
-------
This library is by Adrian Sampson. Chromaprint and Acoustid are by `Lukas
Lalinsky`__. This package includes the original `ctypes`_-based bindings
written by Lukas. The entire library is made available under the `MIT license`_.
pyacoustid was written to be used with `beets`_, which you should probably check
out.
__ lukas_
.. _ctypes: http://docs.python.org/library/ctypes.html
.. _beets: http://beets.radbox.org/
.. _MIT license: http://www.opensource.org/licenses/mit-license.php
Raw data
{
"_id": null,
"home_page": "https://github.com/sampsyo/pyacoustid",
"name": "pyacoustid",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Adrian Sampson",
"author_email": "adrian@radbox.org",
"download_url": "https://files.pythonhosted.org/packages/1e/c7/48a17b6a75888cf760a95f677cec5fe68fd00edf9072df14071008d9b2c0/pyacoustid-1.3.0.tar.gz",
"platform": "ALL",
"description": "Chromaprint and Acoustid for Python\n===================================\n\n`Chromaprint`_ and its associated `Acoustid`_ Web service make up a\nhigh-quality, open-source acoustic fingerprinting system. This package provides\nPython bindings for both the fingerprinting algorithm library, which is written\nin C but portable, and the Web service, which provides fingerprint lookups.\n\n.. _Chromaprint: http://acoustid.org/chromaprint\n.. _Acoustid: http://acoustid.org/\n\n\nInstallation\n------------\n\nThis library works with Python 2 (2.7+, possibly also 2.6) and Python 3\n(3.3+).\n\nFirst, install the `Chromaprint`_ fingerprinting library by `Lukas Lalinsky`__.\n(The library itself depends on an FFT library, but it's smart enough to use an\nalgorithm from software you probably already have installed; see the Chromaprint\npage for details.) This module can use either the Chromaprint dynamic library or\nthe ``fpcalc`` command-line tool, which itself depends on `libavcodec`_. If you\nuse ``fpcalc``, either ensure that it is on your ``$PATH`` or set the ``FPCALC``\nenvironment variable to its location.\n\n__ lukas_\n.. _lukas: https://oxygene.sk/about/\n.. _libavcodec: http://ffmpeg.org/\n\nThen you can install this library from `PyPI`_ using `pip`_::\n\n $ pip install pyacoustid\n\nThis library uses `audioread`_ to do audio decoding when not using ``fpcalc``\nand `requests`_ to talk to the HTTP API (pip should automatically install\nthese dependencies).\n\n.. _pip: http://www.pip-installer.org/\n.. _PyPI: http://pypi.python.org/\n.. _audioread: https://github.com/sampsyo/audioread\n.. _requests: http://python-requests.org\n\n\nRunning\n-------\n\nYou can run the included demonstration script, ``aidmatch.py``, to test your\ninstallation::\n\n $ python aidmatch.py mysterious_music.mp3\n\nThis will show the top metadata match from Acoustid's database. The script uses\n`audioread`_ to decode music, so it should transparently use a media library\navailable on your system (GStreamer, FFmpeg, MAD, or Core Audio).\n\n\nUsing in Your Code\n------------------\n\nThe simplest way to use pyacoustid to identify audio files is to call the\n``match`` function::\n\n >>> import acoustid\n >>> for score, recording_id, title, artist in acoustid.match(apikey, path):\n >>> ...\n\nThis convenience function uses `audioread`_ to decode audio and parses the\nresponse for you, pulling out the most important track metadata. It returns in\niterable over tuples of relevant information. Everything happens in one fell\nswoop. There are also a number of \"smaller\" functions you can use to perform\nparts of the process:\n\n- ``fingerprint(samplerate, channels, pcmiter)``: Generate a fingerprint for raw\n audio data. Specify the audio parameters and give an iterable containing\n blocks of PCM data.\n- ``fingerprint_file(path)``: Using either the Chromaprint dynamic library or\n the ``fpcalc`` command-line tool, fingerprint an audio file. (You can use\n ``force_fpcalc`` to use only the latter.) Returns a pair consisting of the\n file's duration and its fingerprint.\n- ``lookup(apikey, fingerprint, duration)``: Make a request to the `Acoustid`_\n API to look up the fingerprint returned by the previous function. An API key\n is required, as is the length, in seconds, of the source audio. Returns a\n parsed JSON response.\n- ``parse_lookup_result(data)``: Given a parsed JSON response, return an\n iterator over tuples containing the match score (a float between 0 and 1), the\n MusicBrainz recording ID, title, and artist name for each match.\n- ``compare_fingerprints(a, b)``: Compare two fingerprints produced by\n `fingerprint_file`, returning a similarity score.\n\nThe module internally performs thread-safe API rate limiting to 3 queries per\nsecond whenever the Web API is called, in accordance with the `Web service\ndocumentation`_.\n\nIf you're running your own Acoustid database server, you can set the base URL\nfor all API calls with the ``set_base_url`` function.\n\nCalls to the library can raise ``AcoustidError`` exceptions of two subtypes:\n``FingerprintGenerationError`` and ``WebServiceError``. Catch these exceptions\nif you want to proceed when audio can't be decoded or no match is found on the\nserver. ``NoBackendError``, a subclass of ``FingerprintGenerationError``, is\nused when the Chromaprint library or fpcalc command-line tool cannot be found.\n\n.. _Web service documentation: http://acoustid.org/webservice\n\n\nVersion History\n---------------\n\n1.3.0\n Multiple artists are joined by join phrases, as displayed on the web page.\n A new (pure-Python) function compares two Chromaprint fingerprints for\n similarity.\n Search more shared-library locations for the Chromaprint library on Windows.\n\n1.2.3\n Fix the signedness of numbers returned from\n `chromaprint_decode_fingerprint`.\n\n1.2.2\n Fix a regression in the previous version that caused a `KeyError` crash when\n calling `submit`.\n\n1.2.1\n The `meta` parameter to some API functions can now be a list (instead of\n just a single string).\n\n1.2.0\n Add a `force_fpcalc` option to `fingerprint_file` and `match`.\n Avoid leaving a dangling socket after communicating with the server.\n Fix a crash when passing a `memoryview` object to the fingerprinter.\n API requests can now optionally time out.\n More reliably find the library on Windows on Python 3.8.\n Add a `hash_fingerprint` function to the low-level library.\n\n1.1.7\n Include a LICENSE file.\n\n1.1.6\n In submission, avoid an error on non-integer durations.\n A new function, `get_submission_status`, abstracts the API endpoint for\n monitoring submissions using the (new) result from the `submit` function.\n\n1.1.5\n Fix compatibility with Python 3 in the `submit` function.\n Errors in `submit` are now also handled correctly (i.e., they raise an\n informative `WebServiceError` instead of a `TypeError`).\n\n1.1.4\n Fix an error on versions of the `fpcalc` tool that report the duration as a\n fractional number.\n\n1.1.3\n Accept `bytearray` objects in addition to other bytes-like types.\n\n1.1.2\n Fix a possible crash on Unicode text in Python 2 in a non-Unicode locale.\n Look for version \"1\" of the Chromaprint shared library file.\n\n1.1.1\n Fix a possible setup error on Python 3 (thanks to Simon Chopin).\n\n1.1.0\n Include ``fpcalc.py`` script in source distributions.\n Add Python 3 support (thanks to Igor Tsarev).\n\n1.0.0\n Include ``fpcalc.py``, a script mimicking the ``fpcalc`` program from the\n Chromaprint package.\n Handle a ``UnicodeDecodeError`` raised when using the ``fpcalc`` backend on\n Windows with Unicode filenames.\n Standard error output from ``fpcalc`` is suppressed.\n\n0.7\n Properly encode Unicode parameters (resolves a ``UnicodeEncodeError``\n in fingerprint submission).\n Parse all recordings for each Acoustid lookup result.\n\n0.6\n Add a new function, ``fingerprint_file``, that automatically selects a\n backend for fingerprinting a single file.\n\n0.5\n Fix response parsing when recording has no artists or title.\n Fix compatibility with Python < 2.7.\n Add specific ``NoBackendError`` exception.\n\n0.4\n Fingerprinting can now fall back to using the ``fpcalc`` command-line tool\n instead of the Chromaprint dynamic library so the library can be used with\n the binary distributions (thanks to Lukas Lalinsky).\n Fingerprint submission (thanks to Alastair Porter).\n Data chunks can now be buffers as well as bytestrings (fixes compatibility\n with pymad).\n\n0.3\n Configurable API base URL.\n Result parser now generates all results instead of returning just one.\n Find the chromaprint library on Cygwin.\n New module names: ``chromaprint`` and ``acoustid`` (no package).\n\n0.2\n Compress HTTP requests and responses.\n Limit audio decoding to 120 seconds.\n Return score from convenience function.\n\n0.1\n Initial release.\n\n\nCredits\n-------\n\nThis library is by Adrian Sampson. Chromaprint and Acoustid are by `Lukas\nLalinsky`__. This package includes the original `ctypes`_-based bindings\nwritten by Lukas. The entire library is made available under the `MIT license`_.\npyacoustid was written to be used with `beets`_, which you should probably check\nout.\n\n__ lukas_\n.. _ctypes: http://docs.python.org/library/ctypes.html\n.. _beets: http://beets.radbox.org/\n.. _MIT license: http://www.opensource.org/licenses/mit-license.php\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "bindings for Chromaprint acoustic fingerprinting and the Acoustid API",
"version": "1.3.0",
"project_urls": {
"Homepage": "https://github.com/sampsyo/pyacoustid"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "1ec748a17b6a75888cf760a95f677cec5fe68fd00edf9072df14071008d9b2c0",
"md5": "dd7332cd4be244e54f17609f9626e165",
"sha256": "5f4f487191c19ebb908270b1b7b5297f132da332b1568b96a914574c079ed177"
},
"downloads": -1,
"filename": "pyacoustid-1.3.0.tar.gz",
"has_sig": false,
"md5_digest": "dd7332cd4be244e54f17609f9626e165",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17369,
"upload_time": "2023-09-12T19:25:21",
"upload_time_iso_8601": "2023-09-12T19:25:21.258979Z",
"url": "https://files.pythonhosted.org/packages/1e/c7/48a17b6a75888cf760a95f677cec5fe68fd00edf9072df14071008d9b2c0/pyacoustid-1.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-12 19:25:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sampsyo",
"github_project": "pyacoustid",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pyacoustid"
}