Added a dejavu.py script and added documentation

This commit is contained in:
Jonathon Hill 2014-02-22 18:56:07 -05:00
parent eefcf0991c
commit 12ca65546d
4 changed files with 135 additions and 1 deletions

29
DEPENDENCIES.md Normal file
View file

@ -0,0 +1,29 @@
# Dependencies required by dejavu
* [`pyaudio`](http://people.csail.mit.edu/hubert/pyaudio/)
* [`ffmpeg`](https://github.com/FFmpeg/FFmpeg)
* [`pydub`](http://pydub.com/)
* [`numpy`](http://www.numpy.org/)
* [`scipy`](http://www.scipy.org/)
* [`matplotlib`](http://matplotlib.org/)
* [`MySQLdb`](http://mysql-python.sourceforge.net/MySQLdb.html)
## Dependency installation for Mac OS X
Tested on OS X Mavericks. Needs [Homebrew](http://brew.sh) to be installed.
```
brew install portaudio
brew install ffmpeg
sudo easy_install pyaudio
sudo easy_install pydub
sudo easy_install numpy
sudo easy_install scipy
sudo easy_install matplotlib
sudo easy_install pip
sudo pip install MySQL-python
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
```

8
dejavu.cnf.SAMPLE Normal file
View file

@ -0,0 +1,8 @@
{
"database": {
"host": "127.0.0.1",
"user": "root",
"passwd": "",
"db": "dejavu"
}
}

97
dejavu.py Executable file
View file

@ -0,0 +1,97 @@
#!/usr/bin/python
import sys
import json
import warnings
from dejavu import Dejavu
from dejavu.recognize import FileRecognizer
from dejavu.recognize import MicrophoneRecognizer
from dejavu.recognize import FileRecognizer
warnings.filterwarnings("ignore")
def init():
# load config from a JSON file (or anything outputting a python dictionary)
with open("dejavu.cnf") as f:
config = json.load(f)
# create a Dejavu instance
return Dejavu(config)
def showHelp():
print ""
print "------------------------------------------------"
print "DejaVu audio fingerprinting and recognition tool"
print "------------------------------------------------"
print ""
print "Usage: dejavu.py [command] [arguments]"
print ""
print "Available commands:"
print ""
print " Fingerprint a file"
print " dejavu.py fingerprint /path/to/file.extension"
print ""
print " Fingerprint all files in a directory"
print " dejavu.py fingerprint /path/to/directory extension"
print ""
print " Recognize what is playing through the microphone"
print " dejavu.py recognize mic number_of_seconds"
print ""
print " Recognize a file by listening to it"
print " dejavu.py recognize file /path/to/file"
print ""
print " Display this help screen"
print " dejavu.py help"
print ""
exit
if len(sys.argv) > 1:
command = sys.argv[1]
else:
showHelp()
if command == 'fingerprint': # Fingerprint all files in a directory
djv = init()
if len(sys.argv) == 4:
directory = sys.argv[2]
extension = sys.argv[3]
print "Fingerprinting all .%s files in the %s directory" % (extension, directory)
djv.fingerprint_directory(directory, ["." + extension], 4)
else:
filepath = sys.argv[2]
djv.fingerprint_file(filepath)
elif command == 'recognize': # Recognize audio
source = sys.argv[2]
if source in ['mic', 'microphone']:
seconds = int(sys.argv[3])
djv = init()
song = djv.recognize(MicrophoneRecognizer, seconds=seconds)
elif source == 'file':
djv = init()
sourceFile = sys.argv[3]
song = djv.recognize(FileRecognizer, sourceFile)
else:
showHelp()
print song
else:
showHelp()

2
go.py → example.py Executable file → Normal file
View file

@ -23,4 +23,4 @@ song = djv.recognize(MicrophoneRecognizer, seconds=2)
# Or use a recognizer without the shortcut, in anyway you would like # Or use a recognizer without the shortcut, in anyway you would like
from dejavu.recognize import FileRecognizer from dejavu.recognize import FileRecognizer
recognizer = FileRecognizer(djv) recognizer = FileRecognizer(djv)
song = recognizer.recognize_file("mp3/sail.mp3") song = recognizer.recognize_file("mp3/sail.mp3")