def getMedleyDB(xml_path): tree = etree.parse(xml_path) root = tree.getroot() db_path = root.find("./databaseFolderPath").text mixes, accs, vocals = list(), list(), list() tracks = root.xpath(".//track") for track in tracks: instrument_paths = list() # Mix together vocals, if they exist vocal_tracks = track.xpath(".//instrument[instrumentName='Voice']/relativeFilepath") + \ track.xpath(".//instrument[instrumentName='Voice']/relativeFilepath") + \ track.xpath(".//instrument[instrumentName='Voice']/relativeFilepath") if len( vocal_tracks ) > 0: # If there are vocals, get their file paths and mix them together vocal_track = Input.Input.add_audio( [db_path + os.path.sep + f.text for f in vocal_tracks], "vocalmix") instrument_paths.append(vocal_track) vocals.append(Sample.from_path(vocal_track)) else: # Otherwise append duration of track so silent input can be generated later on-the-fly duration = float( track.xpath("./instrumentList/instrument/length")[0].text) vocals.append(duration) # Mix together accompaniment, if it exists acc_tracks = track.xpath( ".//instrument[not(instrumentName='Voice') and not(instrumentName='Mix') and not(instrumentName='Instrumental')]/relativeFilepath" ) #TODO # We assume that there is no distinction between male/female here if len( acc_tracks ) > 0: # If there are vocals, get their file paths and mix them together acc_track = Input.Input.add_audio( [db_path + os.path.sep + f.text for f in acc_tracks], "accmix") instrument_paths.append(acc_track) accs.append(Sample.from_path(acc_track)) else: # Otherwise append duration of track so silent input can be generated later on-the-fly duration = float( track.xpath("./instrumentList/instrument/length")[0].text) accs.append(duration) # Mix together vocals and accompaniment mix_track = Input.Input.add_audio(instrument_paths, "totalmix") mixes.append(Sample.from_path(mix_track)) return [mixes, accs, vocals]
def getVocalFMA(database_path, audio_path=None): if audio_path is None: audio_path = database_path track_csv = os.path.join(database_path, "fma_metadata", "raw_tracks.csv") sample_list = list() with open(track_csv, 'rb') as csvfile: reader = csv.DictReader(csvfile) for row in reader: if not int(row["track_instrumental"]): track_id = int(row["track_id"]) filename = '{:06d}'.format(track_id) + ".mp3" folder_id = track_id // 1000 foldername = '{:03d}'.format(folder_id) audio_file = os.path.join(audio_path, "fma_full", foldername, filename) print("Reading in metadata of file " + audio_file) try: sample = Sample.from_path(audio_file) except Exception as e: print("Skipping sample at path " + audio_file) print(e) continue sample_list.append(sample) return sample_list
def get_samples_in_folder(audio_path, extension): audio_file_list = getAllFilesOfType(audio_path, extension) sample_list = list() for audio_file in audio_file_list: print("Reading in metadata of file " + audio_file) try: sample = Sample.from_path(audio_file) except Exception: print("Skipping sample at path " + audio_path) continue sample_list.append(sample) assert(len(sample_list) > 0) # If we did not find any samples something must have gone wrong return sample_list