forked from nwang57/InstrumentClassifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classification.py
27 lines (21 loc) · 903 Bytes
/
classification.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
import os.path
import argparse
import scipy.io.wavfile
from classifier import load_model, predict
def check_format(fn):
"""raise exception if the file is not WAV format"""
if os.path.splitext(fn)[-1] != ".wav":
raise ValueError("Input file should be in WAV format")
def main():
parser = argparse.ArgumentParser(description="classify the instrument in the music sample")
parser.add_argument("-i", dest="filename", required=True, help="input file in WAV format")
args = parser.parse_args()
filename = args.filename
check_format(filename)
model_instrument = load_model("29_svm_instrument")
model_family = load_model("29_svm_family")
scaler = load_model("scaler_instrument")
print("Family: %s" % predict(model_family, filename, scaler))
print("Instrument: %s" % predict(model_instrument, filename, scaler))
if __name__ == "__main__":
main()