Shortcuts

torchaudio.info

torchaudio.info(uri: Union[BinaryIO, str, PathLike], format: Optional[str] = None, buffer_size: int = 4096, backend: Optional[str] = None) AudioMetaData

DEPRECATED

Warning

This function has been deprecated. It will be removed from 2.9 release. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information.

Get signal information of an audio file.

Note:

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.

Args:
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)

Returns:

AudioMetaData

Tutorials using info:
Audio I/O

Audio I/O

Audio I/O

Support Structure

AudioMetaData

class torchaudio.AudioMetaData(sample_rate: int, num_frames: int, num_channels: int, bits_per_sample: int, encoding: str)[source]

DEPRECATED

Warning

This class is deprecated from version 2.8. It will be removed in the 2.9 release. This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. The decoding and encoding capabilities of PyTorch for both audio and video are being consolidated into TorchCodec. Please see https://github.com/pytorch/audio/issues/3902 for more information.

AudioMetaData()

Return type of torchaudio.info function.

ivar int sample_rate

Sample rate

ivar int num_frames

The number of frames

ivar int num_channels

The number of channels

ivar int bits_per_sample

The number of bits per sample. This is 0 for lossy formats, or when it cannot be accurately inferred.

ivar str encoding

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

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