class_docstr: The ``SpeechRecognitionData`` class is a :class:`~flash.core.data.data_module.DataModule` with a set of
  classmethods for loading data for speech recognition.
class_docstr_tok: ["The","``","SpeechRecognitionData","``","class","is","a",":","class",":","`","~flash.core.data.data_module.DataModule","`","with","a","set","of","classmethods","for","loading","data","for","speech","recognition","."]
docstr: Load the :class:`~flash.audio.speech_recognition.data.SpeechRecognitionData` from PyTorch Dataset objects.
  
  The Dataset objects should be one of the following:
  
  * A PyTorch Dataset where the ``__getitem__`` returns a tuple: ``(file_path or , target)``
  * A PyTorch Dataset where the ``__getitem__`` returns a dict: ``{"input": file_path, "target": target}``
  
  The supported file extensions are: ``.aiff``, ``.au``, ``.avr``, ``.caf``, ``.flac``, ``.mat``, ``.mat4``,
  ``.mat5``, ``.mpc2k``, ``.ogg``, ``.paf``, ``.pvf``, ``.rf64``, ``.ircam``, ``.voc``, ``.w64``,
  ``.wav``, ``.nist``, and ``.wavex``.
  To learn how to customize the transforms applied for each stage, read our
  :ref:`customizing transforms guide <customizing_transforms>`.
  
  Args:
      train_dataset: The Dataset to use when training.
      val_dataset: The Dataset to use when validating.
      test_dataset: The Dataset to use when testing.
      predict_dataset: The Dataset to use when predicting.
      sampling_rate: Sampling rate to use when loading the audio files.
      input_cls: The :class:`~flash.core.data.io.input.Input` type to use for loading the data.
      transform: The :class:`~flash.core.data.io.input_transform.InputTransform` type to use.
      transform_kwargs: Dict of keyword arguments to be provided when instantiating the transforms.
      data_module_kwargs: Additional keyword arguments to provide to the
        :class:`~flash.core.data.data_module.DataModule` constructor.
  
  Returns:
      The constructed :class:`~flash.audio.speech_recognition.data.SpeechRecognitionData`.
  
  Examples
  ________
  
  .. testsetup::
  
      >>> import numpy as np
      >>> import soundfile as sf
      >>> samplerate = 1000
      >>> data = np.random.uniform(-1, 1, size=(samplerate, 2))
      >>> _ = [sf.write(f"speech_{i}.wav", data, samplerate, subtype='PCM_24') for i in range(1, 4)]
      >>> _ = [sf.write(f"predict_speech_{i}.wav", data, samplerate, subtype='PCM_24') for i in range(1, 4)]
  
  A PyTorch Dataset where the ``__getitem__`` returns a tuple: ``(file_path, target)``:
  
  .. doctest::
  
      >>> from torch.utils.data import Dataset
      >>> from flash import Trainer
      >>> from flash.audio import SpeechRecognitionData, SpeechRecognition
      >>>
      >>> class CustomDataset(Dataset):
      ...     def __init__(self, files, targets=None):
      ...         self.files = files
      ...         self.targets = targets
      ...     def __getitem__(self, index):
      ...         if self.targets is not None:
      ...             return self.files[index], self.targets[index]
      ...         return self.files[index]
      ...     def __len__(self):
      ...         return len(self.files)
      ...
      >>>
      >>> datamodule = SpeechRecognitionData.from_datasets(
      ...     train_dataset=CustomDataset(
      ...         ["speech_1.wav", "speech_2.wav", "speech_3.wav"],
      ...         ["some speech", "some other speech", "some more speech"],
      ...     ),
      ...     predict_dataset=CustomDataset(
      ...         ["predict_speech_1.wav", "predict_speech_2.wav", "predict_speech_3.wav"],
      ...     ),
      ...     batch_size=2,
      ... )
      >>> model = SpeechRecognition(backbone="patrickvonplaten/wav2vec2_tiny_random_robust")
      >>> trainer = Trainer(fast_dev_run=True)
      >>> trainer.fit(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      Training...
      >>> trainer.predict(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      Predicting...
  
  A PyTorch Dataset where the ``__getitem__`` returns a dict: ``{"input": file_path, "target": target}``:
  
  .. doctest::
  
      >>> from torch.utils.data import Dataset
      >>> from flash import Trainer
      >>> from flash.audio import SpeechRecognitionData, SpeechRecognition
      >>>
      >>> class CustomDataset(Dataset):
      ...     def __init__(self, files, targets=None):
      ...         self.files = files
      ...         self.targets = targets
      ...     def __getitem__(self, index):
      ...         if self.targets is not None:
      ...             return {"input": self.files[index], "target": self.targets[index]}
      ...         return {"input": self.files[index]}
      ...     def __len__(self):
      ...         return len(self.files)
      ...
      >>>
      >>> datamodule = SpeechRecognitionData.from_datasets(
      ...     train_dataset=CustomDataset(
      ...         ["speech_1.wav", "speech_2.wav", "speech_3.wav"],
      ...         ["some speech", "some other speech", "some more speech"],
      ...     ),
      ...     predict_dataset=CustomDataset(
      ...         ["predict_speech_1.wav", "predict_speech_2.wav", "predict_speech_3.wav"],
      ...     ),
      ...     batch_size=2,
      ... )
      >>> model = SpeechRecognition(backbone="patrickvonplaten/wav2vec2_tiny_random_robust")
      >>> trainer = Trainer(fast_dev_run=True)
      >>> trainer.fit(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      Training...
      >>> trainer.predict(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
      Predicting...
  
  .. testcleanup::
  
      >>> import os
      >>> _ = [os.remove(f"speech_{i}.wav") for i in range(1, 4)]
      >>> _ = [os.remove(f"predict_speech_{i}.wav") for i in range(1, 4)]
docstr_tok: ["Load","the",":","class",":","`","~flash.audio.speech_recognition.data.SpeechRecognitionData","`","from","PyTorch","Dataset","objects",".","The","Dataset","objects","should","be","one","of","the","following",":","*","A","PyTorch","Dataset","where","the","``","__getitem__","``","returns","a","tuple",":","``","(","file_path","or",",","target",")","``","*","A","PyTorch","Dataset","where","the","``","__getitem__","``","returns","a","dict",":","``","{","``","input","''",":","file_path",",","``","target","''",":","target","}","``","The","supported","file","extensions","are",":","``",".aiff","``",",","``",".au","``",",","``",".avr","``",",","``",".caf","``",",","``",".flac","``",",","``",".mat","``",",","``",".mat4","``",",","``",".mat5","``",",","``",".mpc2k","``",",","``",".ogg","``",",","``",".paf","``",",","``",".pvf","``",",","``",".rf64","``",",","``",".ircam","``",",","``",".voc","``",",","``",".w64","``",",","``",".wav","``",",","``",".nist","``",",","and","``",".wavex","``",".","To","learn","how","to","customize","the","transforms","applied","for","each","stage",",","read","our",":","ref",":","`","customizing","transforms","guide","<","customizing_transforms",">","`",".","Args",":","train_dataset",":","The","Dataset","to","use","when","training",".","val_dataset",":","The","Dataset","to","use","when","validating",".","test_dataset",":","The","Dataset","to","use","when","testing",".","predict_dataset",":","The","Dataset","to","use","when","predicting",".","sampling_rate",":","Sampling","rate","to","use","when","loading","the","audio","files",".","input_cls",":","The",":","class",":","`","~flash.core.data.io.input.Input","`","type","to","use","for","loading","the","data",".","transform",":","The",":","class",":","`","~flash.core.data.io.input_transform.InputTransform","`","type","to","use",".","transform_kwargs",":","Dict","of","keyword","arguments","to","be","provided","when","instantiating","the","transforms",".","data_module_kwargs",":","Additional","keyword","arguments","to","provide","to","the",":","class",":","`","~flash.core.data.data_module.DataModule","`","constructor",".","Returns",":","The","constructed",":","class",":","`","~flash.audio.speech_recognition.data.SpeechRecognitionData","`",".","Examples","________","..","testsetup",":",":",">",">",">","import","numpy","as","np",">",">",">","import","soundfile","as","sf",">",">",">","samplerate","=","1000",">",">",">","data","=","np.random.uniform","(","-1",",","1",",","size=","(","samplerate",",","2",")",")",">",">",">","_","=","[","sf.write","(","f","''","speech_","{","i","}",".wav","''",",","data",",","samplerate",",","subtype='PCM_24","'",")","for","i","in","range","(","1",",","4",")","]",">",">",">","_","=","[","sf.write","(","f","''","predict_speech_","{","i","}",".wav","''",",","data",",","samplerate",",","subtype='PCM_24","'",")","for","i","in","range","(","1",",","4",")","]","A","PyTorch","Dataset","where","the","``","__getitem__","``","returns","a","tuple",":","``","(","file_path",",","target",")","``",":","..","doctest",":",":",">",">",">","from","torch.utils.data","import","Dataset",">",">",">","from","flash","import","Trainer",">",">",">","from","flash.audio","import","SpeechRecognitionData",",","SpeechRecognition",">",">",">",">",">",">","class","CustomDataset","(","Dataset",")",":","...","def","__init__","(","self",",","files",",","targets=None",")",":","...","self.files","=","files","...","self.targets","=","targets","...","def","__getitem__","(","self",",","index",")",":","...","if","self.targets","is","not","None",":","...","return","self.files","[","index","]",",","self.targets","[","index","]","...","return","self.files","[","index","]","...","def","__len__","(","self",")",":","...","return","len","(","self.files",")","...",">",">",">",">",">",">","datamodule","=","SpeechRecognitionData.from_datasets","(","...","train_dataset=CustomDataset","(","...","[","``","speech_1.wav","''",",","``","speech_2.wav","''",",","``","speech_3.wav","''","]",",","...","[","``","some","speech","''",",","``","some","other","speech","''",",","``","some","more","speech","''","]",",","...",")",",","...","predict_dataset=CustomDataset","(","...","[","``","predict_speech_1.wav","''",",","``","predict_speech_2.wav","''",",","``","predict_speech_3.wav","''","]",",","...",")",",","...","batch_size=2",",","...",")",">",">",">","model","=","SpeechRecognition","(","backbone=","''","patrickvonplaten\/wav2vec2_tiny_random_robust","''",")",">",">",">","trainer","=","Trainer","(","fast_dev_run=True",")",">",">",">","trainer.fit","(","model",",","datamodule=datamodule",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","Training","...",">",">",">","trainer.predict","(","model",",","datamodule=datamodule",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","Predicting","...","A","PyTorch","Dataset","where","the","``","__getitem__","``","returns","a","dict",":","``","{","``","input","''",":","file_path",",","``","target","''",":","target","}","``",":","..","doctest",":",":",">",">",">","from","torch.utils.data","import","Dataset",">",">",">","from","flash","import","Trainer",">",">",">","from","flash.audio","import","SpeechRecognitionData",",","SpeechRecognition",">",">",">",">",">",">","class","CustomDataset","(","Dataset",")",":","...","def","__init__","(","self",",","files",",","targets=None",")",":","...","self.files","=","files","...","self.targets","=","targets","...","def","__getitem__","(","self",",","index",")",":","...","if","self.targets","is","not","None",":","...","return","{","``","input","''",":","self.files","[","index","]",",","``","target","''",":","self.targets","[","index","]","}","...","return","{","``","input","''",":","self.files","[","index","]","}","...","def","__len__","(","self",")",":","...","return","len","(","self.files",")","...",">",">",">",">",">",">","datamodule","=","SpeechRecognitionData.from_datasets","(","...","train_dataset=CustomDataset","(","...","[","``","speech_1.wav","''",",","``","speech_2.wav","''",",","``","speech_3.wav","''","]",",","...","[","``","some","speech","''",",","``","some","other","speech","''",",","``","some","more","speech","''","]",",","...",")",",","...","predict_dataset=CustomDataset","(","...","[","``","predict_speech_1.wav","''",",","``","predict_speech_2.wav","''",",","``","predict_speech_3.wav","''","]",",","...",")",",","...","batch_size=2",",","...",")",">",">",">","model","=","SpeechRecognition","(","backbone=","''","patrickvonplaten\/wav2vec2_tiny_random_robust","''",")",">",">",">","trainer","=","Trainer","(","fast_dev_run=True",")",">",">",">","trainer.fit","(","model",",","datamodule=datamodule",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","Training","...",">",">",">","trainer.predict","(","model",",","datamodule=datamodule",")","#","doctest",":","+ELLIPSIS","+NORMALIZE_WHITESPACE","Predicting","...","..","testcleanup",":",":",">",">",">","import","os",">",">",">","_","=","[","os.remove","(","f","''","speech_","{","i","}",".wav","''",")","for","i","in","range","(","1",",","4",")","]",">",">",">","_","=","[","os.remove","(","f","''","predict_speech_","{","i","}",".wav","''",")","for","i","in","range","(","1",",","4",")","]"]
code: def from_datasets(
      cls,
      train_dataset: Optional[Dataset] = None,
      val_dataset: Optional[Dataset] = None,
      test_dataset: Optional[Dataset] = None,
      predict_dataset: Optional[Dataset] = None,
      sampling_rate: int = 16000,
      input_cls: Type[Input] = SpeechRecognitionDatasetInput,
      transform: INPUT_TRANSFORM_TYPE = InputTransform,
      transform_kwargs: Optional[Dict] = None,
      **data_module_kwargs: Any,
  ) -> "SpeechRecognitionData":
      """Load the :class:`~flash.audio.speech_recognition.data.SpeechRecognitionData` from PyTorch Dataset objects.
  
      The Dataset objects should be one of the following:
  
      * A PyTorch Dataset where the ``__getitem__`` returns a tuple: ``(file_path or , target)``
      * A PyTorch Dataset where the ``__getitem__`` returns a dict: ``{"input": file_path, "target": target}``
  
      The supported file extensions are: ``.aiff``, ``.au``, ``.avr``, ``.caf``, ``.flac``, ``.mat``, ``.mat4``,
      ``.mat5``, ``.mpc2k``, ``.ogg``, ``.paf``, ``.pvf``, ``.rf64``, ``.ircam``, ``.voc``, ``.w64``,
      ``.wav``, ``.nist``, and ``.wavex``.
      To learn how to customize the transforms applied for each stage, read our
      :ref:`customizing transforms guide <customizing_transforms>`.
  
      Args:
          train_dataset: The Dataset to use when training.
          val_dataset: The Dataset to use when validating.
          test_dataset: The Dataset to use when testing.
          predict_dataset: The Dataset to use when predicting.
          sampling_rate: Sampling rate to use when loading the audio files.
          input_cls: The :class:`~flash.core.data.io.input.Input` type to use for loading the data.
          transform: The :class:`~flash.core.data.io.input_transform.InputTransform` type to use.
          transform_kwargs: Dict of keyword arguments to be provided when instantiating the transforms.
          data_module_kwargs: Additional keyword arguments to provide to the
            :class:`~flash.core.data.data_module.DataModule` constructor.
  
      Returns:
          The constructed :class:`~flash.audio.speech_recognition.data.SpeechRecognitionData`.
  
      Examples
      ________
  
      .. testsetup::
  
          >>> import numpy as np
          >>> import soundfile as sf
          >>> samplerate = 1000
          >>> data = np.random.uniform(-1, 1, size=(samplerate, 2))
          >>> _ = [sf.write(f"speech_{i}.wav", data, samplerate, subtype='PCM_24') for i in range(1, 4)]
          >>> _ = [sf.write(f"predict_speech_{i}.wav", data, samplerate, subtype='PCM_24') for i in range(1, 4)]
  
      A PyTorch Dataset where the ``__getitem__`` returns a tuple: ``(file_path, target)``:
  
      .. doctest::
  
          >>> from torch.utils.data import Dataset
          >>> from flash import Trainer
          >>> from flash.audio import SpeechRecognitionData, SpeechRecognition
          >>>
          >>> class CustomDataset(Dataset):
          ...     def __init__(self, files, targets=None):
          ...         self.files = files
          ...         self.targets = targets
          ...     def __getitem__(self, index):
          ...         if self.targets is not None:
          ...             return self.files[index], self.targets[index]
          ...         return self.files[index]
          ...     def __len__(self):
          ...         return len(self.files)
          ...
          >>>
          >>> datamodule = SpeechRecognitionData.from_datasets(
          ...     train_dataset=CustomDataset(
          ...         ["speech_1.wav", "speech_2.wav", "speech_3.wav"],
          ...         ["some speech", "some other speech", "some more speech"],
          ...     ),
          ...     predict_dataset=CustomDataset(
          ...         ["predict_speech_1.wav", "predict_speech_2.wav", "predict_speech_3.wav"],
          ...     ),
          ...     batch_size=2,
          ... )
          >>> model = SpeechRecognition(backbone="patrickvonplaten/wav2vec2_tiny_random_robust")
          >>> trainer = Trainer(fast_dev_run=True)
          >>> trainer.fit(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          Training...
          >>> trainer.predict(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          Predicting...
  
      A PyTorch Dataset where the ``__getitem__`` returns a dict: ``{"input": file_path, "target": target}``:
  
      .. doctest::
  
          >>> from torch.utils.data import Dataset
          >>> from flash import Trainer
          >>> from flash.audio import SpeechRecognitionData, SpeechRecognition
          >>>
          >>> class CustomDataset(Dataset):
          ...     def __init__(self, files, targets=None):
          ...         self.files = files
          ...         self.targets = targets
          ...     def __getitem__(self, index):
          ...         if self.targets is not None:
          ...             return {"input": self.files[index], "target": self.targets[index]}
          ...         return {"input": self.files[index]}
          ...     def __len__(self):
          ...         return len(self.files)
          ...
          >>>
          >>> datamodule = SpeechRecognitionData.from_datasets(
          ...     train_dataset=CustomDataset(
          ...         ["speech_1.wav", "speech_2.wav", "speech_3.wav"],
          ...         ["some speech", "some other speech", "some more speech"],
          ...     ),
          ...     predict_dataset=CustomDataset(
          ...         ["predict_speech_1.wav", "predict_speech_2.wav", "predict_speech_3.wav"],
          ...     ),
          ...     batch_size=2,
          ... )
          >>> model = SpeechRecognition(backbone="patrickvonplaten/wav2vec2_tiny_random_robust")
          >>> trainer = Trainer(fast_dev_run=True)
          >>> trainer.fit(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          Training...
          >>> trainer.predict(model, datamodule=datamodule)  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
          Predicting...
  
      .. testcleanup::
  
          >>> import os
          >>> _ = [os.remove(f"speech_{i}.wav") for i in range(1, 4)]
          >>> _ = [os.remove(f"predict_speech_{i}.wav") for i in range(1, 4)]
  
      """
  
      ds_kw = {"sampling_rate": sampling_rate}
  
      return cls(
          input_cls(RunningStage.TRAINING, train_dataset, **ds_kw),
          input_cls(RunningStage.VALIDATING, val_dataset, **ds_kw),
          input_cls(RunningStage.TESTING, test_dataset, **ds_kw),
          input_cls(RunningStage.PREDICTING, predict_dataset, **ds_kw),
          transform=transform,
          transform_kwargs=transform_kwargs,
          **data_module_kwargs,
      )
  
file_path: lightning-flash/src/flash/audio/speech_recognition/data.py
imports: from typing import Any, Dict, Optional, Sequence, Type
  from torch.utils.data import Dataset
  from flash.audio.speech_recognition.input import SpeechRecognitionCSVInput, SpeechRecognitionDatasetInput, SpeechRecognitionJSONInput, SpeechRecognitionPathsInput
  from flash.audio.speech_recognition.output_transform import SpeechRecognitionOutputTransform
  from flash.core.data.data_module import DataModule
  from flash.core.data.io.input import Input
  from flash.core.data.io.input_transform import INPUT_TRANSFORM_TYPE, InputTransform
  from flash.core.utilities.imports import _TOPIC_AUDIO_AVAILABLE
  from flash.core.utilities.stages import RunningStage
label_desc: Use image node_id 4 for calling the SpeechRecognitionData obj's underlying member method code with example usage: obj.from_datasets(cls, train_dataset, val_dataset, test_dataset, predict_dataset, sampling_rate, input_cls, transform, transform_kwargs) and returns: cls