torchaudio 2.7.1__cp312-cp312-macosx_11_0_arm64.whl → 2.9.0__cp312-cp312-macosx_11_0_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of torchaudio might be problematic. Click here for more details.

Files changed (95) hide show
  1. torchaudio/.dylibs/libc++.1.0.dylib +0 -0
  2. torchaudio/__init__.py +184 -33
  3. torchaudio/_extension/__init__.py +1 -14
  4. torchaudio/_extension/utils.py +0 -47
  5. torchaudio/_internal/module_utils.py +68 -10
  6. torchaudio/_torchcodec.py +340 -0
  7. torchaudio/datasets/cmuarctic.py +1 -1
  8. torchaudio/datasets/utils.py +1 -1
  9. torchaudio/functional/__init__.py +6 -3
  10. torchaudio/functional/_alignment.py +1 -1
  11. torchaudio/functional/filtering.py +70 -55
  12. torchaudio/functional/functional.py +31 -61
  13. torchaudio/lib/_torchaudio.so +0 -0
  14. torchaudio/lib/libtorchaudio.so +0 -0
  15. torchaudio/models/decoder/__init__.py +19 -1
  16. torchaudio/models/decoder/_ctc_decoder.py +6 -6
  17. torchaudio/models/decoder/_cuda_ctc_decoder.py +1 -1
  18. torchaudio/models/squim/objective.py +2 -2
  19. torchaudio/pipelines/_source_separation_pipeline.py +1 -1
  20. torchaudio/pipelines/_squim_pipeline.py +2 -2
  21. torchaudio/pipelines/_tts/utils.py +3 -1
  22. torchaudio/pipelines/rnnt_pipeline.py +4 -4
  23. torchaudio/transforms/__init__.py +4 -1
  24. torchaudio/transforms/_transforms.py +4 -3
  25. torchaudio/utils/__init__.py +2 -9
  26. torchaudio/utils/download.py +1 -1
  27. torchaudio/version.py +2 -2
  28. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/METADATA +15 -7
  29. torchaudio-2.9.0.dist-info/RECORD +86 -0
  30. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/WHEEL +1 -1
  31. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/top_level.txt +0 -1
  32. torchaudio/_backend/__init__.py +0 -61
  33. torchaudio/_backend/backend.py +0 -53
  34. torchaudio/_backend/common.py +0 -52
  35. torchaudio/_backend/ffmpeg.py +0 -334
  36. torchaudio/_backend/soundfile.py +0 -54
  37. torchaudio/_backend/soundfile_backend.py +0 -457
  38. torchaudio/_backend/sox.py +0 -91
  39. torchaudio/_backend/utils.py +0 -317
  40. torchaudio/backend/__init__.py +0 -8
  41. torchaudio/backend/_no_backend.py +0 -25
  42. torchaudio/backend/_sox_io_backend.py +0 -294
  43. torchaudio/backend/common.py +0 -13
  44. torchaudio/backend/no_backend.py +0 -14
  45. torchaudio/backend/soundfile_backend.py +0 -14
  46. torchaudio/backend/sox_io_backend.py +0 -14
  47. torchaudio/io/__init__.py +0 -13
  48. torchaudio/io/_effector.py +0 -347
  49. torchaudio/io/_playback.py +0 -72
  50. torchaudio/kaldi_io.py +0 -144
  51. torchaudio/lib/_torchaudio_sox.so +0 -0
  52. torchaudio/lib/libtorchaudio_sox.so +0 -0
  53. torchaudio/prototype/__init__.py +0 -0
  54. torchaudio/prototype/datasets/__init__.py +0 -4
  55. torchaudio/prototype/datasets/musan.py +0 -67
  56. torchaudio/prototype/functional/__init__.py +0 -26
  57. torchaudio/prototype/functional/_dsp.py +0 -433
  58. torchaudio/prototype/functional/_rir.py +0 -379
  59. torchaudio/prototype/functional/functional.py +0 -190
  60. torchaudio/prototype/models/__init__.py +0 -36
  61. torchaudio/prototype/models/_conformer_wav2vec2.py +0 -794
  62. torchaudio/prototype/models/_emformer_hubert.py +0 -333
  63. torchaudio/prototype/models/conv_emformer.py +0 -525
  64. torchaudio/prototype/models/hifi_gan.py +0 -336
  65. torchaudio/prototype/models/rnnt.py +0 -711
  66. torchaudio/prototype/models/rnnt_decoder.py +0 -399
  67. torchaudio/prototype/pipelines/__init__.py +0 -12
  68. torchaudio/prototype/pipelines/_vggish/__init__.py +0 -3
  69. torchaudio/prototype/pipelines/_vggish/_vggish_impl.py +0 -233
  70. torchaudio/prototype/pipelines/_vggish/_vggish_pipeline.py +0 -82
  71. torchaudio/prototype/pipelines/hifigan_pipeline.py +0 -228
  72. torchaudio/prototype/pipelines/rnnt_pipeline.py +0 -58
  73. torchaudio/prototype/transforms/__init__.py +0 -9
  74. torchaudio/prototype/transforms/_transforms.py +0 -456
  75. torchaudio/sox_effects/__init__.py +0 -10
  76. torchaudio/sox_effects/sox_effects.py +0 -272
  77. torchaudio/utils/ffmpeg_utils.py +0 -11
  78. torchaudio/utils/sox_utils.py +0 -99
  79. torchaudio-2.7.1.dist-info/RECORD +0 -147
  80. torio/__init__.py +0 -8
  81. torio/_extension/__init__.py +0 -13
  82. torio/_extension/utils.py +0 -147
  83. torio/io/__init__.py +0 -9
  84. torio/io/_streaming_media_decoder.py +0 -978
  85. torio/io/_streaming_media_encoder.py +0 -502
  86. torio/lib/__init__.py +0 -0
  87. torio/lib/_torio_ffmpeg4.so +0 -0
  88. torio/lib/_torio_ffmpeg5.so +0 -0
  89. torio/lib/_torio_ffmpeg6.so +0 -0
  90. torio/lib/libtorio_ffmpeg4.so +0 -0
  91. torio/lib/libtorio_ffmpeg5.so +0 -0
  92. torio/lib/libtorio_ffmpeg6.so +0 -0
  93. torio/utils/__init__.py +0 -4
  94. torio/utils/ffmpeg_utils.py +0 -247
  95. {torchaudio-2.7.1.dist-info → torchaudio-2.9.0.dist-info}/licenses/LICENSE +0 -0
