-
Notifications
You must be signed in to change notification settings - Fork 0
/
SongRecognition.py
61 lines (56 loc) · 1.9 KB
/
SongRecognition.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from src import recognize, add_audio, add_dir
from src import Database, Console
import sys, getopt, os, time
import argparse
description = "A song recognize application for malayalam songs"
console_methods = {
"add-audio": "add a audio to the database",
"add-dir": "add audio from a directory",
"recognize": "recognzie a audio sample from file",
"help": "show help",
"quit": "Quit"
}
console_methods_usage = {
"add-audio": "add-audio song/lingyu.mp3",
"add-dir": "add-audio song",
"recognize": "recognzie sample/lingyu_01.mp3"
}
console_methods_factory = {
"add-audio": add_audio,
"add-dir": add_dir,
"recognize": recognize
}
if __name__ == "__main__":
Console.log("Check connection with the database......")
status, code, msg = Database.checkDatabase()
if not status:
Console.log("Connect to database failed: %s" % msg)
Console.log("Please check config or database.")
sys.exit()
Console.log("Success!")
time.sleep(1)
os.system("cls")
Console.log("*" * 40)
Console.log(description)
Console.log("*" * 40)
while True:
command = input("Command: ")
method = command.split(" ")[0]
args = command[len(method) + 1::]
if not method in console_methods.keys():
Console.log("Invalid method.")
continue
if method == "quit":
Console.log("Stop console")
sys.exit()
if method == "help":
for key, value in console_methods.items():
Console.log(key, ":", value)
if key in console_methods_usage.keys():
Console.log(" " * (len(key) + 1), "usage :help"
"", console_methods_usage[key])
continue
if len(args) == 0:
Console.log("args not found.")
continue
console_methods_factory[method](args)