mirror of
https://github.com/correl/dejavu.git
synced 2024-11-23 11:09:52 +00:00
Cleaned up example.py
This commit is contained in:
parent
c186602c63
commit
0b540343c1
1 changed files with 4 additions and 4 deletions
|
@ -1,11 +1,14 @@
|
||||||
from dejavu import Dejavu
|
|
||||||
import warnings
|
import warnings
|
||||||
import json
|
import json
|
||||||
warnings.filterwarnings("ignore")
|
warnings.filterwarnings("ignore")
|
||||||
|
|
||||||
|
from dejavu import Dejavu
|
||||||
|
from dejavu.recognize import FileRecognizer, MicrophoneRecognizer
|
||||||
|
|
||||||
# load config from a JSON file (or anything outputting a python dictionary)
|
# load config from a JSON file (or anything outputting a python dictionary)
|
||||||
with open("dejavu.cnf.SAMPLE") as f:
|
with open("dejavu.cnf.SAMPLE") as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# create a Dejavu instance
|
# create a Dejavu instance
|
||||||
|
@ -15,12 +18,10 @@ if __name__ == '__main__':
|
||||||
djv.fingerprint_directory("mp3", [".mp3"])
|
djv.fingerprint_directory("mp3", [".mp3"])
|
||||||
|
|
||||||
# Recognize audio from a file
|
# Recognize audio from a file
|
||||||
from dejavu.recognize import FileRecognizer
|
|
||||||
song = djv.recognize(FileRecognizer, "mp3/Sean-Fournier--Falling-For-You.mp3")
|
song = djv.recognize(FileRecognizer, "mp3/Sean-Fournier--Falling-For-You.mp3")
|
||||||
print "From file we recognized: %s\n" % song
|
print "From file we recognized: %s\n" % song
|
||||||
|
|
||||||
# Or recognize audio from your microphone for `secs` seconds
|
# Or recognize audio from your microphone for `secs` seconds
|
||||||
from dejavu.recognize import MicrophoneRecognizer
|
|
||||||
secs = 5
|
secs = 5
|
||||||
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
|
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
|
||||||
if song is None:
|
if song is None:
|
||||||
|
@ -29,7 +30,6 @@ if __name__ == '__main__':
|
||||||
print "From mic with %d seconds we recognized: %s\n" % (secs, song)
|
print "From mic with %d seconds we recognized: %s\n" % (secs, song)
|
||||||
|
|
||||||
# Or use a recognizer without the shortcut, in anyway you would like
|
# Or use a recognizer without the shortcut, in anyway you would like
|
||||||
from dejavu.recognize import FileRecognizer
|
|
||||||
recognizer = FileRecognizer(djv)
|
recognizer = FileRecognizer(djv)
|
||||||
song = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
|
song = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
|
||||||
print "No shortcut, we recognized: %s\n" % song
|
print "No shortcut, we recognized: %s\n" % song
|
Loading…
Reference in a new issue