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)
|
|
|
|
with open("dejavu.cnf") as f:
|
|
|
|
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)
|
|
|
|
# Fingerprint all the mp3's in the directory we give it
|
2013-12-25 08:56:43 +00:00
|
|
|
djv.fingerprint_directory("va_us_top_40/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
|
2013-12-25 08:56:43 +00:00
|
|
|
song = djv.recognize(FileRecognizer, "mp3/beware.mp3")
|
2013-11-19 02:51:27 +00:00
|
|
|
|
2013-12-19 16:15:11 +00:00
|
|
|
# Or recognize audio from your microphone for 10 seconds
|
|
|
|
from dejavu.recognize import MicrophoneRecognizer
|
2013-12-25 08:56:43 +00:00
|
|
|
song = djv.recognize(MicrophoneRecognizer, seconds=2)
|
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)
|
|
|
|
song = recognizer.recognize_file("va_us_top_40/wav/17_-_#Beautiful_-_Mariah_Carey_ft.wav")
|