mirror of
https://github.com/correl/dejavu.git
synced 2024-11-23 11:09:52 +00:00
e046eeee93
- Fixed tests. - Refactored solution architecture once more. - Refactored solution hierarchy. - Adding audios for testing. - Solved flake8 issues and reorganized several imports in the process.
34 lines
1.3 KiB
Python
Executable file
34 lines
1.3 KiB
Python
Executable file
import json
|
|
|
|
from dejavu import Dejavu
|
|
from dejavu.logic.recognizer.microphone_recognizer import MicrophoneRecognizer
|
|
from dejavu.logic.recognizer.file_recognizer import FileRecognizer
|
|
|
|
# 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
|
|
song = djv.recognize(FileRecognizer, "mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
|
|
print(f"From file we recognized: {song}\n")
|
|
|
|
# Or recognize audio from your microphone for `secs` seconds
|
|
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(f"From mic with {secs} seconds we recognized: {song}\n")
|
|
|
|
# Or use a recognizer without the shortcut, in anyway you would like
|
|
recognizer = FileRecognizer(djv)
|
|
song = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
|
|
print(f"No shortcut, we recognized: {song}\n")
|