Spaces:
Build error
Build error
constant 25 s song length
Browse files
utils.py
CHANGED
|
@@ -155,13 +155,21 @@ def random_cut_length(audio_data, max_length, sample_rate):
|
|
| 155 |
audio_data_cut = audio_data[start_point*sample_rate : end_point*sample_rate]
|
| 156 |
return audio_data_cut, length_picked
|
| 157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
|
| 159 |
-
def generate_songs(state,
|
| 160 |
idx= pick_and_remove_one()
|
| 161 |
state, audio = get_song(idx)
|
| 162 |
-
if
|
| 163 |
audio_data, sample_rate = librosa.load(audio, sr=None)
|
| 164 |
-
audio_cut, new_length =
|
| 165 |
state.update_duration(new_length)
|
| 166 |
return state, (sample_rate, audio_cut), "Vote to Reveal Label",
|
| 167 |
|
|
|
|
| 155 |
audio_data_cut = audio_data[start_point*sample_rate : end_point*sample_rate]
|
| 156 |
return audio_data_cut, length_picked
|
| 157 |
|
| 158 |
+
def constant_cut_length(audio_data, max_length, sample_rate, length_picked = 25):
|
| 159 |
+
if max_length <= length_picked:
|
| 160 |
+
return audio_data, max_length
|
| 161 |
+
|
| 162 |
+
start_point = np.random.randint(0, max_length - length_picked)
|
| 163 |
+
end_point = start_point + length_picked
|
| 164 |
+
audio_data_cut = audio_data[start_point*sample_rate : end_point*sample_rate]
|
| 165 |
+
return audio_data_cut, length_picked
|
| 166 |
|
| 167 |
+
def generate_songs(state, song_cut_function = constant_cut_length):
|
| 168 |
idx= pick_and_remove_one()
|
| 169 |
state, audio = get_song(idx)
|
| 170 |
+
if song_cut_function is not None:
|
| 171 |
audio_data, sample_rate = librosa.load(audio, sr=None)
|
| 172 |
+
audio_cut, new_length = song_cut_function(audio_data, state.row.duration, sample_rate)
|
| 173 |
state.update_duration(new_length)
|
| 174 |
return state, (sample_rate, audio_cut), "Vote to Reveal Label",
|
| 175 |
|