Add data folder to repo
This commit is contained in:
parent
af26da8cad
commit
cfdab59a34
2 changed files with 77 additions and 0 deletions
29
data/make_text.py
Normal file
29
data/make_text.py
Normal file
|
|
@ -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')
|
||||
48
data/multispeaker/test_data.py
Normal file
48
data/multispeaker/test_data.py
Normal file
|
|
@ -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')
|
||||
Loading…
Reference in a new issue