audfprint

repository·master·Indexed 20 days ago

https://github.com/dpwe/audfprint

A landmark-based audio fingerprinting tool used to identify audio excerpts within a database of reference tracks. It is designed to handle noisy queries and scale to large databases. The tool provides a CLI for creating, adding to, merging, and querying fingerprint databases, as well as utilities like dpwe_builder.py and dpwe_matcher.py. It requires Python, ffmpeg, librosa, and docopt.

Tokens
2.4K
Snippets
9
Records
12
Agent score
20%

What's inside audfprint

  1. Configure time range and capacity with maxtimebits

    master

    By default, audfprint stores time in the bottom 14 bits of each database entry. This means tracks longer than approximately 6 minutes (2^14 * 0.023s) will have aliased time offsets.

    To support longer tracks, increase the --maxtimebits value:

    • Example: --maxtimebits 16 increases the range to ~25 minutes at 11 kHz.

    Trade-off: Increasing --maxtimebits reduces the number of bits available to store the track ID. This reduces the total number of unique tracks the database can distinguish (e.g., the default 14 bits allows for 2^18 = 262k tracks; increasing bits reduces this capacity).

  2. Merge audio fingerprint databases

    master

    Merge into an existing database

    Use merge to add the contents of one database into another existing database.

    python audfprint.py merge --dbase fpdbase.pklz fpdbase0.pklz

    Create a new database from multiple existing ones

    Use newmerge to combine two or more existing databases into a brand new database file.

    python audfprint.py newmerge --dbase fpdbase_new.pklz fpdbase.pklz fpdbase0.pklz
    python audfprint.py merge --dbase fpdbase.pklz fpdbase0.pklz
    python audfprint.py newmerge --dbase fpdbase_new.pklz fpdbase.pklz fpdbase0.pklz
  3. Query the database with dpwe_matcher.py

    master

    Use dpwe_matcher.py to identify query soundfiles against an existing database.

    Usage: ./dpwe_matcher.py <queries.list> <db> <matches.out>

    • <queries.list>: A text file containing the paths to the query soundfiles.
    • <db>: The directory containing the database created by dpwe_builder.py.
    • <matches.out>: The output file where matches will be written.

    Output Format: The <matches.out> file contains one line per entry in <queries.list> using a tab-separated format: <path_from_queries>\t<matching_file_from_ref>

    If no match is found for a query, the second field is left blank.

    ./dpwe_matcher.py queries.list db matches.out
  4. Install audfprint and its dependencies

    master

    To use audfprint, you must install the required Python packages and ensure that the ffmpeg binary is installed and available in your system's PATH.

    1. Install Python dependencies:
    pip install -r requirements.txt
    1. Verify ffmpeg installation:
    ffmpeg -V
    pip install -r requirements.txt
  5. Create and expand an audio fingerprint database

    master

    Create a new database

    Use the new command to initialize a database from a set of reference audio files. Use --dbase <name> to specify the database filename.

    python audfprint.py new --dbase fpdbase.pklz Nine_Lives/0*.mp3

    Add tracks to an existing database

    Use the add command to append more reference tracks to a database you have already created.

    python audfprint.py add --dbase fpdbase.pklz Nine_Lives/1*.mp3
    python audfprint.py new --dbase fpdbase.pklz Nine_Lives/0*.mp3
    python audfprint.py add --dbase fpdbase.pklz Nine_Lives/1*.mp3
  6. Install dpwe-audfprint

    master

    dpwe-audfprint runs under Python (ideally Python 2.7.3 on Ubuntu) and requires librosa and docopt. Note that librosa may also require matplotlib.

    Follow these steps to set up the environment and download the source code:

    # Install dependencies
    pip install librosa
    pip install docopt
    
    # Download and extract the code
    wget https://github.com/dpwe/audfprint/archive/master.zip
    unzip master.zip
    cd audfprint-master
  7. Build an audio fingerprint database with dpwe_builder.py

    master

    Use dpwe_builder.py to create a fingerprint database from a list of soundfiles.

    Usage: ./dpwe_builder.py <ref.list> <db>

    • <ref.list>: A text file containing the paths to the reference soundfiles.
    • <db>: The directory where the database will be stored.
    mkdir db
    ./dpwe_builder.py ref.list db
  8. Configure dpwe_builder.py and dpwe_matcher.py

    master

    Both the builder and matcher accept an optional configuration file using the -C flag. This allows you to tune the fingerprinting parameters.

    Usage: ./dpwe_builder.py -C <config.txt> <ref.list> <db> ./dpwe_matcher.py -C <config.txt> <queries.list> <db> <matches.out>

    Configurable Parameters:

    • density: Approximate number of landmarks per second.
    • fanout: Number of hashes per landmark.
    • ncores: Number of CPU cores to use for multiprocessing.

    Available Example Configurations:

    • config.txt: density=70, fanout=8 (Default)
    • config_low.txt: density=50, fanout=6 (Faster, less accurate)
    • config2_high.txt: density=100, fanout=10 (Slower, more accurate)
    • config2_tiny.txt: density=20, fanout=3 (Very fast/small reference database)
    ./dpwe_builder.py -C config.txt ref.list db
  9. Match a query audio file against a database

    master

    To find where a query audio fragment (e.g., a recording of music playing in the background) exists within your fingerprint database, use the match command.

    python audfprint.py match --dbase fpdbase.pklz query.mp3

    By default, the tool reports the matched file and the timestamp within that file where the match begins.

    python audfprint.py match --dbase fpdbase.pklz query.mp3
  10. Find exact time ranges for matches

    master

    If you need to know the specific duration and time range that matches in both the query and the reference file (rather than just a single starting timestamp), use the --find-time-range flag with the match command.

    python audfprint.py match --dbase fpdbase.pklz query.mp3 --find-time-range

    Note: These time ranges are calculated by discarding a small proportion of matches at the extreme ends of the match region to avoid spurious results. This proportion is controlled by the --time-quantile option (default is 0.05, though the README text mentions 0.01 in its example context; check the CLI help for the current default).

  11. Reference: audfprint CLI options

    master

    The following options are available for the audfprint command:

    OptionLong FlagDescription
    -d <dbase>--dbase <dbase>Fingerprint database file
    -n <dens>--density <dens>Target hashes per second [default: 20.0]
    -h <bits>--hashbits <bits>How many bits in each hash [default: 20]
    -b <val>--bucketsize <val>Number of entries per bucket [default: 100]
    -t <val>--maxtime <val>Largest time value stored [default: 16384]
    -u <val>--maxtimebits <val>maxtime as a number of bits (16384 == 14 bits)
    -r <val>--samplerate <val>Resample input files to this [default: 11025]
    -p <dir>--precompdir <dir>Save precomputed files under this dir [default: .]
    -i <val>--shifts <val>Use this many subframe shifts building fp [default: 0]
    -w <val>--match-win <val>Maximum tolerable frame skew to count as a match [default: 2]
    -N <val>--min-count <val>Minimum number of matching landmarks to count as a match [default: 5]
    -x <val>--max-matches <val>Maximum number of matches to report for each query [default: 1]
    --exact-countFlag to use more precise (but slower) match counting
    --find-time-rangeReport the time support of each match
    -Q <val>--time-quantile <val>Quantile at extremes of time support [default: 0.05]
    -S <val>--freq-sd <val>Frequency peak spreading SD in bins [default: 30.0]
    -F <val>--fanout <val>Max number of hash pairs per peak [default: 3]
    -P <val>--pks-per-frame <val>Maximum number of peaks per frame [default: 5]
    -D <val>--search-depth <val>How far down to search raw matching track list [default: 100]
    -H <val>--ncores <val>Number of processes to use [default: 1]
    -o <name>--opfile <name>Write output (matches) to this file, not stdout [default: ]
    -K--precompute-peaksPrecompute just landmarks (else full hashes)
    -k--skip-existingOn precompute, skip items if output file already exists
    -C--continue-on-errorKeep processing despite errors reading input
    -l--listInput files are lists, not audio
    -T--sortbytimeSort multiple hits per file by time (instead of score)
    -v <val>--verbose <val>Verbosity level [default: 1]
    -I--illustrateMake a plot showing the match
    -J--illustrate-hpfPlot the match, using onset enhancement
    -W <dir>--wavdir <dir>Find sound files under this dir [default: ]
    -V <ext>--wavext <ext>Extension to add to wav file names [default: ]
  12. Use audfprint CLI commands

    master

    The audfprint tool is a command-line utility for landmark-based audio fingerprinting. The general usage pattern is:

    python audfprint.py <command> [options] [<file>]...

    Available commands:

    • new: Create a new fingerprint database.
    • add: Append new files to an existing database.
    • match: Identify noisy query excerpts within the database.
    • precompute: Write *.fpt files containing precomputed fingerprints for input .wav files.
    • merge: Combine previously created databases into an existing database.
    • newmerge: Combine existing databases to create a new one.
    • list: Treat input files as lists rather than audio files.
    • remove: Remove entries (implied by command list).
    python audfprint.py (new | add | match | precompute | merge | newmerge | list | remove) [options] [<file>]...