Binary file
torchaudio/__init__.py CHANGED
@@ -1,30 +1,13 @@
1
+ import os
2
+ from typing import BinaryIO, Optional, Tuple, Union
3
+
4
+ import torch
5
+
1
6
  # Initialize extension and backend first
2
7
  from . import _extension # noqa # usort: skip
3
- from ._backend import ( # noqa # usort: skip
4
- AudioMetaData,
5
- get_audio_backend,
6
- info,
7
- list_audio_backends,
8
- load,
9
- save,
10
- set_audio_backend,
11
- )
12
-
13
- from . import ( # noqa: F401
14
- compliance,
15
- datasets,
16
- functional,
17
- io,
18
- kaldi_io,
19
- models,
20
- pipelines,
21
- sox_effects,
22
- transforms,
23
- utils,
24
- )
25
-
26
- # For BC
27
- from . import backend # noqa # usort: skip
8
+ from . import compliance, datasets, functional, models, pipelines, transforms, utils # noqa: F401
9
+ from ._torchcodec import load_with_torchcodec, save_with_torchcodec
10
+
28
11
 
29
12
  try:
30
13
  from .version import __version__, git_version # noqa: F401
@@ -32,22 +15,190 @@ except ImportError:
32
15
  pass
33
16
 
34
17
 
