What does it do?
It creates an audio fingerprint designed to identify near-identical audio tracks in the AcoustID and MusicBrainz databases. This can be used to identify unknown tracks, find duplicates and look up metadata.
How does it work?
The algorithm performs a pipeline of operations on an audio stream to extract its fingerprint:
- The audio is resampled to mono at 11025Hz
- It is split into a series of short frames
- A Fast Fourier Transform is performed on each frame to extract components of different frequencies
- Audio features such as notes are extracted from each frame
- An image is created from the series of features
- A fingerprint is extracted from the image as a long series of numbers
- This raw fingerprint is compressed into a shorter string
- The string can be compared with other fingerprints to obtain a similarity score
Installation and usage
The FFmpeg library must be installed, along with codecs for files to be analyzed, the
libavcodec-extra package on Debian should provide all of these.
resolvers += Resolver.bintrayRepo("mgdigital", "chromaprint") libraryDependencies += "com.github.mgdigital" %% "chromaprint" % "0.2.1"
Then in your Scala application:
import chromaprint.quick._ val file = new java.io.File("/audio/Pocket Calculator.flac") val fingerprint = Fingerprinter(file).unsafeRunSync() println(fingerprint.compressed) // AQADtNQYhYkYnGhw7X...
Note: The fingerprint is generated using a FS2 stream, and the
Fingerprinter returns a type of
IO[Fingerprint], which is a
Fingerprint type wrapped in a Cats Effect IO type. Running
ùnsafeRunSync() on the
IO[Fingerprint] object is the quickest way to have it return the
Fingerprint, a different
IO method may be better suited to your application.
Build the Docker image
$ docker build -t chromaprint-scala .
Then run the command line app (assuming audio file in current folder, double quotes needed for filenames containing spaces).
$ docker run -ti -v $(pwd):/audio/ chromaprint-scala '"/audio/Pocket Calculator.flac"'
Identify track with AcoustID
Get an AcoustID client ID and provide the
acoustid-client option in the command line app to lookup matches in the AcoustID database:
$ sbt run "/audio/Pocket Calculator.flac" --acoustid-client=MyClientId [info] Running chromaprint.Main /audio/Pocket Calculator.flac --acoustid-client=MyClientId Fingerprinting... Created fingerprint in 1.983s Duration: 296.80008 Fingerprint (compressed): AQADtNQYhYkYnGhw7X.... AcoustID response received c0c5a16f-64e0-4571-aa29-ba80e6cb7874: Result 1 with score 0.923195: 867cf1a1-c46a-4ad5-916f-0c5397ff65e5: 'Pocket Calculator' by 'Kraftwerk' ...
See the code for the command line app under
chromaprint.cli for further examples.
Note that the fingerprinter requires an implicit for the FFT (Fast Fourier Transform) implementation. Adapters are provided for Breeze and through FFTW via JavaCPP Presets. I have seen intermittent errors in the FFTW adapter so would recommend using Breeze.
Copyright (c) 2019 Mike Gibson, https://github.com/mgdigital. Original Chromaprint algorithm Copyright (c) Lukáš Lalinský.