Audio fingerprinting and recognition algorithm implemented in Python.
Users may create a customized music database, view spectral analyses of a song, and identify a song from noisy snippets. Main functionality of this program has been tested on Windows 10.
Software
ffmpegfor converting audio files to .wav formatPostgreSQLfor database construction
Python packages
pyduba Python ffmpeg wrappereyed3for reading mp3 metadatanumpyfor audio signals transformationsscipyused in spectrogram and peak finding algorithmsmatplotlibused for spectrogram plotspsycopg2a Python-PostgreSQL database adapter
First, install the above dependencies.
Second, git clone the project into a local git directory.
Third, you'll allow the program to access your PostgreSQL database where fingerprints can be stored. In the shazam folder, create a python file named credentials.py:
#credentials.py
DB_USER = 'your-db-username'
DB_PASSWORD = your-db-password
Now you're ready to start fingerprinting your audio collection!
This program has the following functionalities:
Database construction
This program allows you to build your own music database at 1-click!
To get started, please copy your music files (preferably in mp3 format) into the freezam/music/mp3 folder. You'll notice that the folder already contains some pre-downloaded music files for testing purposes. Feel free to add or remove files in the folder.
Then run the following command in the terminal:
cd freezam
$python interface.py constructThe program will print a message when it is done.
Database management
Currently the program supports the following manipulations of database:
- add a song to database
python interface.py add [-h] [--pathfile PATHFILE]
- modify song info
python interface.py update [-h] [--title TITLE] [--artist ARTIST] [--album ALBUM]
- remove a song from database
python interface.py remove [-h] [--title TITLE]
- list all songs in database
python interface.py list [-h]
- check and remove duplicate entries (should run regularly for database maintenance)
python interface.py admin --action=rm_dup
- More to come...
Identify a snippet
python interface.py identify [-h] [--pathfile PATHFILE] --type=1
or
python interface.py identify [-h] [--pathfile PATHFILE] --type=2
This program implements two types of fingerprints for audio identification:
type=1computes a signature from local periodograms using the peak positive frequency method.type=2computes a signature by finding the maximum power per octave in local periodograms.
For faster identification, choose type=1; for better precision, choose type=2. The default option is type=2.
Logging
This application writes a message for each action taken to a designated log file shazam.log. Warnings and error messages go to the log file but also to standard error. You can customize the log level by turning on the -vb (verbose) option, so that all log entries will be output to standard error as well as the log file. For example:
python interface.py -vb identify --pathfile="./music/snippet/Track54.wav" --type=2
cd freezam
# create music database
python interface.py -vb construct
# identify a snippet (pre-downloaded)
python interface.py -vb identify --pathfile="./music/snippet/Track54.wav" --type=2
To run the automated tests for this application:
cd shazam
pytest -v test_shazam.py