-
Notifications
You must be signed in to change notification settings - Fork 15
/
whitenoise_dataset_generator.py
46 lines (35 loc) · 2.06 KB
/
whitenoise_dataset_generator.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
46
from pathlib import Path
from matplotlib import pyplot as plt
import numpy as np
import os
from tqdm import tqdm
import colored_noise_utils as noiser
TRAINING_INPUT_PATH = 'Datasets/WhiteNoise_Train_Input'
TRAINING_OUTPUT_PATH = 'Datasets/WhiteNoise_Train_Output'
TESTING_INPUT_PATH = 'Datasets/WhiteNoise_Test_Input'
CLEAN_TRAINING_DIR = Path('Datasets/clean_trainset_28spk_wav')
CLEAN_TESTING_DIR = Path("Datasets/clean_testset_wav")
clean_training_dir_wav_files = sorted(list(CLEAN_TRAINING_DIR.rglob('*.wav')))
clean_testing_dir_wav_files = sorted(list(CLEAN_TESTING_DIR.rglob('*.wav')))
print("Total training samples:",len(clean_training_dir_wav_files))
print("Generating Training data")
if not os.path.exists(TRAINING_INPUT_PATH):
os.makedirs(TRAINING_INPUT_PATH)
if not os.path.exists(TRAINING_OUTPUT_PATH):
os.makedirs(TRAINING_OUTPUT_PATH)
for audio_file in tqdm(clean_training_dir_wav_files):
un_noised_file = noiser.load_audio_file(file_path=audio_file)
random_snr = np.random.randint(0,10)
white_gaussian_noised_audio = noiser.gen_colored_gaussian_noise(file_path=audio_file, snr=random_snr, color='white')
noiser.save_audio_file(np_array=white_gaussian_noised_audio, file_path='{}/{}'.format(TRAINING_INPUT_PATH,audio_file.name))
random_snr = np.random.randint(0,10)
white_gaussian_noised_audio = noiser.gen_colored_gaussian_noise(file_path=audio_file, snr=random_snr, color='white')
noiser.save_audio_file(np_array=white_gaussian_noised_audio, file_path='{}/{}'.format(TRAINING_OUTPUT_PATH,audio_file.name))
print("Generating Testing data")
if not os.path.exists(TESTING_INPUT_PATH):
os.makedirs(TESTING_INPUT_PATH)
for audio_file in tqdm(clean_testing_dir_wav_files):
un_noised_file = noiser.load_audio_file(file_path=audio_file)
random_snr = np.random.randint(0,10)
white_gaussian_noised_audio = noiser.gen_colored_gaussian_noise(file_path=audio_file, snr=random_snr, color='white')
noiser.save_audio_file(np_array=white_gaussian_noised_audio, file_path='{}/{}'.format(TESTING_INPUT_PATH,audio_file.name))