From: Andrew Gundersen <53452154+gundersena@users.noreply.github.com> Date: Mon, 17 Feb 2020 22:48:01 +0000 (-0600) Subject: Add data folder to repo X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=cfdab59a341833af0a91821ca8ae1945ce69376a;p=ml-audio-enhancer Add data folder to repo --- diff --git a/data/make_text.py b/data/make_text.py new file mode 100644 index 0000000..4932d1b --- /dev/null +++ b/data/make_text.py @@ -0,0 +1,29 @@ +import os +import random +import librosa + +file_path = 'VCTK-Corpus/wav48' +dataset_path = './multispeaker' + +folders = os.listdir(file_path) + +for folder in folders: + if folder == '.DS_Store': + folders.remove(folder) +print (folders) + +for folder in folders: + files = os.listdir(os.path.join(file_path, folder)) + random.shuffle(files) + for file in files: + if len(x) < 10: + input('This file is corrupted') + u = random.uniform(0,1) # a single value is returned between 0 and 1 + if u > 0.1: + with open(f'{dataset_path}/train-files1.txt', 'a+') as text_file: + text_file.write(f'{file_path}/{folder}/{file}') + text_file.write('\n') + if u < 0.1: + with open(f'{dataset_path}/val-files1.txt', 'a+') as text_file: + text_file.write(f'{file_path}/{folder}/{file}') + text_file.write('\n') diff --git a/data/multispeaker/test_data.py b/data/multispeaker/test_data.py new file mode 100644 index 0000000..497dcd0 --- /dev/null +++ b/data/multispeaker/test_data.py @@ -0,0 +1,48 @@ +# import a dataset and write spectrograms +from matplotlib import pyplot as plt +import numpy as np +import librosa +import h5py + + +def save_spectrum(S_lr, S_ir, S_pr, outfile, lim=1000): + plt.subplot(1,3,1) + plt.title('Data') + plt.xlabel('Frequency') + plt.ylabel('Time') + plt.imshow(S_lr, aspect=10) + + plt.subplot(1,3,2) + plt.title('Label') + plt.xlabel('Frequency') + plt.ylabel('Time') + plt.imshow(S_ir, aspect=10) + + plt.subplot(1,3,3) + plt.title('Label') + plt.xlabel('Frequency') + plt.ylabel('Time') + plt.imshow(S_pr, aspect=10) + + plt.tight_layout() + plt.savefig(outfile) + + +def get_spectrum(x, n_fft=2048): + S = librosa.stft(x, n_fft) + S = np.log1p(np.abs(S)) + p = np.angle(S) + S = np.log1p(np.abs(S)) + return S.T + + +file = 'vctk-train.4.16000.800.10.0.25.h5' + +with h5py.File(file, 'r') as hf: + X = np.array(hf.get('data')) + Y = np.array(hf.get('label')) + print(X) + +data = get_spectrum(X.flatten(), n_fft=2048) +label = get_spectrum(Y.flatten(), n_fft=2048) +save_spectrum(data, label, outfile='test1.png')