2013-12-16 23:38:58 +00:00
|
|
|
from dejavu import Dejavu
|
2013-11-19 02:51:27 +00:00
|
|
|
import warnings
|
2013-12-19 16:15:11 +00:00
|
|
|
import json
|
2013-11-19 02:51:27 +00:00
|
|
|
warnings.filterwarnings("ignore")
|
|
|
|
|
2013-12-19 16:15:11 +00:00
|
|
|
# load config from a JSON file (or anything outputting a python dictionary)
|
2014-07-03 05:01:56 +00:00
|
|
|
with open("dejavu.cnf.SAMPLE") as f:
|
2013-12-19 16:15:11 +00:00
|
|
|
config = json.load(f)
|
2013-11-19 02:51:27 +00:00
|
|
|
|
2013-12-19 16:15:11 +00:00
|
|
|
# create a Dejavu instance
|
|
|
|
djv = Dejavu(config)
|
2014-07-03 05:01:56 +00:00
|
|
|
|
2013-12-19 16:15:11 +00:00
|
|
|
# Fingerprint all the mp3's in the directory we give it
|
2014-01-08 04:25:55 +00:00
|
|
|
djv.fingerprint_directory("mp3", [".mp3"])
|
2013-11-19 02:51:27 +00:00
|
|
|
|
2013-12-19 16:15:11 +00:00
|
|
|
# Recognize audio from a file
|
|
|
|
from dejavu.recognize import FileRecognizer
|
2014-07-03 05:01:56 +00:00
|
|
|
song = djv.recognize(FileRecognizer, "mp3/Sean-Fournier--Falling-For-You.mp3")
|
2014-12-16 02:30:33 +00:00
|
|
|
print "From file we recognized: %s\n" % song
|
2013-11-19 02:51:27 +00:00
|
|
|
|
2014-12-16 02:30:33 +00:00
|
|
|
# Or recognize audio from your microphone for `secs` seconds
|
2013-12-19 16:15:11 +00:00
|
|
|
from dejavu.recognize import MicrophoneRecognizer
|
2014-12-16 02:30:33 +00:00
|
|
|
secs = 5
|
|
|
|
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
|
|
|
|
if song is None:
|
|
|
|
print "Nothing recognized -- did you play the song out loud so your mic could hear it? :)"
|
|
|
|
else:
|
|
|
|
print "From mic with %d seconds we recognized: %s\n" % (secs, song)
|
2013-12-19 16:15:11 +00:00
|
|
|
|
|
|
|
# Or use a recognizer without the shortcut, in anyway you would like
|
|
|
|
from dejavu.recognize import FileRecognizer
|
|
|
|
recognizer = FileRecognizer(djv)
|
2014-12-16 02:30:33 +00:00
|
|
|
song = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
|
|
|
|
print "No shortcut, we recognized: %s\n" % song
|