/ feature extractor.py
feature extractor.py
 1  # librosa feature extraction
 2  import librosa
 3  import numpy as np
 4  
 5  # Run all the sound files get all the feature data and write it to
 6  # a csv file
 7  
 8  audio = "audio.wav"
 9  y, sr = librosa.load(audio, mono=True, duration=1)
10  # features
11  chroma_stft = librosa.feature.chroma_stft(y=y, sr=sr)
12  spec_cent = librosa.feature.spectral_centroid(y=y, sr=sr)
13  spec_bw = librosa.feature.spectral_bandwidth(y=y, sr=sr)
14  rolloff = librosa.feature.spectral_rolloff(y=y, sr=sr)
15  zcr = librosa.feature.zero_crossing_rate(y)
16  mfcc = librosa.feature.mfcc(y=y, sr=sr)
17  
18  # printing the data
19  for feature in (chroma_stft, spec_cent, spec_bw, rolloff, zcr, mfcc):
20      print(np.mean(feature))