common.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. class AudioMetaData:
  2. """Return type of ``torchaudio.info`` function.
  3. This class is used by :ref:`"sox_io" backend<sox_io_backend>` and
  4. :ref:`"soundfile" backend with the new interface<soundfile_backend>`.
  5. :ivar int sample_rate: Sample rate
  6. :ivar int num_frames: The number of frames
  7. :ivar int num_channels: The number of channels
  8. :ivar int bits_per_sample: The number of bits per sample. This is 0 for lossy formats,
  9. or when it cannot be accurately inferred.
  10. :ivar str encoding: Audio encoding
  11. The values encoding can take are one of the following:
  12. * ``PCM_S``: Signed integer linear PCM
  13. * ``PCM_U``: Unsigned integer linear PCM
  14. * ``PCM_F``: Floating point linear PCM
  15. * ``FLAC``: Flac, Free Lossless Audio Codec
  16. * ``ULAW``: Mu-law
  17. * ``ALAW``: A-law
  18. * ``MP3`` : MP3, MPEG-1 Audio Layer III
  19. * ``VORBIS``: OGG Vorbis
  20. * ``AMR_WB``: Adaptive Multi-Rate
  21. * ``AMR_NB``: Adaptive Multi-Rate Wideband
  22. * ``OPUS``: Opus
  23. * ``HTK``: Single channel 16-bit PCM
  24. * ``UNKNOWN`` : None of above
  25. """
  26. def __init__(
  27. self,
  28. sample_rate: int,
  29. num_frames: int,
  30. num_channels: int,
  31. bits_per_sample: int,
  32. encoding: str,
  33. ):
  34. self.sample_rate = sample_rate
  35. self.num_frames = num_frames
  36. self.num_channels = num_channels
  37. self.bits_per_sample = bits_per_sample
  38. self.encoding = encoding
  39. def __str__(self):
  40. return (
  41. f"AudioMetaData("
  42. f"sample_rate={self.sample_rate}, "
  43. f"num_frames={self.num_frames}, "
  44. f"num_channels={self.num_channels}, "
  45. f"bits_per_sample={self.bits_per_sample}, "
  46. f"encoding={self.encoding}"
  47. f")"
  48. )