.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "acoustic/acoustic_sig_aug_tutorial.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_acoustic_acoustic_sig_aug_tutorial.py: Acoustic Augmentation.Signal_aug Tutorial ============================================================== .. GENERATED FROM PYTHON SOURCE LINES 7-8 !pip install pysensing .. GENERATED FROM PYTHON SOURCE LINES 10-12 In this tutorial, we will be implementing a simple acoustic.augmentation.sig_aug .. GENERATED FROM PYTHON SOURCE LINES 12-17 .. code-block:: Python import torch import torchaudio import matplotlib.pyplot as plt from pysensing.acoustic.augmentation import signal_aug from pysensing.acoustic.preprocessing import transform .. GENERATED FROM PYTHON SOURCE LINES 18-21 Load the audio ----------------------------------- First, the example audio is loaded .. GENERATED FROM PYTHON SOURCE LINES 21-41 .. code-block:: Python # Define the plot function def plot(audio_data_list, titles,channel_first=True): num_audios = len(audio_data_list) fig, axes = plt.subplots(num_audios, 1, figsize=(12, 8)) if num_audios == 1: axes = [axes] for ax, audio_data, title in zip(axes, audio_data_list, titles): if channel_first==False: ax.plot(audio_data.numpy()) else: ax.plot(audio_data[0].numpy()) ax.set_title(title) fig.tight_layout() plt.show() # Load the data # Load the data waveform, sample_rate = torchaudio.load('example_data/example_audio.wav') .. GENERATED FROM PYTHON SOURCE LINES 42-44 1. Add Noise ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 44-54 .. code-block:: Python noise = torch.randn_like(waveform) add_noise_0 = signal_aug.add_noise(noise,torch.tensor([0])) add_noise_5 = signal_aug.add_noise(noise,torch.tensor([20])) noise_data_0 = add_noise_0(waveform) noise_data_5 = add_noise_5(waveform) plot([waveform,noise_data_5,noise_data_0],['Original','SNR=20','SNR=0']) .. image-sg:: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_001.png :alt: Original, SNR=20, SNR=0 :srcset: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 55-57 2. Add echo ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 57-63 .. code-block:: Python waveform, sample_rate = torchaudio.load('example_data/example_audio.wav',channels_first=False) add_echo_tran = signal_aug.add_echo(sample_rate,in_gain=0.6,out_gain=0.3,delays=[1000],decays=[0.5]) echo_data = add_echo_tran(waveform) plot([waveform,echo_data],['Original','Add_echo'],False) .. image-sg:: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_002.png :alt: Original, Add_echo :srcset: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-66 3. Add atempo ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. code-block:: Python add_echo_tran = signal_aug.add_echo(sample_rate,in_gain=0.6,out_gain=0.3,delays=[1000],decays=[0.5]) echo_data = add_echo_tran(waveform) plot([waveform,echo_data],['Original','Add_echo'],False) .. image-sg:: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_003.png :alt: Original, Add_echo :srcset: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 73-75 4. Add chorus ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 75-80 .. code-block:: Python add_chorus_trans = signal_aug.add_chorus(sample_rate,in_gain=0.6,out_gain=0.3,delays=[1000],decays=[0.5],speeds=[0.25],depths=[2.0]) chorus_data = add_chorus_trans(waveform) plot([waveform,chorus_data],['Original','Add_chorus'],False) .. image-sg:: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_004.png :alt: Original, Add_chorus :srcset: /acoustic/images/sphx_glr_acoustic_sig_aug_tutorial_004.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 81-82 And that's it. We're done with our acoustic augmentation.signal_aug tutorials. Thanks for reading. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.013 seconds) .. _sphx_glr_download_acoustic_acoustic_sig_aug_tutorial.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: acoustic_sig_aug_tutorial.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: acoustic_sig_aug_tutorial.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_