From 6217e24e354606ac5a9ec91e8e1e3c2ad5f77934 Mon Sep 17 00:00:00 2001 From: Le Vu Linh Chi Date: Thu, 2 Jan 2025 13:15:58 +0800 Subject: [PATCH 1/2] Add instruction to implement audio augmentation using tourchaudio.sox_effects --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 6494094ebc..9b5d079660 100644 --- a/README.md +++ b/README.md @@ -83,3 +83,33 @@ The pre-trained models provided in this library may have their own licenses or t For instance, SquimSubjective model is released under the Creative Commons Attribution Non Commercial 4.0 International (CC-BY-NC 4.0) license. See [the link](https://zenodo.org/record/4660670#.ZBtWPOxuerN) for additional details. Other pre-trained models that have different license are noted in documentation. Please checkout the [documentation page](https://pytorch.org/audio/main/). + +Audio augmentation using sox_effect +------------------------- +Step 1: Install torchaudio +pip install torchaudio + +Step 2: Import Necessary Libraries +import torchaudio +import torchaudio.sox_effects as sox_effects + +Step 3: Load an Audio File +waveform, sample_rate = torchaudio.load("path_to_audio_file") + +Step 4: Define the SoX Effects and apply the effects to input audio. In this example, I apply time_stretch, loudness, and high-pass filter adjustment. + +effects = [ + ["tempo", "1.25"], # Increase the playback speed (tempo) by 25% + ["gain", "10"], # Amplify the audio by 10 dB + ["highpass", "1000"], # Apply a high-pass filter with a cutoff frequency of 1000 Hz +] + +augmented_waveform, augmented_sample_rate = sox_effects.apply_effects_tensor( + waveform, + sample_rate, + effects +) + +Step 5: Save the Augmented Audio + +torchaudio.save("augmented_audio.wav", augmented_waveform, augmented_sample_rate) From d735f4a5b7751e644c14e0ae6bb6b1bb0d29f835 Mon Sep 17 00:00:00 2001 From: Le Vu Linh Chi Date: Thu, 2 Jan 2025 13:36:09 +0800 Subject: [PATCH 2/2] Update the instruction to implement audio augmentation using tourchaudio.sox_effects --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9b5d079660..1b60899873 100644 --- a/README.md +++ b/README.md @@ -99,15 +99,15 @@ waveform, sample_rate = torchaudio.load("path_to_audio_file") Step 4: Define the SoX Effects and apply the effects to input audio. In this example, I apply time_stretch, loudness, and high-pass filter adjustment. effects = [ - ["tempo", "1.25"], # Increase the playback speed (tempo) by 25% - ["gain", "10"], # Amplify the audio by 10 dB - ["highpass", "1000"], # Apply a high-pass filter with a cutoff frequency of 1000 Hz + ["tempo", "1.25"], # Increase the playback speed (tempo) by 25% + ["gain", "10"], # Amplify the audio by 10 dB + ["highpass", "1000"], # Apply a high-pass filter with a cutoff frequency of 1000 Hz ] augmented_waveform, augmented_sample_rate = sox_effects.apply_effects_tensor( - waveform, - sample_rate, - effects + waveform, + sample_rate, + effects ) Step 5: Save the Augmented Audio