-
Notifications
You must be signed in to change notification settings - Fork 2
/
preprocess.py
executable file
·45 lines (39 loc) · 1.61 KB
/
preprocess.py
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
36
37
38
39
40
41
42
43
44
45
import nmutils
import argparse
# Save .mp3 files to random 6 second .wav snippets
def get_args():
'''This function parses and return arguments passed in'''
# Assign description to the help doc
parser = argparse.ArgumentParser(
description='Script that process fma music to spectrogram tensors')
# Add arguments
parser.add_argument(
'-s', '--size', type=str, help='Size directory name', default='small')
# Array for all arguments passed to script
args = parser.parse_args()
# Assign args to variables
size = args.size
# Return all variable values
return(size)
def main():
home_path = "/home/cblythe2/github/neuralMusic/"
# Match return values from get_arguments()
size = get_args()
# Save master genre list
base_path = home_path + "data/fma_metadata/"
save_path = home_path + "data/"
nmutils.save_genre_master_list(base_path, save_path)
# Save randomized samples for every song in directory containing mp3s
base_path = home_path + "data/fma_" + size + '/'
save_path = home_path + "data/samples/"
nmutils.save_random_clips(base_path, save_path, snip_length=6.0)
# Get melspectrograms from the short random clips, save to directory
base_path = home_path + "data/samples/"
save_path = home_path + "data/spectrogram_tensors/"
nmutils.save_spectrogram_tensors(base_path, save_path)
# Save csv file of the current spectrogram_tensor genres
base_path = home_path + "data/spectrogram_tensors/"
save_path = home_path + "data/"
nmutils.save_tensor_labels(base_path, save_path)
if __name__ == "__main__":
main()