dejavu/example_script.py
mrepetto e6b5976e40 Several fixes and changes:
- isort fixes
- flake8 fixes
- fixed bug of getting duplicated hashes because of sending channels in parallel.
- fixed bug of assigning matches to one offset when the same hash is present in several offsets of a song.
- added type hints and docstring for almost everything.
- added code to list fingerprinted songs in the database.
- added code to delete songs from the database.
- split time in several times: fingerprint time, query time and align time.
- turned the list generator into lists (necessary for split times)
- changed dejavu response.
- added two types of confidences, one that is based on the hashes matched vs the hashes in the db, and another one that is hashes matched vs the hashes from the input song.
- refactored the logic to return more than one result.
2019-10-09 19:22:25 -03:00

42 lines
1.6 KiB
Python
Executable file

import json
from dejavu import Dejavu
from dejavu.logic.recognizer.file_recognizer import FileRecognizer
from dejavu.logic.recognizer.microphone_recognizer import MicrophoneRecognizer
# 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)
# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("test", [".wav"])
# Recognize audio from a file
results = djv.recognize(FileRecognizer, "mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
print(f"From file we recognized: {results}\n")
# Or recognize audio from your microphone for `secs` seconds
secs = 5
results = djv.recognize(MicrophoneRecognizer, seconds=secs)
if results is None:
print("Nothing recognized -- did you play the song out loud so your mic could hear it? :)")
else:
print(f"From mic with {secs} seconds we recognized: {results}\n")
# Or use a recognizer without the shortcut, in anyway you would like
recognizer = FileRecognizer(djv)
results = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
print(f"No shortcut, we recognized: {results}\n")
# To list all fingerprinted songs in the db you can use the following:
# fingerprinted_songs = djv.get_fingerprinted_songs()
# print(fingerprinted_songs)
# And to delete a song or a set of songs you can use the following:
# song_ids_to_delete = [1]
# djv.delete_songs_by_ids(song_ids_to_delete)