From 684902f6b86aee9ebceca3b0cd2152f6cb078a00 Mon Sep 17 00:00:00 2001 From: Will Drevo Date: Fri, 21 Nov 2014 01:21:08 -0500 Subject: [PATCH] Now returns match offset into track in seconds --- README.md | 11 +++-------- dejavu/__init__.py | 7 ++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2d1b79d..bc1c3e0 100755 --- a/README.md +++ b/README.md @@ -107,19 +107,14 @@ There are two ways to recognize audio using Dejavu. You can use Dejavu interacti ```python >>> from dejavu.recognize import MicrophoneRecognizer >>> print djv.recognize(MicrophoneRecognizer, seconds=10) # Defaults to 10 seconds. -{ - 'song_id': 16, - 'song_name': 'Love Somebody - Maroon 5', - 'confidence': 21, - 'offset' : 867 -} +{'song_id': 1, 'song_name': 'Taylor Swift - Shake It Off', 'confidence': 3948, 'offset_seconds': 30.00018, 'match_time': 0.7159781455993652, 'offset': 646L} ``` Or by reading files via scripting functions: ```python >>> from dejavu.recognize import FileRecognizer ->>> song = djv.recognize(FileRecognizer, "va_us_top_40/wav/07 - Mirrors - Justin Timberlake.wav") +>>> song = djv.recognize(FileRecognizer, "va_us_top_40/wav/Mirrors - Justin Timberlake.wav") ``` Note that the `offset` field of the returned song object tells you about the position in which the song was matched. See [here](https://github.com/worldveil/dejavu/issues/43) for a description of how. @@ -169,7 +164,7 @@ python run_tests.py \ ./mp3 ``` -The testing scripts are as of now are a bit rough, and could certainly use some love and attention if you're interested in submitting a PR! +The testing scripts are as of now are a bit rough, and could certainly use some love and attention if you're interested in submitting a PR! For example, underscores in audio filenames currently [breaks](https://github.com/worldveil/dejavu/issues/63) the test scripts. ## How does it work? diff --git a/dejavu/__init__.py b/dejavu/__init__.py index 359063c..2eac959 100755 --- a/dejavu/__init__.py +++ b/dejavu/__init__.py @@ -11,6 +11,7 @@ class Dejavu(object): CONFIDENCE = 'confidence' MATCH_TIME = 'match_time' OFFSET = 'offset' + OFFSET_SECS = 'offset_seconds' def __init__(self, config): super(Dejavu, self).__init__() @@ -148,11 +149,15 @@ class Dejavu(object): return None # return match info + 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 : largest, + Dejavu.OFFSET_SECS : nseconds } return song