Skip to content

Commit

Permalink
Expose AudioMetadata
Browse files Browse the repository at this point in the history
``torchaudio.info`` returns ``AudioMetaData``. It should be exposed as public API.
  • Loading branch information
mthrok committed Aug 11, 2023
1 parent 9bd7ca5 commit 638fd78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/source/backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Structures used to report the metadata of audio files.
AudioMetaData
-------------

.. autoclass:: torchaudio.backend.common.AudioMetaData
.. autoclass:: torchaudio.AudioMetaData

.. py:module:: torchaudio.backend.sox_io_backend
Expand Down
5 changes: 4 additions & 1 deletion torchaudio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from torchaudio import ( # noqa: F401
from . import ( # noqa: F401
_extension,
compliance,
datasets,
Expand All @@ -11,6 +11,8 @@
transforms,
utils,
)
from .backend.common import AudioMetaData


try:
from .version import __version__, git_version # noqa: F401
Expand All @@ -34,6 +36,7 @@ def _is_backend_dispatcher_enabled():


__all__ = [
"AudioMetaData",
"io",
"compliance",
"datasets",
Expand Down
38 changes: 11 additions & 27 deletions torchaudio/backend/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from dataclasses import dataclass


@dataclass
class AudioMetaData:
"""Return type of ``torchaudio.info`` function.
"""AudioMetaData()
This class is used by :py:mod:`"sox_io" backend<torchaudio.backends.sox_io_backend>` and
:py:mod:`"soundfile" backend<torchaudio.backends.soundfile_backend>`.
Return type of :py:func:`torchaudio.info` function.
:ivar int sample_rate: Sample rate
:ivar int num_frames: The number of frames
Expand All @@ -27,27 +30,8 @@ class AudioMetaData:
* ``UNKNOWN`` : None of above
"""

def __init__(
self,
sample_rate: int,
num_frames: int,
num_channels: int,
bits_per_sample: int,
encoding: str,
):
self.sample_rate = sample_rate
self.num_frames = num_frames
self.num_channels = num_channels
self.bits_per_sample = bits_per_sample
self.encoding = encoding

def __str__(self):
return (
f"AudioMetaData("
f"sample_rate={self.sample_rate}, "
f"num_frames={self.num_frames}, "
f"num_channels={self.num_channels}, "
f"bits_per_sample={self.bits_per_sample}, "
f"encoding={self.encoding}"
f")"
)
sample_rate: int
num_frames: int
num_channels: int
bits_per_sample: int
encoding: str

0 comments on commit 638fd78

Please sign in to comment.