.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/audio_datasets_tutorial.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_audio_datasets_tutorial.py: Audio Datasets ============== **Author**: `Moto Hira `__ ``torchaudio`` provides easy access to common, publicly accessible datasets. Please refer to the official documentation for the list of available datasets. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: default import torch import torchaudio print(torch.__version__) print(torchaudio.__version__) .. rst-class:: sphx-glr-script-out .. code-block:: none 2.2.0 2.2.0 .. GENERATED FROM PYTHON SOURCE LINES 20-42 .. code-block:: default import os import IPython import matplotlib.pyplot as plt _SAMPLE_DIR = "_assets" YESNO_DATASET_PATH = os.path.join(_SAMPLE_DIR, "yes_no") os.makedirs(YESNO_DATASET_PATH, exist_ok=True) def plot_specgram(waveform, sample_rate, title="Spectrogram"): waveform = waveform.numpy() figure, ax = plt.subplots() ax.specgram(waveform[0], Fs=sample_rate) figure.suptitle(title) figure.tight_layout() .. GENERATED FROM PYTHON SOURCE LINES 43-46 Here, we show how to use the :py:class:`torchaudio.datasets.YESNO` dataset. .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: default dataset = torchaudio.datasets.YESNO(YESNO_DATASET_PATH, download=True) .. rst-class:: sphx-glr-script-out .. code-block:: none 0%| | 0.00/4.49M [00:00

.. GENERATED FROM PYTHON SOURCE LINES 58-63 .. code-block:: default i = 3 waveform, sample_rate, label = dataset[i] plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}") IPython.display.Audio(waveform, rate=sample_rate) .. image-sg:: /tutorials/images/sphx_glr_audio_datasets_tutorial_002.png :alt: Sample 3: [0, 0, 1, 0, 0, 0, 1, 0] :srcset: /tutorials/images/sphx_glr_audio_datasets_tutorial_002.png :class: sphx-glr-single-img .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 65-69 .. code-block:: default i = 5 waveform, sample_rate, label = dataset[i] plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}") IPython.display.Audio(waveform, rate=sample_rate) .. image-sg:: /tutorials/images/sphx_glr_audio_datasets_tutorial_003.png :alt: Sample 5: [0, 0, 1, 0, 0, 1, 1, 1] :srcset: /tutorials/images/sphx_glr_audio_datasets_tutorial_003.png :class: sphx-glr-single-img .. raw:: html


.. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.859 seconds) .. _sphx_glr_download_tutorials_audio_datasets_tutorial.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: audio_datasets_tutorial.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: audio_datasets_tutorial.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_