text
stringlengths 0
4.99k
|
---|
DATASET_AUDIO_PATH = os.path.join(DATASET_ROOT, AUDIO_SUBFOLDER) |
DATASET_NOISE_PATH = os.path.join(DATASET_ROOT, NOISE_SUBFOLDER) |
# Percentage of samples to use for validation |
VALID_SPLIT = 0.1 |
# Seed to use when shuffling the dataset and the noise |
SHUFFLE_SEED = 43 |
# The sampling rate to use. |
# This is the one used in all of the audio samples. |
# We will resample all of the noise to this sampling rate. |
# This will also be the output size of the audio wave samples |
# (since all samples are of 1 second long) |
SAMPLING_RATE = 16000 |
# The factor to multiply the noise with according to: |
# noisy_sample = sample + noise * prop * scale |
# where prop = sample_amplitude / noise_amplitude |
SCALE = 0.5 |
BATCH_SIZE = 128 |
EPOCHS = 100 |
Data preparation |
The dataset is composed of 7 folders, divided into 2 groups: |
Speech samples, with 5 folders for 5 different speakers. Each folder contains 1500 audio files, each 1 second long and sampled at 16000 Hz. |
Background noise samples, with 2 folders and a total of 6 files. These files are longer than 1 second (and originally not sampled at 16000 Hz, but we will resample them to 16000 Hz). We will use those 6 files to create 354 1-second-long noise samples to be used for training. |
Let's sort these 2 categories into 2 folders: |
An audio folder which will contain all the per-speaker speech sample folders |
A noise folder which will contain all the noise samples |
Before sorting the audio and noise categories into 2 folders, |
main_directory/ |
...speaker_a/ |
...speaker_b/ |
...speaker_c/ |
...speaker_d/ |
...speaker_e/ |
...other/ |
..._background_noise_/ |
After sorting, we end up with the following structure: |
main_directory/ |
...audio/ |
......speaker_a/ |
......speaker_b/ |
......speaker_c/ |
......speaker_d/ |
......speaker_e/ |
...noise/ |
......other/ |
......_background_noise_/ |
# If folder `audio`, does not exist, create it, otherwise do nothing |
if os.path.exists(DATASET_AUDIO_PATH) is False: |
os.makedirs(DATASET_AUDIO_PATH) |
# If folder `noise`, does not exist, create it, otherwise do nothing |
if os.path.exists(DATASET_NOISE_PATH) is False: |
os.makedirs(DATASET_NOISE_PATH) |
for folder in os.listdir(DATASET_ROOT): |
if os.path.isdir(os.path.join(DATASET_ROOT, folder)): |
if folder in [AUDIO_SUBFOLDER, NOISE_SUBFOLDER]: |
# If folder is `audio` or `noise`, do nothing |
continue |
elif folder in [\"other\", \"_background_noise_\"]: |
# If folder is one of the folders that contains noise samples, |
# move it to the `noise` folder |
shutil.move( |
os.path.join(DATASET_ROOT, folder), |
os.path.join(DATASET_NOISE_PATH, folder), |
) |
else: |
# Otherwise, it should be a speaker folder, then move it to |
# `audio` folder |
shutil.move( |
os.path.join(DATASET_ROOT, folder), |
os.path.join(DATASET_AUDIO_PATH, folder), |
) |
Noise preparation |
In this section: |
We load all noise samples (which should have been resampled to 16000) |
We split those noise samples to chuncks of 16000 samples which correspond to 1 second duration each |
# Get the list of all noise files |
noise_paths = [] |
for subdir in os.listdir(DATASET_NOISE_PATH): |
subdir_path = Path(DATASET_NOISE_PATH) / subdir |
if os.path.isdir(subdir_path): |
noise_paths += [ |
os.path.join(subdir_path, filepath) |
for filepath in os.listdir(subdir_path) |
if filepath.endswith(\".wav\") |
] |
print( |
\"Found {} files belonging to {} directories\".format( |
len(noise_paths), len(os.listdir(DATASET_NOISE_PATH)) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.