18
+ def load(
19
+ uri: Union[BinaryIO, str, os.PathLike],
20
+ frame_offset: int = 0,
21
+ num_frames: int = -1,
22
+ normalize: bool = True,
23
+ channels_first: bool = True,
24
+ format: Optional[str] = None,
25
+ buffer_size: int = 4096,
26
+ backend: Optional[str] = None,
27
+ ) -> Tuple[torch.Tensor, int]:
28
+ """Load audio data from source using TorchCodec's AudioDecoder.
29
+
30
+ .. note::
31
+
32
+ As of TorchAudio 2.9, this function relies on TorchCodec's decoding capabilities under the hood. It is
33
+ provided for convenience, but we do recommend that you port your code to
34
+ natively use ``torchcodec``'s ``AudioDecoder`` class for better
35
+ performance:
36
+ https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.decoders.AudioDecoder.
37
+ Because of the reliance on Torchcodec, the parameters ``normalize``, ``buffer_size``, and
38
+ ``backend`` are ignored and accepted only for backwards compatibility.
39
+ To install torchcodec, follow the instructions at https://github.com/pytorch/torchcodec#installing-torchcodec.
40
+
41
+
42
+ Args:
43
+ uri (path-like object or file-like object):
44
+ Source of audio data. The following types are accepted:
45
+
46
+ * ``path-like``: File path or URL.
47
+ * ``file-like``: Object with ``read(size: int) -> bytes`` method.
48
+
49
+ frame_offset (int, optional):
50
+ Number of samples to skip before start reading data.
51
+ num_frames (int, optional):
52
+ Maximum number of samples to read. ``-1`` reads all the remaining samples,
53
+ starting from ``frame_offset``.
54
+ normalize (bool, optional):
55
+ TorchCodec always returns normalized float32 samples. This parameter
56
+ is ignored and a warning is issued if set to False.
57
+ Default: ``True``.
58
+ channels_first (bool, optional):
59
+ When True, the returned Tensor has dimension `[channel, time]`.
60
+ Otherwise, the returned Tensor's dimension is `[time, channel]`.
61
+ format (str or None, optional):
62
+ Format hint for the decoder. May not be supported by all TorchCodec
63
+ decoders. (Default: ``None``)
64
+ buffer_size (int, optional):
65
+ Not used by TorchCodec AudioDecoder. Provided for API compatibility.
66
+ backend (str or None, optional):
67
+ Not used by TorchCodec AudioDecoder. Provided for API compatibility.
68
+
69
+ Returns:
70
+ (torch.Tensor, int): Resulting Tensor and sample rate.
71
+ Always returns float32 tensors. If ``channels_first=True``, shape is
72
+ `[channel, time]`, otherwise `[time, channel]`.
73
+
74
+ Raises:
75
+ ImportError: If torchcodec is not available.
76
+ ValueError: If unsupported parameters are used.
77
+ RuntimeError: If TorchCodec fails to decode the audio.
78
+
79
+ Note:
80
+ - TorchCodec always returns normalized float32 samples, so the ``normalize``
81
+ parameter has no effect.
82
+ - The ``buffer_size`` and ``backend`` parameters are ignored.
83
+ - Not all audio formats supported by torchaudio backends may be supported
84
+ by TorchCodec.
85
+ """
86
+ return load_with_torchcodec(
87
+ uri,
88
+ frame_offset=frame_offset,
89
+ num_frames=num_frames,
90
+ normalize=normalize,
91
+ channels_first=channels_first,
92
+ format=format,
93
+ buffer_size=buffer_size,
94
+ backend=backend,
95
+ )
96
+
97
+
98
+ def save(
99
+ uri: Union[str, os.PathLike],
100
+ src: torch.Tensor,
101
+ sample_rate: int,
102
+ channels_first: bool = True,
103
+ format: Optional[str] = None,
104
+ encoding: Optional[str] = None,
105
+ bits_per_sample: Optional[int] = None,
106
+ buffer_size: int = 4096,
107
+ backend: Optional[str] = None,
108
+ compression: Optional[Union[float, int]] = None,
109
+ ) -> None:
110
+ """Save audio data to file using TorchCodec's AudioEncoder.
111
+
112
+ .. note::
113
+
114
+ As of TorchAudio 2.9, this function relies on TorchCodec's encoding capabilities under the hood.
115
+ It is provided for convenience, but we do recommend that you port your code to
116
+ natively use ``torchcodec``'s ``AudioEncoder`` class for better
117
+ performance:
118
+ https://docs.pytorch.org/torchcodec/stable/generated/torchcodec.encoders.AudioEncoder.
119
+ Because of the reliance on Torchcodec, the parameters ``format``, ``encoding``,
120
+ ``bits_per_sample``, ``buffer_size``, and ``backend``, are ignored and accepted only for
121
+ backwards compatibility.
122
+ To install torchcodec, follow the instructions at https://github.com/pytorch/torchcodec#installing-torchcodec.
123
+
124
+ Args:
125
+ uri (path-like object):
126
+ Path to save the audio file. The file extension determines the format.
127
+
128
+ src (torch.Tensor):
129
+ Audio data to save. Must be a 1D or 2D tensor with float32 values
130
+ in the range [-1, 1]. If 2D, shape should be [channel, time] when
131
+ channels_first=True, or [time, channel] when channels_first=False.
132
+
133
+ sample_rate (int):
134
+ Sample rate of the audio data.
135
+
136
+ channels_first (bool, optional):
137
+ Indicates whether the input tensor has channels as the first dimension.
138
+ If True, expects [channel, time]. If False, expects [time, channel].
139
+ Default: True.
140
+
141
+ format (str or None, optional):
142
+ Audio format hint. Not used by TorchCodec (format is determined by
143
+ file extension). A warning is issued if provided.
144
+ Default: None.
145
+
146
+ encoding (str or None, optional):
147
+ Audio encoding. Not fully supported by TorchCodec AudioEncoder.
148
+ A warning is issued if provided. Default: None.
149
+
150
+ bits_per_sample (int or None, optional):
151
+ Bits per sample. Not directly supported by TorchCodec AudioEncoder.
152
+ A warning is issued if provided. Default: None.
153
+
154
+ buffer_size (int, optional):
155
+ Not used by TorchCodec AudioEncoder. Provided for API compatibility.
156
+ A warning is issued if not default value. Default: 4096.
157
+
158
+ backend (str or None, optional):
159
+ Not used by TorchCodec AudioEncoder. Provided for API compatibility.
160
+ A warning is issued if provided. Default: None.
161
+
162
+ compression (float, int or None, optional):
163
+ Compression level or bit rate. Maps to bit_rate parameter in
164
+ TorchCodec AudioEncoder. Default: None.
165
+
166
+ Raises:
167
+ ImportError: If torchcodec is not available.
168
+ ValueError: If input parameters are invalid.
169
+ RuntimeError: If TorchCodec fails to encode the audio.
170
+
171
+ Note:
172
+ - TorchCodec AudioEncoder expects float32 samples in [-1, 1] range.
173
+ - Some parameters (format, encoding, bits_per_sample, buffer_size, backend)
174
+ are not used by TorchCodec but are provided for API compatibility.
175
+ - The output format is determined by the file extension in the uri.
176
+ - TorchCodec uses FFmpeg under the hood for encoding.
177
+ """
178
+ return save_with_torchcodec(
179
+ uri,
180
+ src,
181
+ sample_rate,
182
+ channels_first=channels_first,
183
+ format=format,
184
+ encoding=encoding,
185
+ bits_per_sample=bits_per_sample,
186
+ buffer_size=buffer_size,
187
+ backend=backend,
188
+ compression=compression,
189
+ )
190
+
191
+
35
192
  __all__ = [
36
- "AudioMetaData",
37
193
  "load",
38
- "info",
194
+ "load_with_torchcodec",
195
+ "save_with_torchcodec",
39
196
  "save",
40
- "io",
41
197
  "compliance",
42
198
  "datasets",
43
199
  "functional",
44
200
  "models",
45
201
  "pipelines",
46
- "kaldi_io",
47
202
  "utils",
48
- "sox_effects",
49
203
  "transforms",
50
- "list_audio_backends",
51
- "get_audio_backend",
52
- "set_audio_backend",
53
204
  ]
