Facebook
From Thundering Kangaroo, 4 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 29
  1. def extract_features_file(fn, bands=60, frames=41):
  2.     print('extract features: ' + fn)
  3.  
  4.     window_size = 512 * (frames - 1)
  5.  
  6.     segment_log_specgrams, segment_labels = [], []
  7.     sound_clip, sr = librosa.load(fn)
  8.     for (start, end) in _windows(sound_clip, window_size):
  9.         if len(sound_clip[start:end]) == window_size:
  10.             signal = sound_clip[start:end]
  11.             melspec = librosa.feature.melspectrogram(signal, n_mels=bands)
  12.             logspec = librosa.amplitude_to_db(melspec)
  13.             logspec = logspec.T.flatten()[:, np.newaxis].T
  14.             segment_log_specgrams.append(logspec)
  15.     segment_log_specgrams = np.asarray(segment_log_specgrams).reshape(len(segment_log_specgrams), bands, frames, 1)
  16.     segment_features = np.concatenate((segment_log_specgrams, np.zeros(np.shape(segment_log_specgrams))), axis=3)
  17.     for i in range(len(segment_features)):
  18.         segment_features[i, :, :, 1] = librosa.feature.delta(
  19.             segment_features[i, :, :, 0])
  20.     return segment_features