From 4aabea7814b6da8ab52eaad669e776fea6aa62f4 Mon Sep 17 00:00:00 2001 From: Saleem Ansari Date: Fri, 28 Nov 2014 22:56:22 +0530 Subject: [PATCH 1/2] Refactor and update documentation for installation on Fedora 20+ --- DEPENDENCIES.md | 31 ----------------------- INSTALLATION.md | 63 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 16 +++--------- dejavu/__init__.py | 37 ++++++++++++++------------- 4 files changed, 85 insertions(+), 62 deletions(-) delete mode 100755 DEPENDENCIES.md create mode 100644 INSTALLATION.md diff --git a/DEPENDENCIES.md b/DEPENDENCIES.md deleted file mode 100755 index a9259d7..0000000 --- a/DEPENDENCIES.md +++ /dev/null @@ -1,31 +0,0 @@ -# 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. An option is to install [Homebrew](http://brew.sh) and do the following: - -``` -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 -``` - -However installing `portaudio` and/or `ffmpeg` from source is also doable. \ No newline at end of file diff --git a/INSTALLATION.md b/INSTALLATION.md new file mode 100644 index 0000000..33b429e --- /dev/null +++ b/INSTALLATION.md @@ -0,0 +1,63 @@ +# Installation of dejavu + +So far dejavu has only been tested 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 +* [`matplotlib`](http://matplotlib.org/), used for spectrograms and plotting +* [`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). + +## Fedora 20+ + +### Dependency installation for Mac OS X + +Install the dependencies + + sudo yum install numpy scipy python-matplotlib ffmpeg portaudio-devel + pip install PyAudio + pip install pydub + +Now setup virtualenv ([howto?](http://www.pythoncentral.io/how-to-install-virtualenv-python/)) + + pip install virtualenv + virtualenv --system-site-packages env_with_system + +Install from PyPI + + source env_with_system/bin/activate + pip install PyDejavu + + +You can also install the latest code from GitHub: + + source env_with_system/bin/activate + pip install https://github.com/tuxdna/dejavu/zipball/master + +## Max OS X + +### Dependency installation for Mac OS X + +Tested on OS X Mavericks. An option is to install [Homebrew](http://brew.sh) and do the following: + +``` +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 +``` + +However installing `portaudio` and/or `ffmpeg` from source is also doable. diff --git a/README.md b/README.md index 8b4f9b4..e8ea2e5 100755 --- a/README.md +++ b/README.md @@ -6,19 +6,9 @@ Audio fingerprinting and recognition algorithm implemented in Python, see the ex 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. -## Dependencies: +## Installation and Dependencies: -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 -* [`matplotlib`](http://matplotlib.org/), used for spectrograms and plotting -* [`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). +Read [INSTALLATION.md](INSTALLATION.md) ## Setup @@ -148,7 +138,7 @@ and with the command line script, you specify the number of seconds to listen: $ python dejavu.py recognize mic 10 ``` -## Testing (New!) +## Testing Testing out different parameterizations of the fingerprinting algorithm is often useful as the corpus becomes larger and larger, and inevitable tradeoffs between speed and accuracy come into play. diff --git a/dejavu/__init__.py b/dejavu/__init__.py index 2eac959..66d9c92 100755 --- a/dejavu/__init__.py +++ b/dejavu/__init__.py @@ -3,6 +3,9 @@ import dejavu.decoder as decoder import fingerprint import multiprocessing import os +import traceback +import sys + class Dejavu(object): @@ -27,7 +30,7 @@ class Dejavu(object): # if we should limit seconds fingerprinted, # None|-1 means use entire track self.limit = self.config.get("fingerprint_limit", None) - if self.limit == -1: # for JSON compatibility + if self.limit == -1: # for JSON compatibility self.limit = None self.get_fingerprinted_songs() @@ -79,9 +82,7 @@ class Dejavu(object): break except: print("Failed fingerprinting") - # Print traceback because we can't reraise it here - import traceback, sys traceback.print_exc(file=sys.stdout) else: sid = self.db.insert_song(song_name) @@ -94,13 +95,12 @@ class Dejavu(object): pool.join() def fingerprint_file(self, filepath, song_name=None): - - songname = decoder.path_to_songname(filepath) - song_name = song_name or songname - # don't refingerprint already fingerprinted files + songname = decoder.path_to_songname(filepath) + song_name = song_name or songname + # don't refingerprint already fingerprinted files if song_name in self.songnames_set: print "%s already fingerprinted, continuing..." % song_name - else: + else: song_name, hashes = _fingerprint_worker(filepath, self.limit, song_name=song_name) @@ -129,9 +129,9 @@ class Dejavu(object): song_id = -1 for tup in matches: sid, diff = tup - if not diff in diff_counter: + if diff not in diff_counter: diff_counter[diff] = {} - if not sid in diff_counter[diff]: + if sid not in diff_counter[diff]: diff_counter[diff][sid] = 0 diff_counter[diff][sid] += 1 @@ -149,15 +149,16 @@ class Dejavu(object): return None # return match info - nseconds = round(float(largest) / fingerprint.DEFAULT_FS * \ - fingerprint.DEFAULT_WINDOW_SIZE * \ - fingerprint.DEFAULT_OVERLAP_RATIO, 5) + nseconds = round(float(largest) / fingerprint.DEFAULT_FS * + fingerprint.DEFAULT_WINDOW_SIZE * + fingerprint.DEFAULT_OVERLAP_RATIO, 5) song = { - Dejavu.SONG_ID : song_id, - Dejavu.SONG_NAME : songname, - Dejavu.CONFIDENCE : largest_count, - Dejavu.OFFSET : largest, - Dejavu.OFFSET_SECS : nseconds } + Dejavu.SONG_ID: song_id, + Dejavu.SONG_NAME: songname, + Dejavu.CONFIDENCE: largest_count, + Dejavu.OFFSET: largest, + Dejavu.OFFSET_SECS: nseconds + } return song From 785a1db92d243c705581f34a61d8401f267b64d8 Mon Sep 17 00:00:00 2001 From: Saleem Ansari Date: Tue, 2 Dec 2014 15:42:09 +0530 Subject: [PATCH 2/2] Bump version to 0.1.2 --- requirements.txt | 2 +- setup.py | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8b3eea8..6e13078 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ ### BEGIN ### pydub==0.9.4 -PyAudio==0.2.8 +PyAudio>=0.2.7 numpy==1.8.2 scipy==0.12.1 matplotlib==1.3.1 diff --git a/setup.py b/setup.py index f0b6def..cfb64ad 100644 --- a/setup.py +++ b/setup.py @@ -15,9 +15,22 @@ def parse_requirements(requirements): return reqs PACKAGE_NAME = "PyDejavu" -PACKAGE_VERSION = "0.1.1" -SUMMARY = 'Dejavu Audio Fingerprinting' -DESCRIPTION = """Dejavu Audio Fingerprinting""" +PACKAGE_VERSION = "0.1.2" +SUMMARY = 'Dejavu: Audio Fingerprinting in Python' +DESCRIPTION = """ +Audio fingerprinting and recognition algorithm implemented in Python + +See the explanation here: + +`http://willdrevo.com/fingerprinting-and-audio-recognition-with-python/`__ + +Dejavu can memorize recorded audio by listening to it once and fingerprinting +it. Then by playing a song and recording microphone input or on disk file, +Dejavu attempts to match the audio against the fingerprints held in the +database, returning the song or recording being played. + +__ http://willdrevo.com/fingerprinting-and-audio-recognition-with-python/ +""" REQUIREMENTS = parse_requirements("requirements.txt") setup( @@ -25,20 +38,23 @@ setup( version=PACKAGE_VERSION, description=SUMMARY, long_description=DESCRIPTION, - author='worldveil', + author='Will Drevo', author_email='will.drevo@gmail.com', + maintainer="Saleem Ansari", + maintainer_email="tuxdna@gmail.com", url='http://github.com/tuxdna/dejavu', - license='Apache 2.0', + license='MIT License', include_package_data=True, packages=find_packages(), - platforms=['Any'], + platforms=['Unix'], install_requires=REQUIREMENTS, classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Console', 'Intended Audience :: Developers', - 'License :: OSI Approved :: Apache Software License', + 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Topic :: Software Development :: Libraries :: Python Modules', ], + keywords="python, audio, fingerprinting, music, numpy, landmark", )