• Docs >
  • Audio Datasets >
  • Nightly (unstable)
Shortcuts

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.

import torch
import torchaudio

print(torch.__version__)
print(torchaudio.__version__)
2.2.0.dev20231205
2.2.0.dev20231206
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()

Here, we show how to use the torchaudio.datasets.YESNO dataset.

  0%|          | 0.00/4.49M [00:00<?, ?B/s]
  1%|          | 40.0k/4.49M [00:00<00:20, 230kB/s]
  5%|4         | 208k/4.49M [00:00<00:06, 661kB/s]
 19%|#9        | 888k/4.49M [00:00<00:01, 2.13MB/s]
 78%|#######8  | 3.51M/4.49M [00:00<00:00, 7.39MB/s]
100%|##########| 4.49M/4.49M [00:00<00:00, 6.53MB/s]
i = 1
waveform, sample_rate, label = dataset[i]
plot_specgram(waveform, sample_rate, title=f"Sample {i}: {label}")
IPython.display.Audio(waveform, rate=sample_rate)
Sample 1: [0, 0, 0, 1, 0, 0, 0, 1]


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)
Sample 3: [0, 0, 1, 0, 0, 0, 1, 0]


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)
Sample 5: [0, 0, 1, 0, 0, 1, 1, 1]


Total running time of the script: ( 0 minutes 1.842 seconds)

Gallery generated by Sphinx-Gallery

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources