-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature extractor.py
More file actions
35 lines (27 loc) · 1004 Bytes
/
feature extractor.py
File metadata and controls
35 lines (27 loc) · 1004 Bytes
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
#librosa feature extraction
import librosa
import numpy as np
#Run all the sound files get all the feature data and write it to
#a csv file
audio = 'path to audio file'
y , sr = librosa.load(audio, mono=True, duration=1)
#features
chroma_stft = librosa.feature.chroma_stft(y=y, sr=sr)
spec_cent = librosa.feature.spectral_centroid(y=y, sr=sr)
spec_bw = librosa.feature.spectral_bandwidth(y=y, sr=sr)
rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)
zcr = librosa.feature.zero_crossing_rate(y)
mfcc = librosa.feature.mfcc(y=y, sr=sr)
#printing the data
print(np.mean(chroma_stft))
print(".................................")
print(np.mean(spec_cent))
print(".................................")
print(np.mean(spec_bw))
print(".................................")
print(np.mean(rolloff))
print(".................................")
print(np.mean(zcr))
print(".................................")
print(np.mean(mfcc))
print(".................................")