def main(): files = glob(config.data_path+'/*.wav') # + glob('data/*.mp3') # try ffmpeg -i input.mp3 output.wav data, meta = [], [] for file_id, file in enumerate(files): print(f'reading: {file}') d, sample_rate = load(file, config.sample_rate) data.append(d) # synthesis # signal_recons = data_to_audio(data) # write(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate, signal_recons) # signal_recons, sample_rate = load(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate) data_min = min([min(d) for d in data]) data_max = max([max(d) for d in data]) data = [(d-data_min)/(data_max-data_min) for d in data] meta.extend([data_min, data_max]) pickle_save([data,meta], config.data_path+('.pk' if config.data_path[-3:]!='.pk' else '')) print('saved data.')
def save_model(model, path=None, py_serialize=True): if not path: path = config.model_save_path if py_serialize: model = [type(layer)(*[getattr(layer,field).detach().numpy() for field in layer._fields]) for layer in model] meta = [[[e.detach().numpy() for e in ee] for ee in moments],[[e.detach().numpy() for e in ee] for ee in variances]] else: meta = [moments,variances] pickle_save([model,meta],path+'.pk')
def save_model(model, path=None): from warnings import filterwarnings filterwarnings("ignore") if not path: path = config.model_path if path[-3:] != '.pk': path += '.pk' if config.use_gpu: moments_ = [[e2.detach().cuda() for e2 in e1] for e1 in moments] variances_ = [[e2.detach().cuda() for e2 in e1] for e1 in variances] meta = [moments_, variances_] model = pull_copy_from_gpu(model) else: meta = [moments, variances] configs = [[field, getattr(config, field)] for field in dir(config) if field in config.config_to_save] pickle_save([model, meta, configs], path)
def main(): files = glob(config.data_path + '*/*.wav') shuffle(files) data = [] for file_id, file in enumerate(files): print(f'reading: {file}') signal, sample_rate = load(file, config.sample_rate) data.append(audio_to_data(signal)) # signal_recons = data_to_audio(data,1) # write(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate, signal_recons) # signal_recons, sample_rate = load(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate) meta = [max([max(d) for d in data]), min([min(d) for d in data])] data = [(d - meta[1]) / (meta[0] - meta[1]) for d in data] pickle_save([data, meta], config.data_path + '.pk') print('saved data.')
def main(): files = glob(config.data_path+'/*.wav') # + glob('data/*.mp3') # try ffmpeg -i input.mp3 output.wav converted = [] for file_id, file in enumerate(files): print(f'reading: {file}') song_id = [0 if i == file_id else 1 for i in range(len(files))] # analysis signal, sample_rate = load(file, config.sample_rate) data, meta = audio_to_data(signal, song_id) converted.append([data,meta]) # synthesis signal_recons = data_to_audio(data,meta) write(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate, signal_recons) signal_recons, sample_rate = load(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate) pickle_save(converted, config.data_path+'.pk') print('saved data.')
def save_data(data, path=None): if not path: path = config.data_path if path[-3:] != '.pk': path += '.pk' pickle_save(data, path)
def save_data(): pickle_save([ load(file, config.sample_rate)[0] for file in glob(config.data_path + '/*.wav') ], config.data_path + '.pk')
def save_data(data, path=None): if not path: path = config.data_path pickle_save(data, path + '.pk')
def main(): files = glob( config.data_path + '/*.wav') # + glob('data/*.mp3') # try ffmpeg -i input.mp3 output.wav if not config.frequencies_to_pick: # gather initial info from all files frequency_strengths = zeros(len(config.frequencies_of_bins)) for file in files: signal = load(file, config.sample_rate)[0] spec = abs( stft(signal, config.fft_bins, config.fft_hop_len, config.fft_window_len)) # print('\tmax min initially:', max(spec), min(spec)) # show(specshow(spec, sr=config.sample_rate, hop_length=config.fft_hop_len)) frequency_strengths += spec.sum(1) / spec.shape[1] max_strength = max(frequency_strengths) strength_thr = max_strength / config.frequency_strength_thr band_low_hz = 999_999 band_high_hz = -1 for frequency, strength in zip(config.frequencies_of_bins, frequency_strengths): if strength >= strength_thr: config.frequencies_to_pick.append(frequency) if frequency < band_low_hz: band_low_hz = frequency if frequency > band_high_hz: band_low_hz = frequency # spec = cat([spec[config.frequencies_of_bins.index(i),:] for i in config.frequencies_to_pick], 0) # print('\tmax min after bandpass:'******'with bandpass, timestep size: {len(config.frequencies_of_bins)} -> {len(config.frequencies_to_pick)}' ) print( f'copy paste this line into frequencies_to_pick @ config: \n{config.frequencies_to_pick}' ) # proceed to separately processing each file converted = [] for file_id, file in enumerate(files): print(f'reading: {file}') song_id = [0 if i == file_id else 1 for i in range(len(files))] # analysis signal, sample_rate = load(file, config.sample_rate) data, meta = audio_to_data(signal, song_id) converted.append([data, meta]) # synthesis signal_recons = data_to_audio(data, meta) write(f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate, signal_recons) signal_recons, sample_rate = load( f'{file.split("/")[-1]}_{file_id}.wav', config.sample_rate) pickle_save(converted, config.data_path + '.pk') print('saved data.')