Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
DEMO_DIR = os.path.dirname(__file__)
if __name__ == "__main__":
"""
For each transformation, apply it to an example sound and write the transformed sounds to
an output folder.
"""
output_dir = os.path.join(DEMO_DIR, "output")
os.makedirs(output_dir, exist_ok=True)
samples = load_wav_file(os.path.join(DEMO_DIR, "acoustic_guitar_0.wav"))
# AddImpulseResponse
augmenter = Compose(
[AddImpulseResponse(p=1.0, ir_path=os.path.join(DEMO_DIR, "ir"))]
)
output_file_path = os.path.join(
output_dir, "AddImpulseResponse_{:03d}.wav".format(0)
)
augmented_samples = augmenter(samples=samples, sample_rate=SAMPLE_RATE)
wavfile.write(output_file_path, rate=SAMPLE_RATE, data=augmented_samples)
# FrequencyMask
augmenter = Compose([FrequencyMask(p=1.0)])
for i in range(5):
output_file_path = os.path.join(
output_dir, "FrequencyMask_{:03d}.wav".format(i)
)
augmented_samples = augmenter(samples=samples, sample_rate=SAMPLE_RATE)
wavfile.write(output_file_path, rate=SAMPLE_RATE, data=augmented_samples)