From c186602c63f0d7bc8d113805c90ef3e0eaa500a1 Mon Sep 17 00:00:00 2001 From: Isko Date: Mon, 23 Mar 2015 00:50:42 +0200 Subject: [PATCH] windows compatible --- example.py | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/example.py b/example.py index 991c6a9..22c651c 100755 --- a/example.py +++ b/example.py @@ -6,29 +6,30 @@ warnings.filterwarnings("ignore") # load config from a JSON file (or anything outputting a python dictionary) with open("dejavu.cnf.SAMPLE") as f: config = json.load(f) +if __name__ == '__main__': -# create a Dejavu instance -djv = Dejavu(config) + # create a Dejavu instance + djv = Dejavu(config) -# Fingerprint all the mp3's in the directory we give it -djv.fingerprint_directory("mp3", [".mp3"]) + # Fingerprint all the mp3's in the directory we give it + djv.fingerprint_directory("mp3", [".mp3"]) -# Recognize audio from a file -from dejavu.recognize import FileRecognizer -song = djv.recognize(FileRecognizer, "mp3/Sean-Fournier--Falling-For-You.mp3") -print "From file we recognized: %s\n" % song + # Recognize audio from a file + from dejavu.recognize import FileRecognizer + song = djv.recognize(FileRecognizer, "mp3/Sean-Fournier--Falling-For-You.mp3") + print "From file we recognized: %s\n" % song -# Or recognize audio from your microphone for `secs` seconds -from dejavu.recognize import MicrophoneRecognizer -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) + # Or recognize audio from your microphone for `secs` seconds + from dejavu.recognize import MicrophoneRecognizer + 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) -# Or use a recognizer without the shortcut, in anyway you would like -from dejavu.recognize import FileRecognizer -recognizer = FileRecognizer(djv) -song = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3") -print "No shortcut, we recognized: %s\n" % song \ No newline at end of file + # Or use a recognizer without the shortcut, in anyway you would like + from dejavu.recognize import FileRecognizer + recognizer = FileRecognizer(djv) + song = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3") + print "No shortcut, we recognized: %s\n" % song \ No newline at end of file