forked from worldveil/dejavu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dejavu.py
executable file
·98 lines (71 loc) · 2.3 KB
/
dejavu.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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]
song = None
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()