mirror of
https://github.com/correl/dejavu.git
synced 2024-11-23 19:19:53 +00:00
200 lines
10 KiB
Markdown
200 lines
10 KiB
Markdown
|
dejavu
|
|||
|
==========
|
|||
|
|
|||
|
Mutlithreaded audio fingerprinting and recognition algorithm implemented in Python.
|
|||
|
|
|||
|
Dejavu can memorize audio by listening to it once and fingerprinting it. Then by playing a song and recording microphone input, Dejavu attempts to match the audio against the fingerprints held in the database, returning the song being played.
|
|||
|
|
|||
|
## Depedencies:
|
|||
|
|
|||
|
I've only tested this on Unix systems.
|
|||
|
|
|||
|
* [`pyaudio`](http://people.csail.mit.edu/hubert/pyaudio/) for grabbing audio from microphone
|
|||
|
* [`ffmpeg`](https://github.com/FFmpeg/FFmpeg) for converting audio files to .wav format
|
|||
|
* [`pydub`](http://pydub.com/), a Python `ffmpeg` wrapper
|
|||
|
* [`numpy`](http://www.numpy.org/) for taking the FFT of audio signals
|
|||
|
* [`scipy`](http://www.scipy.org/), used in peak finding algorithms
|
|||
|
* [`MySQLdb`](http://mysql-python.sourceforge.net/MySQLdb.html) for interfacing with MySQL databases
|
|||
|
|
|||
|
For installing `ffmpeg` on Mac OS X, I highly recommend [this post](http://jungels.net/articles/ffmpeg-howto.html).
|
|||
|
|
|||
|
## Setup
|
|||
|
|
|||
|
First, install the above dependencies.
|
|||
|
|
|||
|
Second, you'll need to create a MySQL database where Dejavu can store fingerprints. For example, on your local setup:
|
|||
|
|
|||
|
$ mysql -u root -p
|
|||
|
Enter password: **********
|
|||
|
mysql> CREATE DATABASE IF NOT EXISTS dejavu;
|
|||
|
|
|||
|
Next, create a configuration file. Let's call it `dejavu.cnf`:
|
|||
|
|
|||
|
[connection]
|
|||
|
username: root
|
|||
|
password: <password above>
|
|||
|
database: <name of database you created above>
|
|||
|
hostname: 127.0.0.1
|
|||
|
|
|||
|
Now you're ready to start fingerprinting your audio collection!
|
|||
|
|
|||
|
## Fingerprinting
|
|||
|
|
|||
|
Let's say we want to fingerprint all of July 2013's VA US Top 40 hits.
|
|||
|
|
|||
|
Start by loading the configuration file and creating a Dejavu object.
|
|||
|
```python
|
|||
|
>>> from dejavu.control import Dejavu
|
|||
|
>>> from ConfigParser import ConfigParser
|
|||
|
>>> config = ConfigParser()
|
|||
|
>>> config.read("dejavu.cnf")
|
|||
|
>>> dejavu = Dejavu(config)
|
|||
|
```
|
|||
|
|
|||
|
Next, give the `fingerprint()` command four arguments:
|
|||
|
* input directory to look for audio files
|
|||
|
* output directory to place .wav files (for computing fingerprints)
|
|||
|
* audio extensions to look for in the input directory
|
|||
|
* number of processes
|
|||
|
|
|||
|
```python
|
|||
|
>>> dejavu.fingerprint("va_us_top_40/mp3", "va_us_top_40/wav", [".mp3"], 3)
|
|||
|
```
|
|||
|
|
|||
|
For a large amount of files, this will take a while. However, Dejavu is robust enough you can kill and restart without affecting progress: Dejavu remembers which songs it fingerprinted and converted and which it didn't, and so won't repeat itself.
|
|||
|
|
|||
|
You'll have a lot of fingerprints once it completes a large folder of mp3s:
|
|||
|
```python
|
|||
|
>>> print dejavu.fingerprinter.db.get_num_fingerprints() |