-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
example_script.py
executable file
·34 lines (26 loc) · 1.3 KB
/
example_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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")