-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_features.py
executable file
·46 lines (39 loc) · 1.64 KB
/
extract_features.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
#!/usr/local/bin/python3
import subprocess
from subprocess import Popen, PIPE
import sys
from split_30_seconds import iterate_audio
import os
audio_features = [
# "vamp:qm-vamp-plugins:qm-tempotracker:tempo",
"vamp:qm-vamp-plugins:qm-mfcc:coefficients",
"vamp:bbc-vamp-plugins:bbc-spectral-contrast:peaks",
"vamp:bbc-vamp-plugins:bbc-spectral-contrast:valleys",
]
def extract_features(path="."):
for feature in audio_features:
cmd = "sonic-annotator -d {0} {1} -r -w csv --csv-force".format(feature,path)
subprocess.call(cmd.split())
#p = Popen(cmd.split(), stdin=PIPE, stdout=PIPE, stderr=PIPE)
#output, err = p.communicate()
def extract_features_single(path="."):
for feature in audio_features:
cmd = "sonic-annotator -d {0} {1} -w csv --csv-force".format(feature,path)
subprocess.call(cmd.split())
if __name__=="__main__":
# extract_features("dataset/gztan_split_10sec")
# extract_features_single(audio_path)
# extract_features("dataset/train/hiphop")
# extract_features("dataset/train/rock")
# extract_features("dataset/train/pop")
# extract_features("dataset/train")
if len(sys.argv) < 2:
print("missing parameter for dataset or file path")
else:
if os.path.isdir(sys.argv[1]):
for file in iterate_audio(path=sys.argv[1]):
print("extracing" + file)
extract_features_single(file)
else:
extract_features_single(sys.argv[1])
#extract features for single file