@@ -4,7 +4,7 @@ import sys
4
4
 
5
5
  from torchaudio._internal.module_utils import fail_with_message, is_module_available, no_op
6
6
 
7
- from .utils import _check_cuda_version, _init_dll_path, _init_sox, _LazyImporter, _load_lib
7
+ from .utils import _check_cuda_version, _init_dll_path, _load_lib
8
8
 
9
9
  _LG = logging.getLogger(__name__)
10
10
 
@@ -17,7 +17,6 @@ __all__ = [
17
17
  "_check_cuda_version",
18
18
  "_IS_TORCHAUDIO_EXT_AVAILABLE",
19
19
  "_IS_RIR_AVAILABLE",
20
- "lazy_import_sox_ext",
21
20
  ]
22
21
 
23
22
 
@@ -44,18 +43,6 @@ if _IS_TORCHAUDIO_EXT_AVAILABLE:
44
43
  _IS_ALIGN_AVAILABLE = torchaudio.lib._torchaudio.is_align_available()
45
44
 
46
45
 
47
- _SOX_EXT = None
48
-
49
-
50
- def lazy_import_sox_ext():
51
- """Load SoX integration based on availability in lazy manner"""
52
-
53
- global _SOX_EXT
54
- if _SOX_EXT is None:
55
- _SOX_EXT = _LazyImporter("_torchaudio_sox", _init_sox)
56
- return _SOX_EXT
57
-
58
-
59
46
  fail_if_no_rir = (
60
47
  no_op
61
48
  if _IS_RIR_AVAILABLE
@@ -4,14 +4,12 @@ The implementations here should be stateless.
4
4
  They should not depend on external state.
5
5
  Anything that depends on external state should happen in __init__.py
6
6
  """
7
- import importlib
8
7
  import logging
9
8
  import os
10
9
  import types
11
10
  from pathlib import Path
12
11
 
13
12
  import torch
14
- from torchaudio._internal.module_utils import eval_env
15
13
 
16
14
  _LG = logging.getLogger(__name__)
17
15
  _LIB_DIR = Path(__file__).parent.parent / "lib"
@@ -61,51 +59,6 @@ def _load_lib(lib: str) -> bool:
61
59
  return True
62
60
 
63
61
 
64
- def _import_sox_ext():
65
- if os.name == "nt":
66
- raise RuntimeError("sox extension is not supported on Windows")
67
- if not eval_env("TORCHAUDIO_USE_SOX", True):
68
- raise RuntimeError("sox extension is disabled. (TORCHAUDIO_USE_SOX=0)")
69
-
70
- ext = "torchaudio.lib._torchaudio_sox"
71
-
72
- if not importlib.util.find_spec(ext):
73
- raise RuntimeError(
74
- # fmt: off
75
- "TorchAudio is not built with sox extension. "
76
- "Please build TorchAudio with libsox support. (BUILD_SOX=1)"
77
- # fmt: on
78
- )
79
-
80
- _load_lib("libtorchaudio_sox")
81
- return importlib.import_module(ext)
82
-
83
-
84
- def _init_sox():
85
- ext = _import_sox_ext()
86
- ext.set_verbosity(0)
87
-
88
- import atexit
89
-
90
- torch.ops.torchaudio_sox.initialize_sox_effects()
91
- atexit.register(torch.ops.torchaudio_sox.shutdown_sox_effects)
92
-
93
- # Bundle functions registered with TORCH_LIBRARY into extension
94
- # so that they can also be accessed in the same (lazy) manner
95
- # from the extension.
96
- keys = [
97
- "get_info",
98
- "load_audio_file",
99
- "save_audio_file",
100
- "apply_effects_tensor",
101
- "apply_effects_file",
102
- ]
103
- for key in keys:
104
- setattr(ext, key, getattr(torch.ops.torchaudio_sox, key))
105
-
106
- return ext
107
-
108
-
109
62
  class _LazyImporter(types.ModuleType):
110
63
  """Lazily import module/extension."""
111
64
 
@@ -1,7 +1,7 @@
1
1
  import importlib.util
2
2
  import os
3
3
  import warnings
4
- from functools import wraps
4
+ from functools import partial, wraps
5
5
  from typing import Optional
6
6
 
7
7
 
@@ -60,6 +60,21 @@ def requires_module(*modules: str):
60
60
  return decorator
61
61
 
62
62
 
63
+ UNSUPPORTED = []
64
+
65
+
66
+ def wrap_deprecated(func, name, direction: str, version: Optional[str] = None, remove: bool = False):
67
+ @wraps(func)
68
+ def wrapped(*args, **kwargs):
69
+ message = f"{name} has been deprecated. {direction}"
70
+ if remove:
71
+ message += f' It will be removed from {"a future" if version is None else "the " + str(version)} release. '
72
+ warnings.warn(message, stacklevel=2)
73
+ return func(*args, **kwargs)
74
+
75
+ return wrapped
76
+
77
+
63
78
  def deprecated(direction: str, version: Optional[str] = None, remove: bool = False):
64
79
  """Decorator to add deprecation message
65
80
 
@@ -70,31 +85,74 @@ def deprecated(direction: str, version: Optional[str] = None, remove: bool = Fal
70
85
  """
71
86
 
72
87
  def decorator(func):
73
- @wraps(func)
74
- def wrapped(*args, **kwargs):
75
- message = f"{func.__module__}.{func.__name__} has been deprecated. {direction}"
76
- if remove:
77
- message += f' It will be removed from {"future" if version is None else version} release. '
78
- warnings.warn(message, stacklevel=2)
79
- return func(*args, **kwargs)
88
+ wrapped = wrap_deprecated(func, f"{func.__module__}.{func.__name__}", direction, version=version, remove=remove)
80
89
 
81
90
  message = "This function has been deprecated. "
82
91
  if remove:
83
92
  message += f'It will be removed from {"future" if version is None else version} release. '
84
93
 
85
- wrapped.__doc__ = f"""DEPRECATED: {func.__doc__}
94
+ wrapped.__doc__ = f"""DEPRECATED
86
95
 
87
96
  .. warning::
88
97
 
89
98
  {message}
90
99
  {direction}
91
- """
100
+
101
+ {func.__doc__}
102
+ """
92
103
 
93
104
  return wrapped
94
105
 
95
106
  return decorator
96
107
 
97
108
 
109
+ DEPRECATION_MSG = (
110
+ "This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. "
111
+ "Please see https://github.com/pytorch/audio/issues/3902 for more information."
112
+ )
113
+
114
+ IO_DEPRECATION_MSG = (
115
+ "This deprecation is part of a large refactoring effort to transition TorchAudio into a maintenance phase. "
116
+ "The decoding and encoding capabilities of PyTorch for both audio"
117
+ " and video are being consolidated into TorchCodec. "
118
+ "Please see https://github.com/pytorch/audio/issues/3902 for more information."
119
+ )
120
+
121
+ dropping_support = deprecated(DEPRECATION_MSG, version="2.9", remove=True)
122
+
123
+
124
+ def dropping_class_support(c, msg=DEPRECATION_MSG):
125
+ c.__init__ = wrap_deprecated(c.__init__, f"{c.__module__}.{c.__name__}", msg, version="2.9", remove=True)
126
+ c.__doc__ = f"""DEPRECATED
127
+
128
+ .. warning::
129
+
130
+ This class is deprecated from version 2.8. It will be removed in the 2.9 release.
131
+ {msg}
132
+ {c.__doc__}
133
+ """
134
+
135
+ UNSUPPORTED.append(c)
136
+ return c
137
+
138
+
139
+ def dropping_const_support(c, msg=DEPRECATION_MSG, name=None):
140
+ c.__doc__ = f"""[DEPRECATED]
141
+
142
+ .. warning::
143
+
144
+ This object is deprecated deprecated from version 2.8. It will be removed in the 2.9 release.
145
+ {msg}
146
+ {c.__doc__}
147
+ """
148
+ return c
149
+
150
+
151
+ dropping_class_io_support = partial(dropping_class_support, msg=IO_DEPRECATION_MSG)
152
+
153
+ dropping_io_support = deprecated(IO_DEPRECATION_MSG, version="2.9", remove=True)
154
+
155
+
98
156
  def fail_with_message(message):
99
157
  """Generate decorator to give users message about missing TorchAudio extension."""
100
158