Spaces:
Running
on
Zero
Running
on
Zero
Update utils/mir_eval_modules.py
Browse files- utils/mir_eval_modules.py +46 -10
utils/mir_eval_modules.py
CHANGED
|
@@ -67,23 +67,59 @@ def idx2voca_chord():
|
|
| 67 |
|
| 68 |
def audio_file_to_features(audio_file, config):
|
| 69 |
original_wav, sr = librosa.load(audio_file, sr=config.mp3['song_hz'], mono=True)
|
|
|
|
|
|
|
| 70 |
currunt_sec_hz = 0
|
| 71 |
-
|
|
|
|
|
|
|
| 72 |
start_idx = int(currunt_sec_hz)
|
| 73 |
-
end_idx = int(currunt_sec_hz +
|
| 74 |
-
tmp = librosa.cqt(
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
|
|
|
|
|
|
|
|
|
| 79 |
currunt_sec_hz = end_idx
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
feature = np.log(np.abs(feature) + 1e-6)
|
| 83 |
feature_per_second = config.mp3['inst_len'] / config.model['timestep']
|
| 84 |
-
|
| 85 |
return feature, feature_per_second, song_length_second
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
# Audio files with format of wav and mp3
|
| 88 |
def get_audio_paths(audio_dir):
|
| 89 |
return [os.path.join(root, fname) for (root, dir_names, file_names) in os.walk(audio_dir, followlinks=True)
|
|
|
|
| 67 |
|
| 68 |
def audio_file_to_features(audio_file, config):
|
| 69 |
original_wav, sr = librosa.load(audio_file, sr=config.mp3['song_hz'], mono=True)
|
| 70 |
+
song_length_second = len(original_wav) / sr
|
| 71 |
+
inst_samples = int(sr * config.mp3['inst_len'])
|
| 72 |
currunt_sec_hz = 0
|
| 73 |
+
feature = None
|
| 74 |
+
|
| 75 |
+
while currunt_sec_hz + inst_samples <= len(original_wav):
|
| 76 |
start_idx = int(currunt_sec_hz)
|
| 77 |
+
end_idx = int(currunt_sec_hz + inst_samples)
|
| 78 |
+
tmp = librosa.cqt(
|
| 79 |
+
original_wav[start_idx:end_idx],
|
| 80 |
+
sr=sr,
|
| 81 |
+
n_bins=config.feature['n_bins'],
|
| 82 |
+
bins_per_octave=config.feature['bins_per_octave'],
|
| 83 |
+
hop_length=config.feature['hop_length']
|
| 84 |
+
)
|
| 85 |
+
feature = tmp if feature is None else np.concatenate((feature, tmp), axis=1)
|
| 86 |
currunt_sec_hz = end_idx
|
| 87 |
+
|
| 88 |
+
# Handle remaining samples (including case where audio < inst_len)
|
| 89 |
+
if currunt_sec_hz < len(original_wav):
|
| 90 |
+
tmp = librosa.cqt(
|
| 91 |
+
original_wav[currunt_sec_hz:],
|
| 92 |
+
sr=sr,
|
| 93 |
+
n_bins=config.feature['n_bins'],
|
| 94 |
+
bins_per_octave=config.feature['bins_per_octave'],
|
| 95 |
+
hop_length=config.feature['hop_length']
|
| 96 |
+
)
|
| 97 |
+
feature = tmp if feature is None else np.concatenate((feature, tmp), axis=1)
|
| 98 |
+
|
| 99 |
feature = np.log(np.abs(feature) + 1e-6)
|
| 100 |
feature_per_second = config.mp3['inst_len'] / config.model['timestep']
|
| 101 |
+
|
| 102 |
return feature, feature_per_second, song_length_second
|
| 103 |
|
| 104 |
+
# def audio_file_to_features(audio_file, config):
|
| 105 |
+
# original_wav, sr = librosa.load(audio_file, sr=config.mp3['song_hz'], mono=True)
|
| 106 |
+
# currunt_sec_hz = 0
|
| 107 |
+
# while len(original_wav) > currunt_sec_hz + config.mp3['song_hz'] * config.mp3['inst_len']:
|
| 108 |
+
# start_idx = int(currunt_sec_hz)
|
| 109 |
+
# end_idx = int(currunt_sec_hz + config.mp3['song_hz'] * config.mp3['inst_len'])
|
| 110 |
+
# tmp = librosa.cqt(original_wav[start_idx:end_idx], sr=sr, n_bins=config.feature['n_bins'], bins_per_octave=config.feature['bins_per_octave'], hop_length=config.feature['hop_length'])
|
| 111 |
+
# if start_idx == 0:
|
| 112 |
+
# feature = tmp
|
| 113 |
+
# else:
|
| 114 |
+
# feature = np.concatenate((feature, tmp), axis=1)
|
| 115 |
+
# currunt_sec_hz = end_idx
|
| 116 |
+
# tmp = librosa.cqt(original_wav[currunt_sec_hz:], sr=sr, n_bins=config.feature['n_bins'], bins_per_octave=config.feature['bins_per_octave'], hop_length=config.feature['hop_length'])
|
| 117 |
+
# feature = np.concatenate((feature, tmp), axis=1)
|
| 118 |
+
# feature = np.log(np.abs(feature) + 1e-6)
|
| 119 |
+
# feature_per_second = config.mp3['inst_len'] / config.model['timestep']
|
| 120 |
+
# song_length_second = len(original_wav)/config.mp3['song_hz']
|
| 121 |
+
# return feature, feature_per_second, song_length_second
|
| 122 |
+
|
| 123 |
# Audio files with format of wav and mp3
|
| 124 |
def get_audio_paths(audio_dir):
|
| 125 |
return [os.path.join(root, fname) for (root, dir_names, file_names) in os.walk(audio_dir, followlinks=True)
|