Shortcuts Union[BinaryIO, str, PathLike], format: Optional[str] = None, buffer_size: int = 4096, backend: Optional[str] = None) AudioMetaData

Get signal information of an audio file.


When the input type is file-like object, this function cannot get the correct length (num_samples) for certain formats, such as vorbis. In this case, the value of num_samples is 0.

  • uri (path-like object or file-like object) –

    Source of audio data. The following types are accepted:

    • path-like: File path or URL.

    • file-like: Object with read(size: int) -> bytes method, which returns byte string of at most size length.

  • format (str or None, optional) – If not None, interpreted as hint that may allow backend to override the detected format. (Default: None)

  • buffer_size (int, optional) – Size of buffer to use when processing file-like objects, in bytes. (Default: 4096)

  • backend (str or None, optional) –

    I/O backend to use. If None, function selects backend given input and available backends. Otherwise, must be one of ["ffmpeg", "sox", "soundfile"], with the corresponding backend available. (Default: None)



Tutorials using info:
Audio I/O

Audio I/O

Audio I/O

Support Structure


class torchaudio.AudioMetaData[source]

Return type of function.

  • sample_rate (int) – Sample rate

  • num_frames (int) – The number of frames

  • num_channels (int) – The number of channels

  • bits_per_sample (int) – The number of bits per sample. This is 0 for lossy formats, or when it cannot be accurately inferred.

  • encoding (str) –

    Audio encoding The values encoding can take are one of the following:

    • PCM_S: Signed integer linear PCM

    • PCM_U: Unsigned integer linear PCM

    • PCM_F: Floating point linear PCM

    • FLAC: Flac, Free Lossless Audio Codec

    • ULAW: Mu-law

    • ALAW: A-law

    • MP3 : MP3, MPEG-1 Audio Layer III

    • VORBIS: OGG Vorbis

    • AMR_WB: Adaptive Multi-Rate Wideband

    • AMR_NB: Adaptive Multi-Rate Narrowband

    • OPUS: Opus

    • HTK: Single channel 16-bit PCM

    • UNKNOWN : None of above

Tutorials using AudioMetaData:
Audio I/O

Audio I/O

Audio I/O


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