def setUp(self):
        self.sample_rate = 16000
        self.batch_size = 32
        self.empty_input_audio = torch.empty(0)
        # TODO: use utils.io.Audio
        self.input_audio = (
            torch.from_numpy(
                load_audio(
                    TEST_FIXTURES_DIR / "acoustic_guitar_0.wav",
                    sample_rate=self.sample_rate,
                )
            )
            .unsqueeze(0)
            .unsqueeze(0)
        )

        self.input_audios = torch.cat([self.input_audio] * self.batch_size, dim=0)

        self.bg_path = TEST_FIXTURES_DIR / "bg"
        self.bg_short_path = TEST_FIXTURES_DIR / "bg_short"
        self.bg_noise_transform_guaranteed = AddBackgroundNoise(self.bg_path, 20, p=1.0)
        self.bg_short_noise_transform_guaranteed = AddBackgroundNoise(
            self.bg_short_path, 20, p=1.0
        )
        self.bg_noise_transform_no_guarantee = AddBackgroundNoise(self.bg_path, 20, p=0.0)
Exemple #2
0
 def setUp(self):
     self.sample_rate = 16000
     self.batch_size = 32
     self.empty_input_audio = torch.empty(0)
     self.input_audio = torch.from_numpy(
         load_audio(
             os.path.join(TEST_FIXTURES_DIR, "acoustic_guitar_0.wav"), self.sample_rate
         )
     ).unsqueeze(0)
     self.input_audios = torch.stack([self.input_audio] * self.batch_size).squeeze(1)
     self.ir_path = os.path.join(TEST_FIXTURES_DIR, "ir")
     self.ir_transform_guaranteed = ApplyImpulseResponse(self.ir_path, p=1.0)
     self.ir_transform_no_guarantee = ApplyImpulseResponse(self.ir_path, p=0.0)
    def setUp(self):
        self.sample_rate = 16000
        self.guitar = (
            torch.from_numpy(
                load_audio(
                    TEST_FIXTURES_DIR / "acoustic_guitar_0.wav",
                    sample_rate=self.sample_rate,
                )
            )
            .unsqueeze(0)
            .unsqueeze(0)
        )
        self.noise = (
            torch.from_numpy(
                load_audio(
                    TEST_FIXTURES_DIR / "bg" / "bg.wav", sample_rate=self.sample_rate
                )
            )
            .unsqueeze(0)
            .unsqueeze(0)
        )

        common_num_samples = min(self.guitar.shape[-1], self.noise.shape[-1])
        self.guitar = self.guitar[:, :, :common_num_samples]

        self.guitar_target = torch.zeros(
            (1, 1, common_num_samples // 7, 2), dtype=torch.int64
        )
        self.guitar_target[:, :, :, 0] = 1

        self.noise = self.noise[:, :, :common_num_samples]
        self.noise_target = torch.zeros(
            (1, 1, common_num_samples // 7, 2), dtype=torch.int64
        )
        self.noise_target[:, :, :, 1] = 1

        self.input_audios = torch.cat([self.guitar, self.noise], dim=0)
        self.input_targets = torch.cat([self.guitar_target, self.noise_target], dim=0)
# Convert everything to .wav
# for file_name in os.listdir(ORIGINAL_AUDIO_PATH):
# 	if not file_name.endswith(".flac"):
# 		continue
# 	name, ext = os.path.splitext(file_name)
# 	ext = "wav"
# 	output_file_path = "{name}.{ext}".format(name=name, ext=ext)
# 	print("Converting {} to {}".format(file_name, output_file_path))
# 	process = subprocess.Popen(['ffmpeg', '-i', os.path.join(ORIGINAL_AUDIO_PATH, file_name), os.path.join(ORIGINAL_AUDIO_PATH, output_file_path)], shell=True)

print("Working on augmenting the audio files")
for file_name in os.listdir(ORIGINAL_AUDIO_PATH):
	if not file_name.endswith(".wav"):
		continue
	audio_samples = torch.from_numpy(load_audio(os.path.join(ORIGINAL_AUDIO_PATH, file_name), SAMPLE_RATE)).unsqueeze(0).unsqueeze(0)
	input_audios = torch.cat([audio_samples]*BATCH_SIZE)
	print("Applying augmentation on {}".format(file_name))
	perturbed_audio_samples = apply_augmentation(input_audios, sample_rate=16000).numpy()
	name, ext = os.path.splitext(file_name)
	output_file_path = "{name}_{extra}{ext}".format(name=name, extra=extra, ext=ext)
	wavfile.write(os.path.join(ORIGINAL_AUDIO_OUT_PATH, output_file_path), rate=SAMPLE_RATE,data=perturbed_audio_samples.transpose())

print("Working on creating copies of the ground truth")
# Create copy for the perturbed
for file_name in os.listdir(ORIGINAL_TSV_PATH):
	name, ext = os.path.splitext(file_name)
	file_ending = extra + ext
	if file_ending in file_name:
		continue
	output_file_path = "{name}_{extra}{ext}".format(name=name, extra=extra, ext=ext)
def input_audio(sample_rate):
    return (torch.from_numpy(
        load_audio(
            os.path.join(TEST_FIXTURES_DIR, "acoustic_guitar_0.wav"),
            sample_rate=sample_rate,
        )).unsqueeze(0).unsqueeze(0))