Now returns match offset into track in seconds

This commit is contained in:
Will Drevo 2014-11-21 01:21:08 -05:00
parent 5741964391
commit 684902f6b8
2 changed files with 9 additions and 9 deletions

View file

@ -107,19 +107,14 @@ There are two ways to recognize audio using Dejavu. You can use Dejavu interacti
```python ```python
>>> from dejavu.recognize import MicrophoneRecognizer >>> from dejavu.recognize import MicrophoneRecognizer
>>> print djv.recognize(MicrophoneRecognizer, seconds=10) # Defaults to 10 seconds. >>> print djv.recognize(MicrophoneRecognizer, seconds=10) # Defaults to 10 seconds.
{ {'song_id': 1, 'song_name': 'Taylor Swift - Shake It Off', 'confidence': 3948, 'offset_seconds': 30.00018, 'match_time': 0.7159781455993652, 'offset': 646L}
'song_id': 16,
'song_name': 'Love Somebody - Maroon 5',
'confidence': 21,
'offset' : 867
}
``` ```
Or by reading files via scripting functions: Or by reading files via scripting functions:
```python ```python
>>> from dejavu.recognize import FileRecognizer >>> 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. 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 ./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? ## How does it work?

View file

@ -11,6 +11,7 @@ class Dejavu(object):
CONFIDENCE = 'confidence' CONFIDENCE = 'confidence'
MATCH_TIME = 'match_time' MATCH_TIME = 'match_time'
OFFSET = 'offset' OFFSET = 'offset'
OFFSET_SECS = 'offset_seconds'
def __init__(self, config): def __init__(self, config):
super(Dejavu, self).__init__() super(Dejavu, self).__init__()
@ -148,11 +149,15 @@ class Dejavu(object):
return None return None
# return match info # return match info
nseconds = round(float(largest) / fingerprint.DEFAULT_FS * \
fingerprint.DEFAULT_WINDOW_SIZE * \
fingerprint.DEFAULT_OVERLAP_RATIO, 5)
song = { song = {
Dejavu.SONG_ID : song_id, Dejavu.SONG_ID : song_id,
Dejavu.SONG_NAME : songname, Dejavu.SONG_NAME : songname,
Dejavu.CONFIDENCE : largest_count, Dejavu.CONFIDENCE : largest_count,
Dejavu.OFFSET : largest } Dejavu.OFFSET : largest,
Dejavu.OFFSET_SECS : nseconds }
return song return song