diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md new file mode 100644 index 0000000..a38ab2f --- /dev/null +++ b/DEPENDENCIES.md @@ -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 +``` diff --git a/dejavu.cnf.SAMPLE b/dejavu.cnf.SAMPLE new file mode 100644 index 0000000..3e980a9 --- /dev/null +++ b/dejavu.cnf.SAMPLE @@ -0,0 +1,8 @@ +{ + "database": { + "host": "127.0.0.1", + "user": "root", + "passwd": "", + "db": "dejavu" + } +} \ No newline at end of file diff --git a/dejavu.py b/dejavu.py new file mode 100755 index 0000000..50c767f --- /dev/null +++ b/dejavu.py @@ -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() + diff --git a/go.py b/example.py old mode 100755 new mode 100644 similarity index 94% rename from go.py rename to example.py index 1df4d26..0268a03 --- a/go.py +++ b/example.py @@ -23,4 +23,4 @@ song = djv.recognize(MicrophoneRecognizer, seconds=2) # Or use a recognizer without the shortcut, in anyway you would like from dejavu.recognize import FileRecognizer recognizer = FileRecognizer(djv) -song = recognizer.recognize_file("mp3/sail.mp3") +song = recognizer.recognize_file("mp3/sail.mp3") \ No newline at end of file