Source code for torchaudio.datasets.cmuarctic

import os
import csv
from pathlib import Path
from typing import Tuple, Union

import torchaudio
from torch import Tensor
from import Dataset
from torchaudio.datasets.utils import (

URL = "aew"

def load_cmuarctic_item(line: str,
                        path: str,
                        folder_audio: str,
                        ext_audio: str) -> Tuple[Tensor, int, str, str]:

    utterance_id, utterance = line[0].strip().split(" ", 2)[1:]

    # Remove space, double quote, and single parenthesis from utterance
    utterance = utterance[1:-3]

    file_audio = os.path.join(path, folder_audio, utterance_id + ext_audio)

    # Load audio
    waveform, sample_rate = torchaudio.load(file_audio)

    return (

[docs]class CMUARCTIC(Dataset): """Create a Dataset for CMU_ARCTIC. Args: root (str or Path): Path to the directory where the dataset is found or downloaded. url (str, optional): The URL to download the dataset from or the type of the dataset to dowload. (default: ``"aew"``) Allowed type values are ``"aew"``, ``"ahw"``, ``"aup"``, ``"awb"``, ``"axb"``, ``"bdl"``, ``"clb"``, ``"eey"``, ``"fem"``, ``"gka"``, ``"jmk"``, ``"ksp"``, ``"ljm"``, ``"lnh"``, ``"rms"``, ``"rxr"``, ``"slp"`` or ``"slt"``. folder_in_archive (str, optional): The top-level directory of the dataset. (default: ``"ARCTIC"``) download (bool, optional): Whether to download the dataset if it is not found at root path. (default: ``False``). """ _file_text = "" _folder_text = "etc" _ext_audio = ".wav" _folder_audio = "wav" def __init__(self, root: Union[str, Path], url: str = URL, folder_in_archive: str = FOLDER_IN_ARCHIVE, download: bool = False) -> None: if url in [ "aew", "ahw", "aup", "awb", "axb", "bdl", "clb", "eey", "fem", "gka", "jmk", "ksp", "ljm", "lnh", "rms", "rxr", "slp", "slt" ]: url = "cmu_us_" + url + "_arctic" ext_archive = ".tar.bz2" base_url = "" url = os.path.join(base_url, url + ext_archive) # Get string representation of 'root' in case Path object is passed root = os.fspath(root) basename = os.path.basename(url) root = os.path.join(root, folder_in_archive) if not os.path.isdir(root): os.mkdir(root) archive = os.path.join(root, basename) basename = basename.split(".")[0] self._path = os.path.join(root, basename) if download: if not os.path.isdir(self._path): if not os.path.isfile(archive): checksum = _CHECKSUMS.get(url, None) download_url(url, root, hash_value=checksum, hash_type="md5") extract_archive(archive) self._text = os.path.join(self._path, self._folder_text, self._file_text) with open(self._text, "r") as text: walker = csv.reader(text, delimiter="\n") self._walker = list(walker)
[docs] def __getitem__(self, n: int) -> Tuple[Tensor, int, str, str]: """Load the n-th sample from the dataset. Args: n (int): The index of the sample to be loaded Returns: tuple: ``(waveform, sample_rate, utterance, utterance_id)`` """ line = self._walker[n] return load_cmuarctic_item(line, self._path, self._folder_audio, self._ext_audio)
def __len__(self) -> int: return len(self._walker)


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources